2019-05-08 12:47:52 +02:00
|
|
|
#!/usr/bin/env python
|
2011-02-06 23:25:55 +00:00
|
|
|
|
|
|
|
|
"""
|
2023-01-02 23:24:59 +01:00
|
|
|
Copyright (c) 2006-2023 sqlmap developers (https://sqlmap.org/)
|
2017-10-11 14:50:46 +02:00
|
|
|
See the file 'LICENSE' for copying permission
|
2011-02-06 23:25:55 +00:00
|
|
|
"""
|
|
|
|
|
|
2011-07-11 10:39:30 +00:00
|
|
|
import os
|
2011-02-06 23:25:55 +00:00
|
|
|
import string
|
|
|
|
|
|
2011-07-11 10:39:30 +00:00
|
|
|
from lib.core.common import singleTimeWarnMessage
|
2019-06-04 14:44:06 +02:00
|
|
|
from lib.core.enums import PRIORITY
|
2011-02-06 23:25:55 +00:00
|
|
|
|
|
|
|
|
__priority__ = PRIORITY.LOWEST
|
|
|
|
|
|
2011-07-06 21:04:45 +00:00
|
|
|
def dependencies():
|
2011-07-11 10:39:30 +00:00
|
|
|
singleTimeWarnMessage("tamper script '%s' is only meant to be run against ASP or ASP.NET web applications" % os.path.basename(__file__).split(".")[0])
|
2011-07-06 21:04:45 +00:00
|
|
|
|
2012-12-03 14:27:01 +01:00
|
|
|
def tamper(payload, **kwargs):
|
2011-02-06 23:25:55 +00:00
|
|
|
"""
|
2018-07-31 02:18:33 +02:00
|
|
|
Unicode-URL-encodes all characters in a given payload (not processing already encoded) (e.g. SELECT -> %u0053%u0045%u004C%u0045%u0043%u0054)
|
2011-07-06 21:04:45 +00:00
|
|
|
|
2011-07-11 10:39:30 +00:00
|
|
|
Requirement:
|
|
|
|
|
* ASP
|
|
|
|
|
* ASP.NET
|
|
|
|
|
|
2011-07-11 10:04:19 +00:00
|
|
|
Tested against:
|
|
|
|
|
* Microsoft SQL Server 2000
|
|
|
|
|
* Microsoft SQL Server 2005
|
2011-07-11 10:39:30 +00:00
|
|
|
* MySQL 5.1.56
|
|
|
|
|
* PostgreSQL 9.0.3
|
2011-07-11 10:04:19 +00:00
|
|
|
|
2011-07-06 21:04:45 +00:00
|
|
|
Notes:
|
2018-07-31 01:17:11 +02:00
|
|
|
* Useful to bypass weak web application firewalls that do not unicode URL-decode the request before processing it through their ruleset
|
2013-03-13 21:57:09 +01:00
|
|
|
|
|
|
|
|
>>> tamper('SELECT FIELD%20FROM TABLE')
|
|
|
|
|
'%u0053%u0045%u004C%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004C%u0044%u0020%u0046%u0052%u004F%u004D%u0020%u0054%u0041%u0042%u004C%u0045'
|
2011-02-06 23:25:55 +00:00
|
|
|
"""
|
|
|
|
|
|
2011-04-04 08:18:26 +00:00
|
|
|
retVal = payload
|
2011-02-06 23:25:55 +00:00
|
|
|
|
2011-04-04 08:18:26 +00:00
|
|
|
if payload:
|
2011-02-06 23:25:55 +00:00
|
|
|
retVal = ""
|
|
|
|
|
i = 0
|
|
|
|
|
|
2011-04-04 08:18:26 +00:00
|
|
|
while i < len(payload):
|
2013-01-10 13:18:44 +01:00
|
|
|
if payload[i] == '%' and (i < len(payload) - 2) and payload[i + 1:i + 2] in string.hexdigits and payload[i + 2:i + 3] in string.hexdigits:
|
|
|
|
|
retVal += "%%u00%s" % payload[i + 1:i + 3]
|
2011-02-06 23:25:55 +00:00
|
|
|
i += 3
|
|
|
|
|
else:
|
2012-07-24 01:21:32 +02:00
|
|
|
retVal += '%%u%.4X' % ord(payload[i])
|
2011-02-06 23:25:55 +00:00
|
|
|
i += 1
|
|
|
|
|
|
2012-10-25 10:10:23 +02:00
|
|
|
return retVal
|