Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up logs in Agent Metasploit #21

Merged
merged 4 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading