-
Notifications
You must be signed in to change notification settings - Fork 1.2k
HTTP error handling in w3af
-
Sub-classes of
urllib2.URLErrorare raised by w3af when one HTTP request fails -
HTTPRequestExceptionis raised by w3af when one HTTP request fails -
ScanMustStopExceptionis raised by the extended_urllib.py when multiple HTTP requests fail in a row, potentially indicating that the remote server is unreachable. There are two important sub-classes ofScanMustStopException:-
ScanMustStopByKnownReasonExc: To be used when we know the base exception which generated many HTTP request fails -
ScanMustStopByUnknownReasonExc: To be used when the base error is unknown
-
-
ScanMustStopByUserRequestis a subclass ofScanMustStopExceptionwhich is raised when we want to stop the scan. This exception is raised by the extended_urllib.py only when the user clicks "stop" in the UI.
-
ScanMustStopByKnownReasonExc,ScanMustStopByUnknownReasonExc,HTTPRequestExceptionandScanMustStopByUserRequestare usually raised by the extended_urllib.py but might be raised in other places. -
Sub-classes of
urllib2.URLErrorare usually raised by the keep alive handler.
-
One "hidden" section where exceptions are handled is in plugins.py, where
UrlOpenerProxywill catch anyHTTPRequestExceptionexceptions and ignore them. This is useful to avoid having that try/except code in all the plugins. -
The last part of the code where exceptions before they reach the custom
ExceptionHandlerisw3afCore
All urllib2 handlers (which are used by the extended_urllib.py module) raise exceptions and might have errors, but the only place where we retry to send an HTTP request is in ExtendedUrllib._retry.
Avoid retries in any other code section, since that might lead to "multiple retries":
- Your wants to send an HTTP request using
ExtendedUrllib.send - For some reason that request fails
-
ExtendedUrllib._retryis called three times to retry sending the request - The request still fails and a
HTTPRequestExceptionis raised - Your code catches
HTTPRequestExceptionand re-sends the request. It does this in a loop, three times. - The result is that the request was sent (or at least w3af tried to) 9 times.
If all fails, w3af overrides the default python exception handler with ExceptionHandler. Ideally we should never get here, but it has proven to be a really important source of bug reports.
Related with HTTP requests, we'll reach the custom ExceptionHandler when ScanMustStopByUnknownReasonExc is raised by extended_urllib.py