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:
- http req in scenario should have a value token value
- available only if user actually visited/used page
- original idea: prevention of scenarios with malicious links
- i.e. click a link to open admin page and add new user with creds for example
- this inadvertently hardened apps against unwanted automation
sqlmap can bypass this protection with --csrf-token
- specify token param name (already available within request data)
- sqlmap will parse target response content and search for fresh token values to use in next request
- even if not specified via csrf-token flag if one of provided parameters contains a common infix (
csrf,xsrf,token) user will be prompted whether to update it in future requests
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
- i.e.
--proxy="socks4://10.10.10.10:33283"
if we have list of proxies we can provide them to sqlmap with --proxy-file
- sqlmap sequentially iterates through list
- if ip blacklisted it will just be skipped
good option here is to use Tor as easy anonymization
- ip can appear anywhere from a large list of Tor exit nodes
- when properly installed there should be a SOCKS4 proxy svc at local port 9050 or 9150
- use
--torand sqlmap will automatically try to find the local port and use it
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
- predef malicious looking payload
- using nonexistent param name
- i.e.
?pfox=...this is to test for existence of waf
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
- signatures of 80 diff waf provider solutions
- if we want to skip this and produce less noise, use
--skip-waf
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
- special kind of python scripts written for modifying requests just before being sent to the target, in most cases to bypass some protection
example: https://github.com/sqlmapproject/sqlmap/blob/master/tamper/between.py
replaces all occurrences of greater than operator > with
not between 0 and #and the=operator withBETWEEN # and #
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
- they are run and applied based on predefined priority
- priority predefined to prevent unwanted behavior, some scripts modify payloads by changing sql syntax
- some dont care about inner content:
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
- turned on by using
--chunked- splits POST request body into chunks
- blacklisted SQL keywords split between chunks in a way that request containing them can pass unnoticed
HTTP Parameter pollution (HPP)
- payloads split in a similar way as using
--chunked - split between different same parameter named values
- i.e.
?id=1&id=UNION&id=SELECT&id=username,password&id=FROM&id=users...
- i.e.
- concatenated by the target platform if its supported
- such as
ASP
- such as