SQL Injection Attack Lab (TASK-4) Sai Ram
SQL Injection Attack Lab (TASK-4) Sai Ram
Overview
SQL injection is a code injection technique that exploits the vulnerabilities in the interface
between web applications and database servers. The vulnerability is present when user’s
inputs are not correctly checked within the web applications before being sent to the back-
end database servers.
Many web applications take inputs from users, and then use these inputs to construct SQL
queries, so the web applications can get information from the database. Web applications
also use SQL queries to store information in the database. These are common practices in
the development of web applications. When SQL queries are not carefully constructed,
SQL injection vulnerabilities can occur. The SQL injection attack is one of the most
common attacks on web applications.
In this lab, we have a web application that is vulnerable to the SQL injection attack. The
web application includes the common mistakes made by many web developers. The main
goal is to find ways to exploit the SQL injection vulnerabilities, demonstrate the damage
that can be achieved by the attack, and master the techniques that can help defend
against such type of attacks.
Configuring DNS
This URL is only accessible from inside of the virtual machine, because we have modified
the /etc/hosts file to map the domain name (www.sqllabmysqlphpbb.com) to the virtual
machine’s local IP address (127.0.0.1). We may map any domain name to a particular IP
address using the /etc/hosts. For example you can map http://www.example.com to the
local IP address by appending the following entry to /etc/hosts file:
127.0.0.1 www.example.com
Apache Configuring
The name-based virtual hosting feature in Apache could be used to host several web sites
(or URLs) on the same machine. A configuration file named default in the directory "/etc/
apache2/sites-available" contains the necessary directives for the configuration:
1. The directive "NameVirtualHost *" instructs the web server to use all IP addresses in
the machine (some machines may have multiple IP addresses)
2. Each web site has a VirtualHost block that specifies the URL for the web site and
directory in the file system that contains the sources for the web site. For example,
to configure a web site with URL http://www.example1.com with sources in
directory /var/www/Example_1/, and to configure a web site with URL
http://www.example2.com with sources in directory /var/www/Example_2/, we use
the following blocks:
<VirtualHost *>
ServerName http://www.example1.com
DocumentRoot /var/www/Example_1/
</VirtualHost>
<VirtualHost *>
ServerName http://www.example2.com
DocumentRoot /var/www/Example_2/
</VirtualHost>
We can modify the web application by accessing the source in the mentioned
directories. For example, with the above configuration, the web application
http://www.example1.com can be changed by modifying the sources in the
directory /var/www/Example_1/.
SQL Injection Attack on SELECT Statements
SQL injection is basically a technique through which attackers can execute their own
malicious SQL statements generally referred as malicious payload. Through the malicious
SQL statements, attackers can steal information from the victim database; even worse,
they may be able to make changes to the database. Our employee management web
application has SQL injection vulnerabilities, which mimic the mistakes frequently made by
developers.
We will use the login page from www.SEEDLabSQLInjection.com for this task. The login
page is shown in Figure 1. It asks users to provide a user name and a password. The web
application authenticate users based on these two pieces of data, so only employees who
know their passwords are allowed to log in. our job, as an attacker, is to log into the web
application without knowing any employee’s credential.
$input_uname = $_GET[’username’];
$input_pwd = $_GET[’Password’];
$hashed_pwd = sha1($input_pwd);
...
$sql = "SELECT id, name, eid, salary, birth, ssn, address, email,
nickname, Password
FROM credential
WHERE name= ’$input_uname’ and Password=’$hashed_pwd’";
$result = $conn -> query($sql);
// The following is Pseudo Code
if(id != NULL) {
if(name==’admin’) {
return All employees information;
} else if (name !=NULL){
return employee information;
}
} else {
Authentication Fails;
}
The above SQL statement selects personal employee information such as id, name, salary,
ssn etc from the credential table. The SQL statement uses two variables input uname and
hashed pwd, where input uname holds the string typed by users in the username field of
the login page, while hashed pwd holds the sha1 hash of the password typed by the user.
The program checks whether any record matches with the provided username and
password; if there is a match, the user is successfully authenticated, and is given the
corresponding employee information. If there is no match, the authentication fails.