From f7760554308ef39b7faa3aa0ae856b676c65cc21 Mon Sep 17 00:00:00 2001 From: shelld3v <59408894+shelld3v@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:49:36 +0700 Subject: [PATCH] Fix in asyncio mode as well --- lib/core/fuzzer.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/lib/core/fuzzer.py b/lib/core/fuzzer.py index 85cc1304..a4688ebd 100755 --- a/lib/core/fuzzer.py +++ b/lib/core/fuzzer.py @@ -53,7 +53,6 @@ def __init__( self._requester = requester self._dictionary = dictionary self._base_path: str = "" - self.exc: Exception | None = None self.match_callbacks = match_callbacks self.not_found_callbacks = not_found_callbacks self.error_callbacks = error_callbacks @@ -148,6 +147,7 @@ def __init__( not_found_callbacks=not_found_callbacks, error_callbacks=error_callbacks, ) + self._exc: Exception | None = None self._threads = [] self._play_event = threading.Event() self._quit_event = threading.Event() @@ -207,8 +207,8 @@ def start(self) -> None: thread.start() def is_finished(self) -> bool: - if self.exc: - raise self.exc + if self._exc: + raise self._exc for thread in self._threads: if thread.is_alive(): @@ -266,7 +266,7 @@ def thread_proc(self) -> None: break except Exception as e: - self.exc = e + self._exc = e finally: time.sleep(options["delay"]) @@ -358,12 +358,6 @@ async def start(self) -> None: await asyncio.gather(*self._background_tasks) - def is_finished(self) -> bool: - if self.exc: - raise self.exc - - return len(self._background_tasks) == 0 - def play(self) -> None: self._play_event.set() @@ -376,7 +370,12 @@ def quit(self) -> None: async def scan(self, path: str) -> None: scanners = self.get_scanners_for(path) - response = await self._requester.request(path) + try: + response = await self._requester.request(path) + except RequestException as e: + for callback in self.error_callbacks: + callback(e) + return if self.is_excluded(response): for callback in self.not_found_callbacks: @@ -390,11 +389,8 @@ async def scan(self, path: str) -> None: callback(response) return - try: - for callback in self.match_callbacks: - callback(response) - except Exception as e: - self.exc = e + for callback in self.match_callbacks: + callback(response) async def task_proc(self) -> None: async with self.sem: @@ -405,8 +401,5 @@ async def task_proc(self) -> None: await self.scan(self._base_path + path) except StopIteration: pass - except RequestException as e: - for callback in self.error_callbacks: - callback(e) finally: await asyncio.sleep(options["delay"])