@@ -81,73 +81,74 @@ def _orderByTest(cols):
8181
8282 return found
8383
84- pushValue (kb .errorIsNone )
85- items , ratios = [], []
86- kb .errorIsNone = False
87- lowerCount , upperCount = conf .uColsStart , conf .uColsStop
88-
89- if lowerCount == 1 :
90- found = kb .orderByColumns or _orderByTechnique ()
91- if found :
92- kb .orderByColumns = found
93- infoMsg = "target URL appears to have %d column%s in query" % (found , 's' if found > 1 else "" )
94- singleTimeLogMessage (infoMsg )
95- return found
96-
97- if abs (upperCount - lowerCount ) < MIN_UNION_RESPONSES :
98- upperCount = lowerCount + MIN_UNION_RESPONSES
99-
100- min_ , max_ = MAX_RATIO , MIN_RATIO
101- pages = {}
84+ try :
85+ pushValue (kb .errorIsNone )
86+ items , ratios = [], []
87+ kb .errorIsNone = False
88+ lowerCount , upperCount = conf .uColsStart , conf .uColsStop
89+
90+ if lowerCount == 1 :
91+ found = kb .orderByColumns or _orderByTechnique ()
92+ if found :
93+ kb .orderByColumns = found
94+ infoMsg = "target URL appears to have %d column%s in query" % (found , 's' if found > 1 else "" )
95+ singleTimeLogMessage (infoMsg )
96+ return found
97+
98+ if abs (upperCount - lowerCount ) < MIN_UNION_RESPONSES :
99+ upperCount = lowerCount + MIN_UNION_RESPONSES
100+
101+ min_ , max_ = MAX_RATIO , MIN_RATIO
102+ pages = {}
103+
104+ for count in xrange (lowerCount , upperCount + 1 ):
105+ query = agent .forgeUnionQuery ('' , - 1 , count , comment , prefix , suffix , kb .uChar , where )
106+ payload = agent .payload (place = place , parameter = parameter , newValue = query , where = where )
107+ page , headers = Request .queryPage (payload , place = place , content = True , raise404 = False )
108+ if not isNullValue (kb .uChar ):
109+ pages [count ] = page
110+ ratio = comparison (page , headers , getRatioValue = True ) or MIN_RATIO
111+ ratios .append (ratio )
112+ min_ , max_ = min (min_ , ratio ), max (max_ , ratio )
113+ items .append ((count , ratio ))
102114
103- for count in xrange (lowerCount , upperCount + 1 ):
104- query = agent .forgeUnionQuery ('' , - 1 , count , comment , prefix , suffix , kb .uChar , where )
105- payload = agent .payload (place = place , parameter = parameter , newValue = query , where = where )
106- page , headers = Request .queryPage (payload , place = place , content = True , raise404 = False )
107115 if not isNullValue (kb .uChar ):
108- pages [count ] = page
109- ratio = comparison (page , headers , getRatioValue = True ) or MIN_RATIO
110- ratios .append (ratio )
111- min_ , max_ = min (min_ , ratio ), max (max_ , ratio )
112- items .append ((count , ratio ))
113-
114- if not isNullValue (kb .uChar ):
115- for regex in (kb .uChar , r'>\s*%s\s*<' % kb .uChar ):
116- contains = [(count , re .search (regex , page or "" , re .IGNORECASE ) is not None ) for count , page in pages .items ()]
117- if len (filter (lambda x : x [1 ], contains )) == 1 :
118- retVal = filter (lambda x : x [1 ], contains )[0 ][0 ]
119- break
120-
121- if not retVal :
122- ratios .pop (ratios .index (min_ ))
123- ratios .pop (ratios .index (max_ ))
124-
125- minItem , maxItem = None , None
126-
127- for item in items :
128- if item [1 ] == min_ :
129- minItem = item
130- elif item [1 ] == max_ :
131- maxItem = item
132-
133- if all (map (lambda x : x == min_ and x != max_ , ratios )):
134- retVal = maxItem [0 ]
135-
136- elif all (map (lambda x : x != min_ and x == max_ , ratios )):
137- retVal = minItem [0 ]
138-
139- elif abs (max_ - min_ ) >= MIN_STATISTICAL_RANGE :
140- deviation = stdev (ratios )
141- lower , upper = average (ratios ) - UNION_STDEV_COEFF * deviation , average (ratios ) + UNION_STDEV_COEFF * deviation
142-
143- if min_ < lower :
144- retVal = minItem [0 ]
145-
146- if max_ > upper :
147- if retVal is None or abs (max_ - upper ) > abs (min_ - lower ):
148- retVal = maxItem [0 ]
149-
150- kb .errorIsNone = popValue ()
116+ for regex in (kb .uChar , r'>\s*%s\s*<' % kb .uChar ):
117+ contains = [(count , re .search (regex , page or "" , re .IGNORECASE ) is not None ) for count , page in pages .items ()]
118+ if len (filter (lambda x : x [1 ], contains )) == 1 :
119+ retVal = filter (lambda x : x [1 ], contains )[0 ][0 ]
120+ break
121+
122+ if not retVal :
123+ ratios .pop (ratios .index (min_ ))
124+ ratios .pop (ratios .index (max_ ))
125+
126+ minItem , maxItem = None , None
127+
128+ for item in items :
129+ if item [1 ] == min_ :
130+ minItem = item
131+ elif item [1 ] == max_ :
132+ maxItem = item
133+
134+ if all (map (lambda x : x == min_ and x != max_ , ratios )):
135+ retVal = maxItem [0 ]
136+
137+ elif all (map (lambda x : x != min_ and x == max_ , ratios )):
138+ retVal = minItem [0 ]
139+
140+ elif abs (max_ - min_ ) >= MIN_STATISTICAL_RANGE :
141+ deviation = stdev (ratios )
142+ lower , upper = average (ratios ) - UNION_STDEV_COEFF * deviation , average (ratios ) + UNION_STDEV_COEFF * deviation
143+
144+ if min_ < lower :
145+ retVal = minItem [0 ]
146+
147+ if max_ > upper :
148+ if retVal is None or abs (max_ - upper ) > abs (min_ - lower ):
149+ retVal = maxItem [0 ]
150+ finally :
151+ kb .errorIsNone = popValue ()
151152
152153 if retVal :
153154 infoMsg = "target URL appears to be UNION injectable with %d columns" % retVal
0 commit comments