Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sqlmapproject
GitHub Repository: sqlmapproject/sqlmap
Path: blob/master/tamper/commalessmid.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 re
10
11
from lib.core.common import singleTimeWarnMessage
12
from lib.core.enums import DBMS
13
from lib.core.enums import PRIORITY
14
15
__priority__ = PRIORITY.HIGH
16
17
def dependencies():
18
singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s" % (os.path.basename(__file__).split(".")[0], DBMS.MYSQL))
19
20
def tamper(payload, **kwargs):
21
"""
22
Replaces (MySQL) instances like 'MID(A, B, C)' with 'MID(A FROM B FOR C)' counterpart
23
24
Requirement:
25
* MySQL
26
27
Tested against:
28
* MySQL 5.0 and 5.5
29
30
>>> tamper('MID(VERSION(), 1, 1)')
31
'MID(VERSION() FROM 1 FOR 1)'
32
"""
33
34
retVal = payload
35
36
warnMsg = "you should consider usage of switch '--no-cast' along with "
37
warnMsg += "tamper script '%s'" % os.path.basename(__file__).split(".")[0]
38
singleTimeWarnMessage(warnMsg)
39
40
match = re.search(r"(?i)MID\((.+?)\s*,\s*(\d+)\s*\,\s*(\d+)\s*\)", payload or "")
41
if match:
42
retVal = retVal.replace(match.group(0), "MID(%s FROM %s FOR %s)" % (match.group(1), match.group(2), match.group(3)))
43
44
return retVal
45
46