[Go to site: main page, start]

0% found this document useful (0 votes)
53 views7 pages

SQL Injection Lab with SQLmap Guide

This lab teaches students how to conduct an automated SQL injection attack using SQLmap, a penetration testing tool. Students will learn to identify vulnerable web applications, extract database information, and utilize Google Dorks to find potential targets. The document also discusses protective measures against SQL injection attacks, such as using the POST method and implementing string escape techniques.

Uploaded by

siwapa5775
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views7 pages

SQL Injection Lab with SQLmap Guide

This lab teaches students how to conduct an automated SQL injection attack using SQLmap, a penetration testing tool. Students will learn to identify vulnerable web applications, extract database information, and utilize Google Dorks to find potential targets. The document also discusses protective measures against SQL injection attacks, such as using the POST method and implementing string escape techniques.

Uploaded by

siwapa5775
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lab - SQL Injection Attack Using SQLmap

Overview

In this lab, students will learn to perform an automated SQL injection attack using SQLmap.

SQLmap

Straight from the source….

SQLmap is an open source penetration testing tool that automates the process of detecting and
exploiting SQL injection flaws and taking over of database servers. It comes with a powerful
detection engine, many niche features for the ultimate penetration tester and a broad range of
switches lasting from database fingerprinting, over data fetching from the database, to
accessing the underlying file system and executing commands on the operating system via
out-of-band connections.

Lab Requirements

• One virtual install of Kali Linux with an Internet connection.

Begin the lab!

Open a terminal and at the prompt type sqlmap -h. This will list the commands
supported by SqlMap.

We begin by executing a simple query of a potential target running a web application using
SQL.

1
At the terminal prompt, type:
sqlmap -u [Link]

Be sure to read everything in the output. There’s a lot of good information returned. Notice
the use of the union query use to combine two or more SQL statement. Also, take note of how
the null command was used to locate database information from the backend of the SQL
server.

What we hope to do is capture some information about the version of SQL running and
version information.

SQLmap may ask questions during the enumeration of the target when in doubt how best to
answer, type in a ‘y’ for yes.

In our next step, we gather information about the different databases that are present. To do
this, we will add --dbs to the end of our previous command.

Tip! Remember to use your up arrow to see your command history. Type in space, 2 single
dashes (--) followed by dbs.

2
Two databases were identified.

We are now ready to obtain information about what the acuart database holds. To get this
information, we need to view the tables in the database. To do this, we will use the -D switch
telling Sqlmap to find the tables inside the acuart database.

sqlmap -u [Link] -D
acuart --tables

We are shown the tables present in the database.

3
We next need to tell SQLmap to show use the columns present in the table named users inside
the acuart database. Use your up arrow and add the needed commands.

sqlmap -u [Link] -D
acuart -T users --columns

We are shown the columns present in the user table inside the acuart database.

Let’s have SQLmap show us the contents of the following columns of information using the
following command.

4
sqlmap -u [Link] -D
acuart -T users -C email,name,pass --dump

We are given the email address, the name, and password for the account.

Summary

Using an automated tool such as SQLmap makes performing a SQL injection attack quite
painless. We can use what we have demonstrated here using a test site and replacing the URL
for the site with any web address running a vulnerable web application attached to a SQL
database.

The question that remains is how we locate these vulnerable web applications. The answer is
by using something called Google Dorks. Google is just a big search engine the information it
stores is data driven which means it uses a database of some type.

The Dork part is a reference to the SQL or website administrator that failed to secure their
database from SQL injection attacks.

Open a Google search engine and type the following:

inurl:"[Link]?prodID="

You should be able to read the query and discern that we are looking for any URL that
contains the following information. When we wrap in quotes, we are telling Google exactly
what to search for.

My search results show 5,920 URL that contains this string.

5
We can use SQLmap to conduct the search for us.

sqlmap -g "inurl:\"[Link]?prodID=1\""

SQLmap is scanning the URL of the website that fit the criteria of our search.

This time the attack failed, but there are plenty more targets to choose from. As a Pentester,
this is another tool we can use to test for vulnerable web applications. Normally we would
conduct a vulnerability scan using a web application vulnerability scanner such as Vega. If the
results are positive for a SQL injection attack, we would ask for permission to proceed with
trying to exploit the target.

Type in the following Google Dorks one line at a time to search for more targets of
opportunities.

allinurl:*.php?txtCodiInfo=
inurl:[Link]?=
inurl:”ViewerFrame?Mode=”
inurl:[Link]?id=
inurl:[Link]?id=
inurl:[Link]?category=

6
inurl:[Link]?ID=
inurl:play_old.php?id=
inurl:declaration_more.php?decl_id=
inurl:pageid=

Locating the latest Google Dorks

Google Hacking Database (GHDB)

Summary

How can we protect our DB against SQLMap? One solution might be to use the POST method
instead of GET so sensitive data will not be visible in a browser. Also, use string escape against
SQL injection. Another might be turning off Search Engine Optimization (SEO) for all
vulnerable endpoints after the main domain, allow [Link] to be searched but
everything after / will not be searched.

End of the lab!

Common questions

Powered by AI

Using SQLmap and Google Dorks raises ethical issues, as these tools can be applied for malicious as well as defensive purposes. Ethical use mandates obtaining explicit permission from system owners before testing and only conducting such activities to identify and remediate vulnerabilities. Unauthorized testing constitutes illegal activity, privacy violations, and potential damages to the data integrity of the targeted systems .

SEO practices aim to expose web content to search engines, potentially increasing visibility of sensitive endpoints when no filtering is applied. This exposure can illuminate data entry points to exploit, allowing attackers to use tools like SQLmap more effectively. Disabling SEO on unsafe parts of a site mitigates these vulnerabilities by concealing the backend structures from general search queries .

Google Dorks help identify vulnerable web applications by using specific search queries that reveal URLs potentially exposing SQL vulnerabilities. By searching for pattern URLs such as "inurl:'products.php?prodID='", Dorks exploit the data-driven nature of search engines to find insecure configurations left by developers, allowing penetration testers to target them with tools like SQLmap .

The steps involve: executing a SQLmap command targeting a vulnerable URL to identify databases; appending --dbs to list databases; using -D followed by a database name and --tables to get tables in a database; specifying a table with -T and --columns to see its columns; and finally, using -C and --dump to view data like email, name, and password in certain columns .

Key security measures include using the POST method instead of GET to hide sensitive data from URLs, implementing input string escaping to neutralize SQL incursion attempts, and disabling search engine indexing (SEO) of vulnerable endpoints. This ensures exposed data paths are less visible, reducing the attack surface against automated tools like SQLmap .

The "--tables" switch is crucial for listing all tables within a specified database, guiding the attacker toward valuable data structures. The "--columns" switch subsequently lists column names in a table, allowing precise targeting of data extraction commands. These switches provide necessary insights into the database schema, facilitating deeper and more effective data exfiltration .

Identifying the database version helps in tailoring SQLmap’s injection techniques since different versions have varying vulnerabilities and syntax requirements. Understanding the structural layout, such as tables and columns, informs the attacker’s strategy, enabling them to target specific data without blind operations, increasing the precision and likelihood of successful data extraction .

SQLmap automates the detection and exploitation of SQL injection vulnerabilities, allowing penetration testers to take over database servers. It features a robust detection engine and various capabilities, including database fingerprinting, data retrieval, accessing the file system, and executing OS commands via out-of-band connections .

When an SQL injection attempt fails, penetration testers can adjust their strategies by employing Google Dorks to discover a multitude of potential target URLs, each with different query string architectures (e.g., "inurl:index.php?id="). This exploration identifies new, possibly unprotected entry points, allowing continued SQLmap testing until successful exploitation .

SQLmap can exploit SQL injection vulnerabilities not just to extract data but to obtain a foothold that allows execution of operating system commands through out-of-band connections. This exploits not only the database but potentially the entire server's environment, drastically increasing the attack vector and impact of the intrusion by allowing deeper system-level access .

You might also like