Web Hacking
◾
331
query, which allows the attacker to do multiple things such as data retrieval and reading system
files such as
/etc/passwd
; however, here our only focus is using
SQL Injection to bypass the
authentication mechanism.
Let’s take a look at a potentially vulnerable code that would result in an SQL injection:
Code
$query="SELECT * FROM users WHERE username='".$_POST['username']. "' AND
password='". $POST_['password']."'"
response=mysql_query($query);
?>
As we can see, line 2 accepts two user inputs: a username and a password. The username and
password inputs
are accepted from a user, and then without any validation they are inserted as an
SQL query and later executed. The username and password would then be compared with the data-
base
to see if they match; if they do, the user would be authenticated, if not, an error would pop up.
This is how the query would be executed:
SELECT * FROM users WHERE username = 'administrator' AND password =
'mypass'
This query would retrieve the details of username “administrator” with the password “mypass”
from the table users.
Dostları ilə paylaş: