I admin a website at work that was the victim of a SQL injection attack. By examining the logs, it appears the attacker used sqlmap
with the file-read option and grabbed a bunch of config files from the server, due to our web developer being sloppy and using the root mysql account to connect (which had the FILE permission).
Here's the wierd as hell part I'm trying to understand. The files were read - I know they were - because the attacker then used a password in one of those files to do some system infiltrating. Looking at the logs he first grabbed an index.php, which referenced config.php and a few others. They were all targeted.
To tighten up security, I grabbed sqlmap and hit our server, and after figuring out how it worked, I was able to grab the files.
Our SQL server is not outside facing, so the attacker could not have tried this. Here is the weird part:
I connected to our MySQL server
from my desktop, and tried select LOAD_FILE
as well as LOAD DATA INFILE into TABLE.
SOME of them worked. For example, select LOAD_FILE('/etc/passwd')
returned the /etc/passwd.
But not ALL of them worked.
select LOAD_FILE('/var/www/site_name/index.php')
returned NULL
.
LOAD DATA INFILE '/var/www/site_name/index.php' INTO temp;
returned:
ERROR 29 (HY000): File '/var/www/site_name/index.php' not found (Errcode: 13)
What? File not found? Huh?
So I ran the sqlmap against the same file and it downloaded.
I ran sqlmap
with -v 6
so I could see everything - it was using LOAD_FILE to get the file.
Why would LOAD_FILE in the injection attack work, but load file from the mysql client command line return NULL or file not found? But only for SOME files? /etc/passwd and /etc/hosts was readable.
Any clue?