powershell Invoke-WebRequest
不支持直接 -Headers
带入cookie,所以就写了个Invoke-Http
作为补充
![2020-10-28-02-21-56]()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
function Invoke-Http {
Param ( [Parameter(Mandatory=$false)] [String] $cookie, [Parameter(Mandatory=$true)] [string] $url, [Parameter(Mandatory=$false)][ValidatePattern('POST|GET')] [String] $method='GET', [Parameter(Mandatory=$false)] [String] $post ) try { if($url.StartsWith('http://') -eq $false -and $url.StartsWith('https://') -eq $false ){ $url='http://'+$url }else{ $url=$url } if($url.StartsWith('https://')){ [Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } } [net.httpWebRequest] $req = [net.webRequest]::create($url) $req.UserAgent ='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36' $req.Headers.Add("Origin: $url") $req.ContentType='application/json' $req.Referer = $url $req.AllowAutoRedirect = $true if($cookie){ $req.Headers.add("Cookie: $cookie") } if($method -eq 'POST'){ $req.method = "POST" $reqst = $req.getRequestStream() $buffer = [text.encoding]::ascii.getbytes($post) $reqst.write($buffer, 0, $buffer.length) $reqst.flush() $reqst.close() }else{ $req.method = "GET" } [net.httpWebResponse] $res = $req.getResponse() $response = $res.getResponseStream() $sr = new-object IO.StreamReader($response) $result = $sr.ReadToEnd() return $result }catch { Write-Verbose "An exception was caught: $($_.Exception.Message)" $_.Exception.Response } }
|
FROM :WOLVEZ'S BLOG| Author:wolve
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
点赞
https://cn-sec.com/archives/1012623.html
复制链接
复制链接
-
左青龙
- 微信扫一扫
-
-
右白虎
- 微信扫一扫
-
评论