3333from lib .parse .html import htmlParser
3434from lib .request .connect import Connect as Request
3535
36+ def __forgeUserFriendlyValue (payload ):
37+ value = ""
38+
39+ if kb .injPlace == "GET" :
40+ value = "%s?%s" % (conf .url , payload )
41+ elif kb .injPlace == "POST" :
42+ value = "URL:\t '%s'" % conf .url
43+ value += "\n POST:\t '%s'\n " % payload
44+ elif kb .injPlace == "Cookie" :
45+ value = "URL:\t '%s'" % conf .url
46+ value += "\n Cookie:\t '%s'\n " % payload
47+ elif kb .injPlace == "User-Agent" :
48+ value = "URL:\t \t '%s'" % conf .url
49+ value += "\n User-Agent:\t '%s'\n " % payload
50+
51+ return value
52+
3653def __unionPosition (negative = False , falseCond = False ):
54+ value = None
55+
3756 if negative or falseCond :
3857 negLogMsg = "partial (single entry)"
3958 else :
@@ -73,6 +92,7 @@ def __unionPosition(negative=False, falseCond=False):
7392
7493 if randQuery in resultPage and not htmlParsed :
7594 setUnion (position = exprPosition )
95+ value = __forgeUserFriendlyValue (payload )
7696
7797 break
7898
@@ -90,47 +110,36 @@ def __unionPosition(negative=False, falseCond=False):
90110
91111 logger .warn (warnMsg )
92112
113+ return value
114+
93115def __unionConfirm ():
116+ value = None
117+
94118 # Confirm the inband SQL injection and get the exact column
95119 # position
96120 if not isinstance (kb .unionPosition , int ):
97- __unionPosition ()
121+ value = __unionPosition ()
98122
99123 # Assure that the above function found the exploitable full inband
100124 # SQL injection position
101125 if not isinstance (kb .unionPosition , int ):
102- __unionPosition (falseCond = True )
126+ value = __unionPosition (falseCond = True )
103127
104128 # Assure that the above function found the exploitable partial
105129 # (single entry) inband SQL injection position by appending
106130 # a false condition after the parameter value
107131 if not isinstance (kb .unionPosition , int ):
108- __unionPosition (negative = True )
132+ value = __unionPosition (negative = True )
109133
110134 # Assure that the above function found the exploitable partial
111135 # (single entry) inband SQL injection position with negative
112136 # parameter value
113137 if not isinstance (kb .unionPosition , int ):
114138 return
115139 else :
116- conf . paramNegative = True
140+ setUnion ( negative = True )
117141 else :
118- conf .paramFalseCond = True
119-
120- def __forgeUserFriendlyValue (payload ):
121- value = ""
122-
123- if kb .injPlace == "GET" :
124- value = "%s?%s" % (conf .url , payload )
125- elif kb .injPlace == "POST" :
126- value = "URL:\t '%s'" % conf .url
127- value += "\n POST:\t '%s'\n " % payload
128- elif kb .injPlace == "Cookie" :
129- value = "URL:\t '%s'" % conf .url
130- value += "\n Cookie:\t '%s'\n " % payload
131- elif kb .injPlace == "User-Agent" :
132- value = "URL:\t \t '%s'" % conf .url
133- value += "\n User-Agent:\t '%s'\n " % payload
142+ setUnion (falseCond = True )
134143
135144 return value
136145
@@ -142,7 +151,6 @@ def __unionTestByNULLBruteforce(comment):
142151 """
143152
144153 columns = None
145- value = None
146154 query = agent .prefixQuery (" UNION ALL SELECT NULL" )
147155
148156 for count in range (0 , 50 ):
@@ -161,15 +169,13 @@ def __unionTestByNULLBruteforce(comment):
161169
162170 if seqMatcher >= 0.6 :
163171 columns = count + 1
164- value = __forgeUserFriendlyValue (payload )
165172
166173 break
167174
168- return value , columns
175+ return columns
169176
170177def __unionTestByOrderBy (comment ):
171178 columns = None
172- value = None
173179 prevPayload = ""
174180
175181 for count in range (1 , 51 ):
@@ -182,13 +188,11 @@ def __unionTestByOrderBy(comment):
182188 columns = count
183189
184190 elif columns :
185- value = __forgeUserFriendlyValue (prevPayload )
186-
187191 break
188192
189193 prevPayload = payload
190194
191- return value , columns
195+ return columns
192196
193197def unionTest ():
194198 """
@@ -205,25 +209,28 @@ def unionTest():
205209 infoMsg += "'%s' with %s technique" % (kb .injParameter , technique )
206210 logger .info (infoMsg )
207211
208- value = ""
212+ value = None
209213 columns = None
210214
211215 for comment in (queries [kb .dbms ].comment , "" ):
212216 if conf .uTech == "orderby" :
213- value , columns = __unionTestByOrderBy (comment )
217+ columns = __unionTestByOrderBy (comment )
214218 else :
215- value , columns = __unionTestByNULLBruteforce (comment )
219+ columns = __unionTestByNULLBruteforce (comment )
216220
217221 if columns :
218- setUnion (comment , columns )
222+ setUnion (comment = comment , count = columns )
219223
220224 break
221225
222226 if kb .unionCount :
223- __unionConfirm ()
227+ value = __unionConfirm ()
224228 else :
225229 warnMsg = "the target url is not affected by an "
226230 warnMsg += "inband sql injection vulnerability"
227231 logger .warn (warnMsg )
228232
233+ if value is None :
234+ value = ""
235+
229236 return value
0 commit comments