There are situations where we must specify the entire HTTP Request with all its headers and body
To do so, we have two different approaches
HTTP Proxy
We can capture the HTTP Request in question using an HTTP Proxy such as Burpsuite or Caido and copy the entire request into a request.txt file, which will be passed to SQLMap through the -r option
To do so, simply copy the entire HTTP Request from the HTTP Proxy
Zoom in
Then, paste it into a file and run the following command
sqlmap -r request.txt
Custom Requests
If it is necessary to be logged in to test a given HTTP Parameter, we can use the --cookie option to specify a valid cookie
sqlmap ... --cookie='<COOKIE_NAME>=<COOKIE_VALUE>' # e.g. PHPSESSID=ab4530f4a7d10448457fa8b0eadac29c
Similarly, we can specifiy any other type of HTTP Header using the --header
sqlmap ... --header='<HEADER_NAME>:<HEADER_VALUE>' # e.g. Content-Type: application/json
Nowadays, most web application are protected by some kind of Web Application Firewall. The most frequent action it usually performs is returning a 403 error in the HTTP Response if the clientβs request contains a blank User-Agent or one used by web pentesting tools, such as SQLMap
Therefore, we can use the --random-agent option, which is designed to randomly select a User-Agent header value from the included database of regular browser values
sqlmap ... --random-agent
Attack Tuning
Prefixes and Suffixes
SQLMap comes with a set of different boundaries, both prefixes and suffixes, which, together with the vector, make up the entire payload sent to the target
Moreover, we can pass a custom preffix or suffix ( or both ) to SQLMAP, which will be used along with the original payloads
By default, SQLmap sends a total of 72 payloads when testing a single parameter i.e. --risk=1 --level=1
However, when both parameters are set to their maximum value ( i.e. --level=5 --risk=5 ), the number of payloads increase to 7,865
We have to bear in mind the risks of setting the --risk parameter above 3, as the tool begins to include OR statements within the payloads, which can cause damage to the database if the user input is enclosed inside an UPDATE or DELETE statement
βTamper scripts are a special kind of (Python) scripts written for modifying requests just before being sent to the target, in most cases to bypass some protectionβ
All the existing tampers, along with its description, can be listed as follows
sqlmap --list-tampers
OS Exploitation
File Read/Write
As stated in other sections, the current database user must have the FILE privilege set
Furthermore, the secure_file_priv global parameter should have an empty value in order to allow input and output operation to the file system
However, even if these two requirements are met, the system user running the DBMS service must have either read permission on the given file or write permission on the directory where we want to create the file
SQLMap has a parameter called --is-dba, which tell us if the current database user has this type of permissions
Is the current user a DBA?
DBA stands for Database Administrator
sqlmap --url '<URL>' --method POST --data '<PARAM>=<VALUE>*' --batch --random-agent --is-dba
Reading Files
Once we verify that the current DB user has the appropiate permissions, we can proceed as follows to read a given file