How to use SQLMAP to test a website for SQL Injection vulnerability with example.
How to use SQLMAP to test a website for SQL Injection vulnerability with example.
In this article I am explains how to test whether a website is safe from SQL injection using the SQLMAP penetration testing tool.
What is SQL Injection?
SQL Injection is a code injection technique where an
attacker executes malicious SQL queries that control a web application’s
database. With the right set of queries, a user can gain access to information
stored in databases. SQLMAP tests whether a ‘GET’ parameter is vulnerable to
SQL Injection.
Where can you use SQLMAP?
If you observe a web url that is of the form http://testphp.vulnweb.com/listproducts.php?cat=1, where the ‘GET’ parameter is in bold, then the website may be vulnerable to this mode of SQL injection, and an attacker may be able to gain access to information in the database. Furthermore, SQLMAP works when it is php based.
A simple test to check whether your website is vulnerable
would to be to replace the value in the get request parameter with an asterisk
(‘).
Installing sqlmap
SQLMAP comes pre – installed with kali linux, which is the preferred choice of most penetration testers. However, you can install sqlmap on other debian based linux systems using the command
sudo apt-get install sqlmap
Usage
In this article, we will make use of a website that is designed with vulnerabilities for demonstration purposes:
http://testphp.vulnweb.com/listproducts.php?cat=1
As you can see, there is a GET request parameter (cat = 1)
that can be changed by the user by modifying the value of cat. So this website
might be vulnerable to SQL injection of this kind.
Here two database we get
* ] acurat
* ] information_schema
lets get further testing............
To try and access any of the databases, we have to slightly modify our command. We now use -D to specify the name of the database that we wish to access, and once we have access to the database, we would want to see whether we can access the tables. For this, we use the –tables query. Let us access the acuart database.
sqlmap -u
http://testphp.vulnweb.com/listproducts.php?cat=1
If we want to view
the columns of a particular table, we can use the following command, in which
we use -T to specify the table name, and –columns to query the column names. We
will try to access the table ‘artists’.
sqlmap -u http://testphp.vulnweb.com/listproducts.php?cat=1 -D acuart -T artists --columns --batch
Similarly, we can
access the information in a specific column by using the following command,
where -C can be used to specify multiple column name separated by a comma, and
the –dump query retrieves the data
sqlmap -u http://testphp.vulnweb.com/listproducts.php?cat=1
-D acuart -T artists -C aname --dump --batch
Comments
Post a Comment