From 4b410c8aa93b1cf0a60d640e5e5778c666017546 Mon Sep 17 00:00:00 2001 From: thorinaboenke Date: Tue, 16 Dec 2025 17:00:44 +0100 Subject: [PATCH 1/3] add keep_serving option to webserv command --- docs/source/playbook/commands/webserv.rst | 9 ++++++++- src/attackmate/executors/http/webservexecutor.py | 9 ++++++++- src/attackmate/schemas/http.py | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/source/playbook/commands/webserv.rst b/docs/source/playbook/commands/webserv.rst index 9e683e4c..ba9ea6a4 100644 --- a/docs/source/playbook/commands/webserv.rst +++ b/docs/source/playbook/commands/webserv.rst @@ -3,7 +3,7 @@ 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. .. 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') From cc4b179c874243217a1f0d7dc78d8bf759b65a56 Mon Sep 17 00:00:00 2001 From: thorinaboenke Date: Tue, 16 Dec 2025 17:02:55 +0100 Subject: [PATCH 2/3] add instruction on background mode to webserv docs --- docs/source/playbook/commands/webserv.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/playbook/commands/webserv.rst b/docs/source/playbook/commands/webserv.rst index ba9ea6a4..52a33299 100644 --- a/docs/source/playbook/commands/webserv.rst +++ b/docs/source/playbook/commands/webserv.rst @@ -4,7 +4,7 @@ webserv Start a http-server and share a file. This command 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 ### From 9ed1ef026ae2fdc0b43a5f88d1ae040619b24e62 Mon Sep 17 00:00:00 2001 From: thorinaboenke Date: Wed, 17 Dec 2025 08:19:21 +0100 Subject: [PATCH 3/3] update brwoser executor test --- test/units/test_browserexecutor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)