@@ -71,7 +71,7 @@ def __goInference(payload, expression):
71
71
return value
72
72
73
73
74
- def __goInferenceFields (expression , expressionFields , expressionFieldsList , payload ):
74
+ def __goInferenceFields (expression , expressionFields , expressionFieldsList , payload , expected = None ):
75
75
outputs = []
76
76
77
77
for field in expressionFieldsList :
@@ -80,15 +80,20 @@ def __goInferenceFields(expression, expressionFields, expressionFieldsList, payl
80
80
expressionReplaced = expression .replace (expressionFields , field , 1 )
81
81
output = resume (expressionReplaced , payload )
82
82
83
- if not output :
83
+ if not output or ( expected == "int" and not output .isdigit () ):
84
+ if output :
85
+ warnMsg = "expected value type %s, resumed '%s', " % (expected , output )
86
+ warnMsg += "sqlmap is going to retrieve the value again"
87
+ logger .warn (warnMsg )
88
+
84
89
output = __goInference (payload , expressionReplaced )
85
90
86
91
outputs .append (output )
87
92
88
93
return outputs
89
94
90
95
91
- def __goInferenceProxy (expression , fromUser = False ):
96
+ def __goInferenceProxy (expression , fromUser = False , expected = None ):
92
97
"""
93
98
Retrieve the output of a SQL query characted by character taking
94
99
advantage of an blind SQL injection vulnerability on the affected
@@ -108,7 +113,7 @@ def __goInferenceProxy(expression, fromUser=False):
108
113
109
114
output = resume (expression , payload )
110
115
111
- if output :
116
+ if output and ( expected == None or ( expected == "int" and output . isdigit () ) ) :
112
117
return output
113
118
114
119
if kb .dbmsDetected :
@@ -179,7 +184,7 @@ def __goInferenceProxy(expression, fromUser=False):
179
184
count = resume (countedExpression , payload )
180
185
181
186
if not stopLimit :
182
- if not count :
187
+ if not count or not count . isdigit () :
183
188
count = __goInference (payload , countedExpression )
184
189
185
190
if count .isdigit () and int (count ) > 0 :
@@ -268,15 +273,15 @@ def __goInferenceProxy(expression, fromUser=False):
268
273
limitedExpr += "NOT IN (%s" % (limitStr % num )
269
274
limitedExpr += "%s %s)" % (expressionFieldsList [0 ], fromFrom )
270
275
271
- output = __goInferenceFields (limitedExpr , expressionFields , expressionFieldsList , payload )
276
+ output = __goInferenceFields (limitedExpr , expressionFields , expressionFieldsList , payload , expected )
272
277
outputs .append (output )
273
278
274
279
return outputs
275
280
276
281
elif kb .dbms == "Oracle" and expression .startswith ("SELECT " ) and " FROM " not in expression :
277
282
expression = "%s FROM DUAL" % expression
278
283
279
- outputs = __goInferenceFields (expression , expressionFields , expressionFieldsList , payload )
284
+ outputs = __goInferenceFields (expression , expressionFields , expressionFieldsList , payload , expected )
280
285
281
286
returnValue = ", " .join ([output for output in outputs ])
282
287
else :
@@ -285,7 +290,7 @@ def __goInferenceProxy(expression, fromUser=False):
285
290
return returnValue
286
291
287
292
288
- def __goInband (expression ):
293
+ def __goInband (expression , expected = None ):
289
294
"""
290
295
Retrieve the output of a SQL query taking advantage of an inband SQL
291
296
injection vulnerability on the affected parameter.
@@ -304,7 +309,7 @@ def __goInband(expression):
304
309
if condition :
305
310
output = resume (expression , None )
306
311
307
- if not output :
312
+ if not output or ( expected == "int" and not output . isdigit () ) :
308
313
partial = True
309
314
310
315
if not output :
@@ -355,7 +360,7 @@ def __goInband(expression):
355
360
return data
356
361
357
362
358
- def getValue (expression , blind = True , inband = True , fromUser = False ):
363
+ def getValue (expression , blind = True , inband = True , fromUser = False , expected = None ):
359
364
"""
360
365
Called each time sqlmap inject a SQL query on the SQL injection
361
366
affected parameter. It can call a function to retrieve the output
@@ -368,9 +373,9 @@ def getValue(expression, blind=True, inband=True, fromUser=False):
368
373
value = None
369
374
370
375
if inband and conf .unionUse and kb .dbms :
371
- value = __goInband (expression )
376
+ value = __goInband (expression , expected )
372
377
373
378
if blind and not value :
374
- value = __goInferenceProxy (expression , fromUser )
379
+ value = __goInferenceProxy (expression , fromUser , expected )
375
380
376
381
return value
0 commit comments