diff --git a/lib/core/common.py b/lib/core/common.py index 2c425fab5..4d8ab91ce 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -3207,3 +3207,6 @@ def resetCookieJar(cookieJar): errMsg += "cookies file ('%s')" % msg raise sqlmapGenericException, errMsg +def prioritySortColumns(columns): + _ = lambda x: x and "id" in x.lower() + return sorted(sorted(columns, key=len), lambda x, y: -1 if _(x) and not _(y) else 1 if not _(x) and _(y) else 0) diff --git a/lib/core/dump.py b/lib/core/dump.py index 774b16d61..1e798d274 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -19,6 +19,7 @@ from lib.core.common import dataToStdout from lib.core.common import getUnicode from lib.core.common import normalizeUnicode from lib.core.common import openFile +from lib.core.common import prioritySortColumns from lib.core.common import restoreDumpMarkedChars from lib.core.common import safeCSValue from lib.core.common import unsafeSQLIdentificatorNaming @@ -357,9 +358,7 @@ class Dump: field = 1 fields = len(tableValues) - 1 - columns = tableValues.keys() - _ = lambda x: x and "id" in x.lower() - columns = sorted(sorted(columns, key=len), lambda x, y: -1 if _(x) and not _(y) else 1 if not _(x) and _(y) else 0) + columns = prioritySortColumns(tableValues.keys()) for column in columns: if column != "__infos__": diff --git a/plugins/generic/enumeration.py b/plugins/generic/enumeration.py index ccddb3823..6b223c6d6 100644 --- a/plugins/generic/enumeration.py +++ b/plugins/generic/enumeration.py @@ -26,6 +26,7 @@ from lib.core.common import isTechniqueAvailable from lib.core.common import parsePasswordHash from lib.core.common import parseSqliteTableSchema from lib.core.common import popValue +from lib.core.common import prioritySortColumns from lib.core.common import pushValue from lib.core.common import randomStr from lib.core.common import readInput @@ -1608,9 +1609,7 @@ class Enumeration: else: query = rootQuery.inband.query % (colString, conf.db, tbl) elif Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL): - _ = lambda x: x and "id" in x.lower() - orderby = sorted(sorted(colList, key=len), lambda x, y: -1 if _(x) and not _(y) else 1 if not _(x) and _(y) else 0)[0] - query = rootQuery.inband.query % (colString, conf.db, tbl, orderby) + query = rootQuery.inband.query % (colString, conf.db, tbl, prioritySortColumns(colList)[0]) else: query = rootQuery.inband.query % (colString, conf.db, tbl)