Adding embedded dbwire library

This commit is contained in:
Miroslav Štampar 2026-07-12 10:32:57 +02:00
parent d5ff557a13
commit 921870ccf0
13 changed files with 1682 additions and 3 deletions

View file

@ -12,7 +12,9 @@ from lib.core.data import conf
from lib.core.data import kb
from lib.core.dicts import DBMS_DICT
from lib.core.enums import DBMS
from lib.core.dicts import DBWIRE_MODULES
from lib.core.exception import SqlmapConnectionException
from lib.utils.dbwire import Connector as DbwireConnector
from lib.core.settings import ACCESS_ALIASES
from lib.core.settings import ALTIBASE_ALIASES
from lib.core.settings import CACHE_ALIASES
@ -158,7 +160,12 @@ def setHandler():
try:
conf.dbmsConnector.connect()
except NameError:
if exception:
# neither a native driver nor SQLAlchemy is available: fall back to our dependency-free
# pure-python 'dbwire' client if it covers this DBMS (so '-d' works out of the box)
if dbms in DBWIRE_MODULES:
conf.dbmsConnector = DbwireConnector(DBWIRE_MODULES[dbms])
conf.dbmsConnector.connect()
elif exception:
raise exception
else:
msg = "support for direct connection to '%s' is not available. " % dbms

View file

@ -71,6 +71,7 @@ from lib.core.datatype import OrderedSet
from lib.core.decorators import cachedmethod
from lib.core.defaults import defaults
from lib.core.dicts import DBMS_DICT
from lib.core.dicts import DBWIRE_MODULES
from lib.core.dicts import DEFAULT_DOC_ROOTS
from lib.core.dicts import DEPRECATED_OPTIONS
from lib.core.dicts import OBSOLETE_OPTIONS
@ -1755,6 +1756,8 @@ def parseTargetDirect():
except:
if _sqlalchemy and data[3] and any(_ in _sqlalchemy.dialects.__all__ for _ in (data[3], data[3].split('+')[0])):
pass
elif dbmsName in DBWIRE_MODULES: # our dependency-free pure-python 'dbwire' client covers this DBMS
pass
else:
errMsg = "sqlmap requires '%s' third-party library " % data[1]
errMsg += "in order to directly connect to the DBMS "

View file

@ -258,6 +258,20 @@ DBMS_DICT = {
DBMS.HANA: (HANA_ALIASES, "hdbcli", "https://pypi.org/project/hdbcli/", "hana"),
}
# DBMS -> pure-python 'extra/dbwire' wire-protocol module, used as a dependency-free '-d' fallback when
# neither a native driver nor SQLAlchemy is installed (a single module serves the whole compatible family,
# e.g. 'postgres' also covers CockroachDB/CrateDB/Redshift/Greenplum)
DBWIRE_MODULES = {
DBMS.PGSQL: "postgres",
DBMS.CRATEDB: "postgres", # CrateDB speaks the PostgreSQL wire protocol
DBMS.MYSQL: "mysql",
DBMS.MSSQL: "tds",
DBMS.SYBASE: "tds",
DBMS.CLICKHOUSE: "clickhouse",
DBMS.MONETDB: "monetdb",
DBMS.PRESTO: "presto",
}
# Reference: https://blog.jooq.org/tag/sysibm-sysdummy1/
FROM_DUMMY_TABLE = {
DBMS.ORACLE: " FROM DUAL",

View file

@ -20,7 +20,7 @@ from lib.core.enums import OS
from thirdparty import six
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.10.7.84"
VERSION = "1.10.7.85"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

57
lib/utils/dbwire.py Normal file
View file

@ -0,0 +1,57 @@
#!/usr/bin/env python
"""
Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org)
See the file 'LICENSE' for copying permission
"""
import importlib
import logging
import extra.dbwire
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):
"""
Adapter exposing sqlmap's connector interface over a dependency-free 'extra/dbwire' pure-python
wire-protocol client. Used for '-d' when neither a native driver nor SQLAlchemy is available.
"""
def __init__(self, module):
GenericConnector.__init__(self)
self._driver = importlib.import_module("extra.dbwire.%s" % module)
def connect(self):
self.initConnection()
try:
self.connector = self._driver.connect(host=self.hostname, port=self.port, user=self.user, password=self.password, database=self.db, connect_timeout=conf.timeout)
except extra.dbwire.Error as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.initCursor()
self.printConnected()
def fetchall(self):
try:
return self.cursor.fetchall()
except extra.dbwire.Error as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
return None
def execute(self, query):
try:
self.cursor.execute(query)
except extra.dbwire.Error as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
self.connector.commit()
def select(self, query):
self.execute(query)
return self.fetchall()