Skip to content

Commit 34476e3

Browse files
committed
More improvements for dbwire
1 parent 79a6479 commit 34476e3

6 files changed

Lines changed: 16 additions & 13 deletions

File tree

‎extra/dbwire/firebird.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import socket
2121
import struct
2222

23+
from extra.dbwire import ConnectionLostError
2324
from extra.dbwire import DatabaseError
2425
from extra.dbwire import DataError
2526
from extra.dbwire import IntegrityError
@@ -806,6 +807,9 @@ def connect(host=None, port=3050, user=None, password=None, database=None, conne
806807
for setup in ("SET BIND OF DECFLOAT TO VARCHAR", "SET BIND OF TIME WITH TIME ZONE TO VARCHAR(64)", "SET BIND OF TIMESTAMP WITH TIME ZONE TO VARCHAR(64)"):
807808
try:
808809
connection._query(setup)
810+
except (ConnectionLostError, InterfaceError):
811+
wire.close()
812+
raise
809813
except DatabaseError:
810814
pass
811815
return connection

‎extra/dbwire/sybase.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ def connect(host=None, port=5000, user=None, password=None, database=None, conne
420420
connection._read_response(login=True)
421421
handshake_done(sock)
422422
# ASE silently cuts TEXT/IMAGE values at @@textsize (32K by default); native clients raise it at login too
423-
connection._query("SET TEXTSIZE 2147483647")
423+
try:
424+
connection._query("SET TEXTSIZE 2147483647")
425+
except ProgrammingError: # best-effort (e.g. an Open Server gateway refusing it)
426+
pass
424427
if database:
425428
if not _IDENTIFIER.match(database):
426429
raise ProgrammingError("unsupported database name '%s'" % database)

‎lib/core/settings.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from thirdparty import six
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.10.12.10"
22+
VERSION = "1.10.12.11"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

‎lib/request/direct.py‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ def direct(query, content=True):
7878
start = time.time()
7979

8080
if not select and re.search(r"(?i)\bEXEC ", query) is None:
81-
_, state = timeout(func=conf.dbmsConnector.execute, args=(query,), duration=conf.timeout, default=None)
82-
if state in (TIMEOUT_STATE.TIMEOUT, TIMEOUT_STATE.EXCEPTION):
83-
# same as below: a statement still running (or dead) on this connection would answer the next query
84-
conf.dbmsConnector.close()
85-
conf.dbmsConnector.connect()
81+
timeout(func=conf.dbmsConnector.execute, args=(query,), duration=conf.timeout, default=None)
8682
elif not (output and ("%soutput" % conf.tablePrefix) not in query and ("%sfile" % conf.tablePrefix) not in query):
8783
output, state = timeout(func=conf.dbmsConnector.select, args=(query,), duration=conf.timeout, default=None)
8884
if output and isListLike(output):

‎plugins/generic/databases.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None, dumpMod
652652

653653
if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL, DBMS.HSQLDB, DBMS.H2, DBMS.MONETDB, DBMS.VERTICA, DBMS.PRESTO, DBMS.CRATEDB, DBMS.CUBRID, DBMS.CACHE, DBMS.FRONTBASE, DBMS.VIRTUOSO, DBMS.CLICKHOUSE, DBMS.SNOWFLAKE):
654654
query = rootQuery.inband.query % (unsafeSQLIdentificatorNaming(tbl), unsafeSQLIdentificatorNaming(conf.db))
655-
query += condQuery
655+
query = query.replace(" ORDER BY ", "%s ORDER BY " % condQuery) if " ORDER BY " in query else query + condQuery # e.g. PostgreSQL
656656

657657
if Backend.isDbms(DBMS.MYSQL) and Backend.isFork(FORK.DRIZZLE):
658658
query = re.sub("column_type", "data_type", query, flags=re.I)
@@ -663,7 +663,7 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None, dumpMod
663663

664664
elif Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.DB2, DBMS.DERBY, DBMS.ALTIBASE, DBMS.MIMERSQL, DBMS.SNOWFLAKE, DBMS.HANA):
665665
query = rootQuery.inband.query % (unsafeSQLIdentificatorNaming(tbl.upper()), unsafeSQLIdentificatorNaming(conf.db.upper()))
666-
query += condQuery
666+
query = query.replace(" ORDER BY ", "%s ORDER BY " % condQuery) if " ORDER BY " in query else query + condQuery # e.g. SAP HANA
667667

668668
elif Backend.isDbms(DBMS.MSSQL):
669669
query = rootQuery.inband.query % (conf.db, conf.db, conf.db, conf.db, conf.db, safeSQLIdentificatorNaming(tbl, True))
@@ -864,7 +864,7 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None, dumpMod
864864
def columnNameQuery(index):
865865
if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL, DBMS.HSQLDB, DBMS.VERTICA, DBMS.PRESTO, DBMS.CRATEDB, DBMS.CUBRID, DBMS.CACHE, DBMS.FRONTBASE, DBMS.VIRTUOSO):
866866
query = rootQuery.blind.query % (unsafeSQLIdentificatorNaming(tbl), unsafeSQLIdentificatorNaming(conf.db))
867-
query += condQuery
867+
query = query.replace(" ORDER BY ", "%s ORDER BY " % condQuery) if " ORDER BY " in query else query + condQuery # e.g. PostgreSQL
868868
field = None
869869
elif Backend.isDbms(DBMS.H2):
870870
query = rootQuery.blind.query % (unsafeSQLIdentificatorNaming(tbl), unsafeSQLIdentificatorNaming(conf.db))

‎plugins/generic/users.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def getPasswordHashes(self):
196196
users = [_ for _ in users if _]
197197

198198
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR, PAYLOAD.TECHNIQUE.QUERY)) or conf.direct:
199-
if Backend.isDbms(DBMS.MSSQL) and Backend.isVersionWithin(("2005", "2008")):
199+
if Backend.isDbms(DBMS.MSSQL) and Backend.isVersionGreaterOrEqualThan("2005"):
200200
query = rootQuery.inband.query2
201201
else:
202202
query = rootQuery.inband.query
@@ -285,7 +285,7 @@ def getPasswordHashes(self):
285285
infoMsg += "for user '%s'" % user
286286
logger.info(infoMsg)
287287

288-
if Backend.isDbms(DBMS.MSSQL) and Backend.isVersionWithin(("2005", "2008")):
288+
if Backend.isDbms(DBMS.MSSQL) and Backend.isVersionGreaterOrEqualThan("2005"):
289289
query = rootQuery.blind.count2 % user
290290
else:
291291
query = rootQuery.blind.count % user
@@ -316,7 +316,7 @@ def getPasswordHashes(self):
316316

317317
for index in indexRange:
318318
if Backend.isDbms(DBMS.MSSQL):
319-
if Backend.isVersionWithin(("2005", "2008")):
319+
if Backend.isVersionGreaterOrEqualThan("2005"):
320320
query = rootQuery.blind.query2 % (user, index, user)
321321
else:
322322
query = rootQuery.blind.query % (user, index, user)

0 commit comments

Comments
 (0)