Skip to content

Commit 9a2d5d5

Browse files
authored
Merge pull request #188 from thorinaboenke/feature_186_webserver_keeps_serving
add keep_serving option to webserv command
2 parents a771e8f + 9ed1ef0 commit 9a2d5d5

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

docs/source/playbook/commands/webserv.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ webserv
33
=======
44

55
Start a http-server and share a file. This command
6-
will return after the first HTTP-request.
7-
6+
will return after the first HTTP-request. To keep serving the file instead set keep_serving to True.
7+
The webserv command has to be run in background mode, otherwise the playbook execution will halt until a request is received.
88
.. code-block:: yaml
99
1010
###
@@ -35,3 +35,10 @@ will return after the first HTTP-request.
3535

3636
:type: str
3737
:default: ``0.0.0.0``
38+
39+
.. confval:: keep_servng
40+
41+
Keep serving even after a request has been processed
42+
43+
:type: bool
44+
:default: False

src/attackmate/executors/http/webservexecutor.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@ def _exec_cmd(self, command: WebServCommand) -> Result:
6161
address = (command.address, CmdVars.variable_to_int('Port', command.port))
6262
try:
6363
server = WebServe(address, WebRequestHandler, local_path=command.local_path)
64-
server.handle_request()
64+
if command.keep_serving:
65+
self.logger.info('Keeping server alive to serve multiple requests')
66+
try:
67+
server.serve_forever()
68+
except KeyboardInterrupt:
69+
server.server_close()
70+
else:
71+
server.handle_request()
6572
except Exception as e:
6673
raise ExecException(e)
6774

src/attackmate/schemas/http.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class WebServCommand(BaseCommand):
1010
local_path: str
1111
port: StringNumber = '8000'
1212
address: str = '0.0.0.0' # nosec
13+
keep_serving: bool = False
1314

1415

1516
@CommandRegistry.register('http-client')

test/units/test_browserexecutor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def test_browser_executor_named_session(browser_executor):
176176
reuse_cmd = BrowserCommand(
177177
type='browser',
178178
cmd='click',
179-
selector='a[href="https://www.iana.org/domains/example"]',
179+
selector='a[href="http://www.iana.org/domains/example"]',
180180
session='my_session'
181181
)
182182
result2 = browser_executor._exec_cmd(reuse_cmd)

0 commit comments

Comments
 (0)