Lab-4-Perform-an-SQL-Injection-Attack-Against-MSSQL-to-Extract-Databases-using-sqlmap
Lab-4-Perform-an-SQL-Injection-Attack-Against-MSSQL-to-Extract-Databases-using-sqlmap
Lab Scenario
In SQL injection attacks, the attacker injects malicious SQL queries into the user input form
either to gain unauthorized access to a database or to retrieve information directly from the
database. Such attacks are possible because of a flaw in web applications and not because of
any issue with the database or a web server.
A security professional must have the required knowledge to perform an SQL injection attack
on the organization's website to check its security infrastructure.
Lab Objectives
This lab demonstrates how to perform an SQL injection attack using sqlmap.
SQL injection attacks use a series of malicious SQL queries or SQL statements to manipulate
the database directly. Applications often use SQL statements to authenticate users, validate
roles and access levels, store and obtain information for the application and user, and link to
other data sources. SQL injection attacks work when an application does not properly
validate an input before passing it to an SQL statement.
Lab Tasks
In this lab, you will pretend that you are a registered user on http://www.moviescope.com
website and wish to crack the passwords of other users from the website’s database.
If you are already logged into the Attacker Machine-2, then skip to Step#3.
If a Question pop-up window appears asking you to update the machine, click
No to close the window.
3. Click the Mozilla Firefox icon from the menu bar in the top-left corner of Desktop to
launch the web browser.
4. Type http://www.moviescope.com/ and press Enter. A Login page loads; enter the
Username and Password as sam and test, respectively. Click the Login button.
12. Now, type cd and press Enter to jump to the root directory.
13. In the Parrot Terminal window, type sqlmap -u
"http://www.moviescope.com/viewprofile.aspx?id=1" --cookie="[cookie value
that you copied in Step 8]" --dbs and press Enter.
In this query, -u specifies the target URL (the one noted down in Step 6), --
cookie specifies the HTTP cookie header value, and --dbs enumerates DBMS
databases.
14. The above query causes sqlmap to apply various injection techniques on the name
parameter of the URL in an attempt to extract the database information of the
MovieScope website.
15. If the message Do you want to skip test payloads specific for other DBMSes?
[Y/n] appears, type Y and press Enter.
16. If the message for the remaining tests, do you want to include all tests for
‘Microsoft SQL Server’ extending provided level (1) and risk (1) values? [Y/n]
appears, type Y and press Enter.
17. Similarly, if any other message appears, type Y and press Enter to continue.
18. sqlmap retrieves the databases present in the MSSQL server. It also displays
information about the web server OS, web application technology, and the backend
DBMS, as shown in the screenshot below.
19. Now, we will choose a database and use sqlmap to retrieve the tables in the database.
In this lab, we will determine the tables associated with the database moviescope.
20. Type sqlmap -u "http://www.moviescope.com/viewprofile.aspx?id=1" --
cookie="[cookie value which you have copied in Step 8]" -D moviescope --tables
and press Enter.
21. The above query causes sqlmap to scan the moviescope database for tables.
22. sqlmap retrieves and displays the table contents of the moviescope, as shown in
screenshot below.
23. Now, we will retrieve the content of the column User_Login.
24. Type sqlmap -u "http://www.moviescope.com/viewprofile.aspx?id=1" --
cookie="[cookie value which you have copied in Step 8]" -D moviescope -T
User_Login --dump and press Enter to dump all the User_Login table content.
25. sqlmap retrieves the complete User_Login table data from the database moviescope,
containing all users’ usernames under the Uname column and passwords under the
password column, as shown in screenshot below.
26. Under the password column, the passwords are shown in plain text.
27. To verify whether the login details are valid, attempt to log in with the extracted login
details of any of the users. To do so, switch back to the web browser, close the
Developer Tools console, and click Logout to start a new session on the site.
28. The Login page appears. Log in into the website using the retrieved credentials
john/qwerty.
To view the available commands under the OS shell, type help and press
Enter.
38. This concludes the demonstration of launching a SQL injection attack against
MSSQL to extract databases using sqlmap.
39. Close all open windows and document all the acquired information.
Question 2.4.1
In the Attacker Machine-2 machine, perform an SQL injection attack using the sqlmap tool
on the target website www.moviescope.com. Enumerate the DBMS databases and tables
associated with the target website. Dump the table content of the User_Login table and
identify the password associated with the username steve.