Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sqlmapproject
GitHub Repository: sqlmapproject/sqlmap
Path: blob/master/tamper/charunicodeencode.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 os
9
import string
10
11
from lib.core.common import singleTimeWarnMessage
12
from lib.core.enums import PRIORITY
13
14
__priority__ = PRIORITY.LOWEST
15
16
def dependencies():
17
singleTimeWarnMessage("tamper script '%s' is only meant to be run against ASP or ASP.NET web applications" % os.path.basename(__file__).split(".")[0])
18
19
def tamper(payload, **kwargs):
20
"""
21
Unicode-URL-encodes all characters in a given payload (not processing already encoded) (e.g. SELECT -> %u0053%u0045%u004C%u0045%u0043%u0054)
22
23
Requirement:
24
* ASP
25
* ASP.NET
26
27
Tested against:
28
* Microsoft SQL Server 2000
29
* Microsoft SQL Server 2005
30
* MySQL 5.1.56
31
* PostgreSQL 9.0.3
32
33
Notes:
34
* Useful to bypass weak web application firewalls that do not unicode URL-decode the request before processing it through their ruleset
35
36
>>> tamper('SELECT FIELD%20FROM TABLE')
37
'%u0053%u0045%u004C%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004C%u0044%u0020%u0046%u0052%u004F%u004D%u0020%u0054%u0041%u0042%u004C%u0045'
38
"""
39
40
retVal = payload
41
42
if payload:
43
retVal = ""
44
i = 0
45
46
while i < len(payload):
47
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:
48
retVal += "%%u00%s" % payload[i + 1:i + 3]
49
i += 3
50
else:
51
retVal += '%%u%.4X' % ord(payload[i])
52
i += 1
53
54
return retVal
55
56