def goto_path(self, path_name: str) -> TestCase or None: """ Prepare the session, self.test_case and self._test_cases in the test_case with the path_name identified. Args: path_name: The test_case to go. It must be "request_name" or "request_name.mutant_name" Returns: The first test_case specified by path_name """ destination = Request.get_mutant_by_path(path_name) if not destination.fuzzable: raise exception.FuzzowskiRuntimeError(f"You can't go to {path_name}. It is not fuzzable!") self._reset() for test_case in self._test_cases: if test_case.request == destination or test_case.request.mutant == destination: return test_case
def disable_by_path_name(self, path_name: str, disable: bool = True): """ Disable/enable the element specified by path_name Args: path_name: it should be REQUEST_NAME to disable a request, or REQUEST_NAME.MUTANT_NAME for a mutant disable: (Def True). True to disable, False to enable """ disabled_element = Request.get_mutant_by_path(path_name) disabled_element.disabled = disable if disable: # Add to self.disabled_elements dictionary self.disabled_elements[path_name] = disabled_element else: try: self.disabled_elements.pop(path_name) except KeyError: pass
def transmit(self, request: Request, callback_data: bytes = None, original: bool = False, receive=True): """ Render and transmit a fuzzed node, process callbacks accordingly. Args: request: Request that is being fuzzed callback_data: callback data from a previous callback original: if True, will send the original value and not render receive: if True, it will try to receive data after sending the request Returns: None Raises: FuzzowskiTestCaseAborted when a transmission error occurs """ if callback_data: data = callback_data else: if original: data = request.original_value else: data = request.render() # 1. SEND DATA try: self.last_send = data self.session.target.send(data) except exception.FuzzowskiTargetConnectionReset as e: # Connection was reset self.logger.log_info("Target connection reset.") condition = self.session.opts.ignore_transmission_errors if original \ else self.session.opts.ignore_connection_issues_after_fuzz if not condition: self.add_error(e) self.session.add_suspect(self) raise exception.FuzzowskiTestCaseAborted( str(e)) # Abort TestCase, Connection Reset except exception.FuzzowskiTargetConnectionAborted as e: msg = f"Target connection lost (socket error: {e.socket_errno} {e.socket_errmsg})" condition = self.session.opts.ignore_transmission_errors if original \ else self.session.opts.ignore_connection_issues_after_fuzz if condition: self.logger.log_info(msg) else: self.logger.log_fail(msg) self.add_error(e) self.session.add_suspect(self) raise exception.FuzzowskiTestCaseAborted( str(e)) # Abort TestCase, Connection Failed # 2. RECEIVE DATA if receive: try: receive_failed = False error = '' self.last_recv = self.session.target.recv_all(DEFAULT_MAX_RECV) if not self.last_recv: # Nothing received, probably conn reset receive_failed = True error = "Nothing received. Connection Reset?" # raise exception.FuzzowskiTestCaseAborted("Receive failed. Aborting Test Case") elif len(request.responses ) > 0: # Data received, Responses defined try: self.logger.log_check( "Parsing response with data received") response_str = request.parse_response(self.last_recv) self.logger.log_info(response_str) receive_failed = False except exception.FuzzowskiRuntimeError as e: # Data received, Response do not match self.logger.log_fail(str(e)) # Abort TestCase receive_failed = False raise exception.FuzzowskiTestCaseAborted(str(e)) except Exception as e: # Any other exception not controlled by the Restarter module self.logger.log_fail(str(e)) self.session.is_paused = True # Pause the session if an uncontrolled error occurs raise exception.FuzzowskiTestCaseAborted(str(e)) else: # Data received, no Responses defined receive_failed = False if self.session.opts.check_data_received_each_request: self.logger.log_check("Checking data received...") if receive_failed: # Assume a crash? self.logger.log_fail( f"Nothing received from target. {error}") self.session.add_suspect(self) raise exception.FuzzowskiTestCaseAborted( "Receive failed. Aborting Test Case") except exception.FuzzowskiTargetConnectionReset as e: # Connection reset self.logger.log_info("Target connection reset.") if self.session.opts.check_data_received_each_request: self.logger.log_fail("Target connection reset.") self.add_error(e) self.session.add_suspect(self) raise exception.FuzzowskiTestCaseAborted(str(e)) except exception.FuzzowskiTargetConnectionAborted as e: msg = f"Target connection lost (socket error: {e.socket_errno} {e.socket_errmsg})" if self.session.opts.check_data_received_each_request: self.logger.log_fail(msg) self.add_error(e) self.session.add_suspect(self) else: self.logger.log_info(msg) raise exception.FuzzowskiTestCaseAborted(str(e))