2019-05-08 12:47:52 +02:00
|
|
|
#!/usr/bin/env python
|
2010-03-22 22:57:57 +00:00
|
|
|
|
|
|
|
|
"""
|
2026-01-01 19:12:07 +01:00
|
|
|
Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org)
|
2017-10-11 14:50:46 +02:00
|
|
|
See the file 'LICENSE' for copying permission
|
2010-03-22 22:57:57 +00:00
|
|
|
"""
|
|
|
|
|
|
2011-10-23 20:19:42 +00:00
|
|
|
import binascii
|
2010-03-23 21:26:45 +00:00
|
|
|
|
2019-05-03 13:20:15 +02:00
|
|
|
from lib.core.convert import getBytes
|
|
|
|
|
from lib.core.convert import getOrds
|
2019-05-06 00:54:21 +02:00
|
|
|
from lib.core.convert import getUnicode
|
2010-03-22 22:57:57 +00:00
|
|
|
from plugins.generic.syntax import Syntax as GenericSyntax
|
|
|
|
|
|
|
|
|
|
class Syntax(GenericSyntax):
|
|
|
|
|
@staticmethod
|
2013-01-18 15:40:37 +01:00
|
|
|
def escape(expression, quote=True):
|
2013-03-11 14:58:05 +01:00
|
|
|
"""
|
2019-05-02 12:39:16 +02:00
|
|
|
>>> Syntax.escape("SELECT 'abcdefgh' FROM foobar") == "SELECT 0x6162636465666768 FROM foobar"
|
|
|
|
|
True
|
|
|
|
|
>>> Syntax.escape(u"SELECT 'abcd\xebfgh' FROM foobar") == "SELECT CONVERT(0x61626364c3ab666768 USING utf8) FROM foobar"
|
|
|
|
|
True
|
2013-03-11 14:58:05 +01:00
|
|
|
"""
|
|
|
|
|
|
2013-01-20 13:45:58 +01:00
|
|
|
def escaper(value):
|
2019-05-02 12:39:16 +02:00
|
|
|
if all(_ < 128 for _ in getOrds(value)):
|
|
|
|
|
return "0x%s" % getUnicode(binascii.hexlify(getBytes(value)))
|
|
|
|
|
else:
|
2020-01-09 11:59:50 +01:00
|
|
|
return "CONVERT(0x%s USING utf8)" % getUnicode(binascii.hexlify(getBytes(value, "utf8")))
|
2010-03-22 22:57:57 +00:00
|
|
|
|
2013-01-20 13:45:58 +01:00
|
|
|
return Syntax._escape(expression, quote, escaper)
|