Trying to learn about various SQL injection techniques for work and I'm stuck on the following. I'm trying to craft a SQL injection for the following code. My goal is to enter just the username for a known registered user (Example: test) and attach extra input to it that bypasses the following filter and will ultimately be injected into the SQL statement in the last line that would make it true and log me in as the registered user. I'm a bit lost on how to bypass the series of filters (though I'm guessing that I can use alternatives to whitespace characters to get past one of the checks?) What sort of input would work to bypass this? Thanks!
function sqli_filter($string) {
$filtered_string = $string;
$filtered_string = str_replace("--","",$filtered_string);
$filtered_string = str_replace(";","",$filtered_string);
$filtered_string = str_replace("/*","",$filtered_string);
$filtered_string = str_replace("*/","",$filtered_string);
$filtered_string = str_replace("//","",$filtered_string);
$filtered_string = str_replace(" ","",$filtered_string);
$filtered_string = str_replace("#","",$filtered_string);
$filtered_string = str_replace("||","",$filtered_string);
$filtered_string = str_replace("admin'","",$filtered_string);
$filtered_string = str_replace("UNION","",$filtered_string);
$filtered_string = str_replace("COLLATE","",$filtered_string);
$filtered_string = str_replace("DROP","",$filtered_string);
return $filtered_string;
}
function login($username, $password) {
$escaped_username = $this->sqli_filter($username);
// get the user's salt
$sql = "SELECT salt FROM users WHERE eid='$escaped_username'";
$result = $this->db->query($sql);
$user = $result->next();
// make sure the user exists
if (!$user) {
notify('User does not exist', -1);
return false;
}
// verify the password hash
$salt = $user['salt'];
$hash = md5($salt.$password);
error_log(print_r($escaped_username));
$sql = "SELECT user_id, name, eid FROM users WHERE eid='$escaped_username' AND password='$hash'";