2. basic scenario and usage

In basic scenario:

really basic stuff covered in previous section

sqlmap -u "http://www.example.com/vuln.php?id=1" --batch

In many cases mistakes like forgetting to set proper cookie values and overcomplicated setup / improper declaration of formatted post data will prevent correct detection and exploitation of a sqli vuln

Best/easiest ways to properly setup SQLMap requests is to use Copy as cURL feature in the chrome/edge/firefox dev tools.

We can directly input a curl request as sqlmap input:

sqlmap 'http://www.example.com/?id=1' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0' -H 'Accept: image/webp,*/*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Connection: keep-alive' -H 'DNT: 1'

When providing data for testing sqlmap there needs to be a parameter value that can be assessed or specialized options/switches for automatic parameter finding features

Common scenario: GET param provided with usage of option -u / --url as in previous example If testing POST we use --data

sqlmap 'http://www.example.com/' --data 'uid=1&name=test'

In such cases POST params uid and name will be tested for SQLi vuln if we get clear indication uid is prone we can narrow tests down to a single param with -p uid

sqlmap 'http://www.example.com/' --data 'uid=1*&name=test'

If we need to use complex http req with lots of header values and elongated POST body use -r flag

We can manually copy http req from within burp and write it to a file, or right click within burp and select copy to file

syntax is: `

sqlmap -r req.txt

custom sqlmap request

if there's a requirement to specify session cookie to phpsessid=sakdjalkjd use --option

sqlmap ... --cookie='PHPSESSID=ab4530f4a7d10448457fa8b0eadac29c'

same effect using -H or --header

sqlmap ... -H='Cookie:PHPSESSID=ab4530f4a7d10448457fa8b0eadac29c'

same thing for --host --referer -A / --user-agent

there's also --random-agent to select a random useragent header

sqlmap by default only targets http params its possible to test headers for sqli specify custom injection mark after header's value

same principle above applies to any other part of request

if we want to specify alternative http method other than GET and POST utilize --method

sqlmap -u www.target.com --data='id=1' --method PUT

custom http requests

json sqlmap reference

apart from most common form data POST body style like id=1 sqlmap supports JSON formatted {"id":1} and xml formatted <element><id>1</id></element> http requests

support is implemented in a relaxed manner - no strict constraints on how parameter vals are stored inside

in case POST relatively simple/short, --data is fine

in case of a long/complex POST body again we use -r and supply the request

cat req.txt

HTTP / HTTP/1.0
Host: www.example.com

{
  "data": [{
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "Example JSON",
      "body": "Just an example",
      "created": "2020-05-22T14:56:29.000Z",
      "updated": "2020-05-22T14:56:28.000Z"
    },
    "relationships": {
      "author": {
        "data": {"id": "42", "type": "user"}
      }
    }
  }]
}

and sqlmap -r req.txt