Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sqlmapproject
GitHub Repository: sqlmapproject/sqlmap
Path: blob/master/tamper/overlongutf8.py
2983 views
1
#!/usr/bin/env python
2
3
"""
4
Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)
5
See the file 'LICENSE' for copying permission
6
"""
7
8
import string
9
10
from lib.core.enums import PRIORITY
11
12
__priority__ = PRIORITY.LOWEST
13
14
def dependencies():
15
pass
16
17
def tamper(payload, **kwargs):
18
"""
19
Converts all (non-alphanum) characters in a given payload to overlong UTF8 (not processing already encoded) (e.g. ' -> %C0%A7)
20
21
Reference:
22
* https://www.acunetix.com/vulnerabilities/unicode-transformation-issues/
23
* https://www.thecodingforums.com/threads/newbie-question-about-character-encoding-what-does-0xc0-0x8a-have-in-common-with-0xe0-0x80-0x8a.170201/
24
25
>>> tamper('SELECT FIELD FROM TABLE WHERE 2>1')
26
'SELECT%C0%A0FIELD%C0%A0FROM%C0%A0TABLE%C0%A0WHERE%C0%A02%C0%BE1'
27
"""
28
29
retVal = payload
30
31
if payload:
32
retVal = ""
33
i = 0
34
35
while i < len(payload):
36
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:
37
retVal += payload[i:i + 3]
38
i += 3
39
else:
40
if payload[i] not in (string.ascii_letters + string.digits):
41
retVal += "%%%.2X%%%.2X" % (0xc0 + (ord(payload[i]) >> 6), 0x80 + (ord(payload[i]) & 0x3f))
42
else:
43
retVal += payload[i]
44
i += 1
45
46
return retVal
47
48