Merge pull request #2296 from guardicore/2181-store-stolen-credentials-in-repo
2181 store stolen credentials in repo
This commit is contained in:
commit
0ea1f9576f
|
@ -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
|
|
@ -14,4 +14,4 @@ class save_event_to_event_repository:
|
||||||
try:
|
try:
|
||||||
self._event_repository.save_event(event)
|
self._event_repository.save_event(event)
|
||||||
except StorageError as err:
|
except StorageError as err:
|
||||||
logger.error(f"Error occured storing event {event}: {err}")
|
logger.error(f"Error occurred while storing event {event}: {err}")
|
|
@ -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}")
|
|
@ -1 +0,0 @@
|
||||||
from .save_event_to_event_repository import save_event_to_event_repository
|
|
|
@ -1,7 +1,11 @@
|
||||||
from common import DIContainer
|
from common import DIContainer
|
||||||
from common.event_queue import IAgentEventQueue
|
from common.event_queue import IAgentEventQueue
|
||||||
from monkey_island.cc.agent_event_subscribers import save_event_to_event_repository
|
from common.events import CredentialsStolenEvent
|
||||||
from monkey_island.cc.repository import IEventRepository
|
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):
|
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):
|
def _subscribe_and_store_to_event_repository(container: DIContainer):
|
||||||
agent_event_queue = container.resolve(IAgentEventQueue)
|
agent_event_queue = container.resolve(IAgentEventQueue)
|
||||||
|
|
||||||
event_repository = container.resolve(IEventRepository)
|
save_event_subscriber = save_event_to_event_repository(container.resolve(IEventRepository))
|
||||||
save_event_subscriber = save_event_to_event_repository(event_repository)
|
|
||||||
agent_event_queue.subscribe_all_events(save_event_subscriber)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue