We have this legacy website which has horrendous code in it. I have just been looking through the login form/code and can see un-sanitised sql queries. E.g. in a nutshell:
$email=$_POST['email'];
$password = $_POST['password'];
$query = "SELECT aes_decrypt(password, 'asdasdasd') AS password FROM users WHERE email='$email'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if($password == $row['password']){
// set cookies and redirect user etc etc
}
else {
// error not correct login details
}
My question is, I realise that this is bad because of SQL injection. And I know the basics of that. i.e. You could put '; DROP ALL TABLES; -- and that would "cause havoc".
Can anything more "interesting" or "useful" (to the potential hacker) be done? I.e., can you output a list of passwords, or download the tables with this? Or could you manage to log yourself in as a user of the site, for instance if you only know their email address?
Mainly for interest, but also for better insight (and therein finding better approaches to coding).
$lalapoo. To get stuff out of a database there is first a query which gets all the ids, does awhile($row=mysql_fetch_array($result))to put all the ids into an array. Then does aforeach($lalapoo as $lala)and does anotherSELECTquery for each id to get the info out. There are hugeswitchstatements where the same 100 or so lines of code are repeated for each case with 1 tiny difference in each. Honestly, AES encryption is one of the few "positive" bits! – Thomas Clayson Jun 18 '12 at 13:07