Skip to content

Commit 9d045e1

Browse files
committed
Implementation for an Issue sqlmapproject#437
1 parent 2defc30 commit 9d045e1

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
"getCount": "boolean",
115115
"dumpTable": "boolean",
116116
"dumpAll": "boolean",
117+
"pivotColumn": "string",
117118
"search": "boolean",
118119
"db": "string",
119120
"tbl": "string",

lib/parse/cmdline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ def cmdLineParser():
365365
enumeration.add_option("--dump-all", dest="dumpAll", action="store_true",
366366
help="Dump all DBMS databases tables entries")
367367

368+
enumeration.add_option("--pivot-column", dest="pivotColumn",
369+
help="Pivot column name")
370+
368371
enumeration.add_option("--search", dest="search", action="store_true",
369372
help="Search column(s), table(s) and/or database name(s)")
370373

lib/utils/pivotdumptable.py

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
See the file 'doc/COPYING' for copying permission
66
"""
77

8+
import re
9+
810
from extra.safe2bin.safe2bin import safechardecode
911
from lib.core.agent import agent
1012
from lib.core.bigarray import BigArray
@@ -60,36 +62,50 @@ def pivotDumpTable(table, colList, count=None, blind=True):
6062

6163
colList = filter(None, sorted(colList, key=lambda x: len(x) if x else MAX_INT))
6264

63-
for column in colList:
64-
infoMsg = "fetching number of distinct "
65-
infoMsg += "values for column '%s'" % column
66-
logger.info(infoMsg)
67-
68-
query = dumpNode.count2 % (column, table)
69-
value = inject.getValue(query, blind=blind, union=not blind, error=not blind, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS)
70-
71-
if isNumPosStrValue(value):
72-
validColumnList = True
73-
74-
if value == count:
75-
infoMsg = "using column '%s' as a pivot " % column
76-
infoMsg += "for retrieving row data"
77-
logger.info(infoMsg)
65+
if conf.pivotColumn:
66+
if any(re.search(r"(.+\.)?%s" % conf.pivotColumn, _, re.I) for _ in colList):
67+
infoMsg = "using column '%s' as a pivot " % conf.pivotColumn
68+
infoMsg += "for retrieving row data"
69+
logger.info(infoMsg)
7870

79-
validPivotValue = True
80-
81-
colList.remove(column)
82-
colList.insert(0, column)
83-
break
84-
85-
if not validColumnList:
86-
errMsg = "all column name(s) provided are non-existent"
87-
raise SqlmapNoneDataException(errMsg)
71+
validPivotValue = True
72+
colList.remove(conf.pivotColumn)
73+
colList.insert(0, conf.pivotColumn)
74+
else:
75+
warnMsg = "column '%s' not " % conf.pivotColumn
76+
warnMsg += "found in table '%s'" % table
77+
logger.warn(warnMsg)
8878

8979
if not validPivotValue:
90-
warnMsg = "no proper pivot column provided (with unique values)."
91-
warnMsg += " It won't be possible to retrieve all rows"
92-
logger.warn(warnMsg)
80+
for column in colList:
81+
infoMsg = "fetching number of distinct "
82+
infoMsg += "values for column '%s'" % column
83+
logger.info(infoMsg)
84+
85+
query = dumpNode.count2 % (column, table)
86+
value = inject.getValue(query, blind=blind, union=not blind, error=not blind, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS)
87+
88+
if isNumPosStrValue(value):
89+
validColumnList = True
90+
91+
if value == count:
92+
infoMsg = "using column '%s' as a pivot " % column
93+
infoMsg += "for retrieving row data"
94+
logger.info(infoMsg)
95+
96+
validPivotValue = True
97+
colList.remove(column)
98+
colList.insert(0, column)
99+
break
100+
101+
if not validColumnList:
102+
errMsg = "all column name(s) provided are non-existent"
103+
raise SqlmapNoneDataException(errMsg)
104+
105+
if not validPivotValue:
106+
warnMsg = "no proper pivot column provided (with unique values)."
107+
warnMsg += " It won't be possible to retrieve all rows"
108+
logger.warn(warnMsg)
93109

94110
pivotValue = " "
95111
breakRetrieval = False

sqlmap.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ dumpTable = False
398398
# Valid: True or False
399399
dumpAll = False
400400

401+
# Pivot column name.
402+
pivotColumn =
403+
401404
# Search column(s), table(s) and/or database name(s).
402405
# Requires: db, tbl or col
403406
# Valid: True or False

0 commit comments

Comments
 (0)