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

Add a build_permission_change_command method to ILinuxAgentCommandBuilder #10

Merged
merged 6 commits into from
Jun 11, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
the [PEP 440 version scheme](https://peps.python.org/pep-0440/#version-scheme).

## [Unreleased]
### Added
- ILinuxAgentCommandBuilder.build_set_permissions_command().
https://github.com/guardicore/monkey/issues/4187

## [v0.8.0] - 2024-06-10
### Changed
- `ReservationID` from a UUID to a string.
Expand Down
1 change: 1 addition & 0 deletions agentpluginapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
LinuxDownloadMethod,
LinuxDownloadOptions,
LinuxRunOptions,
LinuxSetPermissionsOptions,
)
from .i_propagation_credentials_repository import IPropagationCredentialsRepository
from .i_tcp_port_selector import ITCPPortSelector
Expand Down
17 changes: 15 additions & 2 deletions agentpluginapi/i_linux_agent_command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Optional

from monkeytypes import InfectionMonkeyBaseModel
from pydantic import model_validator
from pydantic import Field, model_validator

from .dropper_execution_mode import DropperExecutionMode

Expand All @@ -20,6 +20,11 @@ class LinuxDownloadOptions(InfectionMonkeyBaseModel):
download_url: str


class LinuxSetPermissionsOptions(InfectionMonkeyBaseModel):
agent_destination_path: PurePosixPath
permissions: int = Field(ge=0, le=0o777, default=0o700)


class LinuxRunOptions(InfectionMonkeyBaseModel):
agent_destination_path: PurePosixPath
dropper_execution_mode: DropperExecutionMode
Expand Down Expand Up @@ -47,6 +52,14 @@ def build_download_command(self, download_options: LinuxDownloadOptions):
:param download_options: Options needed for the command to be built
"""

@abc.abstractmethod
def build_set_permissions_command(self, set_permissions_options: LinuxSetPermissionsOptions):
"""
Build Agent's binary permission change command

:param set_permissions_options: Options needed for the command to be built
"""

@abc.abstractmethod
def build_run_command(self, run_options: LinuxRunOptions):
"""
Expand All @@ -61,7 +74,7 @@ def get_command(self) -> str:
Gets the resulting command
"""

@abc.abstractclassmethod
@abc.abstractmethod
def reset_command(self):
"""
Resets the command
Expand Down
2 changes: 1 addition & 1 deletion agentpluginapi/i_windows_agent_command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_command(self) -> str:
Gets the resulting command
"""

@abc.abstractclassmethod
@abc.abstractmethod
def reset_command(self):
"""
Resets the command
Expand Down
11 changes: 10 additions & 1 deletion tests/test_i_linux_agent_command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from agentpluginapi import DropperExecutionMode, LinuxRunOptions
from agentpluginapi import DropperExecutionMode, LinuxRunOptions, LinuxSetPermissionsOptions


@pytest.mark.parametrize(
Expand All @@ -15,3 +15,12 @@ def test_linux_run_options(dropper_execution_mode: DropperExecutionMode):
dropper_execution_mode=dropper_execution_mode,
dropper_destination_path=PurePosixPath("/tmp/dropper"),
)


@pytest.mark.parametrize("permissions", [0o1000, -0o1])
def test_linux_permissions_options(permissions: int):
with pytest.raises(ValueError):
LinuxSetPermissionsOptions(
agent_destination_path=PurePosixPath("/tmp/agent"),
permissions=permissions,
)
5 changes: 5 additions & 0 deletions vulture_allowlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
WindowsRunOptions,
WindowsShell,
)
from agentpluginapi.i_linux_agent_command_builder import LinuxSetPermissionsOptions

IAgentEventPublisher.publish
IAgentEventPublisher.event
Expand Down Expand Up @@ -126,6 +127,8 @@
LinuxDownloadOptions.download_url
LinuxDownloadOptions.download_method

LinuxSetPermissionsOptions.file_path
LinuxSetPermissionsOptions.permissions

LinuxRunOptions.agent_destination_path
LinuxRunOptions.dropper_destination_path
Expand All @@ -134,6 +137,8 @@

ILinuxAgentCommandBuilder.build_download_command
ILinuxAgentCommandBuilder.build_run_command
ILinuxAgentCommandBuilder.build_set_permissions_command
ILinuxAgentCommandBuilder.set_permissions_options
ILinuxAgentCommandBuilder.get_command
ILinuxAgentCommandBuilder.reset_command
ILinuxAgentCommandBuilder.download_options
Expand Down