Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions docs/source/playbook/commands/webserv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

###
Expand Down Expand Up @@ -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
9 changes: 8 additions & 1 deletion src/attackmate/executors/http/webservexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions src/attackmate/schemas/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion test/units/test_browserexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading