Skip to content

Commit

Permalink
Merge pull request #20 from mbrg/rename_machine_pwn_module
Browse files Browse the repository at this point in the history
Rename machine pwn module
  • Loading branch information
lanasalameh1 authored Jul 30, 2023
2 parents 6c487a5 + 261349a commit 105e144
Show file tree
Hide file tree
Showing 51 changed files with 117 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
find . -name '*requirements.txt' | while read file; do pip install -r "$file"; done
- name: Lint with mypy
run: |
mypy ./src/powerpwn/machinepwn/
mypy ./src/powerpwn/nocodemalware/
do-isort:
name: Do isort
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ console_scripts =
plugins = pydantic.mypy

show_error_codes = true
follow_imports = "normal"
follow_imports = normal
ignore_errors = false
implicit_reexport = false
warn_redundant_casts = true
Expand Down
2 changes: 1 addition & 1 deletion src/powerpwn/cli/arguments.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import logging

from powerpwn.machinepwn.enums.code_exec_type_enum import CodeExecTypeEnum
from powerpwn.nocodemalware.enums.code_exec_type_enum import CodeExecTypeEnum
from powerpwn.powerdoor.enums.action_type import BackdoorActionType
from powerpwn.powerdump.utils.const import CACHE_PATH

Expand Down
20 changes: 10 additions & 10 deletions src/powerpwn/cli/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import shutil

from powerpwn.cli.const import LOGGER_NAME
from powerpwn.machinepwn.enums.code_exec_type_enum import CodeExecTypeEnum
from powerpwn.machinepwn.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.machinepwn.machine_pwn import MachinePwn
from powerpwn.nocodemalware.enums.code_exec_type_enum import CodeExecTypeEnum
from powerpwn.nocodemalware.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.nocodemalware.malware_runner import MalwareRunner
from powerpwn.powerdoor.backdoor_flow import BackdoorFlow
from powerpwn.powerdoor.enums.action_type import BackdoorActionType
from powerpwn.powerdoor.flow_factory_installer import FlowFlowInstaller
Expand Down Expand Up @@ -88,21 +88,21 @@ def run_backdoor_flow_command(args):


def run_nocodemalware_command(args):
machine_pwn = MachinePwn(args.webhook_url)
malware_runner = MalwareRunner(args.webhook_url)

command_type = CommandToRunEnum(args.nocodemalware_subcommand)
if command_type == CommandToRunEnum.CLEANUP:
res = machine_pwn.cleanup()
res = malware_runner.cleanup()
elif command_type == CommandToRunEnum.CODE_EXEC:
res = machine_pwn.exec_command(args.command_to_execute, CodeExecTypeEnum(args.type))
res = malware_runner.exec_command(args.command_to_execute, CodeExecTypeEnum(args.type))
elif command_type == CommandToRunEnum.EXFILTRATION:
res = machine_pwn.exfiltrate(args.file)
res = malware_runner.exfiltrate(args.file)
elif command_type == CommandToRunEnum.RANSOMWARE:
res = machine_pwn.ransomware(args.crawl_depth, args.dirs.split(","), args.encryption_key)
res = malware_runner.ransomware(args.crawl_depth, args.dirs.split(","), args.encryption_key)
elif command_type == CommandToRunEnum.STEAL_COOKIE:
res = machine_pwn.steal_cookie(args.cookie)
res = malware_runner.steal_cookie(args.cookie)
elif command_type == CommandToRunEnum.STEAL_POWER_AUTOMATE_TOKEN:
res = machine_pwn.steal_power_automate_token()
res = malware_runner.steal_power_automate_token()
print(res)


Expand Down
21 changes: 0 additions & 21 deletions src/powerpwn/machinepwn/models/any_command_args.py

This file was deleted.

9 changes: 0 additions & 9 deletions src/powerpwn/machinepwn/models/cleanup_command_args.py

This file was deleted.

9 changes: 0 additions & 9 deletions src/powerpwn/machinepwn/models/code_exec_command_args.py

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions src/powerpwn/machinepwn/models/ransomware_command_args.py

This file was deleted.

9 changes: 0 additions & 9 deletions src/powerpwn/machinepwn/models/steal_cookie_command_args.py

This file was deleted.

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
import requests
from pydantic.error_wrappers import ValidationError

from powerpwn.machinepwn.enums.code_exec_type_enum import CodeExecTypeEnum
from powerpwn.machinepwn.models.any_command_args import AnyCommandArgs
from powerpwn.machinepwn.models.cleanup_command_args import CleanupCommandArgs
from powerpwn.machinepwn.models.cmd_results import CommandResults
from powerpwn.machinepwn.models.code_exec_args_properties import CodeExecArgsProperties
from powerpwn.machinepwn.models.code_exec_command_args import CodeExecCommandArgs
from powerpwn.machinepwn.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel
from powerpwn.machinepwn.models.exflirtate_file_args_properties import ExflirtateFileArgsProperties
from powerpwn.machinepwn.models.exflirtate_file_command_args import ExflirtateFileCommandArgs
from powerpwn.machinepwn.models.ransomware_args_properties import RansomwareArgsProperties
from powerpwn.machinepwn.models.ransomware_command_args import RansomwareCommandArgs
from powerpwn.machinepwn.models.steal_cookie_args_properties import StealCookieArgsProperties
from powerpwn.machinepwn.models.steal_cookie_command_args import StealCookieCommandArgs
from powerpwn.machinepwn.models.steal_power_automate_token_command_args import StealPowerAutomateTokenCommandArgs


class MachinePwn:
from powerpwn.nocodemalware.enums.code_exec_type_enum import CodeExecTypeEnum
from powerpwn.nocodemalware.models.any_command_args import AnyCommandArgs
from powerpwn.nocodemalware.models.cleanup_command_args import CleanupCommandArgs
from powerpwn.nocodemalware.models.cmd_results import CommandResults
from powerpwn.nocodemalware.models.code_exec_args_properties import CodeExecArgsProperties
from powerpwn.nocodemalware.models.code_exec_command_args import CodeExecCommandArgs
from powerpwn.nocodemalware.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel
from powerpwn.nocodemalware.models.exflirtate_file_args_properties import ExflirtateFileArgsProperties
from powerpwn.nocodemalware.models.exflirtate_file_command_args import ExflirtateFileCommandArgs
from powerpwn.nocodemalware.models.ransomware_args_properties import RansomwareArgsProperties
from powerpwn.nocodemalware.models.ransomware_command_args import RansomwareCommandArgs
from powerpwn.nocodemalware.models.steal_cookie_args_properties import StealCookieArgsProperties
from powerpwn.nocodemalware.models.steal_cookie_command_args import StealCookieCommandArgs
from powerpwn.nocodemalware.models.steal_power_automate_token_command_args import StealPowerAutomateTokenCommandArgs


class MalwareRunner:
def __init__(self, post_url: str, debug: bool = False):
"""
Power Pwn client to run commands through Microsoft infrastructure
Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions src/powerpwn/nocodemalware/models/any_command_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Union

from pydantic import BaseModel, Field

from powerpwn.nocodemalware.models.cleanup_command_args import CleanupCommandArgs
from powerpwn.nocodemalware.models.code_exec_command_args import CodeExecCommandArgs
from powerpwn.nocodemalware.models.exflirtate_file_command_args import ExflirtateFileCommandArgs
from powerpwn.nocodemalware.models.ransomware_command_args import RansomwareCommandArgs
from powerpwn.nocodemalware.models.steal_cookie_command_args import StealCookieCommandArgs
from powerpwn.nocodemalware.models.steal_power_automate_token_command_args import StealPowerAutomateTokenCommandArgs


class AnyCommandArgs(BaseModel):
__root__: Union[
CleanupCommandArgs,
CodeExecCommandArgs,
RansomwareCommandArgs,
ExflirtateFileCommandArgs,
StealCookieCommandArgs,
StealPowerAutomateTokenCommandArgs,
] = Field(discriminator="command_to_run")
9 changes: 9 additions & 0 deletions src/powerpwn/nocodemalware/models/cleanup_command_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Literal

from powerpwn.nocodemalware.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.nocodemalware.models.cmd_arguments import CommandArguments
from powerpwn.nocodemalware.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel


class CleanupCommandArgs(CommandArguments[CommandArgsPropertiesBaseModel]):
command_to_run: Literal[CommandToRunEnum.CLEANUP] = CommandToRunEnum.CLEANUP
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from pydantic.generics import GenericModel

from powerpwn.machinepwn.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.machinepwn.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel
from powerpwn.nocodemalware.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.nocodemalware.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel

_TCommandArgumentProperties = TypeVar("_TCommandArgumentProperties", bound=CommandArgsPropertiesBaseModel)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pydantic import Field

from powerpwn.machinepwn.enums.code_exec_type_enum import CodeExecTypeEnum
from powerpwn.machinepwn.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel
from powerpwn.nocodemalware.enums.code_exec_type_enum import CodeExecTypeEnum
from powerpwn.nocodemalware.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel


class CodeExecArgsProperties(CommandArgsPropertiesBaseModel):
Expand Down
9 changes: 9 additions & 0 deletions src/powerpwn/nocodemalware/models/code_exec_command_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Literal

from powerpwn.nocodemalware.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.nocodemalware.models.cmd_arguments import CommandArguments
from powerpwn.nocodemalware.models.code_exec_args_properties import CodeExecArgsProperties


class CodeExecCommandArgs(CommandArguments[CodeExecArgsProperties]):
command_to_run: Literal[CommandToRunEnum.CODE_EXEC] = CommandToRunEnum.CODE_EXEC
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import Field

from powerpwn.machinepwn.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel
from powerpwn.nocodemalware.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel


class ExflirtateFileArgsProperties(CommandArgsPropertiesBaseModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Literal

from powerpwn.nocodemalware.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.nocodemalware.models.cmd_arguments import CommandArguments
from powerpwn.nocodemalware.models.exflirtate_file_args_properties import ExflirtateFileArgsProperties


class ExflirtateFileCommandArgs(CommandArguments[ExflirtateFileArgsProperties]):
command_to_run: Literal[CommandToRunEnum.EXFILTRATION] = CommandToRunEnum.EXFILTRATION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import Field

from powerpwn.machinepwn.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel
from powerpwn.nocodemalware.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel


class RansomwareArgsProperties(CommandArgsPropertiesBaseModel):
Expand Down
9 changes: 9 additions & 0 deletions src/powerpwn/nocodemalware/models/ransomware_command_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Literal

from powerpwn.nocodemalware.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.nocodemalware.models.cmd_arguments import CommandArguments
from powerpwn.nocodemalware.models.ransomware_args_properties import RansomwareArgsProperties


class RansomwareCommandArgs(CommandArguments[RansomwareArgsProperties]):
command_to_run: Literal[CommandToRunEnum.RANSOMWARE] = CommandToRunEnum.RANSOMWARE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import Field

from powerpwn.machinepwn.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel
from powerpwn.nocodemalware.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel


class StealCookieArgsProperties(CommandArgsPropertiesBaseModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Literal

from powerpwn.nocodemalware.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.nocodemalware.models.cmd_arguments import CommandArguments
from powerpwn.nocodemalware.models.steal_cookie_args_properties import StealCookieArgsProperties


class StealCookieCommandArgs(CommandArguments[StealCookieArgsProperties]):
command_to_run: Literal[CommandToRunEnum.STEAL_COOKIE] = CommandToRunEnum.STEAL_COOKIE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Literal

from powerpwn.nocodemalware.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.nocodemalware.models.cmd_arguments import CommandArguments
from powerpwn.nocodemalware.models.command_args_properties_base_model import CommandArgsPropertiesBaseModel


class StealPowerAutomateTokenCommandArgs(CommandArguments[CommandArgsPropertiesBaseModel]):
command_to_run: Literal[CommandToRunEnum.STEAL_POWER_AUTOMATE_TOKEN] = CommandToRunEnum.STEAL_POWER_AUTOMATE_TOKEN
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import pytest

from powerpwn.machinepwn.enums.code_exec_type_enum import CodeExecTypeEnum
from powerpwn.machinepwn.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.machinepwn.machine_pwn import MachinePwn
from powerpwn.machinepwn.models.cmd_results import (
from powerpwn.nocodemalware.enums.code_exec_type_enum import CodeExecTypeEnum
from powerpwn.nocodemalware.enums.command_to_run_enum import CommandToRunEnum
from powerpwn.nocodemalware.malware_runner import MalwareRunner
from powerpwn.nocodemalware.models.cmd_results import (
AgentRunErrors,
AgentRunType,
CleanupOutputs,
Expand All @@ -22,7 +22,7 @@
DEBUG = True


class DummyPowerPwnC2(MachinePwn):
class DummyPowerPwnC2(MalwareRunner):
def __init__(self, post_url: str, debug: bool, command_to_run: CommandToRunEnum):
super().__init__(post_url, debug)
self.command_to_run = command_to_run
Expand Down

0 comments on commit 105e144

Please sign in to comment.