Skip to content

Commit

Permalink
SSH Exploiter: Remove operating_system check from command_builder
Browse files Browse the repository at this point in the history
The puppet/master is deciding based on supported operating system if the
plugin is going to be tried.
  • Loading branch information
ilija-lazoroski authored and mssalvatore committed Jul 7, 2023
1 parent e6a7174 commit de4ba9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import PurePath
from typing import Sequence

from common import OperatingSystem
from common.types import AgentID
from infection_monkey.exploit import IAgentOTPProvider
from infection_monkey.i_puppet import TargetHost
Expand All @@ -17,9 +16,6 @@ def build_ssh_command(
remote_agent_binary_destination_path: PurePath,
otp_provider: IAgentOTPProvider,
) -> str:
if target_host.operating_system != OperatingSystem.LINUX:
raise Exception(f"Unsupported operating system: {target_host.operating_system}")

otp = otp_provider.get_otp()
cmdline_arguments = build_monkey_commandline_parameters(
parent=agent_id, servers=servers, depth=current_depth + 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from ipaddress import IPv4Address
from pathlib import PurePosixPath
from typing import Optional
from unittest.mock import MagicMock

import pytest
Expand All @@ -24,22 +26,9 @@ def otp_provider() -> IAgentOTPProvider:
return provider


def test_exception_raised_for_windows(otp_provider: IAgentOTPProvider):
target_host = TargetHost(ip="127.0.0.1", operating_system=OperatingSystem.WINDOWS)

with pytest.raises(Exception):
build_ssh_command(
AGENT_ID,
target_host,
SERVERS,
DEPTH,
AGENT_EXE_PATH,
otp_provider,
)


def test_command(otp_provider: IAgentOTPProvider):
target_host = TargetHost(ip="127.0.0.1", operating_system=OperatingSystem.LINUX)
@pytest.mark.parametrize("os", [OperatingSystem.LINUX, None])
def test_command(otp_provider: IAgentOTPProvider, os: Optional[OperatingSystem]):
target_host = TargetHost(ip=IPv4Address("127.0.0.1"), operating_system=os)

command = build_ssh_command(
AGENT_ID,
Expand Down

0 comments on commit de4ba9d

Please sign in to comment.