Skip to content

Commit

Permalink
added background-mode for ssh and sftp commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfgang Hotwagner committed Nov 27, 2023
1 parent dcc18b9 commit b326cbd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/attackmate/executors/ssh/sessionstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ class SessionStore:
def __init__(self):
self.store: dict[str, tuple[SSHClient, Optional[Channel]]] = {}

def __getstate__(self):
"""
store contains the states of the ssh connections. they are not
serializable.
"""
state = self.__dict__.copy()
state['store'] = None
return state

def has_session(self, session_name: str) -> bool:
if session_name in self.store:
return True
Expand Down
14 changes: 13 additions & 1 deletion src/attackmate/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def list_template_vars(self) -> List[str]:

@validator('background')
def bg_not_implemented_yet(cls, v):
if cls in (SSHCommand, SFTPCommand, MsfSessionCommand, IncludeCommand):
if cls in (MsfSessionCommand, IncludeCommand):
raise ValueError('background mode is unsupported for this command')
return v

Expand Down Expand Up @@ -116,6 +116,18 @@ class RegExCommand(BaseCommand):


class SSHBase(BaseCommand):
@validator('session')
def session_and_background_unsupported(cls, v, values, **kwargs):
if 'background' in values and values['background']:
raise ValueError('background mode combined with session is unsupported for SSH')
return v

@validator('creates_session')
def creates_session_and_background_unsupported(cls, v, values, **kwargs):
if 'background' in values and values['background']:
raise ValueError('background mode combined with session is unsupported for SSH')
return v

hostname: Optional[str]
port: Optional[str] = Field(pattern=VAR_PATTERN, default=None)
username: Optional[str]
Expand Down

0 comments on commit b326cbd

Please sign in to comment.