Skip to content

Commit d323b07

Browse files
Merge pull request #171 from thorinaboenke/feature_delay
add command_delay to config
2 parents c4317e1 + c0de458 commit d323b07

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

docs/source/configuration/command_config.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
cmd_config
33
==========
44

5-
Stores global variables for command options. These are settings for **all** commands.
5+
Stores global variables for command options.
6+
These are settings for **all** commands.
67

78
.. code-block:: yaml
89
910
###
1011
cmd_config:
1112
loop_sleep: 5
13+
command_delay: 0
1214
1315
.. confval:: loop_sleep
1416

@@ -19,3 +21,11 @@ Stores global variables for command options. These are settings for **all** comm
1921

2022
:type: int
2123
:default: 5
24+
25+
.. confval:: command_delay
26+
27+
This delay in seconds is applied to all commands in the playbook.
28+
It is not applied to debug, setvar and sleep commands.
29+
30+
:type: float
31+
:default: 0

docs/source/configuration/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ sliver and metasploit:
2525
###
2626
cmd_config:
2727
loop_sleep: 5
28+
command_delay: 0
2829
2930
msf_config:
3031
password: securepassword

src/attackmate/attackmate.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
configuration.
99
"""
1010

11+
import time
1112
from typing import Dict, Optional
1213
import logging
1314
from attackmate.result import Result
@@ -21,7 +22,6 @@
2122
import asyncio
2223

2324

24-
2525
class AttackMate:
2626
def __init__(
2727
self,
@@ -89,10 +89,14 @@ def _get_executor(self, command_type: str) -> BaseExecutor:
8989
return self.executors[command_type]
9090

9191
def _run_commands(self, commands: Commands):
92+
delay = self.pyconfig.cmd_config.command_delay or 0
93+
self.logger.info(f'Delay before commands: {delay} seconds')
9294
for command in commands:
9395
command_type = 'ssh' if command.type == 'sftp' else command.type
9496
executor = self._get_executor(command_type)
9597
if executor:
98+
if command.type not in ('sleep', 'debug', 'setvar'):
99+
time.sleep(delay)
96100
executor.run(command)
97101

98102
def run_command(self, command: Command) -> Result:
@@ -101,28 +105,25 @@ def run_command(self, command: Command) -> Result:
101105
if executor:
102106
result = executor.run(command)
103107
return result if result else Result(None, None)
104-
108+
105109
def clean_session_stores(self):
106110
self.logger.warning('Cleaning up session stores')
107111
# msf
108-
if (msf_module_executor := self.executors.get("msf-module")):
112+
if (msf_module_executor := self.executors.get('msf-module')):
109113
msf_module_executor.cleanup()
110-
if (msf_session_executor := self.executors.get("msf-session")):
114+
if (msf_session_executor := self.executors.get('msf-session')):
111115
msf_session_executor.cleanup()
112116
# ssh
113-
if (ssh_executor := self.executors.get("ssh")):
117+
if (ssh_executor := self.executors.get('ssh')):
114118
ssh_executor.cleanup()
115119
# vnc
116-
if (vnc_executor := self.executors.get("vnc")):
120+
if (vnc_executor := self.executors.get('vnc')):
117121
vnc_executor.cleanup()
118122
# sliver
119-
if (sliver_executor := self.executors.get("sliver-session")):
123+
if (sliver_executor := self.executors.get('sliver-session')):
120124
loop = asyncio.get_event_loop()
121125
loop.run_until_complete(sliver_executor.cleanup())
122126

123-
124-
125-
126127
def main(self):
127128
"""The main function
128129

src/attackmate/schemas/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ class MsfConfig(BaseModel):
1616

1717
class CommandConfig(BaseModel):
1818
loop_sleep: int = 5
19+
command_delay: float = 0
1920

2021

2122
class Config(BaseModel):
2223
sliver_config: SliverConfig = SliverConfig(config_file=None)
2324
msf_config: MsfConfig = MsfConfig(password=None)
24-
cmd_config: CommandConfig = CommandConfig(loop_sleep=5)
25+
cmd_config: CommandConfig = CommandConfig(loop_sleep=5, command_delay=0)

0 commit comments

Comments
 (0)