Hello everyone! Today, I will share my knowledge about SQLmap, an open-source penetration testing tool designed to detect and exploit SQL injection vulnerabilities in web applications. This tool is an essential addition to your toolbox. ππ
If you do not know anything about SQL injection attacks? Please read this article before going ahead.
The tool described below is intended solely for educational purposes and ethical penetration testing. It should never be used for malicious activities or unauthorized access.
How to Use SQLmap
Setup
Before diving into the usage of SQLmap, you need to install it. To do that, you can simply clone the GIT repository:
It works with Python version 2.6, 2.7 and 3.x on any platform (including Windows, Linux, and MacOS).
Ensure that everything works:
If your output is different, please make sure that Python is installed and working properly by running python -V (remember SQLmap works only with 2.6, 2.7 and 3.x). Also, check that you are in the correct directory.
Usage
Once installed, you can start using SQLmap to test web applications for SQL injection vulnerabilities. Hereβs a basic example:
There are a lot of different options available, you can find the entire list in this way:
These are my favorite options:
-u URL, --url=URL: specifies the URL of the HTTP request (e.g., http://www.site.com/vuln.php?id=1);
--method=METHOD: forces the usage of an HTTP method (e.g., POST);
-r REQUESTFILE: loads the HTTP request from a file (alternative to -u);
--data=DATA: body of the HTTP request (e.g., "id=1");
--cookie=COOKIE: HTTP Cookie header value (e.g. "PHPSESSID=a8d127e..");
--proxy=PROXY: useful in case you need to intercept the requests sent by SQLmap (e.g., http://127.0.0.1:8080);
--dbms=DBMS: restricts the malicious payloads to a specific DBMS (e.g., MySQL);
--level=LEVEL: Level of tests to perform (e.g., 1-5, default 1);
--risk=RISK: Risk of tests to perform (1-3, default 1);
-a, --all: retrieves everything from the DBMS (i.e., all databases, all tables, all columns, etc..);
-b, --banner: retrieves the DBMS banner;
--current-user: retrieves the DBMS current user;
--current-db: retrieves the DBMS current database;
--dbs: enumerates all DBMS databases;
--tables: enumerates all DBMS database tables;
--columns: enumerate all DBMS database table columns;
-D DB: enumerates a specific DBMS database (e.g., -D database_name);
-T TBL DBMS: extracts a table (e.g., -T users);
-C COL DBMS: extracts a column (e.g., -C password);
Example of Usage
First of all, you need a vulnerable SQL injection endpoint. You can find it manually or through SQLmap. As an example, please consider the following command:
As shown above, SQLmap was able to identify a SQL injection entry point (i.e., the "id" parameter) and the backend DBMS (i.e., PostgreSQL). This is enough to generate a proof of concept. However, to accurately assess this vulnerability, we need to proceed further. Our next step is to attempt to extract the list of tables available in the current database:
Users is usually the most interesting table, so we can try to dump it in the following way:
Great job! We now have the admin credentials, giving us access to privileged functions. π
I hope you found this guide on SQLmap informative and helpful. Whether you're a beginner or an experienced professional, your insights and experiences are valuable to us and the community. Have you already used sqlmap in your security assessments? What challenges have you faced, and what tips can you share? π€