diff --git a/docs/source/playbook/commands/webserv.rst b/docs/source/playbook/commands/webserv.rst index 9e683e4c..52a33299 100644 --- a/docs/source/playbook/commands/webserv.rst +++ b/docs/source/playbook/commands/webserv.rst @@ -3,8 +3,8 @@ webserv ======= Start a http-server and share a file. This command -will return after the first HTTP-request. - +will return after the first HTTP-request. To keep serving the file instead set keep_serving to True. +The webserv command has to be run in background mode, otherwise the playbook execution will halt until a request is received. .. code-block:: yaml ### @@ -35,3 +35,10 @@ will return after the first HTTP-request. :type: str :default: ``0.0.0.0`` + +.. confval:: keep_servng + + Keep serving even after a request has been processed + + :type: bool + :default: False diff --git a/src/attackmate/executors/http/webservexecutor.py b/src/attackmate/executors/http/webservexecutor.py index f66e1f1a..e206c162 100644 --- a/src/attackmate/executors/http/webservexecutor.py +++ b/src/attackmate/executors/http/webservexecutor.py @@ -61,7 +61,14 @@ def _exec_cmd(self, command: WebServCommand) -> Result: address = (command.address, CmdVars.variable_to_int('Port', command.port)) try: server = WebServe(address, WebRequestHandler, local_path=command.local_path) - server.handle_request() + if command.keep_serving: + self.logger.info('Keeping server alive to serve multiple requests') + try: + server.serve_forever() + except KeyboardInterrupt: + server.server_close() + else: + server.handle_request() except Exception as e: raise ExecException(e) diff --git a/src/attackmate/schemas/http.py b/src/attackmate/schemas/http.py index 1dbc741d..ac5d8776 100644 --- a/src/attackmate/schemas/http.py +++ b/src/attackmate/schemas/http.py @@ -10,6 +10,7 @@ class WebServCommand(BaseCommand): local_path: str port: StringNumber = '8000' address: str = '0.0.0.0' # nosec + keep_serving: bool = False @CommandRegistry.register('http-client') diff --git a/test/units/test_browserexecutor.py b/test/units/test_browserexecutor.py index 271c4ee3..66353bf3 100644 --- a/test/units/test_browserexecutor.py +++ b/test/units/test_browserexecutor.py @@ -176,7 +176,7 @@ def test_browser_executor_named_session(browser_executor): reuse_cmd = BrowserCommand( type='browser', cmd='click', - selector='a[href="https://www.iana.org/domains/example"]', + selector='a[href="http://www.iana.org/domains/example"]', session='my_session' ) result2 = browser_executor._exec_cmd(reuse_cmd)