How bad guys hack into websites using SQL Injection (part 2)
For those of you who are not familiar with SQL language, in SQL the ‘character is used as a delimiter for string variables. Here we use it to limit the string username and password provided by the user.
In this example we see that the username and password supplied in the query entered into between ‘and the request is then executed by the database engine. If the request for re every line, then the mandate is valid (existing user in the database and have the password provided).
Now, what happens if a user types in ‘character into column username or password? Well, by simply putting ‘into the field and stayed username password blank, the question will be:
SELECT * FROM users WHERE username =” ‘AND password =”
This will trigger an error, because the database engine will consider the end of the string on the second ‘and it will trigger a parsing error in the third’ character. Now let us what would happen if we send this input data:
Username: ‘OR’ a ‘=’ a
Password: ‘OR’ a ‘=’ a
Questions will be
SELECT * FROM users WHERE username =”OR ‘a’ = ‘a’ AND password =”OR ‘a’ = ‘a’
Because it is always equal to a, this query will return all rows from the table the user and the server will “think” we are provided with valid credentials and let as in – SQL Injection work:).
Now we’ll see some more advanced techniques .. For example I will be based on PHP and MySQL platform. In the MySQL database I created the following table: