Lab - Injection Attacks: Objectives
Lab - Injection Attacks: Objectives
Lab - Injection Attacks: Objectives
Objectives
Websites that are connected to backend databases can be vulnerable to SQL
injection. In a SQL injection exploit, an attacker enters malicious queries that interact
with the application database. In this lab, you will exploit a web site vulnerability with
SQL injection and research SQL injection mitigation.
Background / Scenario
SQL injection is a common attack used by hackers to exploit SQL database-driven
web applications. This type of attack involves inserting malicious SQL code or
statements into an input field or URL with the goal of reveling or manipulating the
database contents, causing repudiation system issues, or spoofing identities.
Required Resources
Kali VM customized for the Ethical Hacker course
Internet access
Instructions
Part 1: Exploit an SQL Injection Vulnerability on
DVWA
SQL injection is a code injection technique used to exploit security vulnerabilities in
the database layer of an application. These vulnerabilities could allow an attacker to
execute malicious SQL commands and compromise the security of the database.
You have entered an “always true” expression that was executed by the
database server. The result is that all entries in the ID field of the database
were returned.
a. In the User ID: field type 1' ORDER BY 1 # and click Submit.
b. In the User ID: field type 1' ORDER BY 2 # and click Submit.
c. In the User ID: field type 1' ORDER BY 3 # and click Submit.
This time you should receive the error Unknown column '3' in 'order clause'.
Because the third string returned an error, this tells us the query involves two
fields. This is useful information to know as you continue your exploit.
In the User ID: field type 1' OR 1=1 UNION SELECT 1, VERSION()# and
click Submit.
At the end of the output, you should see a result similar to the following:
<output omitted>
ID: 1' OR 1=1 UNION SELECT 1, VERSION()#
First name: Pablo
Surname: Picasso
The output 5.5.58-0+deb8u1 indicates the DBMS is MySQL version 5.5.58 running
on Debian.
So far you have learned that the database is vulnerable, the query involves two
fields, and the DDMS is MySQL 5.5.58.
Next, you will attempt obtain more schema information about the database.
In the User ID: field type 1' OR 1=1 UNION SELECT 1, DATABASE()# and
click Submit.
At the end of the output, you should see the following result:
b. Click Submit.
Answer Area
guestbook and users
Hide Answer
Which table do you think is the most interesting for a penetration test?
Answer Area
The users table is the most interesting because it may include usernames and
passwords.
Hide Answer
You will now discover the field names in the users table. This will help you to find
information that is useful for the pentest.
b. Click Submit.
The list of column names displays after the listing of user accounts in the output. The
information in which two columns is of interest to use in our penetration test?
Explain.
Answer Area
The user column and the password column are of interest because they seem
to contain information that can be used for unauthorized access.
Hide Answer
b. Click Submit.
After the list of users, you should see several results with usernames and
what appears to be password hashes.
Answer Area
The admin account, it probably has the greatest rights and privileges on the
system.
Hide Answer
c. Try crafting queries to display the contents of other fields in the table by
varying the column names based on the names previously displayed.
Answer Area
The user_id is a number, while the user field is the username.
Hide Answer
b. Copy and paste the password hash from DVWA into CrackStation and
click Crack Hashes.
Answer Area
password
Hide Answer
What is the password for the user pablo?
Answer Area
letmein
Hide Answer
a. Open a web browser and search SQL injection mitigation and SQL injection
prevention.
b. Take notes on your mitigation and prevention findings.
Reflection Questions
What are three mitigation methods for preventing SQL injection exploits?
Answer Area
Answers may vary but may include: using parameterized queries (prepared
statements), input checking, field validation, filtering user inputs, and
escaping user input.
Hide Answer