Merge pull request #2296 from guardicore/2181-store-stolen-credentials-in-repo

2181 store stolen credentials in repo
This commit is contained in:
Mike Salvatore 2022-09-14 14:14:54 -04:00 committed by GitHub
commit 0ea1f9576f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 6 deletions

View File

@ -0,0 +1,2 @@
from .save_event_to_event_repository import save_event_to_event_repository
from .save_stolen_credentials_to_repository import save_stolen_credentials_to_repository

View File

@ -14,4 +14,4 @@ class save_event_to_event_repository:
try:
self._event_repository.save_event(event)
except StorageError as err:
logger.error(f"Error occured storing event {event}: {err}")
logger.error(f"Error occurred while storing event {event}: {err}")

View File

@ -0,0 +1,23 @@
import logging
from common.events import CredentialsStolenEvent
from monkey_island.cc.repository import ICredentialsRepository, StorageError
logger = logging.getLogger(__name__)
class save_stolen_credentials_to_repository:
"""
Accepts CredentialsStolenEvent and pushes the stolen credentials into ICredentialsRepository
"""
def __init__(self, credentials_repository: ICredentialsRepository):
self._credentials_repository = credentials_repository
def __call__(self, credentials_stolen_event: CredentialsStolenEvent):
try:
self._credentials_repository.save_stolen_credentials(
credentials_stolen_event.stolen_credentials
)
except StorageError as err:
logger.error(f"Error occurred while storing stolen credentials: {err}")

View File

@ -1 +0,0 @@
from .save_event_to_event_repository import save_event_to_event_repository

View File

@ -1,7 +1,11 @@
from common import DIContainer
from common.event_queue import IAgentEventQueue
from monkey_island.cc.agent_event_subscribers import save_event_to_event_repository
from monkey_island.cc.repository import IEventRepository
from common.events import CredentialsStolenEvent
from monkey_island.cc.agent_event_handlers import (
save_event_to_event_repository,
save_stolen_credentials_to_repository,
)
from monkey_island.cc.repository import ICredentialsRepository, IEventRepository
def setup_agent_event_handlers(container: DIContainer):
@ -11,6 +15,10 @@ def setup_agent_event_handlers(container: DIContainer):
def _subscribe_and_store_to_event_repository(container: DIContainer):
agent_event_queue = container.resolve(IAgentEventQueue)
event_repository = container.resolve(IEventRepository)
save_event_subscriber = save_event_to_event_repository(event_repository)
save_event_subscriber = save_event_to_event_repository(container.resolve(IEventRepository))
agent_event_queue.subscribe_all_events(save_event_subscriber)
save_stolen_credentials_subscriber = save_stolen_credentials_to_repository(
container.resolve(ICredentialsRepository)
)
agent_event_queue.subscribe_type(CredentialsStolenEvent, save_stolen_credentials_subscriber)