Accessing the backend:
Execute the following SQL statement:
select '' into dumpfile '/Users/zhaozhouqiao/site/evil.php';
You can see that the file has been successfully written.
Subsequently, access evil.php to execute the code:
Note: The prerequisite is that the MySQL variable secure_file_priv must be set to null.
Firstly, in the following code snippet, the content of the POST request is directly passed to the DoExecSql function without any filtering.
The code below passes the content of the query variable to DoRunQuery for execution:
The execution process lacks any filtering, directly executing the SQL statements provided by the user:
Therefore, it is possible to achieve arbitrary file upload using statements like select into outfile.
Set secure_file_priv for the MySQL database to null to prevent file uploads.