Incorrect logic in MySQL & MariaDB protocol leads to remote SSRF/Remote file read
The MySQL client protocol allows a malicious server to request that the client read and send back any local file. An attacker who can make a victim connect to a rogue MySQL server can read files from the victim's server.
Originally disclosed on HackerOne
- Fixed in 10 months
- Disclosed after 3.3 years
Overview
Wrong logic in realization of LOAD DATA LOCAL INFILE function leads to remote attacker can read files from server. Problem exists in many MySQL-drivers and frameworks, on many programming languages, like Python, Java, PHP etc.
For exploitation this vulnerability we need to connect to our special MySQL server (A) from "attacking" remote server (B). For example:
- I found phpMyAdmin interface with connect to any server ability (AllowArbitraryServer option in config) on server B.
- Next I'm run special-MySQL server on my A host.
- Then connect through phpMyAdmin to host A
- After successful connection I can see content of /etc/passwd file from host B in log file on host A
Details
For testing purposes take latest MySQL server, client and tcpdump
- Start server on local machine
- Run tcpdump
- Connect to local MySQL through native mysql-console client
- Run LOAD DATA LOCAL INFILE '/etc/passwd' INTO TABLE pwn FIELDS TERMINATED BY '\n'
- Bye
Look inside packet dump file for LOCAL DATA INFILE query works:
- Client connect initialize.
- Server answers with greeting packet (protocol thread id, version, type of mysql authentication etc.)
- Next authentication packet (username, password, dbs)
- Next packet from client with query LOAD DATA LOCAL INFILE...
- Now here is strange packet from server. Call it
FB-packet:0c 00 00 01 fb 2f 65 74 63 2f 70 61 73 73 77 64
0c - size
000001 - packet No
fb - packet type
2f6574632f706173737764 - filename (/etc/passwd)
There is problem looks like: server says to client what file he needs to read. We need to create special MySQL server which do authorization with any data and then send FB packet with remote filename as payload. That's it.
In attach image successfully exploitation another MySQL administration interface - Adminer
Exploit: https://github.com/allyshka/Rogue-MySql-Server/blob/master/rogue_mysql_server.py See also: http://russiansecurity.expert/2016/04/20/mysql-connect-file-read/
Attachments

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could read arbitrary files from the server running the vulnerable MySQL client, but only if they can make it connect to a malicious server.
What the attacker needed
Victim uses a vulnerable MySQL client; attacker can host a rogue MySQL server; victim connects to the rogue server
How it was found
- Set up a rogue MySQL server that accepts any authentication and sends a file-read request.
- Find a victim application that allows connecting to an arbitrary MySQL server.
- Make the victim connect to the rogue server.
- The rogue server sends a packet requesting a local file (e.g., /etc/passwd).
- The victim's client reads the file and sends its contents to the rogue server.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program connects to a MySQL database, the server can ask the client to read a local file and send its contents. A malicious server can abuse this to steal files from the computer running the client. The attacker needs a way to make the victim connect to their server, such as a database management tool that allows connecting to any server.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.