7. Bypassing web application protections with sqlmap

ideally no protections l0l lots of mechanisms built into sqlmap tho

anti-csrf token bypass

cross-site-request-forgery token is first line of defense against automated tool usage tokens injected in all http reqs , esp those generated as result of webform filling

in basic terms:

sqlmap can bypass this protection with --csrf-token

unique value bypass

in some scenarios web app will require unique values to be provided inside predefined parameters similar to anticsrf but no need to parse web content by ensuring each req has unique value for predefined parameter the web app can prevent csrf attempts + avert some automated tools thus use --randomize in such scenarios - pointing to parameter name

sqlmap -u "http://www.example.com/?id=1&rp=29125" --randomize=rp --batch -v 5 | grep URI

calculated parameter bypass

similar mechanism - app expects proper param value to be calculated based on some other param values most often one param has to contain msg digest (h=MD5(id) ) of another one bypass this with --eval where python code is being evaluated just before request is being sent to target

sqlmap -u "http://www.example.com/?id=1&h=c4ca4238a0b923820dcc509a6f75849b" --eval="import hashlib; h=hashlib.md5(id).hexdigest()" --batch -v 5 | grep URI

ip addr concealment

to conceal our ip or if web app has protection mechanism to blacklist us, try to use proxy or Tor proxy set with --proxy

if we have list of proxies we can provide them to sqlmap with --proxy-file

good option here is to use Tor as easy anonymization

to ensure Tor is being used to prevent unwanted behavior try --check-tor sqlmap will connect to check.torproject.org and test if traffic routed over tor network

waf bypass

when running sqlmap the program sends tests

there will be substantial change in response compared to original in case of any protection between user and target if a popular WAF like ModSecurity is in use, there should be a 406 - Not Acceptable response after such a request

if detection is positive - to idenntify actual protection mechanism - SQLMap uses thirdparty library identYwaf https://github.com/stamparm/identYwaf

user agent blacklisting bypass

if we have immediate problems like 5xx errors from beginning we should make sure our useragent isnt being blacklisted sqlmap uses default useragent (e.g. User-agent: sqlmap/1.4.9 (http://sqlmap.org)).

trivial to bypass with --random-agent


big note here: if some protection detected during run we can expect problems with target even other security mechanisms


tamper scripts

popular method implemented in sqlmap for bypassing waf/ips is tamper scripts

example: https://github.com/sqlmapproject/sqlmap/blob/master/tamper/between.py replaces all occurrences of greater than operator > with

this way many primitive protection mechanisms (that are historically focused on XSS) are easily bypassed, atleast for sqli purposes

tamper scripts can be chained one after another with --tamper=between,randomcase etc

check overview [[0. Overview, cheatsheet#sqlmap tamper script list, most common]] for more examples of tamper scripts


misc bypasses

other protection mechanisms theres two more important mentions Chunked transfer encoding

HTTP Parameter pollution (HPP)