mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-12-03 16:24:15 +03:00
Added plugin logic for the 'Snowflake' DBMS
This commit is contained in:
parent
3b47fea525
commit
37bb07394c
29
plugins/dbms/snowflake/__init__.py
Normal file
29
plugins/dbms/snowflake/__init__.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
from lib.core.enums import DBMS
|
||||
from lib.core.settings import SNOWFLAKE_SYSTEM_DBS
|
||||
from lib.core.unescaper import unescaper
|
||||
from plugins.dbms.snowflake.enumeration import Enumeration
|
||||
from plugins.dbms.snowflake.filesystem import Filesystem
|
||||
from plugins.dbms.snowflake.fingerprint import Fingerprint
|
||||
from plugins.dbms.snowflake.syntax import Syntax
|
||||
from plugins.dbms.snowflake.takeover import Takeover
|
||||
from plugins.generic.misc import Miscellaneous
|
||||
|
||||
class SnowflakeMap(Syntax, Fingerprint, Enumeration, Filesystem, Miscellaneous, Takeover):
|
||||
"""
|
||||
This class defines Snowflake methods
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.excludeDbsList = SNOWFLAKE_SYSTEM_DBS
|
||||
|
||||
for cls in self.__class__.__bases__:
|
||||
cls.__init__(self)
|
||||
|
||||
unescaper[DBMS.SNOWFLAKE] = Syntax.escape
|
||||
70
plugins/dbms/snowflake/connector.py
Normal file
70
plugins/dbms/snowflake/connector.py
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
try:
|
||||
import snowflake.connector
|
||||
except:
|
||||
pass
|
||||
|
||||
import logging
|
||||
|
||||
from lib.core.common import getSafeExString
|
||||
from lib.core.convert import getText
|
||||
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://www.snowflake.com/
|
||||
User guide: https://docs.snowflake.com/en/developer-guide/python-connector/python-connector
|
||||
API: https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-api
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
GenericConnector.__init__(self)
|
||||
|
||||
def connect(self):
|
||||
self.initConnection()
|
||||
|
||||
try:
|
||||
self.connector = snowflake.connector.connect(
|
||||
user=self.user,
|
||||
password=self.password,
|
||||
account=self.account,
|
||||
warehouse=self.warehouse,
|
||||
database=self.db,
|
||||
schema=self.schema
|
||||
)
|
||||
cursor = self.connector.cursor()
|
||||
cursor.execute("SELECT CURRENT_VERSION()")
|
||||
cursor.close()
|
||||
|
||||
except Exception as ex:
|
||||
raise SqlmapConnectionException(getSafeExString(ex))
|
||||
|
||||
self.initCursor()
|
||||
self.printConnected()
|
||||
|
||||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except Exception as ex:
|
||||
logger.log(logging.WARNING if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
|
||||
return None
|
||||
|
||||
def execute(self, query):
|
||||
try:
|
||||
self.cursor.execute(getText(query))
|
||||
except Exception as ex:
|
||||
logger.log(logging.WARNING if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
|
||||
return None
|
||||
|
||||
def select(self, query):
|
||||
self.execute(query)
|
||||
return self.fetchall()
|
||||
39
plugins/dbms/snowflake/enumeration.py
Normal file
39
plugins/dbms/snowflake/enumeration.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
from lib.core.data import logger
|
||||
from lib.core.exception import SqlmapUnsupportedFeatureException
|
||||
from plugins.generic.enumeration import Enumeration as GenericEnumeration
|
||||
|
||||
class Enumeration(GenericEnumeration):
|
||||
def getPasswordHashes(self):
|
||||
warnMsg = "on Snowflake it is not possible to enumerate the user password hashes"
|
||||
logger.warning(warnMsg)
|
||||
return {}
|
||||
|
||||
def getHostname(self):
|
||||
warnMsg = "on Snowflake it is not possible to enumerate the hostname"
|
||||
logger.warning(warnMsg)
|
||||
|
||||
def searchDb(self):
|
||||
warnMsg = "on Snowflake it is not possible to search databases"
|
||||
logger.warning(warnMsg)
|
||||
return []
|
||||
|
||||
def searchColumn(self):
|
||||
errMsg = "on Snowflake it is not possible to search columns"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
|
||||
def getPrivileges(self, *args, **kwargs):
|
||||
warnMsg = "on SQLite it is not possible to enumerate the user privileges"
|
||||
logger.warning(warnMsg)
|
||||
return {}
|
||||
|
||||
def getStatements(self):
|
||||
warnMsg = "on Snowflake it is not possible to enumerate the SQL statements"
|
||||
logger.warning(warnMsg)
|
||||
return []
|
||||
18
plugins/dbms/snowflake/filesystem.py
Normal file
18
plugins/dbms/snowflake/filesystem.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2025 sqlmap developers (https://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 Snowflake it is not possible to read files"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
|
||||
def writeFile(self, localFile, remoteFile, fileType=None, forceCheck=False):
|
||||
errMsg = "on Snowflake it is not possible to write files"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
96
plugins/dbms/snowflake/fingerprint.py
Normal file
96
plugins/dbms/snowflake/fingerprint.py
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2025 sqlmap developers (https://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 METADB_SUFFIX
|
||||
from lib.core.settings import SNOWFLAKE_ALIASES
|
||||
from lib.request import inject
|
||||
from plugins.generic.fingerprint import Fingerprint as GenericFingerprint
|
||||
|
||||
class Fingerprint(GenericFingerprint):
|
||||
def __init__(self):
|
||||
GenericFingerprint.__init__(self, DBMS.SNOWFLAKE)
|
||||
|
||||
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.SNOWFLAKE
|
||||
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):
|
||||
"""
|
||||
References for fingerprint:
|
||||
|
||||
* https://docs.snowflake.com/en/sql-reference/functions/current_warehouse
|
||||
* https://docs.snowflake.com/en/sql-reference/functions/md5_number_upper64
|
||||
"""
|
||||
|
||||
if not conf.extensiveFp and Backend.isDbmsWithin(SNOWFLAKE_ALIASES):
|
||||
setDbms("%s %s" % (DBMS.SNOWFLAKE, Backend.getVersion()))
|
||||
self.getBanner()
|
||||
return True
|
||||
|
||||
infoMsg = "testing %s" % DBMS.SNOWFLAKE
|
||||
logger.info(infoMsg)
|
||||
|
||||
result = inject.checkBooleanExpression("CURRENT_WAREHOUSE()=CURRENT_WAREHOUSE()")
|
||||
if result:
|
||||
infoMsg = "confirming %s" % DBMS.SNOWFLAKE
|
||||
logger.info(infoMsg)
|
||||
|
||||
result = inject.checkBooleanExpression("MD5_NUMBER_UPPER64('z')=MD5_NUMBER_UPPER64('z')")
|
||||
if not result:
|
||||
warnMsg = "the back-end DBMS is not %s" % DBMS.SNOWFLAKE
|
||||
logger.warning(warnMsg)
|
||||
return False
|
||||
|
||||
setDbms(DBMS.SNOWFLAKE)
|
||||
self.getBanner()
|
||||
return True
|
||||
|
||||
else:
|
||||
warnMsg = "the back-end DBMS is not %s" % DBMS.SNOWFLAKE
|
||||
logger.warning(warnMsg)
|
||||
|
||||
return False
|
||||
23
plugins/dbms/snowflake/syntax.py
Normal file
23
plugins/dbms/snowflake/syntax.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2025 sqlmap developers (https://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):
|
||||
# Convert each character to its ASCII code and wrap with CHR()
|
||||
return "||".join(f"CHR({ord(c)})" for c in value)
|
||||
|
||||
return Syntax._escape(expression, quote, escaper)
|
||||
28
plugins/dbms/snowflake/takeover.py
Normal file
28
plugins/dbms/snowflake/takeover.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Copyright (c) 2006-2025 sqlmap developers (https://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 Snowflake it is not possible to execute commands"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
|
||||
def osShell(self):
|
||||
errMsg = "on Snowflake it is not possible to execute commands"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
|
||||
def osPwn(self):
|
||||
errMsg = "on Snowflake it is not possible to establish an "
|
||||
errMsg += "out-of-band connection"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
|
||||
def osSmb(self):
|
||||
errMsg = "on Snowflake it is not possible to establish an "
|
||||
errMsg += "out-of-band connection"
|
||||
raise SqlmapUnsupportedFeatureException(errMsg)
|
||||
Loading…
Reference in New Issue
Block a user