diff --git a/w3af/core/controllers/auto_update/git_client.py b/w3af/core/controllers/auto_update/git_client.py index 77d57a7b7a..b446de0670 100644 --- a/w3af/core/controllers/auto_update/git_client.py +++ b/w3af/core/controllers/auto_update/git_client.py @@ -75,7 +75,7 @@ def pull(self): # or which exception would be raised. So I'm catching all and # verifying if there are conflicts in an exception and in the # case were no exceptions were raised - except Exception, e: + except Exception as e: self.handle_conflicts(latest_before_pull) msg = self.UPD_ERROR_MSG + ' The original exception was: "%s"' raise GitClientError(msg % e) diff --git a/w3af/core/controllers/auto_update/ui_wrapper.py b/w3af/core/controllers/auto_update/ui_wrapper.py index 89c9527e97..d6456c3952 100644 --- a/w3af/core/controllers/auto_update/ui_wrapper.py +++ b/w3af/core/controllers/auto_update/ui_wrapper.py @@ -63,7 +63,7 @@ def update(self): self._handle_update_output(resp) except KeyboardInterrupt: pass - except Exception, ex: + except Exception as ex: self._logger('An error occurred while updating: "%s"' % ex) # TODO: Please read https://github.com/andresriancho/w3af/issues/6 diff --git a/w3af/core/controllers/core_helpers/consumers/audit.py b/w3af/core/controllers/core_helpers/consumers/audit.py index 2f4290e46b..8c66e19351 100644 --- a/w3af/core/controllers/core_helpers/consumers/audit.py +++ b/w3af/core/controllers/core_helpers/consumers/audit.py @@ -76,7 +76,7 @@ def _teardown(self): ' scan must stop exception was raised') self._log_end_took(msg_fmt, start_time, plugin) - except Exception, e: + except Exception as e: msg_fmt = ('Spent %.2f seconds running %s.end() until an' ' unhandled exception was found') self._log_end_took(msg_fmt, start_time, plugin) @@ -110,7 +110,7 @@ def _consume(self, fuzzable_request): """ try: orig_resp = self.get_original_response(fuzzable_request) - except Exception, e: + except Exception as e: self.handle_exception('audit', 'audit.get_original_response()', 'audit.get_original_response()', e) @@ -147,7 +147,7 @@ def _run_observers(self, fuzzable_request): try: for observer in self._observers: observer.audit(self, fuzzable_request) - except Exception, e: + except Exception as e: self.handle_exception('audit', 'audit._run_observers()', 'audit._run_observers()', e) @@ -175,10 +175,12 @@ def _audit(self, function_id, plugin, fuzzable_request, orig_resp, debugging_id) try: plugin.audit_with_copy(fuzzable_request, orig_resp, debugging_id) + except Exception, e: self.handle_exception('audit', plugin.get_name(), fuzzable_request, e) + took_line.send() diff --git a/w3af/core/controllers/core_helpers/consumers/auth.py b/w3af/core/controllers/core_helpers/consumers/auth.py index 4b0e39bc70..88333bd16b 100644 --- a/w3af/core/controllers/core_helpers/consumers/auth.py +++ b/w3af/core/controllers/core_helpers/consumers/auth.py @@ -110,7 +110,7 @@ def _login(self, function_id): try: if not plugin.has_active_session(): plugin.login() - except Exception, e: + except Exception as e: self.handle_exception('auth', plugin.get_name(), None, e) took_line.send() diff --git a/w3af/core/controllers/core_helpers/consumers/bruteforce.py b/w3af/core/controllers/core_helpers/consumers/bruteforce.py index 9aecf1564a..c66ef35057 100644 --- a/w3af/core/controllers/core_helpers/consumers/bruteforce.py +++ b/w3af/core/controllers/core_helpers/consumers/bruteforce.py @@ -70,7 +70,7 @@ def _teardown(self): ' scan must stop exception was raised') self._log_end_took(msg_fmt, start_time, plugin) - except Exception, e: + except Exception as e: msg_fmt = ('Spent %.2f seconds running %s.end() until an' ' unhandled exception was found') self._log_end_took(msg_fmt, start_time, plugin) @@ -92,7 +92,7 @@ def _run_observers(self, fuzzable_request): try: for observer in self._observers: observer.bruteforce(self, fuzzable_request) - except Exception, e: + except Exception as e: self.handle_exception('bruteforce', 'bruteforce._run_observers()', 'bruteforce._run_observers()', e) @@ -146,7 +146,7 @@ def _bruteforce(self, function_id, plugin, fuzzable_request): # TODO: Report progress to the core. try: new_frs = plugin.bruteforce_wrapper(fuzzable_request) - except Exception, e: + except Exception as e: self.handle_exception('bruteforce', plugin.get_name(), fuzzable_request, e) else: diff --git a/w3af/core/controllers/core_helpers/consumers/crawl_infrastructure.py b/w3af/core/controllers/core_helpers/consumers/crawl_infrastructure.py index 9980922c31..5f13c44795 100644 --- a/w3af/core/controllers/core_helpers/consumers/crawl_infrastructure.py +++ b/w3af/core/controllers/core_helpers/consumers/crawl_infrastructure.py @@ -166,7 +166,7 @@ def _teardown(self, plugin=None): ' scan must stop exception was raised') self._log_end_took(msg_fmt, start_time, plugin) - except Exception, e: + except Exception as e: msg_fmt = ('Spent %.2f seconds running %s.end() until an' ' unhandled exception was found') self._log_end_took(msg_fmt, start_time, plugin) @@ -212,7 +212,7 @@ def _run_observers(self, fuzzable_request): try: for observer in self._observers: observer.crawl(self, fuzzable_request) - except Exception, e: + except Exception as e: self.handle_exception('CrawlInfrastructure', 'CrawlInfrastructure._run_observers()', 'CrawlInfrastructure._run_observers()', e) @@ -534,11 +534,19 @@ def _discover_worker(self, function_id, plugin, fuzzable_request): # that is implemented by raising a RunOnce # exception self._remove_discovery_plugin(plugin) + except Exception, e: self.handle_exception(plugin.get_type(), plugin.get_name(), fuzzable_request, e) + + except Exception, e: + self.handle_exception(plugin.get_type(), + plugin.get_name(), + fuzzable_request, + e) + else: # The plugin output is retrieved and analyzed by the # _route_plugin_results method, here we just verify that the plugin diff --git a/w3af/core/controllers/core_helpers/consumers/grep.py b/w3af/core/controllers/core_helpers/consumers/grep.py index c404a2642e..42c59b9361 100644 --- a/w3af/core/controllers/core_helpers/consumers/grep.py +++ b/w3af/core/controllers/core_helpers/consumers/grep.py @@ -126,7 +126,9 @@ def _teardown(self): try: plugin.end() + except Exception as exception: + msg = 'An exception was found while running %s.end(): "%s"' args = (plugin.get_name(), exception) om.out.debug(msg % args) @@ -290,6 +292,7 @@ def _run_all_plugins(self, http_response_id): def _get_plugin_from_name(self, plugin_name): plugin = self._consumer_plugin_dict.get(plugin_name, None) + if plugin is None: msg = ('Internal error in grep consumer: plugin with name %s' ' does not exist in dict.') @@ -298,6 +301,7 @@ def _get_plugin_from_name(self, plugin_name): return plugin + def _run_one_plugin(self, plugin_name, http_response_id): """ :param plugin_name: Grep plugin name to run diff --git a/w3af/core/controllers/core_helpers/consumers/seed.py b/w3af/core/controllers/core_helpers/consumers/seed.py index a889893301..e8719cf592 100644 --- a/w3af/core/controllers/core_helpers/consumers/seed.py +++ b/w3af/core/controllers/core_helpers/consumers/seed.py @@ -107,7 +107,7 @@ def seed_output_queue(self, target_urls): except HTTPRequestException, hre: msg = 'The target URL: "%s" is unreachable. Exception: "%s".' om.out.error(msg % (url, hre)) - except Exception, e: + except Exception as e: msg = ('The target URL: "%s" is unreachable because of an' ' unhandled exception. Error description: "%s". See' ' debug output for more information.\n' diff --git a/w3af/core/controllers/core_helpers/consumers/tests/test_base_consumer.py b/w3af/core/controllers/core_helpers/consumers/tests/test_base_consumer.py index 17334489d3..19c1f578d2 100644 --- a/w3af/core/controllers/core_helpers/consumers/tests/test_base_consumer.py +++ b/w3af/core/controllers/core_helpers/consumers/tests/test_base_consumer.py @@ -38,7 +38,7 @@ def test_handle_exception(self): fr = FuzzableRequest(url) try: raise Exception() - except Exception, e: + except Exception as e: self.bc.handle_exception('audit', 'sqli', fr, e) exception_data = self.bc.out_queue.get() diff --git a/w3af/core/controllers/core_helpers/profiles.py b/w3af/core/controllers/core_helpers/profiles.py index c27472e090..61d7275b60 100644 --- a/w3af/core/controllers/core_helpers/profiles.py +++ b/w3af/core/controllers/core_helpers/profiles.py @@ -143,7 +143,7 @@ def use_profile(self, profile_name, workdir=None): # Set the misc and http settings try: profile_misc_settings = profile_inst.get_misc_settings() - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = ('Setting the framework misc-settings raised an exception' ' due to unknown or invalid configuration parameters. %s') error_messages.append(msg % e) @@ -161,7 +161,7 @@ def use_profile(self, profile_name, workdir=None): try: http_settings = profile_inst.get_http_settings() - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = ('Setting the framework http-settings raised an exception' ' due to unknown or invalid configuration parameters. %s') error_messages.append(msg % e) diff --git a/w3af/core/controllers/core_helpers/strategy.py b/w3af/core/controllers/core_helpers/strategy.py index a41a53b069..04470c5a50 100644 --- a/w3af/core/controllers/core_helpers/strategy.py +++ b/w3af/core/controllers/core_helpers/strategy.py @@ -133,7 +133,7 @@ def start(self): self._fuzzable_request_router() - except Exception, e: + except Exception as e: om.out.debug('strategy.start() found exception "%s"' % e) exc_info = sys.exc_info() @@ -141,7 +141,7 @@ def start(self): try: # Terminate the consumers, exceptions at this level stop the scan self.terminate() - except Exception, e: + except Exception as e: msg = 'strategy.start() found exception while terminating workers "%s"' om.out.debug(msg % e) finally: @@ -191,6 +191,7 @@ def terminate(self): om.out.debug('Calling terminate() on %s consumer' % consumer) start = time.time() + # Set it immediately to None to avoid any race conditions where # the terminate() method is called twice (from different # threads) and before the first call finishes @@ -211,6 +212,7 @@ def terminate(self): args = (consumer, spent) om.out.debug('terminate() on %s consumer took %.2f seconds' % args) + self.set_consumers_to_none() def join_all_consumers(self): @@ -491,7 +493,7 @@ def verify_target_server_up(self): except ScanMustStopByUserRequest: # Not a real error, the user stopped the scan raise - except Exception, e: + except Exception as e: dbg = 'Exception found during verify_target_server_up: "%s"' om.out.debug(dbg % e) @@ -582,10 +584,12 @@ def alert_if_target_is_301_all(self): except ScanMustStopByUserRequest: # Not a real error, the user stopped the scan raise + except Exception, e: msg = 'Exception found during alert_if_target_is_301_all(): "%s"' om.out.debug(msg % e) raise ScanMustStopException(msg % e) + else: if http_response.does_redirect_outside_target(): site_does_redirect = True @@ -617,7 +621,7 @@ def _setup_404_detection(self): response = self._w3af_core.uri_opener.GET(url, cache=True) except ScanMustStopByUserRequest: raise - except Exception, e: + except Exception as e: msg = ('Failed to send HTTP request to the configured target' ' URL "%s", the original exception was: "%s" (%s).') args = (url, e, e.__class__.__name__) @@ -627,7 +631,7 @@ def _setup_404_detection(self): current_target_is_404 = is_404(response) except ScanMustStopByUserRequest: raise - except Exception, e: + except Exception as e: msg = ('Failed to initialize the 404 detection using HTTP' ' response from "%s", the original exception was: "%s"' ' (%s).') diff --git a/w3af/core/controllers/core_helpers/tests/test_exception_handler.py b/w3af/core/controllers/core_helpers/tests/test_exception_handler.py index cb98c08400..9f90e557a3 100644 --- a/w3af/core/controllers/core_helpers/tests/test_exception_handler.py +++ b/w3af/core/controllers/core_helpers/tests/test_exception_handler.py @@ -54,7 +54,7 @@ def test_handle_one(self): try: raise Exception('unittest') - except Exception, e: + except Exception as e: exec_info = sys.exc_info() enabled_plugins = '' self.exception_handler.handle(self.status, @@ -89,7 +89,7 @@ def test_handle_multiple(self): for _ in xrange(10): try: raise Exception('unittest') - except Exception, e: + except Exception as e: exec_info = sys.exc_info() enabled_plugins = '' self.exception_handler.handle(self.status, e, exec_info, @@ -115,7 +115,7 @@ def test_get_unique_exceptions(self): for _ in xrange(10): try: raise Exception('unittest') - except Exception, e: + except Exception as e: exec_info = sys.exc_info() enabled_plugins = '' self.exception_handler.handle(self.status, e, exec_info, @@ -145,7 +145,7 @@ def test2(): def test(ehandler): try: test2() - except Exception, e: + except Exception as e: exec_info = sys.exc_info() enabled_plugins = '' ehandler.handle(self.status, e, exec_info, enabled_plugins) @@ -181,7 +181,7 @@ def test2(): def test(ehandler): try: test2() - except Exception, e: + except Exception as e: exec_info = sys.exc_info() enabled_plugins = '' ehandler.handle(self.status, e, exec_info, enabled_plugins) diff --git a/w3af/core/controllers/daemons/proxy/handler.py b/w3af/core/controllers/daemons/proxy/handler.py index 3123955349..77911dade6 100644 --- a/w3af/core/controllers/daemons/proxy/handler.py +++ b/w3af/core/controllers/daemons/proxy/handler.py @@ -185,7 +185,7 @@ def handle_request_in_thread(self, flow): try: # Send the request to the remote webserver http_response = self._send_http_request(http_request) - except Exception, e: + except Exception as e: trace = str(traceback.format_exc()) http_response = self._create_error_response(http_request, None, e, trace=trace) diff --git a/w3af/core/controllers/daemons/proxy/intercept_handler.py b/w3af/core/controllers/daemons/proxy/intercept_handler.py index c9d2fa9a87..afb5dff7b9 100644 --- a/w3af/core/controllers/daemons/proxy/intercept_handler.py +++ b/w3af/core/controllers/daemons/proxy/intercept_handler.py @@ -50,7 +50,7 @@ def handle_request_in_thread(self, flow): else: # Send the request to the remote webserver http_response = self._send_http_request(http_request) - except Exception, e: + except Exception as e: trace = str(traceback.format_exc()) http_response = self._create_error_response(http_request, None, e, trace=trace) @@ -95,7 +95,7 @@ def on_request_edit_finished(self, orig_http_request, head, post_data): try: http_request = http_request_parser(head, post_data) http_response = self._send_http_request(http_request) - except Exception, e: + except Exception as e: trace = str(traceback.format_exc()) http_response = self._create_error_response(orig_http_request, None, e, trace=trace) diff --git a/w3af/core/controllers/daemons/proxy/tests/test_intercept_proxy.py b/w3af/core/controllers/daemons/proxy/tests/test_intercept_proxy.py index ce0a94210c..3cf231db97 100644 --- a/w3af/core/controllers/daemons/proxy/tests/test_intercept_proxy.py +++ b/w3af/core/controllers/daemons/proxy/tests/test_intercept_proxy.py @@ -149,7 +149,7 @@ def send_request(_id, proxy_opener, results, exceptions): results.put(he) except KeyboardInterrupt, k: exceptions.put(k) - except Exception, e: + except Exception as e: exceptions.put(e) else: results.put(response) diff --git a/w3af/core/controllers/daemons/webserver.py b/w3af/core/controllers/daemons/webserver.py index 8770c361c2..3f602d1fd4 100644 --- a/w3af/core/controllers/daemons/webserver.py +++ b/w3af/core/controllers/daemons/webserver.py @@ -129,7 +129,7 @@ def do_GET(self): except IOError: try: self.send_error(404, 'File Not Found: %s' % self.path) - except Exception, e: + except Exception as e: om.out.debug('[webserver] Exception: ' + str(e)) else: try: @@ -144,7 +144,7 @@ def do_GET(self): self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(f.read()) - except Exception, e: + except Exception as e: om.out.debug('[webserver] Exception: ' + str(e)) f.close() diff --git a/w3af/core/controllers/easy_contribution/github_issues.py b/w3af/core/controllers/easy_contribution/github_issues.py index c778862790..7d53846f8b 100644 --- a/w3af/core/controllers/easy_contribution/github_issues.py +++ b/w3af/core/controllers/easy_contribution/github_issues.py @@ -90,7 +90,7 @@ def __init__(self, user_or_token, password=None): def login(self): try: self.gh = Github(self._user_or_token, self._password) - except GithubException, ex: + except GithubException as ex: # Not sure when we get here, but just in case... raise LoginFailed(str(ex)) else: diff --git a/w3af/core/controllers/misc/decorators.py b/w3af/core/controllers/misc/decorators.py index ffcf5dd533..c512af1b50 100644 --- a/w3af/core/controllers/misc/decorators.py +++ b/w3af/core/controllers/misc/decorators.py @@ -85,7 +85,7 @@ def f_retry(*args, **kwargs): while mtries >= 0: try: rv = f(*args, **kwargs) - except Exception, ex: + except Exception as ex: # Ok, fail! if mtries == 0: if exc_class: diff --git a/w3af/core/controllers/misc/factory.py b/w3af/core/controllers/misc/factory.py index 1b8b9c242c..380a2240a5 100644 --- a/w3af/core/controllers/misc/factory.py +++ b/w3af/core/controllers/misc/factory.py @@ -76,7 +76,7 @@ def factory(module_name, *args): # Raise so the user sees the whole traceback raise - except Exception, e: + except Exception as e: msg = 'There was an error while importing %s: "%s".' raise BaseFrameworkException(msg % (module_name, e)) @@ -95,7 +95,7 @@ def factory(module_name, *args): try: inst = a_class(*args) - except Exception, e: + except Exception as e: msg = ('Failed to create an instance of "%s". The original exception' ' was: "%s". Traceback for this error:\n%s') msg = msg % (class_name, e, traceback.format_exc()) diff --git a/w3af/core/controllers/output_manager/manager.py b/w3af/core/controllers/output_manager/manager.py index 298b5b89fb..2b0c926995 100644 --- a/w3af/core/controllers/output_manager/manager.py +++ b/w3af/core/controllers/output_manager/manager.py @@ -249,7 +249,7 @@ def __inner_flush_plugin_output(self, o_plugin): try: o_plugin.flush() - except Exception, exception: + except Exception as exception: self._handle_output_plugin_exception(o_plugin, exception) finally: o_plugin.is_running_flush = False @@ -443,7 +443,7 @@ def _call_output_plugins_action(self, action_name, *args, **kwds): try: opl_func_ptr = getattr(o_plugin, action_name) apply(opl_func_ptr, args, kwds) - except Exception, exception: + except Exception as exception: self._handle_output_plugin_exception(o_plugin, exception) def set_output_plugin_inst(self, output_plugin_inst): diff --git a/w3af/core/controllers/payload_transfer/payload_transfer_factory.py b/w3af/core/controllers/payload_transfer/payload_transfer_factory.py index e803a1ff9f..0aabef09b6 100644 --- a/w3af/core/controllers/payload_transfer/payload_transfer_factory.py +++ b/w3af/core/controllers/payload_transfer/payload_transfer_factory.py @@ -79,7 +79,7 @@ def get_transfer_handler(self, inbound_port=None): 'methods can be used. Trying inband echo transfer method.' ' Error: "%s"') om.out.error(msg % w3) - except Exception, e: + except Exception as e: om.out.error('Unhandled exception: "%s"' % e) else: to_test.append(ReverseFTP(self._exec_method, os, inbound_port)) diff --git a/w3af/core/controllers/plugins/audit_plugin.py b/w3af/core/controllers/plugins/audit_plugin.py index c0ea00a403..1ab9069415 100644 --- a/w3af/core/controllers/plugins/audit_plugin.py +++ b/w3af/core/controllers/plugins/audit_plugin.py @@ -72,7 +72,7 @@ def audit_return_vulns(self, fuzzable_request): try: orig_response = self.get_original_response(fuzzable_request) self.audit_with_copy(fuzzable_request, orig_response, debugging_id) - except Exception, e: + except Exception as e: om.out.error(str(e)) finally: self._store_kb_vulns = False diff --git a/w3af/core/controllers/plugins/tests/test_404_errors.py b/w3af/core/controllers/plugins/tests/test_404_errors.py index 2994746d64..8aa03650ca 100644 --- a/w3af/core/controllers/plugins/tests/test_404_errors.py +++ b/w3af/core/controllers/plugins/tests/test_404_errors.py @@ -74,7 +74,7 @@ def test_raises_other_exceptions(self): try: self.plugin.grep_wrapper(request, resp) - except Exception, e: + except Exception as e: self.assertEqual(str(e), msg) else: self.assertTrue(False, 'Expected exception, success found!') \ No newline at end of file diff --git a/w3af/core/controllers/profiling/core_stats.py b/w3af/core/controllers/profiling/core_stats.py index e42bec6ebf..a76cbdae90 100644 --- a/w3af/core/controllers/profiling/core_stats.py +++ b/w3af/core/controllers/profiling/core_stats.py @@ -87,7 +87,7 @@ def dump_data(w3af_core): 'Output manager input queue size': om.manager.get_in_queue().qsize(), 'Cache stats': get_parser_cache_stats()} - except Exception, e: + except Exception as e: exc_type, exc_value, exc_tb = sys.exc_info() tback = traceback.format_exception(exc_type, exc_value, exc_tb) diff --git a/w3af/core/controllers/profiling/extract_http_from_log.py b/w3af/core/controllers/profiling/extract_http_from_log.py index f086fd6618..35efc2c731 100755 --- a/w3af/core/controllers/profiling/extract_http_from_log.py +++ b/w3af/core/controllers/profiling/extract_http_from_log.py @@ -48,7 +48,7 @@ def extract(log_file, http_request_id): def main(args): try: request, response = extract(args.log_file, args.id) - except Exception, e: + except Exception as e: print(e) sys.exit(1) diff --git a/w3af/core/controllers/profiling/scan_log_analysis/main/watch.py b/w3af/core/controllers/profiling/scan_log_analysis/main/watch.py index 91e140cc85..71640bbc23 100644 --- a/w3af/core/controllers/profiling/scan_log_analysis/main/watch.py +++ b/w3af/core/controllers/profiling/scan_log_analysis/main/watch.py @@ -14,7 +14,7 @@ def watch(scan_log_filename, scan, function_name): output = globals()[function_name](scan_log_filename, scan) except KeyboardInterrupt: sys.exit(0) - except Exception, e: + except Exception as e: print('Exception: %s' % e) sys.exit(1) else: diff --git a/w3af/core/controllers/tests/core_test_suite/test_multiple_instances.py b/w3af/core/controllers/tests/core_test_suite/test_multiple_instances.py index 846022100d..673981b436 100644 --- a/w3af/core/controllers/tests/core_test_suite/test_multiple_instances.py +++ b/w3af/core/controllers/tests/core_test_suite/test_multiple_instances.py @@ -30,7 +30,7 @@ def start_w3af_core(exception_handler): try: w3afCore() - except Exception, e: + except Exception as e: if exception_handler: exception_handler(e) diff --git a/w3af/core/controllers/threads/pool276.py b/w3af/core/controllers/threads/pool276.py index 4cc41f47df..3e62c5be90 100644 --- a/w3af/core/controllers/threads/pool276.py +++ b/w3af/core/controllers/threads/pool276.py @@ -129,7 +129,7 @@ def worker(inqueue, outqueue, initializer=None, initargs=(), maxtasks=None): job, i, func, args, kwds = task try: result = (True, func(*args, **kwds)) - except Exception, e: + except Exception as e: result = (False, e) try: diff --git a/w3af/core/controllers/threads/silent_joinable_queue.py b/w3af/core/controllers/threads/silent_joinable_queue.py index 208de671e9..82fa8ab160 100644 --- a/w3af/core/controllers/threads/silent_joinable_queue.py +++ b/w3af/core/controllers/threads/silent_joinable_queue.py @@ -58,7 +58,7 @@ def _feed(buffer, notempty, send, writelock, close): except Exception as e: if getattr(e, 'errno', 0) == errno.EPIPE: return - except Exception, e: + except Exception as e: # Since this runs in a daemon thread the resources it uses # may be become unusable while the process is cleaning up. # We ignore errors which happen after the process has diff --git a/w3af/core/controllers/threads/threadpool.py b/w3af/core/controllers/threads/threadpool.py index 9a735870ed..170fa1fe65 100644 --- a/w3af/core/controllers/threads/threadpool.py +++ b/w3af/core/controllers/threads/threadpool.py @@ -282,7 +282,7 @@ def __call__(self, inqueue, outqueue, initializer=None, initargs=(), maxtasks=No try: result = (True, func(*args, **kwds)) - except Exception, e: + except Exception as e: add_traceback_string(e) result = (False, e) diff --git a/w3af/core/controllers/vdaemon/pe.py b/w3af/core/controllers/vdaemon/pe.py index 7e3c2f73dd..2ffe44882c 100644 --- a/w3af/core/controllers/vdaemon/pe.py +++ b/w3af/core/controllers/vdaemon/pe.py @@ -52,7 +52,7 @@ def dump(self): """ try: template = file(self._templateFileName, 'r').read() - except Exception, e: + except Exception as e: raise BaseFrameworkException( 'Failed to open PE template file. Exception: ' + str(e)) else: diff --git a/w3af/core/controllers/vdaemon/vdaemon.py b/w3af/core/controllers/vdaemon/vdaemon.py index 93aa70e7df..ba16df90db 100644 --- a/w3af/core/controllers/vdaemon/vdaemon.py +++ b/w3af/core/controllers/vdaemon/vdaemon.py @@ -101,14 +101,14 @@ def run(self, user_defined_parameters): try: executable_file_name = self._generate_exe(payload, msfpayload_parameters) - except Exception, e: + except Exception as e: raise BaseFrameworkException( 'Failed to create the payload file, error: "%s".' % str(e)) try: remote_file_location = self._send_exe_to_server( executable_file_name) - except BaseFrameworkException, e: + except BaseFrameworkException as e: error_msg = 'Failed to send the payload file, error: "%s".' raise BaseFrameworkException(error_msg % e) else: @@ -125,7 +125,7 @@ def run(self, user_defined_parameters): else: try: self._exec_payload(remote_file_location) - except Exception, e: + except Exception as e: raise BaseFrameworkException('Failed to execute the executable file on the server, error: %s' % e) else: om.out.console('Successfully executed the MSF payload on the remote server.') diff --git a/w3af/core/controllers/w3afAgent/client/w3afAgentClient.py b/w3af/core/controllers/w3afAgent/client/w3afAgentClient.py index 6dc63e8938..e9f6598f90 100755 --- a/w3af/core/controllers/w3afAgent/client/w3afAgentClient.py +++ b/w3af/core/controllers/w3afAgent/client/w3afAgentClient.py @@ -254,7 +254,7 @@ def gen_connections(self, number): try: s.connect((self._w3afAgentServer_address, self._w3afAgentServer_port)) - except Exception, e: + except Exception as e: log.debug('Failed to connect to the w3afAgentServer, exception: ' + str(e)) sys.exit(1) else: diff --git a/w3af/core/controllers/w3afAgent/server/w3afAgentServer.py b/w3af/core/controllers/w3afAgent/server/w3afAgentServer.py index 13733b85b6..91718b64db 100644 --- a/w3af/core/controllers/w3afAgent/server/w3afAgentServer.py +++ b/w3af/core/controllers/w3afAgent/server/w3afAgentServer.py @@ -79,7 +79,7 @@ def run(self): self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.bind((self._ip_address, self._port)) self.sock.listen(5) - except Exception, e: + except Exception as e: msg = '[w3afAgentServer] Failed to bind to %s:%s' % ( self._ip_address, self._port) msg += '. Error: "%s".' % e diff --git a/w3af/core/controllers/w3afAgent/w3afAgentManager.py b/w3af/core/controllers/w3afAgent/w3afAgentManager.py index 6f24523fc7..bbce59fe52 100644 --- a/w3af/core/controllers/w3afAgent/w3afAgentManager.py +++ b/w3af/core/controllers/w3afAgent/w3afAgentManager.py @@ -213,7 +213,7 @@ def _get_inbound_port(self): es = extrusionScanner(self._exec_method) try: inbound_port = es.get_inbound_port() - except Exception, e: + except Exception as e: om.out.error('The extrusion scan failed.') om.out.error('Error: ' + str(e)) diff --git a/w3af/core/controllers/w3afCore.py b/w3af/core/controllers/w3afCore.py index a8d8396598..a367fecc7b 100644 --- a/w3af/core/controllers/w3afCore.py +++ b/w3af/core/controllers/w3afCore.py @@ -208,7 +208,7 @@ def start(self): try: # Just in case the GUI / Console forgot to do this... self.verify_environment() - except Exception, e: + except Exception as e: error = ('verify_environment() raised an exception: "%s". This' ' should never happen. Are you (UI developer) sure that' ' you called verify_environment() *before* start() ?') @@ -285,7 +285,7 @@ def start(self): ' resolved:\n%s\n') om.out.error(error % wmse) - except Exception, e: + except Exception as e: msg = 'Unhandled exception "%s", traceback:\n%s' if hasattr(e, 'original_traceback_string'): diff --git a/w3af/core/data/db/dbms.py b/w3af/core/data/db/dbms.py index 0ed56c8709..d1cf34922a 100644 --- a/w3af/core/data/db/dbms.py +++ b/w3af/core/data/db/dbms.py @@ -481,7 +481,7 @@ def run(self): future.set_exception(dbe) - except Exception, e: + except Exception as e: dbe = DBException(str(e)) future.set_exception(dbe) diff --git a/w3af/core/data/db/history.py b/w3af/core/data/db/history.py index 9956d6d35a..7e0425c242 100644 --- a/w3af/core/data/db/history.py +++ b/w3af/core/data/db/history.py @@ -400,6 +400,7 @@ def load(self, _id=None, retry=True): except DBException, dbe: msg = ('An unexpected error occurred while searching for id "%s"' ' in table "%s". Original exception: "%s".') + raise DBException(msg % (_id, self._DATA_TABLE, dbe)) if row is not None: diff --git a/w3af/core/data/kb/exec_shell.py b/w3af/core/data/kb/exec_shell.py index 3dc63178da..89d20e61ef 100644 --- a/w3af/core/data/kb/exec_shell.py +++ b/w3af/core/data/kb/exec_shell.py @@ -149,7 +149,7 @@ def write(self, remote_filename, file_content): try: ptf = payload_transfer_factory(self.execute) self._transfer_handler = ptf.get_transfer_handler() - except BaseFrameworkException, e: + except BaseFrameworkException as e: return '%s' % e if not self._transfer_handler.can_transfer(): diff --git a/w3af/core/data/options/form_id_list_option.py b/w3af/core/data/options/form_id_list_option.py index 632f762fdd..0b7ca0efeb 100644 --- a/w3af/core/data/options/form_id_list_option.py +++ b/w3af/core/data/options/form_id_list_option.py @@ -44,6 +44,6 @@ def set_value(self, value): def validate(self, value): try: return FormIDMatcherList(value) - except Exception, e: + except Exception as e: msg = 'Invalid form ID list configured by user, error: %s.' % e raise BaseFrameworkException(msg) diff --git a/w3af/core/data/options/input_file_option.py b/w3af/core/data/options/input_file_option.py index 8df5207e20..ec6f60bea4 100644 --- a/w3af/core/data/options/input_file_option.py +++ b/w3af/core/data/options/input_file_option.py @@ -95,7 +95,7 @@ def get_value_for_profile(self, self_contained=False): if self_contained or self.should_base64_encode_file(self._value): try: return self.encode_b64_data(self._value) - except Exception, e: + except Exception as e: msg = ('An exception occurred while encoding "%s" for storing' ' into the profile: "%s"') raise BaseFrameworkException(msg % (self._value, e)) diff --git a/w3af/core/data/options/regex_option.py b/w3af/core/data/options/regex_option.py index b1fecf14c3..28d88b3daf 100644 --- a/w3af/core/data/options/regex_option.py +++ b/w3af/core/data/options/regex_option.py @@ -43,7 +43,7 @@ def set_value(self, value): def validate(self, value): try: re.compile(value) - except Exception, e: + except Exception as e: msg = 'The regular expression "%s" is invalid, the compilation'\ ' error was: "%s".' raise BaseFrameworkException(msg % (value, e)) diff --git a/w3af/core/data/options/url_list_option.py b/w3af/core/data/options/url_list_option.py index afaacc0722..e866ff4205 100644 --- a/w3af/core/data/options/url_list_option.py +++ b/w3af/core/data/options/url_list_option.py @@ -39,7 +39,7 @@ def validate(self, value): for input_url in parsed_list: try: res.append(URL(input_url)) - except Exception, e: + except Exception as e: msg = 'Invalid URL configured by user, error: %s.' % e raise BaseFrameworkException(msg) diff --git a/w3af/core/data/options/url_option.py b/w3af/core/data/options/url_option.py index 0804a9b5f2..b5cce4db0a 100644 --- a/w3af/core/data/options/url_option.py +++ b/w3af/core/data/options/url_option.py @@ -45,6 +45,6 @@ def set_value(self, value): def validate(self, value): try: return URL(value) - except Exception, e: + except Exception as e: msg = 'Invalid URL configured by user, error: %s.' % e raise BaseFrameworkException(msg) diff --git a/w3af/core/data/parsers/doc/open_api/main.py b/w3af/core/data/parsers/doc/open_api/main.py index 59521d05a9..36405f8b5f 100644 --- a/w3af/core/data/parsers/doc/open_api/main.py +++ b/w3af/core/data/parsers/doc/open_api/main.py @@ -199,6 +199,7 @@ def parse(self): fuzzable_request = request_factory.get_fuzzable_request(self.discover_fuzzable_headers, self.discover_fuzzable_url_parts) except Exception, e: + # # This is a strange situation because parsing of the OpenAPI # spec can fail awfully for one of the operations but succeed diff --git a/w3af/core/data/parsers/doc/sgml.py b/w3af/core/data/parsers/doc/sgml.py index 0ea5083364..6ba3729b3e 100644 --- a/w3af/core/data/parsers/doc/sgml.py +++ b/w3af/core/data/parsers/doc/sgml.py @@ -149,13 +149,13 @@ def start(self, tag): else: try: method(tag, tag_name, attrs) - except Exception, ex: + except Exception as ex: self._handle_exception('parsing %s tag' % tag_name, ex) try: if tag_name in self.TAGS_WITH_URLS: self._find_references(tag, tag_name, attrs) - except Exception, ex: + except Exception as ex: self._handle_exception('extracting references', ex) try: @@ -164,7 +164,7 @@ def start(self, tag): # changed it to this for performance if tag_name == 'a': self._find_emails(tag, tag_name, attrs) - except Exception, ex: + except Exception as ex: self._handle_exception('finding emails', ex) def end(self, tag): @@ -248,7 +248,7 @@ def _parse_response_body_as_string(self, resp_body, errors='strict'): for event, elem in context: try: event_map[event](elem) - except Exception, e: + except Exception as e: msg = ('Found a parser exception while handling tag "%s" with' ' event "%s". The exception was: "%s"') args = (elem.tag, event, e) diff --git a/w3af/core/data/parsers/doc/wsdl.py b/w3af/core/data/parsers/doc/wsdl.py index 13e71599d5..f8f270ed35 100644 --- a/w3af/core/data/parsers/doc/wsdl.py +++ b/w3af/core/data/parsers/doc/wsdl.py @@ -65,7 +65,7 @@ def set_wsdl(self, xmlData): self._proxy = SOAPpy.WSDL.Proxy(xmlData) except expat.ExpatError: raise BaseFrameworkException('The body content is not a WSDL.') - except Exception, e: + except Exception as e: msg = 'The body content is not a WSDL.' msg += ' Unhandled exception in SOAPpy: "' + str(e) + '".' om.out.debug(msg) diff --git a/w3af/core/data/parsers/mp_document_parser.py b/w3af/core/data/parsers/mp_document_parser.py index e726fe0fd7..8a7262b291 100644 --- a/w3af/core/data/parsers/mp_document_parser.py +++ b/w3af/core/data/parsers/mp_document_parser.py @@ -208,7 +208,7 @@ def get_document_parser_for(self, http_response): try: parser_output = load_object_from_temp_file(process_result) - except Exception, e: + except Exception as e: msg = 'Failed to deserialize sub-process result. Exception: "%s"' args = (e,) raise Exception(msg % args) @@ -302,7 +302,7 @@ def get_tags_by_filter(self, http_response, tags, yield_text=False): try: filtered_tags = load_tags_from_temp_file(process_result) - except Exception, e: + except Exception as e: msg = 'Failed to deserialize sub-process result. Exception: "%s"' args = (e,) raise Exception(msg % args) @@ -356,7 +356,7 @@ def process_document_parser(filename, debug): try: # Parse document_parser = DocumentParser(http_resp) - except Exception, e: + except Exception as e: if debug: msg = ('[mp_document_parser] PID %s finished parsing %s with' ' exception: "%s"') diff --git a/w3af/core/data/parsers/parser_cache.py b/w3af/core/data/parsers/parser_cache.py index 95aa055b54..1b0d3e70dc 100644 --- a/w3af/core/data/parsers/parser_cache.py +++ b/w3af/core/data/parsers/parser_cache.py @@ -207,7 +207,7 @@ def get_document_parser_for(self, http_response, cache=True): # Act just like when there is no parser msg = 'Reached memory usage limit parsing "%s".' % http_response.get_url() raise BaseFrameworkException(msg) - except ScanMustStopException, e: + except ScanMustStopException as e: msg = 'The document parser is in an invalid state! %s' raise ScanMustStopException(msg % e) except: @@ -340,10 +340,10 @@ def get_tags_by_filter(self, http_response, tags, yield_text=False, cache=True): # Act just like when there is no parser self._log_return_empty(http_response, 'Reached memory usage limit') return [] - except ScanMustStopException, e: + except ScanMustStopException as e: msg = 'The document parser is in an invalid state! %s' raise ScanMustStopException(msg % e) - except Exception, e: + except Exception as e: # Act just like when there is no parser msg = 'Unhandled exception running get_tags_by_filter("%s"): %s' args = (http_response.get_url(), e) diff --git a/w3af/core/data/parsers/pynarcissus/string_extractor.py b/w3af/core/data/parsers/pynarcissus/string_extractor.py index 8832ff150d..447d0c09dc 100644 --- a/w3af/core/data/parsers/pynarcissus/string_extractor.py +++ b/w3af/core/data/parsers/pynarcissus/string_extractor.py @@ -51,7 +51,7 @@ def __init__(self, js_source): try: root = parse(js_source) - except Exception, e: + except Exception as e: pass else: self.visit(root) diff --git a/w3af/core/data/parsers/tests/test_mp_document_parser.py b/w3af/core/data/parsers/tests/test_mp_document_parser.py index 717fa339eb..649547fc0a 100644 --- a/w3af/core/data/parsers/tests/test_mp_document_parser.py +++ b/w3af/core/data/parsers/tests/test_mp_document_parser.py @@ -66,7 +66,7 @@ def test_no_parser_for_images(self): try: self.mpdoc.get_document_parser_for(resp) - except Exception, e: + except Exception as e: self.assertEqual(str(e), 'There is no parser for images.') else: self.assertTrue(False, 'Expected exception!') diff --git a/w3af/core/data/profile/profile.py b/w3af/core/data/profile/profile.py index dd0e5e4e97..5652fec39d 100644 --- a/w3af/core/data/profile/profile.py +++ b/w3af/core/data/profile/profile.py @@ -64,10 +64,10 @@ def __init__(self, profname='', workdir=None): with codecs.open(profname, "rb", UTF8) as fp: try: self._config.readfp(fp) - except ConfigParser.Error, cpe: + except ConfigParser.Error as cpe: msg = 'ConfigParser error in profile: "%s". Exception: "%s"' raise BaseFrameworkException(msg % (profname, cpe)) - except Exception, e: + except Exception as e: msg = 'Unknown error in profile: "%s". Exception: "%s"' raise BaseFrameworkException(msg % (profname, e)) else: @@ -179,7 +179,7 @@ def remove(self): """ try: os.unlink(self.profile_file_name) - except Exception, e: + except Exception as e: msg = ('An exception occurred while removing the profile.' ' Exception: "%s".') raise BaseFrameworkException(msg % e) @@ -204,7 +204,7 @@ def copy(self, copy_profile_name): try: shutil.copyfile(self.profile_file_name, new_profile_path_name) - except Exception, e: + except Exception as e: msg = 'An exception occurred while copying the profile. Exception:' msg += ' "%s".' % e raise BaseFrameworkException(msg % e) diff --git a/w3af/core/data/search_engines/google.py b/w3af/core/data/search_engines/google.py index 77b2bc64d0..c62141a5cf 100644 --- a/w3af/core/data/search_engines/google.py +++ b/w3af/core/data/search_engines/google.py @@ -222,7 +222,7 @@ def _do_google_search(self): # Do the request try: resp = self._do_GET(google_url_instance) - except Exception, e: + except Exception as e: msg = 'Failed to GET google.com AJAX API: "%s"' raise BaseFrameworkException(msg % e) diff --git a/w3af/core/data/search_engines/search_engine.py b/w3af/core/data/search_engines/search_engine.py index d8b365a498..65d50784fe 100644 --- a/w3af/core/data/search_engines/search_engine.py +++ b/w3af/core/data/search_engines/search_engine.py @@ -52,7 +52,7 @@ def get_n_results(self, query, limit=0): except BaseFrameworkException, w3: om.out.debug(str(w3)) raise - except Exception, e: + except Exception as e: msg = 'An unhandled exception was found in ' \ 'search_engines.SearchEngine.search(): "%s"' % str(e) om.out.error(msg) @@ -95,7 +95,7 @@ def get_n_result_pages(self, query, limit=0): except BaseFrameworkException, w3: om.out.debug(str(w3)) raise - except Exception, e: + except Exception as e: msg = ('Unhandled exception in SearchEngine.' 'get_n_result_pages(): "%s"') om.out.debug(msg % e) diff --git a/w3af/core/data/url/extended_urllib.py b/w3af/core/data/url/extended_urllib.py index be4453bbde..c296c3307d 100644 --- a/w3af/core/data/url/extended_urllib.py +++ b/w3af/core/data/url/extended_urllib.py @@ -1357,11 +1357,11 @@ def _server_root_path_is_reachable(self, request): try: self.send(req, grep=False) - except HTTPRequestException, e: + except HTTPRequestException as e: msg = 'Remote URL %s is UNREACHABLE due to: "%s"' om.out.debug(msg % (root_url, e)) return False - except Exception, e: + except Exception as e: msg = 'Internal error makes URL %s UNREACHABLE due to: "%s"' om.out.debug(msg % (root_url, e)) return False @@ -1463,11 +1463,13 @@ def _evasion(self, request): for eplugin in self._evasion_plugins: try: request = eplugin.modify_request(request) + except BaseFrameworkException, e: msg = 'Evasion plugin "%s" failed to modify the request: "%s"' args = (eplugin.get_name(), e) om.out.error(msg % args) + return request def _grep(self, request, response): diff --git a/w3af/core/data/url/handlers/cache_backend/db.py b/w3af/core/data/url/handlers/cache_backend/db.py index 9045c0e971..6015f4d9a0 100644 --- a/w3af/core/data/url/handlers/cache_backend/db.py +++ b/w3af/core/data/url/handlers/cache_backend/db.py @@ -93,7 +93,7 @@ def store_in_cache(request, response): # Got this one during a moth scan, need to debug further raise - except Exception, ex: + except Exception as ex: args = (ex, resp.get_id(), request.get_uri(), resp.get_code()) msg = ('Exception while inserting request/response to the' ' database: "%s". The request/response that generated' diff --git a/w3af/core/data/url/handlers/cache_backend/disk.py b/w3af/core/data/url/handlers/cache_backend/disk.py index 9d1ffb27d4..7318cc93bd 100644 --- a/w3af/core/data/url/handlers/cache_backend/disk.py +++ b/w3af/core/data/url/handlers/cache_backend/disk.py @@ -60,20 +60,20 @@ def store_in_cache(request, response): headers = str(response.info()) f.write(headers) f.close() - except Exception, e: + except Exception as e: msg = 'cache.py: Could not save headers file. Exception: "%s".' raise FileException(msg % e) try: body = response.read() - except Exception, e: + except Exception as e: om.out.error('cache.py: Timeout while fetching page body.') else: try: f = open(fname + ".body", "w") f.write(body) f.close() - except Exception, e: + except Exception as e: msg = 'cache.py: Could not save body file. Exception: "%s".' raise FileException(msg % e) @@ -86,7 +86,7 @@ def store_in_cache(request, response): # store data to disk f.write(str(response.code)) f.close() - except Exception, e: + except Exception as e: msg = 'cache.py: Could not save code file. Exception: "%s".' raise FileException(msg % e) @@ -94,7 +94,7 @@ def store_in_cache(request, response): f = open(fname + ".msg", "w") f.write(str(response.msg)) f.close() - except Exception, e: + except Exception as e: msg = 'cache.py: Could not save msg file. Exception: "%s".' raise FileException(msg % e) diff --git a/w3af/core/data/url/handlers/keepalive/connections.py b/w3af/core/data/url/handlers/keepalive/connections.py index f874a9c04f..637599b2b7 100644 --- a/w3af/core/data/url/handlers/keepalive/connections.py +++ b/w3af/core/data/url/handlers/keepalive/connections.py @@ -263,7 +263,7 @@ def make_ssl_aware(self, sock, protocol): # Always close the tcp/ip connection on error sock.close() - except Exception, e: + except Exception as e: msg = "Unexpected exception occurred with protocol %s: '%s'" debug(msg % (protocol, e)) diff --git a/w3af/core/data/url/handlers/keepalive/handler.py b/w3af/core/data/url/handlers/keepalive/handler.py index f1f5d91e75..4681f29748 100644 --- a/w3af/core/data/url/handlers/keepalive/handler.py +++ b/w3af/core/data/url/handlers/keepalive/handler.py @@ -186,7 +186,7 @@ def do_open(self, req): self._cm.remove_connection(conn, reason='socket error') raise - except Exception, e: + except Exception as e: # We better discard this connection, we don't even know what happen! reason = 'unexpected exception "%s"' % e self._cm.remove_connection(conn, reason=reason) @@ -214,7 +214,7 @@ def do_open(self, req): # https://github.com/andresriancho/w3af/issues/2074 self._cm.remove_connection(conn, reason='http connection died') raise HTTPRequestException('The HTTP connection died') - except Exception, e: + except Exception as e: # We better discard this connection, we don't even know what happen! reason = 'unexpected exception while reading "%s"' % e self._cm.remove_connection(conn, reason=reason) @@ -285,7 +285,7 @@ def _reuse_connection(self, conn, req, host): self._cm.remove_connection(conn, reason='OpenSSL.SSL.SysCallError') resp = None reason = e - except Exception, e: + except Exception as e: # adding this block just in case we've missed something we will # still raise the exception, but lets try and close the connection # and remove it first. We previously got into a nasty loop where diff --git a/w3af/core/data/url/tests/helpers/ssl_daemon.py b/w3af/core/data/url/tests/helpers/ssl_daemon.py index c85d28c0b4..2dbbc6a288 100644 --- a/w3af/core/data/url/tests/helpers/ssl_daemon.py +++ b/w3af/core/data/url/tests/helpers/ssl_daemon.py @@ -102,7 +102,7 @@ def accept(self): #print 'Connection from %s port %s, sending HTTP response' % fromaddr try: newsocket.send(self.http_response) - except Exception, e: + except Exception as e: self.errors.append(e) #print 'Failed to send HTTP response to client: "%s"' % e finally: diff --git a/w3af/core/data/url/tests/test_xurllib.py b/w3af/core/data/url/tests/test_xurllib.py index e4817a6c4e..f7c4e92034 100644 --- a/w3af/core/data/url/tests/test_xurllib.py +++ b/w3af/core/data/url/tests/test_xurllib.py @@ -199,7 +199,7 @@ def test_url_port_not_http(self): try: self.uri_opener.GET(url) - except HTTPRequestException, hre: + except HTTPRequestException as hre: self.assertEqual(hre.value, "Bad HTTP response status line: ''") else: self.assertTrue(False, 'Expected HTTPRequestException.') @@ -222,10 +222,10 @@ def test_url_port_not_http_many(self): self.uri_opener.GET(url) except HTTPRequestException: http_request_e += 1 - except ScanMustStopException, smse: + except ScanMustStopException as smse: scan_must_stop_e += 1 break - except Exception, e: + except Exception as e: msg = 'Not expecting "%s".' self.assertTrue(False, msg % e.__class__.__name__) diff --git a/w3af/core/data/url/tests/test_xurllib_error_handling.py b/w3af/core/data/url/tests/test_xurllib_error_handling.py index e67c82e682..01198b00f9 100644 --- a/w3af/core/data/url/tests/test_xurllib_error_handling.py +++ b/w3af/core/data/url/tests/test_xurllib_error_handling.py @@ -81,7 +81,7 @@ def test_increasing_delay_on_errors(self): self.uri_opener.GET(url, cache=False) except HTTPRequestException: http_exception_count += 1 - except Exception, e: + except Exception as e: msg = 'Not expecting: "%s"' self.assertTrue(False, msg % e.__class__.__name__) else: @@ -166,7 +166,7 @@ def test_exception_is_raised_always_after_stop(self): http_exception_count += 1 except ScanMustStopByKnownReasonExc, smse: break - except Exception, e: + except Exception as e: msg = 'Not expecting: "%s"' self.assertTrue(False, msg % e.__class__.__name__) else: diff --git a/w3af/core/data/url/tests/test_xurllib_timeout.py b/w3af/core/data/url/tests/test_xurllib_timeout.py index f291d0e8a4..9eb2c18d5e 100644 --- a/w3af/core/data/url/tests/test_xurllib_timeout.py +++ b/w3af/core/data/url/tests/test_xurllib_timeout.py @@ -69,9 +69,9 @@ def test_timeout(self): try: self.uri_opener.GET(url) - except HTTPRequestException, hre: + except HTTPRequestException as hre: self.assertEqual(hre.message, 'HTTP timeout error') - except Exception, e: + except Exception as e: msg = 'Not expecting: "%s"' self.assertTrue(False, msg % e.__class__.__name__) else: @@ -126,14 +126,14 @@ def test_timeout_many(self): for _ in xrange(MAX_ERROR_COUNT): try: self.uri_opener.GET(url) - except HTTPRequestException, hre: + except HTTPRequestException as hre: http_request_e += 1 self.assertEqual(hre.message, 'HTTP timeout error') except ScanMustStopException: scan_stop_e += 1 self.assertTrue(True) break - except Exception, e: + except Exception as e: msg = 'Not expecting: "%s"' self.assertTrue(False, msg % e.__class__.__name__) else: diff --git a/w3af/core/ui/api/resources/error_handlers.py b/w3af/core/ui/api/resources/error_handlers.py index a3af0070b5..2defc94901 100644 --- a/w3af/core/ui/api/resources/error_handlers.py +++ b/w3af/core/ui/api/resources/error_handlers.py @@ -70,7 +70,7 @@ def error_500_handler(error): 'function_name': function_name, 'exception_type': error.__class__.__name__, 'please': new_issue}) - except Exception, e: + except Exception as e: # I don't want to fail in the exception handler response = jsonify({'code': 500, 'exception': str(error), diff --git a/w3af/core/ui/api/resources/exceptions.py b/w3af/core/ui/api/resources/exceptions.py index 6020ce62c7..07e260c94c 100644 --- a/w3af/core/ui/api/resources/exceptions.py +++ b/w3af/core/ui/api/resources/exceptions.py @@ -121,7 +121,7 @@ def exception_creator(scan_id): try: raise Exception('unittest') - except Exception, exception: + except Exception as exception: exec_info = sys.exc_info() enabled_plugins = '' diff --git a/w3af/core/ui/api/resources/scans.py b/w3af/core/ui/api/resources/scans.py index 2b05663fd8..0786a1f671 100644 --- a/w3af/core/ui/api/resources/scans.py +++ b/w3af/core/ui/api/resources/scans.py @@ -80,7 +80,7 @@ def start_scan(): try: w3af_core.profiles.use_profile(scan_profile_file_name, workdir=profile_path) - except BaseFrameworkException, bfe: + except BaseFrameworkException as bfe: abort(400, str(bfe)) finally: remove_temp_profile(scan_profile_file_name) @@ -102,7 +102,7 @@ def start_scan(): try: target_option.set_value([URL(u) for u in target_urls]) w3af_core.target.set_options(target_options) - except BaseFrameworkException, bfe: + except BaseFrameworkException as bfe: abort(400, str(bfe)) scan_id = get_new_scan_id() diff --git a/w3af/core/ui/api/tests/test_exceptions.py b/w3af/core/ui/api/tests/test_exceptions.py index 931ce251d6..1b66af4331 100644 --- a/w3af/core/ui/api/tests/test_exceptions.py +++ b/w3af/core/ui/api/tests/test_exceptions.py @@ -69,4 +69,4 @@ def test_query_exceptions(self): response = self.app.get('/scans/%s/exceptions/0' % scan_id, headers=self.HEADERS) - self.assertIn('traceback', json.loads(response.data)) \ No newline at end of file + self.assertIn('traceback', json.loads(response.data)) diff --git a/w3af/core/ui/api/utils/scans.py b/w3af/core/ui/api/utils/scans.py index 68619ee1c9..86297bcbc2 100644 --- a/w3af/core/ui/api/utils/scans.py +++ b/w3af/core/ui/api/utils/scans.py @@ -80,7 +80,7 @@ def start_scan_helper(scan_info): # Start the scan! w3af_core.verify_environment() w3af_core.start() - except Exception, e: + except Exception as e: scan_info.exception = e try: w3af_core.stop() diff --git a/w3af/core/ui/console/config.py b/w3af/core/ui/console/config.py index 248e37ca07..5220fba735 100644 --- a/w3af/core/ui/console/config.py +++ b/w3af/core/ui/console/config.py @@ -115,7 +115,7 @@ def _cmd_set(self, params): try: self._options[name].set_value(value) self._unsaved_options[name] = value - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.error(str(e)) else: if value not in self._memory[name]: @@ -151,7 +151,7 @@ def _cmd_save(self, tokens): self._configurable.get_name(), self._options) - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = 'Identified an error with the user-defined settings:\n\n'\ ' - %s \n\n'\ 'No information has been saved.' @@ -163,7 +163,7 @@ def _cmd_save(self, tokens): def _cmd_back(self, tokens): try: self._cmd_save(tokens) - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.error(str(e)) return self._console.back diff --git a/w3af/core/ui/console/console_ui.py b/w3af/core/ui/console/console_ui.py index 99d4ec0938..69fd5fd34f 100644 --- a/w3af/core/ui/console/console_ui.py +++ b/w3af/core/ui/console/console_ui.py @@ -161,7 +161,7 @@ def sh(self, name='w3af', callback=None): try: c = term.getch() self._handleKey(c) - except Exception, e: + except Exception as e: om.out.console(str(e)) term.set_raw_input_mode(False) @@ -230,7 +230,7 @@ def _handleKey(self, key): self._handlers[key]() else: self._paste(key) - except Exception, e: + except Exception as e: # TODO traceback.print_exc() @@ -290,7 +290,7 @@ def _execute(self): menu = None self.exit() - except BaseFrameworkException, e: + except BaseFrameworkException as e: menu = None om.out.console(e.value) diff --git a/w3af/core/ui/console/exploit.py b/w3af/core/ui/console/exploit.py index ac2abd2c82..5cb5e7ea8a 100644 --- a/w3af/core/ui/console/exploit.py +++ b/w3af/core/ui/console/exploit.py @@ -154,7 +154,7 @@ def sortfunc(x, y): try: self._exploit(ap.get_name( ), vuln_obj.get_id(), show_list=False) - except BaseFrameworkException, w: + except BaseFrameworkException as w: continue_exploiting = True om.out.console(str(w)) else: @@ -202,7 +202,7 @@ def _exploit(self, plugin_name, params, show_list=True): try: response = plugin.can_exploit(vuln_to_exploit) - except BaseFrameworkException, e: + except BaseFrameworkException as e: raise e else: if not response: @@ -327,7 +327,7 @@ def _callback(self, command): response = shell.generic_user_input(command, params) except BaseFrameworkException: raise - except Exception, e: + except Exception as e: msg = 'The "%s" plugin failed to execute the user command,'\ ' exception: "%s".' om.out.error(msg % (self._plugin.get_name(), e)) diff --git a/w3af/core/ui/console/io/console.py b/w3af/core/ui/console/io/console.py index 6b161485aa..18b1b28e11 100644 --- a/w3af/core/ui/console/io/console.py +++ b/w3af/core/ui/console/io/console.py @@ -134,12 +134,12 @@ def terminal_width(): import tty import termios from w3af.core.ui.console.io.unixctrl import * -except Exception, e: +except Exception as e: # We aren't on unix ! try: import msvcrt from w3af.core.ui.console.io.winctrl import * - except Exception, a: + except Exception as a: print str(e + '\n' + a) # We arent on windows nor unix raise BaseFrameworkException( diff --git a/w3af/core/ui/console/io/unixctrl.py b/w3af/core/ui/console/io/unixctrl.py index 9b02f01e5d..3511a34ab9 100644 --- a/w3af/core/ui/console/io/unixctrl.py +++ b/w3af/core/ui/console/io/unixctrl.py @@ -73,7 +73,7 @@ def set_raw_input_mode(raw): try: old_settings = termios.tcgetattr(fd) tty.setraw(sys.stdin.fileno()) - except Exception, e: + except Exception as e: om.out.console('termios error: ' + str(e)) elif not (raw or old_settings is None): @@ -82,7 +82,7 @@ def set_raw_input_mode(raw): termios.TCSADRAIN, old_settings) old_settings = None - except Exception, e: + except Exception as e: om.out.console('termios error: ' + str(e)) diff --git a/w3af/core/ui/console/kbMenu.py b/w3af/core/ui/console/kbMenu.py index f6a257baee..ddbfc8227d 100644 --- a/w3af/core/ui/console/kbMenu.py +++ b/w3af/core/ui/console/kbMenu.py @@ -131,7 +131,7 @@ def _cmd_back(self, tokens): try: self._configurable.store_in_kb() - except Exception, e: + except Exception as e: msg = 'Failed to store "%s" in the knowledge base because of a'\ ' configuration error at: "%s".' om.out.console(msg % (vuln_name, e)) diff --git a/w3af/core/ui/console/plugins.py b/w3af/core/ui/console/plugins.py index af3bc7344b..a3c4731f24 100644 --- a/w3af/core/ui/console/plugins.py +++ b/w3af/core/ui/console/plugins.py @@ -121,7 +121,7 @@ def __init__(self, name, console, w3af, parent): try: options = self._w3af.plugins.get_plugin_inst( self._name, p).get_options() - except Exception, e: + except Exception as e: om.out.error('Error while reading plugin options: "%s"' % e) sys.exit(-8) else: diff --git a/w3af/core/ui/console/profiles.py b/w3af/core/ui/console/profiles.py index fdab454ffa..8ff54d8110 100644 --- a/w3af/core/ui/console/profiles.py +++ b/w3af/core/ui/console/profiles.py @@ -60,7 +60,7 @@ def _cmd_use(self, params): try: self._w3af.profiles.use_profile(profile, workdir=workdir) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: om.out.console(str(w3)) om.out.console('The plugins configured by the scan profile have ' @@ -115,7 +115,7 @@ def _cmd_save_as(self, params): # Validate the profile name try: Profile.is_valid_profile_name(profile_name) - except BaseFrameworkException, bfe: + except BaseFrameworkException as bfe: om.out.console('%s' % bfe) return diff --git a/w3af/core/ui/console/rootMenu.py b/w3af/core/ui/console/rootMenu.py index 25db69e9db..0aeef24c36 100644 --- a/w3af/core/ui/console/rootMenu.py +++ b/w3af/core/ui/console/rootMenu.py @@ -142,9 +142,9 @@ def _real_start(self): self._w3af.plugins.init_plugins() self._w3af.verify_environment() self._w3af.start() - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: om.out.error(str(w3)) - except ScanMustStopException, w3: + except ScanMustStopException as w3: om.out.error(str(w3)) except Exception: self._w3af.stop() diff --git a/w3af/core/ui/gui/clusterGraph.py b/w3af/core/ui/gui/clusterGraph.py index f08958c774..a400319abb 100644 --- a/w3af/core/ui/gui/clusterGraph.py +++ b/w3af/core/ui/gui/clusterGraph.py @@ -183,7 +183,7 @@ def _launch_graph_generator(self, widget): window = clusterGraphWidget( self.w3af, self.data, distance_function=selected_function, custom_code=custom_code) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: msg = str(w3) dlg = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg) @@ -304,7 +304,7 @@ def __init__(self, w3af, response_list, distance_function=LEVENSHTEIN, try: callable_object = self._create_callable_object(custom_code) - except Exception, e: + except Exception as e: # TODO: instead of hiding..., which may consume memory... # why don't killing? self.hide() @@ -315,7 +315,7 @@ def __init__(self, w3af, response_list, distance_function=LEVENSHTEIN, try: dotcode = self._generateDotCode(response_list, distance_function=callable_object) - except Exception, e: + except Exception as e: # TODO: instead of hiding..., which may consume memory... # why don't killing? self.hide() diff --git a/w3af/core/ui/gui/clusterTable.py b/w3af/core/ui/gui/clusterTable.py index 1e146bbf14..ba87aebfba 100644 --- a/w3af/core/ui/gui/clusterTable.py +++ b/w3af/core/ui/gui/clusterTable.py @@ -392,7 +392,7 @@ def _getInfoForId(self, id): """ try: obj = [i for i in self._data if i.get_id() == int(id)][0] - except Exception, e: + except Exception as e: return '' else: msg = 'Code: %s\nMessage: %s' \ diff --git a/w3af/core/ui/gui/export_request.py b/w3af/core/ui/gui/export_request.py index bbd210ceab..6b5c5c04ae 100644 --- a/w3af/core/ui/gui/export_request.py +++ b/w3af/core/ui/gui/export_request.py @@ -120,7 +120,7 @@ def _export(self, widg, combo): try: exported_request = func(self.http_request.get_text()) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: error_msg = str(w3) self.exported_text.set_text(error_msg) else: diff --git a/w3af/core/ui/gui/helpers.py b/w3af/core/ui/gui/helpers.py index 905c8d11a4..93366f1e57 100644 --- a/w3af/core/ui/gui/helpers.py +++ b/w3af/core/ui/gui/helpers.py @@ -203,7 +203,7 @@ def __call__(self, func, *args, **kwargs): """Apply the wrap.""" try: return func(*args, **kwargs) - except Exception, err: + except Exception as err: if isinstance(err, self.friendly): FriendlyExceptionDlg(str(err)) raise diff --git a/w3af/core/ui/gui/httpLogTab.py b/w3af/core/ui/gui/httpLogTab.py index 2efc1f692a..9740d77107 100644 --- a/w3af/core/ui/gui/httpLogTab.py +++ b/w3af/core/ui/gui/httpLogTab.py @@ -306,7 +306,7 @@ def _showAllRequestResponses(self, widget=None, event=None): self._searchText.set_text("") try: self.find_request_response() - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: self._empty_results() return @@ -386,6 +386,7 @@ def find_request_response(self, widget=None, refresh=False): searchResultObjects = self._historyItem.find(search_data, result_limit=5001, order_data=[("id", "")]) except BaseFrameworkException, w3: + self._empty_results() return if len(searchResultObjects) == 0: diff --git a/w3af/core/ui/gui/main.py b/w3af/core/ui/gui/main.py index 38004645a7..ca1ebed153 100644 --- a/w3af/core/ui/gui/main.py +++ b/w3af/core/ui/gui/main.py @@ -222,7 +222,7 @@ def __init__(self, profile, do_upd): genconfigfile = os.path.join(get_home_dir(), "gui_config.pkl") try: self.generalconfig = shelve.open(genconfigfile) - except Exception, e: + except Exception as e: print ("WARNING: something bad happened when trying to open the" " general config! File: %s. Problem: %s" % (genconfigfile, e)) self.generalconfig = FakeShelve() diff --git a/w3af/core/ui/gui/output/gtk_output.py b/w3af/core/ui/gui/output/gtk_output.py index 4c132dbe51..4859eb9d29 100644 --- a/w3af/core/ui/gui/output/gtk_output.py +++ b/w3af/core/ui/gui/output/gtk_output.py @@ -113,7 +113,7 @@ def _send_to_observers(self, m): for observer in observers.copy(): try: observer(m) - except Exception, e: + except Exception as e: msg = 'Observer function at "%s" failed with exception "%s".'\ ' Removing observer from list.' om.out.error(msg % (observer, e)) diff --git a/w3af/core/ui/gui/pluginconfig.py b/w3af/core/ui/gui/pluginconfig.py index ebde00c351..dbd862571f 100644 --- a/w3af/core/ui/gui/pluginconfig.py +++ b/w3af/core/ui/gui/pluginconfig.py @@ -421,7 +421,7 @@ def _finishedEditingPlugin(self, path, plugin_type, plugin_name): # Reload the plugin try: self.w3af.plugins.reload_modified_plugin(plugin_type, plugin_name) - except Exception, e: + except Exception as e: msg = 'The plugin you modified raised the following exception' msg += ' while trying to reload it: "%s",' % str(e) msg += ' please fix this issue before continuing or w3af will crash.' diff --git a/w3af/core/ui/gui/profiles.py b/w3af/core/ui/gui/profiles.py index 289059a368..260c41da6a 100644 --- a/w3af/core/ui/gui/profiles.py +++ b/w3af/core/ui/gui/profiles.py @@ -385,7 +385,7 @@ def _use_profile(self, widget=None): try: self.w3af.profiles.use_profile(profile_obj.get_profile_file()) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: dlg = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, str(w3)) @@ -419,7 +419,7 @@ def new_profile(self, widget=None): # use the empty profile try: self.w3af.profiles.use_profile(None) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: dlg = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, str(w3)) diff --git a/w3af/core/ui/gui/reqResViewer.py b/w3af/core/ui/gui/reqResViewer.py index 70e1c4530d..898f469cbd 100644 --- a/w3af/core/ui/gui/reqResViewer.py +++ b/w3af/core/ui/gui/reqResViewer.py @@ -438,7 +438,7 @@ def __init__(self, parent, w3af, editable, widgname='default'): try: rend = getRenderingView(w3af, self) self.add_view(rend) - except Exception, ex: + except Exception as ex: print ex def get_both_texts(self): @@ -510,7 +510,7 @@ def run(self): try: tmp_result = plugin.audit_return_vulns(self.request) plugin.end() - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.error(str(e)) else: # @@ -530,7 +530,7 @@ def run(self): try: self.result = plugin.audit_return_vulns(self.request) plugin.end() - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.error(str(e)) else: # @@ -542,7 +542,7 @@ def run(self): # We got here, everything is OK! self.ok = True - except Exception, e: + except Exception as e: self.exception = e # # This is for debugging errors in the audit button of the diff --git a/w3af/core/ui/gui/rrviews/rendering.py b/w3af/core/ui/gui/rrviews/rendering.py index 5936a9517e..dc83168d06 100644 --- a/w3af/core/ui/gui/rrviews/rendering.py +++ b/w3af/core/ui/gui/rrviews/rendering.py @@ -124,7 +124,7 @@ def show_object(self, obj): # I get here when the mime type is an image or something that I # can't display pass - except Exception, e: + except Exception as e: print _('gtkhtml2 exception:'), type(e), str(e) print _('Please report this issue here:') print 'https://github.com/andresriancho/w3af/issues/new' diff --git a/w3af/core/ui/gui/tabs/exploit/exploit_all.py b/w3af/core/ui/gui/tabs/exploit/exploit_all.py index 8025276173..6179741ee8 100644 --- a/w3af/core/ui/gui/tabs/exploit/exploit_all.py +++ b/w3af/core/ui/gui/tabs/exploit/exploit_all.py @@ -149,13 +149,13 @@ def _launch_exploit_all(dlg, w3af, enabled_plugins, stopOnFirst): try: can_exploit = exploit.can_exploit(vuln.get_id()) - except BaseFrameworkException, e: + except BaseFrameworkException as e: dlg.add_message(_("\nERROR: ")) dlg.add_message(str(e) + '\n') dlg.done() dlg.dialog_run() yield False - except ScanMustStopException, wmse: + except ScanMustStopException as wmse: dlg.add_message(_("\nERROR: ")) dlg.add_message(str(wmse) + '\n') dlg.done() @@ -172,11 +172,11 @@ def _launch_exploit_all(dlg, w3af, enabled_plugins, stopOnFirst): dlg.add_message(_("Exploiting...\n")) try: exploit.exploit() - except BaseFrameworkException, e: + except BaseFrameworkException as e: dlg.add_message(str(e) + '\n') yield True continue - except ScanMustStopException, wmse: + except ScanMustStopException as wmse: dlg.add_message(_("\nERROR:")) dlg.add_message(str(wmse) + '\n') dlg.done() diff --git a/w3af/core/ui/gui/tabs/exploit/vuln_list.py b/w3af/core/ui/gui/tabs/exploit/vuln_list.py index 1c01c946e7..a70fa925b9 100644 --- a/w3af/core/ui/gui/tabs/exploit/vuln_list.py +++ b/w3af/core/ui/gui/tabs/exploit/vuln_list.py @@ -232,7 +232,7 @@ def _launch_exploit(self, dlg, expl, vuln): try: can_exploit = expl.can_exploit(vuln_id_list) - except BaseFrameworkException, e: + except BaseFrameworkException as e: dlg.add_message(_("\nERROR: ")) dlg.add_message(str(e) + '\n') dlg.done() # set button to sensitive @@ -254,9 +254,9 @@ def _launch_exploit(self, dlg, expl, vuln): expl.exploit(vuln_id_list) # print the console messages to the dialog yield True - except NoVulnerabilityFoundException, e: + except NoVulnerabilityFoundException as e: dlg.add_message(str(e) + '\n') - except ExploitFailedException, e: + except ExploitFailedException as e: dlg.add_message(str(e) + '\n') else: dlg.add_message(_("Done\n")) diff --git a/w3af/core/ui/gui/tools/encdec.py b/w3af/core/ui/gui/tools/encdec.py index 7157d83e6a..250fcc7e8b 100644 --- a/w3af/core/ui/gui/tools/encdec.py +++ b/w3af/core/ui/gui/tools/encdec.py @@ -222,7 +222,7 @@ def run(self): try: self.result = self.func(self.text) self.ok = True - except Exception, e: + except Exception as e: self.exception = e self.ok = False finally: diff --git a/w3af/core/ui/gui/tools/fuzzy_requests.py b/w3af/core/ui/gui/tools/fuzzy_requests.py index af4956fce8..3922616885 100644 --- a/w3af/core/ui/gui/tools/fuzzy_requests.py +++ b/w3af/core/ui/gui/tools/fuzzy_requests.py @@ -412,12 +412,12 @@ def _real_send(self, fixContentLength, requestGenerator): fixContentLength) error_msg = None self.result_ok += 1 - except HTTPRequestException, e: + except HTTPRequestException as e: # One HTTP request failed error_msg = str(e) http_resp = None self.result_err += 1 - except ScanMustStopException, e: + except ScanMustStopException as e: # Many HTTP requests failed and the URL library wants to stop error_msg = str(e) self.result_err += 1 diff --git a/w3af/core/ui/gui/tools/helpers/fuzzygen.py b/w3af/core/ui/gui/tools/helpers/fuzzygen.py index fd3a663ee0..ed37a057d2 100644 --- a/w3af/core/ui/gui/tools/helpers/fuzzygen.py +++ b/w3af/core/ui/gui/tools/helpers/fuzzygen.py @@ -79,7 +79,7 @@ def _genIterator(self, text): namespace = {"string": __import__("string")} try: it = eval(text, namespace) - except Exception, e: + except Exception as e: msg = _("%s: %s (generated from %r)") % (e.__class__.__name__, e, text) raise FuzzyError(msg) diff --git a/w3af/core/ui/gui/tools/helpers/threaded_impact.py b/w3af/core/ui/gui/tools/helpers/threaded_impact.py index c393a9e6d9..3e08f4824e 100644 --- a/w3af/core/ui/gui/tools/helpers/threaded_impact.py +++ b/w3af/core/ui/gui/tools/helpers/threaded_impact.py @@ -42,7 +42,7 @@ def run(self): self.tlow, self.fixContentLength) self.ok = True - except Exception, e: + except Exception as e: self.exception = e finally: self.event.set() \ No newline at end of file diff --git a/w3af/core/ui/gui/tools/proxywin.py b/w3af/core/ui/gui/tools/proxywin.py index 38a4a448f2..fb1e89d68e 100644 --- a/w3af/core/ui/gui/tools/proxywin.py +++ b/w3af/core/ui/gui/tools/proxywin.py @@ -272,7 +272,7 @@ def reload_options(self): self.proxy.set_what_to_trap(self.pref.get_value('proxy', 'trap')) self.proxy.set_what_not_to_trap(self.pref.get_value('proxy', 'notrap')) self.proxy.set_methods_to_trap(self.pref.get_value('proxy', 'methodtrap')) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: self.show_alert(_("Invalid configuration!\n" + str(w3))) self._prev_ip_port = new_port @@ -306,7 +306,7 @@ def _start_proxy(self, ip=None, port=None, silent=False): try: self.proxy = InterceptProxy(ip, int(port), self.w3af.uri_opener) - except ProxyException, w3: + except ProxyException as w3: if not silent: self.show_alert(_(str(w3))) raise w3 diff --git a/w3af/core/ui/gui/wizard.py b/w3af/core/ui/gui/wizard.py index 27919c3c34..a7cf4898f3 100644 --- a/w3af/core/ui/gui/wizard.py +++ b/w3af/core/ui/gui/wizard.py @@ -63,7 +63,7 @@ def save_options(self): # To get more info: try: opt.widg - except Exception, e: + except Exception as e: raise Exception(str(e) + ' || ' + opt.get_name()) # end of debugging code diff --git a/w3af/plugins/attack/dav.py b/w3af/plugins/attack/dav.py index cd91636889..5d33148bd8 100644 --- a/w3af/plugins/attack/dav.py +++ b/w3af/plugins/attack/dav.py @@ -175,7 +175,7 @@ def end(self): try: self._uri_opener.DELETE(url_to_del) - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.error('DAVShell cleanup failed with exception: "%s".' % e) else: om.out.debug('DAVShell cleanup complete, %s deleted.' % url_to_del) diff --git a/w3af/plugins/attack/local_file_reader.py b/w3af/plugins/attack/local_file_reader.py index 54f2123660..697bd3d4fd 100644 --- a/w3af/plugins/attack/local_file_reader.py +++ b/w3af/plugins/attack/local_file_reader.py @@ -111,7 +111,7 @@ def _guess_with_diff(self, vuln_obj): try: response_a = self._uri_opener.send_mutant(orig_mutant) response_b = self._uri_opener.send_mutant(copy_mutant) - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.error(str(e)) return False else: @@ -138,7 +138,7 @@ def _strict_with_etc_passwd(self, vuln_obj): try: response_a = self._uri_opener.send_mutant(mutant) response_b = self._uri_opener.send_mutant(mutant) - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.error(str(e)) return False @@ -231,7 +231,7 @@ def _init_read(self): try: #FIXME: This only works in Linux! response = self._read_with_b64('/etc/passwd') - except Exception, e: + except Exception as e: msg = 'Not using base64 wrapper for reading because of ' \ 'exception: "%s"' om.out.debug(msg % e) @@ -259,7 +259,7 @@ def read(self, filename): if self._use_base64_wrapper: try: return self._read_with_b64(filename) - except Exception, e: + except Exception as e: om.out.debug('read_with_b64 failed: "%s"' % e) return self._read_basic(filename) @@ -292,7 +292,7 @@ def _read_utils(self, filename): try: response = self._uri_opener.send_mutant(mutant) - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = 'Error "%s" while sending request to remote host. Try again.' return msg % e diff --git a/w3af/plugins/attack/os_commanding.py b/w3af/plugins/attack/os_commanding.py index 7c11bd8014..621ad1c3cc 100644 --- a/w3af/plugins/attack/os_commanding.py +++ b/w3af/plugins/attack/os_commanding.py @@ -320,7 +320,7 @@ def execute(self, command): try: http_response = self.strategy.send(strategy_cmd, self.get_url_opener()) - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = ('Error "%s" while sending HTTP request with OS command to' ' remote host. Please try again.') return msg % e diff --git a/w3af/plugins/attack/payloads/payloads/metasploit.py b/w3af/plugins/attack/payloads/payloads/metasploit.py index d402fc0e91..9c1905d383 100644 --- a/w3af/plugins/attack/payloads/payloads/metasploit.py +++ b/w3af/plugins/attack/payloads/payloads/metasploit.py @@ -21,7 +21,7 @@ class metasploit(Payload): def api_execute(self, msf_args): try: vd = get_virtual_daemon(self.shell.execute) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: return 'Error, %s' % w3 else: vd.run(msf_args) diff --git a/w3af/plugins/attack/payloads/payloads/php_sca.py b/w3af/plugins/attack/payloads/payloads/php_sca.py index 09daf0a0ce..475c674df9 100644 --- a/w3af/plugins/attack/payloads/payloads/php_sca.py +++ b/w3af/plugins/attack/payloads/payloads/php_sca.py @@ -98,7 +98,7 @@ def write_vuln_to_kb(vulnty, url, funcs): try: sca = PhpSCA(file=file[1]) vulns = sca.get_vulns() - except Exception, e: + except Exception as e: msg = 'The PHP SCA failed with an unhandled exception: "%s".' om.out.console(msg % e) return {} diff --git a/w3af/plugins/attack/payloads/payloads/w3af_agent.py b/w3af/plugins/attack/payloads/payloads/w3af_agent.py index ce106ad48b..356a8723e6 100644 --- a/w3af/plugins/attack/payloads/payloads/w3af_agent.py +++ b/w3af/plugins/attack/payloads/payloads/w3af_agent.py @@ -24,7 +24,7 @@ def api_execute(self, ip_address): try: agentManager = w3afAgentManager(self.shell.execute, ip_address) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: return 'Error' + str(w3) else: agentManager.run() diff --git a/w3af/plugins/attack/rfi.py b/w3af/plugins/attack/rfi.py index 1159a834ef..4c677391be 100644 --- a/w3af/plugins/attack/rfi.py +++ b/w3af/plugins/attack/rfi.py @@ -397,7 +397,7 @@ def is_open_port(self, host, port): http_response = self._uri_opener.send_mutant(mutant) except BaseFrameworkException, w3: return 'Exception from the remote web application: "%s"' % w3 - except Exception, e: + except Exception as e: return 'Unhandled exception, "%s"' % e else: if 'HTTP request failed!' in http_response.get_body(): @@ -482,7 +482,7 @@ def execute(self, command): http_res = self._uri_opener.send_mutant(mutant) except BaseFrameworkException, w3: return 'Exception from the remote web application: "%s"' % w3 - except Exception, e: + except Exception as e: return 'Unhandled exception from the remote web application: "%s"' % e else: return shell_handler.extract_result(http_res.get_body()) @@ -494,7 +494,7 @@ def end(self): om.out.debug('Remote file inclusion shell is cleaning up.') try: self._rm_file(self._exploit_mutant.get_token_value()) - except Exception, e: + except Exception as e: msg = 'Remote file inclusion shell cleanup failed with exception: %s' om.out.error(msg % e) else: diff --git a/w3af/plugins/attack/xpath.py b/w3af/plugins/attack/xpath.py index 5070b39747..7a3b71a6a4 100644 --- a/w3af/plugins/attack/xpath.py +++ b/w3af/plugins/attack/xpath.py @@ -142,7 +142,7 @@ def _verify_vuln(self, vuln): try: false_resp = self._uri_opener.send_mutant(mutant_false) true_resp = self._uri_opener.send_mutant(mutant_true) - except BaseFrameworkException, e: + except BaseFrameworkException as e: return 'Error "%s".' % e else: if (is_error_resp(false_resp.get_body()) @@ -177,7 +177,7 @@ def _get_delimiter(self, vuln, is_error_resp): try: true_resp = self._uri_opener.send_mutant(mutant_true) false_resp = self._uri_opener.send_mutant(mutant_false) - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.debug('Error "%s"' % e) else: if (is_error_resp(false_resp.get_body()) @@ -210,7 +210,7 @@ def _configure_is_error_function(self, vuln, count): diff_ratio += difflib.SequenceMatcher(None, base_res.get_body(), req_x.get_body()).ratio() - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.debug('Error "%s"' % e) except RuntimeError, rte: issue = 'https://github.com/andresriancho/w3af/issues/5278' @@ -314,13 +314,13 @@ def getxml(self): """ try: data_len = self._get_data_len() - except BaseFrameworkException, e: + except BaseFrameworkException as e: return 'Error found during data length extraction: "%s"' % e if data_len is not None: try: data = self.get_data(data_len) - except BaseFrameworkException, e: + except BaseFrameworkException as e: return 'Error found during data extraction: "%s"' % e else: return data diff --git a/w3af/plugins/audit/deserialization/java/generator.py b/w3af/plugins/audit/deserialization/java/generator.py index dbe93af4b7..23470ecd7f 100644 --- a/w3af/plugins/audit/deserialization/java/generator.py +++ b/w3af/plugins/audit/deserialization/java/generator.py @@ -91,7 +91,7 @@ def main(payloads): try: p1, o1 = get_payload_bin_for_command_len(payload, 1) p2, o2 = get_payload_bin_for_command_len(payload, 2) - except Exception, e: + except Exception as e: args = (payload, e) msg = 'Failed to create %s.json, exception: "%s"' print(msg % args) diff --git a/w3af/plugins/audit/deserialization/net/generator.py b/w3af/plugins/audit/deserialization/net/generator.py index 2a337ed3d0..16ad02559b 100644 --- a/w3af/plugins/audit/deserialization/net/generator.py +++ b/w3af/plugins/audit/deserialization/net/generator.py @@ -92,7 +92,7 @@ def main(payloads): try: p1, o1 = get_payload_bin_for_command_len(payload, 1) p2, o2 = get_payload_bin_for_command_len(payload, 2) - except Exception, e: + except Exception as e: args = (payload, e) msg = 'Failed to create %s.json, exception: "%s"' print(msg % args) diff --git a/w3af/plugins/audit/frontpage.py b/w3af/plugins/audit/frontpage.py index 1e1f987a56..f1ce8b65bd 100644 --- a/w3af/plugins/audit/frontpage.py +++ b/w3af/plugins/audit/frontpage.py @@ -115,7 +115,7 @@ def _upload_file(self, domain_path, rand_file, debugging_id): res = self._uri_opener.POST(target_url, data=data, debugging_id=debugging_id) - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.debug('Exception while uploading file using author.dll: %s' % e) return None else: @@ -139,7 +139,7 @@ def _verify_upload(self, domain_path, rand_file, upload_id, debugging_id): cache=False, grep=False, debugging_id=debugging_id) - except BaseFrameworkException, e: + except BaseFrameworkException as e: om.out.debug('Exception while verifying if the file that was uploaded' 'using author.dll was there: %s' % e) else: diff --git a/w3af/plugins/audit/redos.py b/w3af/plugins/audit/redos.py index 4d5146d6f6..a621d5289e 100644 --- a/w3af/plugins/audit/redos.py +++ b/w3af/plugins/audit/redos.py @@ -59,7 +59,7 @@ def _generate_delay_tests(self, freq, debugging_id): for delay_obj in self.get_delays(): yield mutant, delay_obj, debugging_id - def _find_delay_in_mutant(self, (mutant, delay_obj, debugging_id)): + def _find_delay_in_mutant(self, mutant, delay_obj, debugging_id): """ Try to delay the response and save a vulnerability if successful diff --git a/w3af/plugins/audit/rfi.py b/w3af/plugins/audit/rfi.py index 81339ad17f..90733962a4 100644 --- a/w3af/plugins/audit/rfi.py +++ b/w3af/plugins/audit/rfi.py @@ -246,7 +246,7 @@ def _local_test_inclusion(self, freq, orig_response, debugging_id): # Perform the real work self._test_inclusion(freq, rfi_data, orig_response, debugging_id) - except socket.error, se: + except socket.error as se: errorcode = se[0] if errorcode == errno.EADDRINUSE: # We can't use this address because it is already in use @@ -257,7 +257,7 @@ def _local_test_inclusion(self, freq, orig_response, debugging_id): 'rfi plugin. The address is already in use by another process.') om.out.error(msg) - except Exception, e: + except Exception as e: msg = 'An error occurred while running local web server for' \ ' the remote file inclusion (rfi) plugin: "%s"' om.out.error(msg % e) @@ -491,7 +491,7 @@ def do_GET(self): self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(self.RESPONSE_BODY) - except Exception, e: + except Exception as e: om.out.debug('[RFIWebHandler] Exception: "%s".' % e) finally: # Clean up diff --git a/w3af/plugins/audit/ssl_certificate.py b/w3af/plugins/audit/ssl_certificate.py index ef1154f1e8..a85c1d6cf2 100644 --- a/w3af/plugins/audit/ssl_certificate.py +++ b/w3af/plugins/audit/ssl_certificate.py @@ -104,7 +104,7 @@ def _analyze_ssl_cert(self, domain, port): try: cert, cert_der, cipher = self._get_ssl_cert(domain, port) - except Exception, e: + except Exception as e: om.out.debug('Failed to retrieve SSL certificate: "%s"' % e) else: self._cert_expiration_analysis(domain, port, cert, cert_der, cipher) @@ -285,7 +285,7 @@ def _ssl_connect_specific_protocol(self, # Raise SSL errors raise - except Exception, e: + except Exception as e: msg = 'Unhandled %s exception in _ssl_connect_specific_protocol(): "%s"' args = (e.__class__.__name__, e) om.out.debug(msg % args) @@ -300,7 +300,7 @@ def _ssl_connect_specific_protocol(self, try: ssl_sock.close() - except Exception, e: + except Exception as e: om.out.debug('Exception found while closing SSL socket: "%s"' % e) return result diff --git a/w3af/plugins/bruteforce/basic_auth.py b/w3af/plugins/bruteforce/basic_auth.py index 87f4a547a8..bfa5a31a40 100644 --- a/w3af/plugins/bruteforce/basic_auth.py +++ b/w3af/plugins/bruteforce/basic_auth.py @@ -93,6 +93,7 @@ def _brute_worker(self, url, combination, debugging_id): # # If one thread sees that we already bruteforced the access, the rest # will simply no-op + if self._found and self._stop_on_first: return @@ -140,6 +141,7 @@ def _brute_worker(self, url, combination, debugging_id): severity=v.get_severity()) def _configure_credentials_in_opener(self): + """ Configure the main urllib with the newly found credentials. """ diff --git a/w3af/plugins/bruteforce/form_auth.py b/w3af/plugins/bruteforce/form_auth.py index c947eef28f..2dc1b24854 100644 --- a/w3af/plugins/bruteforce/form_auth.py +++ b/w3af/plugins/bruteforce/form_auth.py @@ -75,6 +75,7 @@ def audit(self, freq, debugging_id=None): self._already_tested.append(mutant.get_url()) try: + session = self._create_new_session(mutant, debugging_id) except BaseFrameworkException, bfe: msg = 'Failed to create new session during form bruteforce setup: "%s"' @@ -92,6 +93,7 @@ def audit(self, freq, debugging_id=None): self._signature_test(mutant, session, login_failed_bodies, debugging_id) except BaseFrameworkException, bfe: msg = 'Signature test failed during form bruteforce setup: "%s"' + om.out.debug(msg % bfe) return diff --git a/w3af/plugins/crawl/dot_ds_store.py b/w3af/plugins/crawl/dot_ds_store.py index fc3e079d2b..adb4ca1dbe 100644 --- a/w3af/plugins/crawl/dot_ds_store.py +++ b/w3af/plugins/crawl/dot_ds_store.py @@ -82,7 +82,7 @@ def _check_and_analyze(self, domain_path): try: response = self.http_get_and_parse(url, binary_response=True) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: msg = 'Failed to GET .DS_Store file: %s. Exception: %s.' om.out.debug(msg, (url, w3)) return @@ -94,7 +94,7 @@ def _check_and_analyze(self, domain_path): try: store = DsStore(response.get_raw_body()) entries = store.get_file_entries() - except Exception, e: + except Exception as e: om.out.debug('Unexpected error while parsing DS_Store file: "%s"' % e) return diff --git a/w3af/plugins/crawl/dot_listing.py b/w3af/plugins/crawl/dot_listing.py index 804356a04b..1fff19ca54 100644 --- a/w3af/plugins/crawl/dot_listing.py +++ b/w3af/plugins/crawl/dot_listing.py @@ -73,8 +73,10 @@ def _check_and_analyze(self, domain_path): :return: None, everything is saved to the self.out_queue. """ url = domain_path.url_join('.listing') + response = self._uri_opener.GET(url, cache=True) + if is_404(response): return diff --git a/w3af/plugins/crawl/dwsync_xml.py b/w3af/plugins/crawl/dwsync_xml.py index fae807842d..042a54817c 100644 --- a/w3af/plugins/crawl/dwsync_xml.py +++ b/w3af/plugins/crawl/dwsync_xml.py @@ -80,7 +80,7 @@ def _find_dwsync(self, domain_path): try: dom = xml.dom.minidom.parseString(response.get_body()) - except Exception, e: + except Exception as e: msg = 'Exception while parsing dwsync.xml file at %s : "%s"' om.out.debug(msg % (dwsync_url, e)) return @@ -95,7 +95,7 @@ def _find_dwsync(self, domain_path): except ValueError, ve: msg = 'dwsync file had an invalid URL: "%s"' om.out.debug(msg % ve) - except Exception, e: + except Exception as e: msg = 'Sitemap file had an invalid format: "%s"' om.out.debug(msg % e) diff --git a/w3af/plugins/crawl/find_dvcs.py b/w3af/plugins/crawl/find_dvcs.py index 7f25be19e1..1374c82614 100644 --- a/w3af/plugins/crawl/find_dvcs.py +++ b/w3af/plugins/crawl/find_dvcs.py @@ -160,7 +160,7 @@ def _send_and_check(self, repo_url, repo_get_files, repo, domain_path): try: filenames = repo_get_files(http_response.get_raw_body()) - except Exception, e: + except Exception as e: # We get here when the HTTP response is NOT a 404, but the response # body couldn't be properly parsed. This is usually because of a false # positive in the is_404 function, OR a new version-format of the file @@ -373,7 +373,7 @@ def svn_wc_db(self, body): for path, svn_path in query_result: filenames.add(path) filenames.add(svn_path) - except Exception, e: + except Exception as e: msg = 'Failed to extract filenames from wc.db file. The exception was: "%s"' args = (e,) om.out.debug(msg % args) diff --git a/w3af/plugins/crawl/ghdb.py b/w3af/plugins/crawl/ghdb.py index 19a0adbf03..a9793d7e32 100644 --- a/w3af/plugins/crawl/ghdb.py +++ b/w3af/plugins/crawl/ghdb.py @@ -91,7 +91,7 @@ def _do_clasic_GHDB(self, domain): search_term = 'site:%s %s' % (domain, gh.search) try: self._classic_worker(gh, search_term) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: # Google is saying: "no more automated tests". om.out.error('GHDB exception: "' + str(w3) + '".') break @@ -130,13 +130,13 @@ def _read_ghdb(self): """ try: ghdb_fd = file(self._ghdb_file) - except Exception, e: + except Exception as e: msg = 'Failed to open ghdb file: "%s", error: "%s".' raise BaseFrameworkException(msg % (self._ghdb_file, e)) try: dom = xml.dom.minidom.parseString(ghdb_fd.read()) - except Exception, e: + except Exception as e: msg = 'Failed to parse XML file: "%s", error: "%s".' raise BaseFrameworkException(msg % (self._ghdb_file, e)) @@ -152,6 +152,7 @@ def _read_ghdb(self): try: query_string = signature.childNodes[4].childNodes[0].data + except Exception, e: msg = ('There is a corrupt signature in the GHDB. No query ' ' string was found in the following XML code: "%s".') diff --git a/w3af/plugins/crawl/import_results.py b/w3af/plugins/crawl/import_results.py index bf48688185..928508d8f0 100644 --- a/w3af/plugins/crawl/import_results.py +++ b/w3af/plugins/crawl/import_results.py @@ -75,7 +75,7 @@ def _load_data_from_base64(self): try: file_handler = file(self._input_base64, 'rb') - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = 'An error was found while trying to read "%s": "%s".' om.out.error(msg % (self._input_base64, e)) return @@ -110,7 +110,7 @@ def _load_data_from_burp(self): try: fuzzable_request_list = self._objs_from_burp_log(self._input_burp) - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = ('An error was found while trying to read the Burp log' ' file (%s): "%s".') om.out.error(msg % (self._input_burp, e)) diff --git a/w3af/plugins/crawl/phishtank.py b/w3af/plugins/crawl/phishtank.py index 4e879d93cc..8163129d70 100644 --- a/w3af/plugins/crawl/phishtank.py +++ b/w3af/plugins/crawl/phishtank.py @@ -121,7 +121,7 @@ def _is_in_phishtank(self, to_check): """ try: phishtank_db_fd = file(self.PHISHTANK_DB, 'r') - except Exception, e: + except Exception as e: msg = 'Failed to open phishtank database: "%s", exception: "%s".' raise BaseFrameworkException(msg % (self.PHISHTANK_DB, e)) diff --git a/w3af/plugins/crawl/phishtank/update.py b/w3af/plugins/crawl/phishtank/update.py index 308827e25d..2228251beb 100755 --- a/w3af/plugins/crawl/phishtank/update.py +++ b/w3af/plugins/crawl/phishtank/update.py @@ -133,13 +133,13 @@ def convert_xml_to_csv(): # # phishtank_db_fd = file(XML_DB_FILE, 'r') - except Exception, e: + except Exception as e: msg = 'Failed to open XML phishtank database: "%s", exception: "%s".' sys.exit(msg % (XML_DB_FILE, e)) try: output_csv_file = file(CSV_DB_FILE, 'w') - except Exception, e: + except Exception as e: msg = 'Failed to open CSV phishtank database: "%s", exception: "%s".' sys.exit(msg % (CSV_DB_FILE, e)) @@ -150,7 +150,7 @@ def convert_xml_to_csv(): try: etree.parse(phishtank_db_fd, parser) - except Exception, e: + except Exception as e: msg = 'XML parsing error in phishtank DB, exception: "%s".' sys.exit(msg % e) diff --git a/w3af/plugins/crawl/pykto.py b/w3af/plugins/crawl/pykto.py index 779a654804..707457a3b4 100644 --- a/w3af/plugins/crawl/pykto.py +++ b/w3af/plugins/crawl/pykto.py @@ -150,7 +150,7 @@ def _send_and_check(self, nikto_test): try: http_response = function_ptr(nikto_test.uri) - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = ('An exception was raised while requesting "%s", the error' ' message is: "%s".') om.out.error(msg % (nikto_test.uri, e)) @@ -346,7 +346,7 @@ def test_generator(self): """ try: db_file = codecs.open(self.filename, "r", "utf-8" ) - except Exception, e: + except Exception as e: msg = 'Failed to open the scan database. Exception: "%s".' om.out.error(msg % e) raise StopIteration diff --git a/w3af/plugins/crawl/spider_man.py b/w3af/plugins/crawl/spider_man.py index 914970ccd6..65a8a5c759 100644 --- a/w3af/plugins/crawl/spider_man.py +++ b/w3af/plugins/crawl/spider_man.py @@ -81,7 +81,7 @@ def crawl(self, fuzzable_request, debugging_id): plugin=self, target_domain=fuzzable_request.get_url().get_domain(), name='SpiderManProxyThread') - except ProxyException, proxy_exc: + except ProxyException as proxy_exc: om.out.error('%s' % proxy_exc) else: @@ -195,7 +195,7 @@ def handle_request_in_thread(self, flow): # Send the request to the remote webserver http_response = self._send_http_request(http_request, grep=grep) - except Exception, e: + except Exception as e: trace = str(traceback.format_exc()) http_response = self._create_error_response(http_request, None, e, trace=trace) diff --git a/w3af/plugins/crawl/url_fuzzer.py b/w3af/plugins/crawl/url_fuzzer.py index 0d650c90dc..d2a8d7abfe 100644 --- a/w3af/plugins/crawl/url_fuzzer.py +++ b/w3af/plugins/crawl/url_fuzzer.py @@ -131,6 +131,7 @@ def _do_request(self, url, mutant): # Report only once self._seen.add(response.get_url()) + desc = 'A potentially interesting file was found at: "%s".' desc %= response.get_url() @@ -140,6 +141,7 @@ def _do_request(self, url, mutant): kb.kb.append(self, 'files', i) om.out.information(i.get_desc()) + def _mutate_domain_name(self, url): """ If the url is : "http://www.foobar.com/asd.txt" this method returns: diff --git a/w3af/plugins/crawl/web_spider.py b/w3af/plugins/crawl/web_spider.py index 21ceded426..e32d41368f 100644 --- a/w3af/plugins/crawl/web_spider.py +++ b/w3af/plugins/crawl/web_spider.py @@ -236,7 +236,7 @@ def _body_url_generator(self, resp, fuzzable_req): # try: doc_parser = parser_cache.dpc.get_document_parser_for(resp) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: om.out.debug('Failed to find a suitable document parser. ' 'Exception "%s"' % w3) else: diff --git a/w3af/plugins/crawl/wordpress_fingerprint.py b/w3af/plugins/crawl/wordpress_fingerprint.py index 1a0cdf329e..d46a7400c2 100644 --- a/w3af/plugins/crawl/wordpress_fingerprint.py +++ b/w3af/plugins/crawl/wordpress_fingerprint.py @@ -256,6 +256,7 @@ def _get_wp_fingerprints(self): try: wordpress_fp_fd = codecs.open(self.WP_VERSIONS_XML, 'r', 'utf-8', errors='ignore') + except Exception, e: msg = 'Failed to open wordpress fingerprint database "%s": "%s".' args = (self.WP_VERSIONS_XML, e) @@ -268,7 +269,7 @@ def _get_wp_fingerprints(self): try: parser.parse(wordpress_fp_fd) - except Exception, e: + except Exception as e: msg = 'XML parsing error in wordpress version DB, exception: "%s".' raise BaseFrameworkException(msg % e) diff --git a/w3af/plugins/grep/clamav.py b/w3af/plugins/grep/clamav.py index f9df088397..e5238be9c4 100644 --- a/w3af/plugins/grep/clamav.py +++ b/w3af/plugins/grep/clamav.py @@ -145,7 +145,7 @@ def _scan_http_response(self, request, response): try: cd = self._get_connection() result_dict = cd.scan_stream(body) - except Exception, e: + except Exception as e: msg = ('The ClamAV plugin failed to connect to clamd using' ' the provided unix socket: "%s". Please verify your' ' configuration and try again. The exception was: "%s".') diff --git a/w3af/plugins/grep/http_auth_detect.py b/w3af/plugins/grep/http_auth_detect.py index 00c1f6751a..4c50fbb21a 100644 --- a/w3af/plugins/grep/http_auth_detect.py +++ b/w3af/plugins/grep/http_auth_detect.py @@ -96,7 +96,7 @@ def _find_auth_uri(self, response): url_list = [] try: document_parser = parser_cache.dpc.get_document_parser_for(response) - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = 'Failed to find a suitable document parser. Exception: "%s"' om.out.debug(msg % e) else: diff --git a/w3af/plugins/grep/retirejs.py b/w3af/plugins/grep/retirejs.py index 8f1b9e3625..b2062d38a0 100644 --- a/w3af/plugins/grep/retirejs.py +++ b/w3af/plugins/grep/retirejs.py @@ -179,7 +179,7 @@ def _download_retire_db(self): http_response = self._uri_opener.GET(self._retire_db_url, binary_response=True, respect_size_limit=False) - except Exception, e: + except Exception as e: msg = 'Failed to download the retirejs database: "%s"' om.out.error(msg % e) return diff --git a/w3af/plugins/grep/serialized_object.py b/w3af/plugins/grep/serialized_object.py index 7169897014..87cb10b0e2 100644 --- a/w3af/plugins/grep/serialized_object.py +++ b/w3af/plugins/grep/serialized_object.py @@ -131,7 +131,7 @@ def _analyze_param(self, request, response, parameter_name, parameter_value, """ try: match_object = serialized_object_re.search(parameter_value) - except Exception, e: + except Exception as e: args = (e, parameter_value) om.out.debug('An exception was found while trying to find a' ' serialized object in a parameter value. The exception' diff --git a/w3af/plugins/grep/user_defined_regex.py b/w3af/plugins/grep/user_defined_regex.py index b8a64f1d05..2bab183012 100644 --- a/w3af/plugins/grep/user_defined_regex.py +++ b/w3af/plugins/grep/user_defined_regex.py @@ -125,7 +125,7 @@ def set_options(self, options_list): try: f = file(self._regex_file_path) - except Exception, e: + except Exception as e: msg = 'Unable to open file "%s", error: "%s".' raise BaseFrameworkException(msg % (self._regex_file_path, e)) else: diff --git a/w3af/plugins/infrastructure/afd.py b/w3af/plugins/infrastructure/afd.py index 936e95b00c..c9d3ce45e6 100644 --- a/w3af/plugins/infrastructure/afd.py +++ b/w3af/plugins/infrastructure/afd.py @@ -86,6 +86,7 @@ def _send_requests(self, fuzzable_request, debugging_id): cache=True, debugging_id=debugging_id) except BaseFrameworkException, bfe: + msg = ('Active filter detection plugin failed to receive a' ' response for the first request. The exception was: "%s".' ' Can not perform analysis.') diff --git a/w3af/plugins/infrastructure/domain_dot.py b/w3af/plugins/infrastructure/domain_dot.py index 7c6c265d49..7f0ec6ce44 100644 --- a/w3af/plugins/infrastructure/domain_dot.py +++ b/w3af/plugins/infrastructure/domain_dot.py @@ -71,7 +71,7 @@ def discover(self, fuzzable_request, debugging_id): headers = Headers([('Host', domain_dot)]) response = self._uri_opener.GET(orig_url, cache=False, headers=headers) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: om.out.error(str(w3)) else: self._analyze_response(original_response, response) diff --git a/w3af/plugins/infrastructure/favicon_identification.py b/w3af/plugins/infrastructure/favicon_identification.py index 659289a5ed..7367977175 100644 --- a/w3af/plugins/infrastructure/favicon_identification.py +++ b/w3af/plugins/infrastructure/favicon_identification.py @@ -108,7 +108,7 @@ def _read_favicon_db(self): try: # read MD5 database. db_file = open(self._db_file, "r") - except Exception, e: + except Exception as e: msg = 'Failed to open the MD5 database at %s. Exception: "%s".' om.out.error(msg % (self._db_file, e)) else: diff --git a/w3af/plugins/infrastructure/finger_bing.py b/w3af/plugins/infrastructure/finger_bing.py index 8feadb3d44..4549213fea 100644 --- a/w3af/plugins/infrastructure/finger_bing.py +++ b/w3af/plugins/infrastructure/finger_bing.py @@ -83,7 +83,7 @@ def _find_accounts(self, page): except ScanMustStopOnUrlError: # Just ignore it pass - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: msg = 'ExtendedUrllib exception raised while fetching page in' \ ' finger_bing, error description: "%s"' om.out.debug(msg % w3) diff --git a/w3af/plugins/infrastructure/finger_google.py b/w3af/plugins/infrastructure/finger_google.py index 0b92a3bccb..094c89d0fa 100644 --- a/w3af/plugins/infrastructure/finger_google.py +++ b/w3af/plugins/infrastructure/finger_google.py @@ -92,6 +92,7 @@ def _do_complete_search(self): google_results = self._google.search(search_string, self._result_limit) self.worker_pool.map(self._find_accounts, google_results) + def _find_accounts(self, google_result): """ Finds emails in google result page. @@ -108,6 +109,7 @@ def _find_accounts(self, google_result): grep=grep_res) self._parse_document(response) + def _parse_document(self, response): """ Parses the HTML and adds the mail addresses to the kb. diff --git a/w3af/plugins/infrastructure/fingerprint_WAF.py b/w3af/plugins/infrastructure/fingerprint_WAF.py index 5588114c2d..24619defb1 100644 --- a/w3af/plugins/infrastructure/fingerprint_WAF.py +++ b/w3af/plugins/infrastructure/fingerprint_WAF.py @@ -95,7 +95,7 @@ def _fingerprint_SecureIIS(self, fuzzable_request): try: lock_response2 = self._uri_opener.GET(fuzzable_request.get_url(), headers=headers, cache=True) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: om.out.debug( 'Failed to identify secure IIS, exception: ' + str(w3)) else: diff --git a/w3af/plugins/infrastructure/frontpage_version.py b/w3af/plugins/infrastructure/frontpage_version.py index e7df91c44a..101c5f9cbd 100644 --- a/w3af/plugins/infrastructure/frontpage_version.py +++ b/w3af/plugins/infrastructure/frontpage_version.py @@ -72,7 +72,7 @@ def discover(self, fuzzable_request, debugging_id): try: response = self._uri_opener.GET(frontpage_info_url, cache=True) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: fmt = ('Failed to GET Frontpage Server _vti_inf.html file: "%s". ' 'Exception: "%s".') om.out.debug(fmt % (frontpage_info_url, w3)) diff --git a/w3af/plugins/infrastructure/hmap.py b/w3af/plugins/infrastructure/hmap.py index ad1ffa55e7..564c8e7c96 100644 --- a/w3af/plugins/infrastructure/hmap.py +++ b/w3af/plugins/infrastructure/hmap.py @@ -67,11 +67,11 @@ def discover(self, fuzzable_request, debugging_id): try: results = upstream_hmap.testServer(ssl, server, port, 1, self._gen_fp, self._threads) - except BaseFrameworkException, w3: + except BaseFrameworkException as w3: msg = 'A BaseFrameworkException occurred while running hmap: "%s"' om.out.error(msg % w3) return - except Exception, e: + except Exception as e: msg = 'An unhandled exception occurred while running hmap: "%s"' om.out.error(msg % e) return diff --git a/w3af/plugins/infrastructure/http_vs_https_dist.py b/w3af/plugins/infrastructure/http_vs_https_dist.py index d3e3e27476..7d4a40a200 100644 --- a/w3af/plugins/infrastructure/http_vs_https_dist.py +++ b/w3af/plugins/infrastructure/http_vs_https_dist.py @@ -105,7 +105,7 @@ def set_info(name, desc): http_troute = traceroute(domain, dport=http_port)[0].get_trace() # pylint: enable=E1124,E1136 - except Exception, e: + except Exception as e: # I've seen numerous bug reports with the following exception: # "error: illegal IP address string passed to inet_aton" # that come from this part of the code. It seems that in some cases diff --git a/w3af/plugins/infrastructure/oHmap/hmap.py b/w3af/plugins/infrastructure/oHmap/hmap.py index 8c88c17217..7e1df94ac8 100644 --- a/w3af/plugins/infrastructure/oHmap/hmap.py +++ b/w3af/plugins/infrastructure/oHmap/hmap.py @@ -72,7 +72,7 @@ def get_connection(self): else: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) - except Exception, e: + except Exception as e: msg = 'hmap connection failed to %s:%s. Exception: "%s"' args = (HOST, PORT, e) raise BaseFrameworkException(msg % args) @@ -81,7 +81,7 @@ def get_connection(self): if useSSL: try: s2 = ssl.wrap_socket(s) - except Exception, e: + except Exception as e: msg = 'hmap SSL connection failed to %s:%s. Exception: "%s"' args = (HOST, PORT, e) raise BaseFrameworkException(msg % args) @@ -107,7 +107,7 @@ def submit(self): # Send the "HTTP request" to the socket try: s.send(str(self)) - except Exception, e: + except Exception as e: om.out.debug('hmap failed to send data to socket: "%s"' % e) # Try again @@ -155,7 +155,7 @@ def submit(self): continue - except Exception, e: + except Exception as e: msg = 'hmap found an exception while reading data from socket: "%s"' om.out.debug(msg % e) @@ -994,7 +994,7 @@ def testServer(ssl, server, port, matchCount, generateFP, threads): try: ### FIXME: This eval is awful, I should change it to pickle. ks = eval(ksf.read()) - except Exception, e: + except Exception as e: raise BaseFrameworkException( 'The signature file "' + f + '" has an invalid syntax.') else: @@ -1006,7 +1006,7 @@ def testServer(ssl, server, port, matchCount, generateFP, threads): for i in xrange(10): try: fd = open('hmap-fingerprint-' + server + '-' + str(i), 'w') - except Exception, e: + except Exception as e: raise BaseFrameworkException( 'Cannot open fingerprint file. Error:' + str(e)) else: diff --git a/w3af/plugins/infrastructure/xssed_dot_com.py b/w3af/plugins/infrastructure/xssed_dot_com.py index 93b6cc96b8..4ada91dfce 100644 --- a/w3af/plugins/infrastructure/xssed_dot_com.py +++ b/w3af/plugins/infrastructure/xssed_dot_com.py @@ -64,7 +64,7 @@ def discover(self, fuzzable_request, debugging_id): try: response = self._uri_opener.GET(check_url) - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = ('An exception was raised while running xssed_dot_com' ' plugin. Exception: "%s".') om.out.debug(msg % e) @@ -84,7 +84,7 @@ def _parse_xssed_search_result(self, response): try: xss_report_response = self._uri_opener.GET(mirror_url) - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = ('An exception was raised while running xssed_dot_com' ' plugin. Exception: "%s".') om.out.debug(msg % e) diff --git a/w3af/plugins/infrastructure/zone_h.py b/w3af/plugins/infrastructure/zone_h.py index fbfd5d2f01..52408b96da 100644 --- a/w3af/plugins/infrastructure/zone_h.py +++ b/w3af/plugins/infrastructure/zone_h.py @@ -59,7 +59,7 @@ def discover(self, fuzzable_request, debugging_id): try: response = self._uri_opener.GET(zone_h_url) - except BaseFrameworkException, e: + except BaseFrameworkException as e: msg = 'An exception was raised while running zone-h plugin.' msg += ' Exception: "%s"' % e om.out.debug(msg) diff --git a/w3af/plugins/output/csv_file.py b/w3af/plugins/output/csv_file.py index 68b6bfac8d..fb99f4789b 100644 --- a/w3af/plugins/output/csv_file.py +++ b/w3af/plugins/output/csv_file.py @@ -71,7 +71,7 @@ def flush(self): delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) - except Exception, e: + except Exception as e: msg = ('An exception was raised while trying to open the ' ' CSV writer. Exception: "%s"') om.out.error(msg % e) @@ -89,7 +89,7 @@ def flush(self): info.get_id(), info.get_desc()] csv_writer.writerow(row) - except Exception, e: + except Exception as e: msg = ('An exception was raised while trying to write the ' ' vulnerabilities to the output file. Exception: "%s"') om.out.error(msg % e) diff --git a/w3af/plugins/output/email_report.py b/w3af/plugins/output/email_report.py index b0218fa9bf..05cb9c9e06 100644 --- a/w3af/plugins/output/email_report.py +++ b/w3af/plugins/output/email_report.py @@ -107,7 +107,7 @@ def end(self): server = smtplib.SMTP(self.smtpServer, self.smtpPort) server.sendmail(self.fromAddr, self.toAddrs, msg.as_string()) server.quit() - except Exception, e: + except Exception as e: msg = 'The SMTP settings in email_report plugin seem to be'\ ' incorrect. Original error: "%s".' om.out.error(msg % e) diff --git a/w3af/plugins/output/export_requests.py b/w3af/plugins/output/export_requests.py index 602f4af638..7c69eb5e98 100644 --- a/w3af/plugins/output/export_requests.py +++ b/w3af/plugins/output/export_requests.py @@ -69,7 +69,7 @@ def flush(self): for fr in fuzzable_request_set: out_file.write(fr.to_base64() + '\n') - except Exception, e: + except Exception as e: msg = ('An exception was raised while trying to export fuzzable' ' requests to the output file: "%s".' % e) om.out.error(msg) diff --git a/w3af/plugins/output/json_file.py b/w3af/plugins/output/json_file.py index 537bcf07af..d9157681e6 100644 --- a/w3af/plugins/output/json_file.py +++ b/w3af/plugins/output/json_file.py @@ -125,7 +125,7 @@ def _get_desc(x): "VulnDB ID": info.get_vulndb_id(), "Description": info.get_desc()} items.append(item) - except Exception, e: + except Exception as e: msg = ('An exception was raised while trying to write the ' ' vulnerabilities to the output file. Exception: "%s"') om.out.error(msg % e) diff --git a/w3af/plugins/output/text_file.py b/w3af/plugins/output/text_file.py index 42e4c39a2d..70d38031c2 100644 --- a/w3af/plugins/output/text_file.py +++ b/w3af/plugins/output/text_file.py @@ -80,7 +80,7 @@ def _init(self): msg = 'Can\'t open report file "%s" for writing, error: %s.' args = (os.path.abspath(self._output_file_name), io.strerror) raise BaseFrameworkException(msg % args) - except Exception, e: + except Exception as e: msg = 'Can\'t open report file "%s" for writing, error: %s.' args = (os.path.abspath(self._output_file_name), e) raise BaseFrameworkException(msg % args) @@ -97,7 +97,7 @@ def _init(self): msg = 'Can\'t open HTTP report file "%s" for writing, error: %s.' args = (os.path.abspath(self._http_file_name), io.strerror) raise BaseFrameworkException(msg % args) - except Exception, e: + except Exception as e: msg = 'Can\'t open HTTP report file "%s" for writing, error: %s.' args = (os.path.abspath(self._http_file_name), e) raise BaseFrameworkException(msg % args) @@ -135,7 +135,7 @@ def _write_to_http_log(self, msg): try: self._http.write(msg) - except Exception, e: + except Exception as e: self._http = None msg = ('An exception was raised while trying to write to the output' ' file "%s", error: "%s". Disabling output to this file.') diff --git a/w3af/plugins/tests/audit/test_deserialization.py b/w3af/plugins/tests/audit/test_deserialization.py index ee33aff858..fdeee457c4 100644 --- a/w3af/plugins/tests/audit/test_deserialization.py +++ b/w3af/plugins/tests/audit/test_deserialization.py @@ -54,13 +54,13 @@ def get_response(self, http_request, uri, response_headers): try: message = base64.b64decode(b64message) - except Exception, e: + except Exception as e: body = str(e) return self.status, response_headers, body try: cPickle.loads(message) - except Exception, e: + except Exception as e: body = str(e) return self.status, response_headers, body @@ -94,7 +94,7 @@ def get_response(self, http_request, uri, response_headers): try: cPickle.loads(message) - except Exception, e: + except Exception as e: body = str(e) return self.status, response_headers, body @@ -128,13 +128,13 @@ def get_response(self, http_request, uri, response_headers): try: message = base64.b64decode(b64message) - except Exception, e: + except Exception as e: body = str(e) return self.status, response_headers, body try: cPickle.loads(message) - except Exception, e: + except Exception as e: body = str(e) return self.status, response_headers, body @@ -339,7 +339,7 @@ def test_get_payload_all(self): try: payload_1 = ed.get_string_for_delay(1) payload_22 = ed.get_string_for_delay(22) - except Exception, e: + except Exception as e: msg = 'Raised exception "%s" on "%s"' args = (e, file_name) self.assertTrue(False, msg % args) diff --git a/w3af/plugins/tests/audit/test_xxe.py b/w3af/plugins/tests/audit/test_xxe.py index 35281c5e39..bbf6cf866c 100644 --- a/w3af/plugins/tests/audit/test_xxe.py +++ b/w3af/plugins/tests/audit/test_xxe.py @@ -49,7 +49,7 @@ def get_response(self, http_request, uri, response_headers): try: root = etree.fromstring(str(xml), parser=parser) body = etree.tostring(root) - except Exception, e: + except Exception as e: body = str(e) return self.status, response_headers, body @@ -99,7 +99,7 @@ def get_response(self, http_request, uri, response_headers): try: sax.parseString(xml, handler) - except Exception, e: + except Exception as e: body = str(e) else: body = handler.chars @@ -145,7 +145,7 @@ def get_response(self, http_request, uri, response_headers): try: root = etree.fromstring(str(xml), parser=parser) body = etree.tostring(root) - except Exception, e: + except Exception as e: body = str(e) return self.status, response_headers, body @@ -185,7 +185,7 @@ def get_response(self, http_request, uri, response_headers): try: root = etree.fromstring(str(xml), parser=parser) body = etree.tostring(root) - except Exception, e: + except Exception as e: body = 'Generic error here' return self.status, response_headers, body @@ -225,7 +225,7 @@ def get_response(self, http_request, uri, response_headers): try: root = etree.fromstring(str(xml), parser=parser) - except Exception, e: + except Exception as e: body = str(e) return self.status, response_headers, body diff --git a/w3af/plugins/tests/crawl/phpinfo/phpinfo-5.1.3-rc4dev.html b/w3af/plugins/tests/crawl/phpinfo/phpinfo-5.1.3-rc4dev.html index 2859cbb6fb..843ad3f392 100644 --- a/w3af/plugins/tests/crawl/phpinfo/phpinfo-5.1.3-rc4dev.html +++ b/w3af/plugins/tests/crawl/phpinfo/phpinfo-5.1.3-rc4dev.html @@ -571,4 +571,4 @@