Skip to content

Commit

Permalink
Merge pull request #21 from Ostorlab/fix/cleanup-logs
Browse files Browse the repository at this point in the history
Clean up logs in Agent Metasploit
  • Loading branch information
elyousfi5 authored Mar 13, 2024
2 parents e183b37 + 74b5f8e commit 17d40bd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
21 changes: 17 additions & 4 deletions agent/metasploit_agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ostorlab Agent implementation for metasploit"""

import logging
import socket
import ipaddress
Expand Down Expand Up @@ -72,7 +73,7 @@ def process(self, message: m.Message) -> None:
"""

logger.info("processing message of selector : %s", message.selector)
logger.debug("processing message of selector : %s", message.selector)
if self._is_target_already_processed(message) is True:
return

Expand All @@ -87,7 +88,10 @@ def process(self, message: m.Message) -> None:
logger.error("Specified module %s does not exist", module)
continue
logger.info("Selected metasploit module: %s", selected_module.modulename)

logger.info("Preparing targets ...")
targets = utils.prepare_targets(message)
logger.info("Scanning targets `%s`.", targets)
for target in targets:
vhost = target.host
rport = target.port
Expand Down Expand Up @@ -125,18 +129,27 @@ def process(self, message: m.Message) -> None:
isinstance(results, dict)
and results.get("code") in VULNERABLE_STATUSES
):
logger.info(
"Target `%s` is vulnerable to %s",
vhost,
module_instance.modulename,
)
technical_detail = f"Using `{module_instance.moduletype}` module `{module_instance.modulename}`\n"
technical_detail += f"Target: {vhost}:{rport}\n"
technical_detail += (
f'Message: \n```shell\n{results["message"]}\n```'
)

self._emit_results(module_instance, technical_detail)

else:
logger.info(
"Target `%s` is not vulnerable to %s",
vhost,
module_instance.modulename,
)
client.logout()

self._mark_target_as_processed(message)
logger.info("Done processing message of selector : %s", message.selector)
logger.debug("Done processing message of selector : %s", message.selector)

def _is_target_already_processed(self, message: m.Message) -> bool:
"""Checks if the target has already been processed before, relies on the redis server."""
Expand Down
1 change: 1 addition & 0 deletions agent/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for agent Metasploit"""

import dataclasses
import ipaddress
from typing import cast
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pytest fixtures for agent Metasploit"""

import pathlib
import random
from typing import Any
Expand Down
1 change: 1 addition & 0 deletions tests/metasploit_agent_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for agent Metasploit."""

import pytest
from ostorlab.agent.message import message
from pytest_mock import plugin
Expand Down
1 change: 1 addition & 0 deletions tests/utils_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for metasploit agent utilities"""

from ostorlab.agent.message import message

from agent import utils
Expand Down

0 comments on commit 17d40bd

Please sign in to comment.