3535from lib .core .data import conf
3636from lib .core .data import kb
3737from lib .core .data import logger
38+ from lib .core .exception import exceptionsTuple
3839from lib .core .exception import sqlmapNotVulnerableException
3940from lib .core .session import setInjection
4041from lib .core .target import initTargetEnv
@@ -88,6 +89,9 @@ def start():
8889 check if they are dynamic and SQL injection affected
8990 """
9091
92+ if not conf .start :
93+ return
94+
9195 if conf .url :
9296 kb .targetUrls .add (( conf .url , conf .method , conf .data , conf .cookie ))
9397
@@ -105,158 +109,165 @@ def start():
105109 setCookieAsInjectable = True
106110
107111 for targetUrl , targetMethod , targetData , targetCookie in kb .targetUrls :
108- conf .url = targetUrl
109- conf .method = targetMethod
110- conf .data = targetData
111- conf .cookie = targetCookie
112- injData = []
112+ try :
113+ conf .url = targetUrl
114+ conf .method = targetMethod
115+ conf .data = targetData
116+ conf .cookie = targetCookie
117+ injData = []
118+
119+ if conf .multipleTargets :
120+ hostCount += 1
121+ message = "url %d:\n %s %s" % (hostCount , conf .method or "GET" , targetUrl )
113122
114- if conf .multipleTargets :
115- hostCount += 1
116- message = "url %d:\n %s %s" % (hostCount , conf .method or "GET" , targetUrl )
123+ if conf .cookie :
124+ message += "\n Cookie: %s" % conf .cookie
117125
118- if conf .cookie :
119- message += "\n Cookie : %s" % conf .cookie
126+ if conf .data :
127+ message += "\n POST data : %s" % conf .data
120128
121- if conf . data :
122- message += " \n POST data: %s" % conf . data
129+ message += " \n do you want to test this url? [Y/n/q]"
130+ test = readInput ( message , default = "Y" )
123131
124- message += "\n do you want to test this url? [Y/n/q]"
125- test = readInput (message , default = "Y" )
132+ if not test :
133+ pass
134+ elif test [0 ] in ("n" , "N" ):
135+ continue
136+ elif test [0 ] in ("q" , "Q" ):
137+ break
126138
127- if not test :
128- pass
129- elif test [0 ] in ("n" , "N" ):
139+ logMsg = "testing url %s" % targetUrl
140+ logger .info (logMsg )
141+
142+ initTargetEnv ()
143+ parseTargetUrl ()
144+ setupTargetEnv ()
145+
146+ if not checkConnection () or not checkString () or not checkRegexp ():
130147 continue
131- elif test [0 ] in ("q" , "Q" ):
132- break
133148
134- logMsg = "testing url %s" % targetUrl
135- logger .info (logMsg )
149+ if not conf .dropSetCookie :
150+ for _ , cookie in enumerate (conf .cj ):
151+ cookie = str (cookie )
152+ index = cookie .index (" for " )
136153
137- initTargetEnv ()
138- parseTargetUrl ()
139- setupTargetEnv ()
140-
141- if not checkConnection () or not checkString () or not checkRegexp ():
142- continue
143-
144- if not conf .dropSetCookie :
145- for _ , cookie in enumerate (conf .cj ):
146- cookie = str (cookie )
147- index = cookie .index (" for " )
148-
149- cookieStr += "%s;" % cookie [8 :index ]
150-
151- if cookieStr :
152- cookieStr = cookieStr [:- 1 ]
153-
154- if "Cookie" in conf .parameters :
155- message = "you provided an HTTP Cookie header value. "
156- message += "The target url provided its own Cookie within "
157- message += "the HTTP Set-Cookie header. Do you want to "
158- message += "continue using the HTTP Cookie values that "
159- message += "you provided? [Y/n] "
160- test = readInput (message , default = "Y" )
161-
162- if not test or test [0 ] in ("y" , "Y" ):
163- setCookieAsInjectable = False
164-
165- if setCookieAsInjectable :
166- conf .httpHeaders .append (("Cookie" , cookieStr ))
167- conf .parameters ["Cookie" ] = cookieStr
168- __paramDict = paramToDict ("Cookie" , cookieStr )
169-
170- if __paramDict :
171- conf .paramDict ["Cookie" ] = __paramDict
172- __testableParameters = True
173-
174- if not kb .injPlace or not kb .injParameter or not kb .injType :
175- if not conf .string and not conf .regexp and not conf .eRegexp :
176- # NOTE: this is not needed anymore, leaving only to display
177- # a warning message to the user in case the page is not stable
178- checkStability ()
179-
180- for place in conf .parameters .keys ():
181- if not conf .paramDict .has_key (place ):
182- continue
154+ cookieStr += "%s;" % cookie [8 :index ]
183155
184- paramDict = conf .paramDict [place ]
156+ if cookieStr :
157+ cookieStr = cookieStr [:- 1 ]
158+
159+ if "Cookie" in conf .parameters :
160+ message = "you provided an HTTP Cookie header value. "
161+ message += "The target url provided its own Cookie within "
162+ message += "the HTTP Set-Cookie header. Do you want to "
163+ message += "continue using the HTTP Cookie values that "
164+ message += "you provided? [Y/n] "
165+ test = readInput (message , default = "Y" )
166+
167+ if not test or test [0 ] in ("y" , "Y" ):
168+ setCookieAsInjectable = False
169+
170+ if setCookieAsInjectable :
171+ conf .httpHeaders .append (("Cookie" , cookieStr ))
172+ conf .parameters ["Cookie" ] = cookieStr
173+ __paramDict = paramToDict ("Cookie" , cookieStr )
174+
175+ if __paramDict :
176+ conf .paramDict ["Cookie" ] = __paramDict
177+ __testableParameters = True
185178
186- for parameter , value in paramDict .items ():
187- testSqlInj = True
179+ if not kb .injPlace or not kb .injParameter or not kb .injType :
180+ if not conf .string and not conf .regexp and not conf .eRegexp :
181+ # NOTE: this is not needed anymore, leaving only to display
182+ # a warning message to the user in case the page is not stable
183+ checkStability ()
188184
189- # Avoid dinamicity test if the user provided the
190- # parameter manually
191- if parameter in conf .testParameter :
192- pass
185+ for place in conf .parameters .keys ():
186+ if not conf .paramDict .has_key (place ):
187+ continue
193188
194- elif not checkDynParam (place , parameter , value ):
195- warnMsg = "%s parameter '%s' is not dynamic" % (place , parameter )
196- logger .warn (warnMsg )
197- testSqlInj = False
189+ paramDict = conf .paramDict [place ]
198190
199- else :
200- logMsg = "%s parameter '%s' is dynamic" % (place , parameter )
201- logger .info (logMsg )
191+ for parameter , value in paramDict .items ():
192+ testSqlInj = True
193+
194+ # Avoid dinamicity test if the user provided the
195+ # parameter manually
196+ if parameter in conf .testParameter :
197+ pass
198+
199+ elif not checkDynParam (place , parameter , value ):
200+ warnMsg = "%s parameter '%s' is not dynamic" % (place , parameter )
201+ logger .warn (warnMsg )
202+ testSqlInj = False
202203
203- if testSqlInj :
204- for parenthesis in range (0 , 4 ):
205- logMsg = "testing sql injection on %s " % place
206- logMsg += "parameter '%s' with " % parameter
207- logMsg += "%d parenthesis" % parenthesis
204+ else :
205+ logMsg = "%s parameter '%s' is dynamic" % (place , parameter )
208206 logger .info (logMsg )
209207
210- injType = checkSqlInjection (place , parameter , value , parenthesis )
208+ if testSqlInj :
209+ for parenthesis in range (0 , 4 ):
210+ logMsg = "testing sql injection on %s " % place
211+ logMsg += "parameter '%s' with " % parameter
212+ logMsg += "%d parenthesis" % parenthesis
213+ logger .info (logMsg )
211214
212- if injType :
213- injData .append ((place , parameter , injType ))
215+ injType = checkSqlInjection (place , parameter , value , parenthesis )
214216
215- break
216- else :
217- infoMsg = "%s parameter '%s' is not " % (place , parameter )
218- infoMsg += "injectable with %d parenthesis" % parenthesis
219- logger .info (infoMsg )
217+ if injType :
218+ injData .append ((place , parameter , injType ))
220219
221- if not injData :
222- warnMsg = "%s parameter '%s' is not " % (place , parameter )
223- warnMsg += "injectable"
224- logger .warn (warnMsg )
220+ break
221+ else :
222+ infoMsg = "%s parameter '%s' is not " % (place , parameter )
223+ infoMsg += "injectable with %d parenthesis" % parenthesis
224+ logger .info (infoMsg )
225225
226- if not kb .injPlace or not kb .injParameter or not kb .injType :
227- if len (injData ) == 1 :
228- injDataSelected = injData [0 ]
226+ if not injData :
227+ warnMsg = "%s parameter '%s' is not " % (place , parameter )
228+ warnMsg += "injectable"
229+ logger .warn (warnMsg )
229230
230- elif len (injData ) > 1 :
231- injDataSelected = __selectInjection (injData )
231+ if not kb .injPlace or not kb .injParameter or not kb .injType :
232+ if len (injData ) == 1 :
233+ injDataSelected = injData [0 ]
232234
233- elif conf . multipleTargets :
234- continue
235+ elif len ( injData ) > 1 :
236+ injDataSelected = __selectInjection ( injData )
235237
236- else :
237- return
238+ else :
239+ raise sqlmapNotVulnerableException , "all parameters are not injectable"
240+ return
238241
239- if injDataSelected == "Quit" :
240- return
242+ if injDataSelected == "Quit" :
243+ return
241244
242- else :
243- kb .injPlace , kb .injParameter , kb .injType = injDataSelected
244- setInjection ()
245+ else :
246+ kb .injPlace , kb .injParameter , kb .injType = injDataSelected
247+ setInjection ()
245248
246- if not conf .multipleTargets and ( not kb .injPlace or not kb .injParameter or not kb .injType ):
247- raise sqlmapNotVulnerableException , "all parameters are not injectable"
248- elif kb .injPlace and kb .injParameter and kb .injType :
249- if conf .multipleTargets :
250- message = "do you want to exploit this SQL injection? [Y/n] "
251- exploit = readInput (message , default = "Y" )
249+ elif kb .injPlace and kb .injParameter and kb .injType :
250+ if conf .multipleTargets :
251+ message = "do you want to exploit this SQL injection? [Y/n] "
252+ exploit = readInput (message , default = "Y" )
252253
253- condition = not exploit or exploit [0 ] in ("y" , "Y" )
254- else :
255- condition = True
254+ condition = not exploit or exploit [0 ] in ("y" , "Y" )
255+ else :
256+ condition = True
257+
258+ if condition :
259+ checkForParenthesis ()
260+ action ()
261+
262+ except exceptionsTuple , e :
263+ e = str (e )
256264
257- if condition :
258- checkForParenthesis ()
259- action ()
265+ if conf .multipleTargets :
266+ e += ", skipping to next url"
267+ logger .error (e )
268+ else :
269+ logger .error (e )
270+ return
260271
261272 if conf .loggedToOut :
262273 logger .info ("Fetched data logged to text files under '%s'" % conf .outputPath )
0 commit comments