Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sqlmapproject
GitHub Repository: sqlmapproject/sqlmap
Path: blob/master/plugins/dbms/mysql/syntax.py
2992 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 binascii
9
10
from lib.core.convert import getBytes
11
from lib.core.convert import getOrds
12
from lib.core.convert import getUnicode
13
from plugins.generic.syntax import Syntax as GenericSyntax
14
15
class Syntax(GenericSyntax):
16
@staticmethod
17
def escape(expression, quote=True):
18
"""
19
>>> Syntax.escape("SELECT 'abcdefgh' FROM foobar") == "SELECT 0x6162636465666768 FROM foobar"
20
True
21
>>> Syntax.escape(u"SELECT 'abcd\xebfgh' FROM foobar") == "SELECT CONVERT(0x61626364c3ab666768 USING utf8) FROM foobar"
22
True
23
"""
24
25
def escaper(value):
26
if all(_ < 128 for _ in getOrds(value)):
27
return "0x%s" % getUnicode(binascii.hexlify(getBytes(value)))
28
else:
29
return "CONVERT(0x%s USING utf8)" % getUnicode(binascii.hexlify(getBytes(value, "utf8")))
30
31
return Syntax._escape(expression, quote, escaper)
32
33