Lab3 SQL Injection
Lab3 SQL Injection
Lab3 SQL Injection
Lab3
SQL Injection Attack
Lab Environment:
1. Follow the instructions given on the Lab Setup page and the Web_SQL_Injection page to download,
install, and configure the virtual machines (VMs).
2. The SQL injection Attack will have to use one VM.
3. In the VM, modify the /etc/hosts file to map the domain name of www.xsslabelgg.com to the attacker
machine’s IP address. Modify 127.0.0.1 to the attacker machine’s IP address as shown in Figure 1.
192.168.0.165 www.seedlabsqlinjection.com
Figure 1: /etc/hosts
Lab Tasks:
In this lab, we need to construct HTTP requests. To figure out what an acceptable HTTP request in Elgg looks like,
we need to be able to capture and analyze HTTP requests. We can use a Firefox add-on called "HTTP Header
Live" for this purpose. Before you start working on this lab, you should get familiar with this tool. Instructions on
how to use this tool is given in Lab 1.
1
Task 1: Get Familiar with SQL Statements
In this task, we have to login the SQL database and show tables and Alice’s credential table. Figure 1 shows how
to login to the database, Figure 2 shows how to load database, Figure 3 shows tables, and Figure 4 shows Alice’s
credential table.
2
Figure 3: Show tables
3
Task 2: SQL Injection Attack on SELECT Statement
Task 2.1: SQL Injection Attack from webpage
In this task, we need to login into the admin page without knowing any employee’s credential. Figure 5 shows
login to the SQL injection webpage.
After having logged into the SQL Injection webpage, we can see the details as shown in Figure 6.
4
Task 2.2: SQL Injection Attack from
1command line
In this task, we need to login into the admin
in terminal without knowing any employee’s
credential. Figure 7 shows login to the SQL
without password.
5
Task 2.3: Append a new SQL statement
In this task, you are required to update the database by using SQL injection attack. You are required to use
multiple SQL statements separated by “;”. You can try the following SQL injection string in the webpage. Figure
8 shows the SQL injection in the webpage. Please perform this attack and describe your observation in your
report.
6
We can see before you update Alice’s data, Alice’s data in the database should have $20000.00 salary. Figure
10 shows Alice’s profile before update.
After you have updated Alice’s profile, you should see Alice’s salary increase to $80000.00 salary. Figure 11
shows Alice’s profile after update.
7
Task 3.2: Modify other people’s salary
After you have learned how to update the database by using SQL injection attack from the last task, you can
update Boby’s data. Please update salary for Boby. Perform this task in the webpage and describe your
observation in your report. Figure 10 shows SQL update in Boby’s profile.
8
Figure 14: Hash value for the password
After you successfully updated Boby’s password, you will see log out information as shown in Figure 16. You
can login again to check whether the password is correct.
9
Task 4: Countermeasure—Prepared Statement
In the previous tasks, we learned how to attack database by the SQL injection code. In this task, you are asked
to defend against the previous SQL injection attack you performed. For testing, please login into the database
as task 2.1. to see whether you can login in without password. Figure 17 shows modifying the code. Figure 18
shows the result after you have executed the counter measurement.
10