in most cases sqlmap automatically works pretty good
every sqli payload consists of:
- vector
- (ie.
UNION ALL SELECT 1,2,VERSION()- central part of payload carrying sql
- (ie.
- boundaries
- i.e.
<vector>-- - - prefix + suffix formations used for proper injection of the vector into vulnerable sql statement
- i.e.
sqlmap prefix/suffix specification
sometimes we may need to specify a prefix/suffix for sqli, not covered by typical sqlmap runs
for such runs we use --prefix and --suffix
sqlmap -u "www.example.com/?q=test" --prefix="%'))" --suffix="-- -"
results in enclosure of all vector values between static prefix and suffix i.e. ; vulnerable code may look like:
$query = "SELECT id,name,surname FROM users WHERE id LIKE (('" . $_GET["q"] . "')) LIMIT 0,1";
$result = mysqli_query($link, $query);
vector UNION ALL SELECT 1,2,VERSION() bounded with prefix %')) and suffix -- - will result in the following valid SQL statement:
SELECT id,name,surname FROM users WHERE id LIKE (('test%')) UNION ALL SELECT 1,2,VERSION()-- -')) LIMIT 0,1
sqlmap level/risk
by default:
- predefined set of common boundaries (prefix/suffix pairs)
- predefined vectors
level and risk specify bigger sets of boundaries and vectors already incorporated in sqlmap
--level (1-5)
- extends both vectors and boundaries used
- ordered by expectancy of success
- lower expectancy = higher level
--risk (1-3)
- extends vector set based on risk of causing problems on target
- i.e. risk of database entry loss or DoS condition
you can test differences using different combinations of --level and --risk and check verbosity in stdout, looking at [PAYLOAD] prefixed output
default level value has a pretty small set of boundaries set
level=1, risk=1
- number of payloads used for testing a single param goes up to 72 level=5, risk=3
- payloads increase to 7865 tested
regular users not advised to touch these options because it will make the whole detection process a lot slower
however special cases of sqli vulns (like usage of OR payloads is a must, such as in case of login pages)
ORpayloads are inherently dangerous in a default run - where underlying vulnerable sql statements are actively modifying database content (think DML like delete/update)
sqlmap advanced tuning, page responses
theres a whole lot more to do to tune your requests for sqli Status codes
- dealing with huge target responses
- subtle difference between true/false responses could be used for detection
- if diff between true/false seen in http codes (200 TRUE, 500 FALSE)
--codefixate detection ofTRUE
Titles
- if diff in response can be seen in inspecting page titles
--titlesused to tell detection mechanism to base comparison on<title>HTML tag
Strings
- searching for a specific string in TRUE responses (ie success) when absent in false responses
- use
--string(i.e.--string=successfor detection of successful injection)
text-only
- dealing with hidden content such as html page behavior tags like
<script>,<style>,<meta>
- using
--text-onlyremoves all html tags and bases comparison on visible content
Techniques
- may need to narrow payloads only to specific types
- if time-based blind payloads are causing trouble because of response timeouts, or want to force usage of specific sqli payload type
- use
--technique- i.e.
--technique=BEU - [[0. Overview, cheatsheet#sqlmap payload technique types]]
- i.e.
UNION sqli tuning
- some cases: UNION payloads require extra user-provided info to work
- if we can manually find exact column numbers we can provide this to sqlmap with
--union-cols=XX - if default 'dummy' filling values used by sqlmap (
NULLand random integers) are not compatible, we can specify an alternative value with--union-char='a' - if requirement to use an appendix at the end of a
UNIONquery in form ofFROM <table>we can set it with option--union-fromi.e.--union-from=users- failing to use proper
FROMappendix automatically could be due to inability to detect DBMS name before usage
- failing to use proper