42
42
from lib .core .settings import NULL
43
43
from lib .request import inject
44
44
from lib .utils .hash import attackDumpedTable
45
+ from lib .utils .pivotdumptable import pivotDumpTable
45
46
46
47
class Entries :
47
48
"""
@@ -51,129 +52,6 @@ class Entries:
51
52
def __init__ (self ):
52
53
pass
53
54
54
- def __pivotDumpTable (self , table , colList , count = None , blind = True ):
55
- lengths = {}
56
- entries = {}
57
-
58
- dumpNode = queries [Backend .getIdentifiedDbms ()].dump_table .blind
59
-
60
- validColumnList = False
61
- validPivotValue = False
62
-
63
- if count is None :
64
- query = dumpNode .count % table
65
- count = inject .getValue (query , inband = False , error = False , expected = EXPECTED .INT , charsetType = CHARSET_TYPE .DIGITS ) if blind else inject .getValue (query , blind = False , expected = EXPECTED .INT )
66
-
67
- if isinstance (count , basestring ) and count .isdigit ():
68
- count = int (count )
69
-
70
- if count == 0 :
71
- infoMsg = "table '%s' appears to be empty" % unsafeSQLIdentificatorNaming (table )
72
- logger .info (infoMsg )
73
-
74
- for column in colList :
75
- lengths [column ] = len (column )
76
- entries [column ] = []
77
-
78
- return entries , lengths
79
-
80
- elif not isNumPosStrValue (count ):
81
- return None
82
-
83
- for column in colList :
84
- lengths [column ] = 0
85
- entries [column ] = BigArray ()
86
-
87
- colList = filter (None , sorted (colList , key = lambda x : len (x ) if x else MAX_INT ))
88
-
89
- for column in colList :
90
- infoMsg = "fetching number of distinct "
91
- infoMsg += "values for column '%s'" % column
92
- logger .info (infoMsg )
93
-
94
- query = dumpNode .count2 % (column , table )
95
- value = inject .getValue (query , blind = blind , inband = not blind , error = not blind , expected = EXPECTED .INT , charsetType = CHARSET_TYPE .DIGITS )
96
-
97
- if isNumPosStrValue (value ):
98
- validColumnList = True
99
-
100
- if value == count :
101
- infoMsg = "using column '%s' as a pivot " % column
102
- infoMsg += "for retrieving row data"
103
- logger .info (infoMsg )
104
-
105
- validPivotValue = True
106
-
107
- colList .remove (column )
108
- colList .insert (0 , column )
109
- break
110
-
111
- if not validColumnList :
112
- errMsg = "all column name(s) provided are non-existent"
113
- raise sqlmapNoneDataException , errMsg
114
-
115
- if not validPivotValue :
116
- warnMsg = "no proper pivot column provided (with unique values)."
117
- warnMsg += " It won't be possible to retrieve all rows"
118
- logger .warn (warnMsg )
119
-
120
- pivotValue = " "
121
- breakRetrieval = False
122
-
123
- try :
124
- for i in xrange (count ):
125
- if breakRetrieval :
126
- break
127
-
128
- for column in colList :
129
- # Correction for pivotValues with unrecognized/problematic chars
130
- for char in ('\' ' , '?' ):
131
- if pivotValue and char in pivotValue and pivotValue [0 ] != char :
132
- pivotValue = pivotValue .split (char )[0 ]
133
- pivotValue = pivotValue [:- 1 ] + decodeIntToUnicode (ord (pivotValue [- 1 ]) + 1 )
134
- break
135
- if column == colList [0 ]:
136
- query = dumpNode .query % (column , table , column , pivotValue )
137
- else :
138
- query = dumpNode .query2 % (column , table , colList [0 ], pivotValue )
139
-
140
- value = inject .getValue (query , blind = blind , inband = not blind , error = not blind )
141
-
142
- if column == colList [0 ]:
143
- if isNoneValue (value ):
144
- breakRetrieval = True
145
- break
146
- else :
147
- pivotValue = safechardecode (value )
148
-
149
- if conf .limitStart or conf .limitStop :
150
- if conf .limitStart and (i + 1 ) < conf .limitStart :
151
- warnMsg = "skipping first %d pivot " % conf .limitStart
152
- warnMsg += "point values"
153
- singleTimeWarnMessage (warnMsg )
154
- break
155
- elif conf .limitStop and (i + 1 ) > conf .limitStop :
156
- breakRetrieval = True
157
- break
158
-
159
- value = "" if isNoneValue (value ) else unArrayizeValue (value )
160
-
161
- lengths [column ] = max (lengths [column ], len (value ) if value else 0 )
162
- entries [column ].append (value )
163
-
164
- except KeyboardInterrupt :
165
- warnMsg = "user aborted during enumeration. sqlmap "
166
- warnMsg += "will display partial output"
167
- logger .warn (warnMsg )
168
-
169
- except sqlmapConnectionException , e :
170
- errMsg = "connection exception detected. sqlmap "
171
- errMsg += "will display partial output"
172
- errMsg += "'%s'" % e
173
- logger .critical (errMsg )
174
-
175
- return entries , lengths
176
-
177
55
def dumpTable (self , foundData = None ):
178
56
self .forceDbmsEnum ()
179
57
@@ -269,7 +147,7 @@ def dumpTable(self, foundData=None):
269
147
if not (isTechniqueAvailable (PAYLOAD .TECHNIQUE .UNION ) and kb .injection .data [PAYLOAD .TECHNIQUE .UNION ].where == PAYLOAD .WHERE .ORIGINAL ):
270
148
table = "%s.%s" % (conf .db , tbl )
271
149
272
- retVal = self . __pivotDumpTable (table , colList , blind = False )
150
+ retVal = pivotDumpTable (table , colList , blind = False )
273
151
274
152
if retVal :
275
153
entries , _ = retVal
@@ -365,7 +243,7 @@ def dumpTable(self, foundData=None):
365
243
elif Backend .isDbms (DBMS .MAXDB ):
366
244
table = "%s.%s" % (conf .db , tbl )
367
245
368
- retVal = self . __pivotDumpTable (table , colList , count , blind = True )
246
+ retVal = pivotDumpTable (table , colList , count , blind = True )
369
247
370
248
if retVal :
371
249
entries , lengths = retVal
0 commit comments