SQLMap Usage Guide and Cheat Sheet
SQLMap Usage Guide and Cheat Sheet
Manual testing is critical before confirming SQL injection findings from sqlmap due to the nuances in web application logic and defenses that automated tools might misinterpret. Manual testing helps verify false positives and ensures thorough understanding of the vulnerability context, allowing for responsible and precise assessments .
The '--batch' option in sqlmap automates interactions by using default answers, which is useful for non-interactive operations, enabling efficiency in script-based or repeated testing scenarios. The '--random-agent' option spoofs a random User-Agent header, helping to simulate different browsers and avoid easy detection by security systems, enhancing the realism of the testing process .
Sqlmap's '--technique' option supports six SQL injection techniques: B for Boolean-based blind, E for Error-based, U for UNION query-based, S for Stacked queries, T for Time-based blind, and Q for Inline queries. Specifying techniques is important because it tailors the injection attempts to the application’s behavior and defenses, potentially bypassing security mechanisms and achieving deeper penetration, facilitating targeted testing for vulnerabilities .
The '--os-shell' feature in sqlmap should be used with caution as it attempts to gain an interactive shell on the target's operating system, which could lead to unintended server disruptions or legal complications if not authorized. It's crucial to ensure proper authorization and understanding of the target system architecture to avoid causing irreversible damage or exposing sensitive environments .
Sqlmap can enumerate database structures using several commands: '--dbs' lists all available databases, '--current-db' shows the currently selected database, '--tables -D [database_name]' lists tables from a database, '--columns -D [dbname] -T [tablename]' lists columns from a table, and '--dump -D [db] -T [table]' retrieves data from a table. These commands help in methodically exploring and mapping the database structure .
Sqlmap handles authenticated areas by allowing testers to pass authentication cookies with the '--cookie' option. For managing HTTP Basic Authentication, sqlmap provides the '--auth-type=basic' and '--auth-cred' options for specifying credentials. Moreover, it includes a '--csrf-token' option to automatically capture CSRF tokens, facilitating the testing of authenticated sessions without altering the application's integrity .
Sqlmap offers advanced post-exploitation features including '--os-shell' for obtaining an interactive shell on the target system, '--file-read' for reading files from the server, '--file-write' to upload files, and '--identify-waf' to detect presence of a WAF. These capabilities can significantly amplify the impact of a successful SQL injection by allowing attackers to manipulate the server environment, potentially leading to complete system compromise .
Tamper scripts in sqlmap can modify injection payloads to circumvent security filters such as WAFs (Web Application Firewalls). For example, using the '--tamper=space2comment' script transforms spaces into comments, potentially bypassing filters that do not recognize SQL comments as delimiters. Such bypassing techniques are crucial for penetrating obstacles that might block standard injection attempts .
Integrating sqlmap with proxy tools like Burp Suite through the '--proxy' option allows for detailed inspection and manipulation of HTTP requests and responses. This integration offers advantages such as enhanced visibility, ability to intercept and modify traffic on-the-fly, and facilitating a hybrid approach that combines automated scanning with manual expert analysis, improving overall test accuracy and effectiveness .
The '--level' option in sqlmap sets the extent of tests to perform, with values ranging from 1 to 5, where a higher level means more comprehensive tests with more payloads. The '--risk' option defines how aggressive the payloads will be, with values from 1 to 3. A higher risk allows for potentially more invasive tests. Together, these options allow users to balance thoroughness and potential impact on the target, tailoring the depth and invasiveness of the injection attempts .