mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-12-07 05:01:30 +00:00
Adding support for Presto
This commit is contained in:
30
plugins/dbms/presto/__init__.py
Normal file
30
plugins/dbms/presto/__init__.py
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
from lib.core.enums import DBMS
|
||||
from lib.core.settings import PRESTO_SYSTEM_DBS
|
||||
from lib.core.unescaper import unescaper
|
||||
|
||||
from plugins.dbms.presto.enumeration import Enumeration
|
||||
from plugins.dbms.presto.filesystem import Filesystem
|
||||
from plugins.dbms.presto.fingerprint import Fingerprint
|
||||
from plugins.dbms.presto.syntax import Syntax
|
||||
from plugins.dbms.presto.takeover import Takeover
|
||||
from plugins.generic.misc import Miscellaneous
|
||||
|
||||
class PrestoMap(Syntax, Fingerprint, Enumeration, Filesystem, Miscellaneous, Takeover):
|
||||
"""
|
||||
This class defines Presto methods
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.excludeDbsList = PRESTO_SYSTEM_DBS
|
||||
|
||||
for cls in self.__class__.__bases__:
|
||||
cls.__init__(self)
|
||||
|
||||
unescaper[DBMS.PRESTO] = Syntax.escape
|
||||
70
plugins/dbms/presto/connector.py
Normal file
70
plugins/dbms/presto/connector.py
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
try:
|
||||
import prestodb
|
||||
except:
|
||||
pass
|
||||
|
||||
import logging
|
||||
import struct
|
||||
|
||||
from lib.core.common import getSafeExString
|
||||
from lib.core.data import conf
|
||||
from lib.core.data import logger
|
||||
from lib.core.exception import SqlmapConnectionException
|
||||
from plugins.generic.connector import Connector as GenericConnector
|
||||
|
||||
class Connector(GenericConnector):
|
||||
"""
|
||||
Homepage: https://github.com/prestodb/presto-python-client
|
||||
User guide: https://github.com/prestodb/presto-python-client/blob/master/README.md
|
||||
API: https://www.python.org/dev/peps/pep-0249/
|
||||
PyPI package: presto-python-client
|
||||
License: Apache License 2.0
|
||||
"""
|
||||
|
||||
def connect(self):
|
||||
self.initConnection()
|
||||
|
||||
try:
|
||||
self.connector = prestodb.dbapi.connect(host=self.hostname, user=self.user, catalog=self.db, port=self.port, request_timeout=conf.timeout)
|
||||
except (prestodb.exceptions.OperationalError, prestodb.exceptions.InternalError, prestodb.exceptions.ProgrammingError, struct.error) as ex:
|
||||
raise SqlmapConnectionException(getSafeExString(ex))
|
||||
|
||||
self.initCursor()
|
||||
self.printConnected()
|
||||
|
||||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except prestodb.exceptions.ProgrammingError as ex:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
|
||||
return None
|
||||
|
||||
def execute(self, query):
|
||||
retVal = False
|
||||
|
||||
try:
|
||||
self.cursor.execute(query)
|
||||
retVal = True
|
||||
except (prestodb.exceptions.OperationalError, prestodb.exceptions.ProgrammingError) as ex:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
|
||||
except prestodb.exceptions.InternalError as ex:
|
||||
raise SqlmapConnectionException(getSafeExString(ex))
|
||||
|
||||
self.connector.commit()
|
||||
|
||||
return retVal
|
||||
|
||||
def select(self, query):
|
||||
retVal = None
|
||||
|
||||
if self.execute(query):
|
||||
retVal = self.fetchall()
|
||||
|
||||
return retVal
|
||||
58
plugins/dbms/presto/enumeration.py
Normal file
58
plugins/dbms/presto/enumeration.py
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
from lib.core.data import logger
|
||||
from plugins.generic.enumeration import Enumeration as GenericEnumeration
|
||||
|
||||
class Enumeration(GenericEnumeration):
|
||||
def getBanner(self):
|
||||
warnMsg = "on Presto it is not possible to get a banner"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
return None
|
||||
|
||||
def getCurrentDb(self):
|
||||
warnMsg = "on Presto it is not possible to get name of the current database (schema)"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
def isDba(self, user=None):
|
||||
warnMsg = "on Presto it is not possible to test if current user is DBA"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
def getUsers(self):
|
||||
warnMsg = "on Presto it is not possible to enumerate the users"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
return []
|
||||
|
||||
def getPasswordHashes(self):
|
||||
warnMsg = "on Presto it is not possible to enumerate the user password hashes"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
return {}
|
||||
|
||||
def getPrivileges(self, *args, **kwargs):
|
||||
warnMsg = "on Presto it is not possible to enumerate the user privileges"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
return {}
|
||||
|
||||
def getRoles(self, *args, **kwargs):
|
||||
warnMsg = "on Presto it is not possible to enumerate the user roles"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
return {}
|
||||
|
||||
def getHostname(self):
|
||||
warnMsg = "on Presto it is not possible to enumerate the hostname"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
def getStatements(self):
|
||||
warnMsg = "on Presto it is not possible to enumerate the SQL statements"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
return []
|
||||
18
plugins/dbms/presto/filesystem.py
Normal file
18
plugins/dbms/presto/filesystem.py
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
from lib.core.exception import SqlmapUnsupportedFeatureException
|
||||
from plugins.generic.filesystem import Filesystem as GenericFilesystem
|
||||
|
||||
class Filesystem(GenericFilesystem):
|
||||
def readFile(self, remoteFile):
|
||||
errMsg = "on Presto it is not possible to read files"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
|
||||
def writeFile(self, localFile, remoteFile, fileType=None, forceCheck=False):
|
||||
errMsg = "on Presto it is not possible to write files"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
137
plugins/dbms/presto/fingerprint.py
Normal file
137
plugins/dbms/presto/fingerprint.py
Normal file
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
from lib.core.common import Backend
|
||||
from lib.core.common import Format
|
||||
from lib.core.data import conf
|
||||
from lib.core.data import kb
|
||||
from lib.core.data import logger
|
||||
from lib.core.enums import DBMS
|
||||
from lib.core.session import setDbms
|
||||
from lib.core.settings import PRESTO_ALIASES
|
||||
from lib.request import inject
|
||||
from plugins.generic.fingerprint import Fingerprint as GenericFingerprint
|
||||
|
||||
class Fingerprint(GenericFingerprint):
|
||||
def __init__(self):
|
||||
GenericFingerprint.__init__(self, DBMS.PRESTO)
|
||||
|
||||
def getFingerprint(self):
|
||||
value = ""
|
||||
wsOsFp = Format.getOs("web server", kb.headersFp)
|
||||
|
||||
if wsOsFp:
|
||||
value += "%s\n" % wsOsFp
|
||||
|
||||
if kb.data.banner:
|
||||
dbmsOsFp = Format.getOs("back-end DBMS", kb.bannerFp)
|
||||
|
||||
if dbmsOsFp:
|
||||
value += "%s\n" % dbmsOsFp
|
||||
|
||||
value += "back-end DBMS: "
|
||||
|
||||
if not conf.extensiveFp:
|
||||
value += DBMS.PRESTO
|
||||
return value
|
||||
|
||||
actVer = Format.getDbms()
|
||||
blank = " " * 15
|
||||
value += "active fingerprint: %s" % actVer
|
||||
|
||||
if kb.bannerFp:
|
||||
banVer = kb.bannerFp.get("dbmsVersion")
|
||||
|
||||
if banVer:
|
||||
banVer = Format.getDbms([banVer])
|
||||
value += "\n%sbanner parsing fingerprint: %s" % (blank, banVer)
|
||||
|
||||
htmlErrorFp = Format.getErrorParsedDBMSes()
|
||||
|
||||
if htmlErrorFp:
|
||||
value += "\n%shtml error message fingerprint: %s" % (blank, htmlErrorFp)
|
||||
|
||||
return value
|
||||
|
||||
def checkDbms(self):
|
||||
if not conf.extensiveFp and Backend.isDbmsWithin(PRESTO_ALIASES):
|
||||
setDbms(DBMS.PRESTO)
|
||||
|
||||
self.getBanner()
|
||||
|
||||
return True
|
||||
|
||||
infoMsg = "testing %s" % DBMS.PRESTO
|
||||
logger.info(infoMsg)
|
||||
|
||||
result = inject.checkBooleanExpression("TO_BASE64URL(NULL) IS NULL")
|
||||
|
||||
if result:
|
||||
infoMsg = "confirming %s" % DBMS.PRESTO
|
||||
logger.info(infoMsg)
|
||||
|
||||
result = inject.checkBooleanExpression("TO_HEX(FROM_HEX(NULL)) IS NULL")
|
||||
|
||||
if not result:
|
||||
warnMsg = "the back-end DBMS is not %s" % DBMS.PRESTO
|
||||
logger.warn(warnMsg)
|
||||
|
||||
return False
|
||||
|
||||
setDbms(DBMS.PRESTO)
|
||||
|
||||
if not conf.extensiveFp:
|
||||
return True
|
||||
|
||||
infoMsg = "actively fingerprinting %s" % DBMS.PRESTO
|
||||
logger.info(infoMsg)
|
||||
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.200.html
|
||||
if inject.checkBooleanExpression("FROM_IEEE754_32(NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.200")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.193.html
|
||||
elif inject.checkBooleanExpression("NORMAL_CDF(NULL,NULL,NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.193")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.183.html
|
||||
elif inject.checkBooleanExpression("MAP_ENTRIES(NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.183")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.171.html
|
||||
elif inject.checkBooleanExpression("CODEPOINT(NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.171")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.162.html
|
||||
elif inject.checkBooleanExpression("XXHASH64(NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.162")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.151.html
|
||||
elif inject.checkBooleanExpression("COSINE_SIMILARITY(NULL,NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.151")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.143.html
|
||||
elif inject.checkBooleanExpression("TRUNCATE(NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.143")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.137.html
|
||||
elif inject.checkBooleanExpression("BIT_COUNT(NULL,NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.137")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.130.html
|
||||
elif inject.checkBooleanExpression("MAP_CONCAT(NULL,NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.130")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.115.html
|
||||
elif inject.checkBooleanExpression("SHA1(NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.115")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.100.html
|
||||
elif inject.checkBooleanExpression("SPLIT(NULL,NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.100")
|
||||
# Reference: https://prestodb.io/docs/current/release/release-0.70.html
|
||||
elif inject.checkBooleanExpression("GREATEST(NULL,NULL) IS NULL"):
|
||||
Backend.setVersion(">= 0.70")
|
||||
else:
|
||||
Backend.setVersion("< 0.100")
|
||||
|
||||
return True
|
||||
else:
|
||||
warnMsg = "the back-end DBMS is not %s" % DBMS.PRESTO
|
||||
logger.warn(warnMsg)
|
||||
|
||||
return False
|
||||
22
plugins/dbms/presto/syntax.py
Normal file
22
plugins/dbms/presto/syntax.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
from lib.core.convert import getOrds
|
||||
from plugins.generic.syntax import Syntax as GenericSyntax
|
||||
|
||||
class Syntax(GenericSyntax):
|
||||
@staticmethod
|
||||
def escape(expression, quote=True):
|
||||
"""
|
||||
>>> Syntax.escape("SELECT 'abcdefgh' FROM foobar") == "SELECT CHR(97)||CHR(98)||CHR(99)||CHR(100)||CHR(101)||CHR(102)||CHR(103)||CHR(104) FROM foobar"
|
||||
True
|
||||
"""
|
||||
|
||||
def escaper(value):
|
||||
return "||".join("CHR(%d)" % _ for _ in getOrds(value))
|
||||
|
||||
return Syntax._escape(expression, quote, escaper)
|
||||
28
plugins/dbms/presto/takeover.py
Normal file
28
plugins/dbms/presto/takeover.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
from lib.core.exception import SqlmapUnsupportedFeatureException
|
||||
from plugins.generic.takeover import Takeover as GenericTakeover
|
||||
|
||||
class Takeover(GenericTakeover):
|
||||
def osCmd(self):
|
||||
errMsg = "on Presto it is not possible to execute commands"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
|
||||
def osShell(self):
|
||||
errMsg = "on Presto it is not possible to execute commands"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
|
||||
def osPwn(self):
|
||||
errMsg = "on Presto it is not possible to establish an "
|
||||
errMsg += "out-of-band connection"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
|
||||
def osSmb(self):
|
||||
errMsg = "on Presto it is not possible to establish an "
|
||||
errMsg += "out-of-band connection"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
Reference in New Issue
Block a user