Skip to content

Commit f43dba3

Browse files
committed
Fixing retrieval of exotic coltypes on MySQL
1 parent fbc3704 commit f43dba3

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

lib/core/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty import six
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.10.7.209"
23+
VERSION = "1.10.7.210"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -934,6 +934,10 @@
934934
# column names (not types) were fetched - i.e. blind dumping (keep in sync with BINARY_FIELDS_TYPE_REGEX)
935935
BINARY_FIELDS_TYPE_KEYWORDS = ("BINARY", "BLOB", "BYTEA", "IMAGE", "RAW")
936936

937+
# MySQL-only: BIT and spatial (WKB) columns store raw bytes that the NCHAR text-cast silently NULLs, so they
938+
# must be hex-extracted too (MSSQL/PostgreSQL 'bit' render fine as 0/1 or a bit-string, hence not global)
939+
MYSQL_BINARY_CAST_TYPE_REGEX = r"(?i)\A(bit|geometry|point|linestring|polygon|multipoint|multilinestring|multipolygon|geomcollection|geometrycollection)\b"
940+
937941
# Maximum number of redirections to any single URL - this is needed because of the state that cookies introduce
938942
MAX_SINGLE_URL_REDIRECTIONS = 4
939943

plugins/generic/entries.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from lib.core.exception import SqlmapNoneDataException
4242
from lib.core.exception import SqlmapUnsupportedFeatureException
4343
from lib.core.settings import BINARY_FIELDS_TYPE_REGEX
44+
from lib.core.settings import MYSQL_BINARY_CAST_TYPE_REGEX
4445
from lib.core.settings import CHECK_ZERO_COLUMNS_THRESHOLD
4546
from lib.core.settings import CURRENT_DB
4647
from lib.core.settings import KEYSET_MIN_ROWS
@@ -178,8 +179,8 @@ def dumpTable(self, foundData=None):
178179
# type is already known from the enumeration above, so this costs no extra request.
179180
# (PostgreSQL excluded: its bytea already renders as readable '\xHEX' through the default text
180181
# cast, and its hex path needs text input, so auto-hexing would double-encode.)
181-
# MySQL BIT stores raw bits that the NCHAR text-cast NULLs (unlike MSSQL/PostgreSQL 'bit', which render as 0/1 or a bit-string), so hex it too
182-
autoBinary = [] if Backend.isDbms(DBMS.PGSQL) else [column for column in colList if columns.get(column) and (re.search(BINARY_FIELDS_TYPE_REGEX, getUnicode(columns[column])) or (Backend.isDbms(DBMS.MYSQL) and re.search(r"(?i)\Abit\b", getUnicode(columns[column]))))]
182+
# MySQL BIT/spatial store raw bytes the NCHAR text-cast NULLs (unlike MSSQL/PostgreSQL 'bit', which render fine), so hex them too
183+
autoBinary = [] if Backend.isDbms(DBMS.PGSQL) else [column for column in colList if columns.get(column) and (re.search(BINARY_FIELDS_TYPE_REGEX, getUnicode(columns[column])) or (Backend.isDbms(DBMS.MYSQL) and re.search(MYSQL_BINARY_CAST_TYPE_REGEX, getUnicode(columns[column]))))]
183184
conf.binaryFields = (list(binaryFields) if binaryFields else []) + [_ for _ in autoBinary if not (binaryFields and _ in binaryFields)]
184185
if autoBinary:
185186
debugMsg = "auto-treating binary column(s) '%s' as binary fields" % ', '.join(unsafeSQLIdentificatorNaming(_) for _ in autoBinary)

0 commit comments

Comments
 (0)