From 87bdfa6bb20a2d284be95808e28803b6d15d99d1 Mon Sep 17 00:00:00 2001 From: Lav Date: Tue, 17 Nov 2026 13:45:28 +0100 Subject: [PATCH] Updated examples for v4.0 --- Payload_Type/go_services/go.mod | 2 +- Payload_Type/python_services/Dockerfile | 12 +- .../agent_functions/builder.py | 1 + .../agent_functions/builder.py | 5 + .../python_services/basic_wrapper/__init__.py | 18 ++ .../basic_wrapper/agent_code/.keep | 0 .../basic_wrapper/agent_functions/__init__.py | 0 .../basic_wrapper/agent_functions/builder.py | 156 ++++++++++++++++++ Payload_Type/python_services/main.py | 3 +- Payload_Type/python_services/requirements.txt | 2 + .../mythic/c2_functions/websocket.py | 1 + 11 files changed, 196 insertions(+), 4 deletions(-) create mode 100644 Payload_Type/python_services/basic_wrapper/__init__.py create mode 100644 Payload_Type/python_services/basic_wrapper/agent_code/.keep create mode 100644 Payload_Type/python_services/basic_wrapper/agent_functions/__init__.py create mode 100644 Payload_Type/python_services/basic_wrapper/agent_functions/builder.py create mode 100644 Payload_Type/python_services/requirements.txt diff --git a/Payload_Type/go_services/go.mod b/Payload_Type/go_services/go.mod index 47adcde..fa31a22 100644 --- a/Payload_Type/go_services/go.mod +++ b/Payload_Type/go_services/go.mod @@ -8,7 +8,7 @@ toolchain go1.23.3 require ( github.com/Khan/genqlient v0.8.0 - github.com/MythicMeta/MythicContainer v1.4.23 + github.com/MythicMeta/MythicContainer v1.7.0-rc4 github.com/crewjam/saml v0.4.14 github.com/mitchellh/mapstructure v1.5.0 ) diff --git a/Payload_Type/python_services/Dockerfile b/Payload_Type/python_services/Dockerfile index ee60ec0..811ca31 100644 --- a/Payload_Type/python_services/Dockerfile +++ b/Payload_Type/python_services/Dockerfile @@ -1,7 +1,15 @@ FROM itsafeaturemythic/mythic_python_go:latest -RUN pip3 install mythic_container==0.5.25 +RUN pip3 install mythic_container==0.7.0rc9 +RUN pip3 install --upgrade --force-reinstall grpcio>=1.78.0 WORKDIR /Mythic/ -CMD ["python3", "main.py"] \ No newline at end of file +COPY [".", "."] + +# fix Windows CRLF in .py files so shebangs and imports work +RUN find . -name '*.py' -exec sed -i 's/\r$//' {} + + +RUN pip3 install -r requirements.txt + +CMD ["python3", "main.py"] diff --git a/Payload_Type/python_services/basic_command_augment/agent_functions/builder.py b/Payload_Type/python_services/basic_command_augment/agent_functions/builder.py index 25ef144..f1e4589 100644 --- a/Payload_Type/python_services/basic_command_augment/agent_functions/builder.py +++ b/Payload_Type/python_services/basic_command_augment/agent_functions/builder.py @@ -12,3 +12,4 @@ class BasicCommandAugment(PayloadType): agent_code_path = agent_path / "agent_code" command_augment_supported_agents = [] # this means these commands are injected into all agent's callbacks on macOS agent_type = AgentType.CommandAugment + semver = "0.4.0" diff --git a/Payload_Type/python_services/basic_python_agent/agent_functions/builder.py b/Payload_Type/python_services/basic_python_agent/agent_functions/builder.py index 2060e23..1c4b10d 100644 --- a/Payload_Type/python_services/basic_python_agent/agent_functions/builder.py +++ b/Payload_Type/python_services/basic_python_agent/agent_functions/builder.py @@ -22,6 +22,7 @@ class BasicPythonAgent(PayloadType): agent_path = pathlib.Path(".") / "basic_python_agent" agent_icon_path = agent_path / "agent_functions" / "basic_python_agent.svg" agent_code_path = agent_path / "agent_code" + semver = "0.4.0" build_steps = [ BuildStep(step_name="Gathering Files", step_description="Making sure all commands have backing files on disk"), @@ -89,6 +90,10 @@ async def build(self) -> BuildResponse: StepSuccess=True )) resp.payload = base_code.encode() + # Mythic v4: return build metadata for wrapper compatibility discovery + resp.build_metadata = PayloadBuildMetadata( + format="Source", + ) if build_msg != "": resp.build_stderr = build_msg resp.set_status(BuildStatus.Error) diff --git a/Payload_Type/python_services/basic_wrapper/__init__.py b/Payload_Type/python_services/basic_wrapper/__init__.py new file mode 100644 index 0000000..a123bb6 --- /dev/null +++ b/Payload_Type/python_services/basic_wrapper/__init__.py @@ -0,0 +1,18 @@ +import glob +import os.path +from pathlib import Path +from importlib import import_module, invalidate_caches +import sys + +currentPath = Path(__file__) +searchPath = currentPath.parent / "agent_functions" / "*.py" +modules = glob.glob(f"{searchPath}") +invalidate_caches() +for x in modules: + if not x.endswith("__init__.py") and x[-3:] == ".py": + module = import_module(f"{__name__}.agent_functions." + Path(x).stem) + for el in dir(module): + if "__" not in el: + globals()[el] = getattr(module, el) + +sys.path.append(os.path.abspath(currentPath.name)) diff --git a/Payload_Type/python_services/basic_wrapper/agent_code/.keep b/Payload_Type/python_services/basic_wrapper/agent_code/.keep new file mode 100644 index 0000000..e69de29 diff --git a/Payload_Type/python_services/basic_wrapper/agent_functions/__init__.py b/Payload_Type/python_services/basic_wrapper/agent_functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Payload_Type/python_services/basic_wrapper/agent_functions/builder.py b/Payload_Type/python_services/basic_wrapper/agent_functions/builder.py new file mode 100644 index 0000000..0a08254 --- /dev/null +++ b/Payload_Type/python_services/basic_wrapper/agent_functions/builder.py @@ -0,0 +1,156 @@ +import pathlib +import zipfile +import tarfile +import io +import base64 +from mythic_container.PayloadBuilder import * +from mythic_container.MythicCommandBase import * +from mythic_container.MythicRPC import * + + +class BasicWrapper(PayloadType): + name = "basic_wrapper" + file_extension = "zip" + author = "Lavender-exe" + supported_os = [ + SupportedOS.Windows, + SupportedOS.Linux, + SupportedOS.MacOS, + ] + wrapper = True + note = ( + "Basic wrapper example: downloads the inner agent payload " + "and packages it into a zip, 7z, or tar.gz archive." + ) + supports_dynamic_loading = False + c2_profiles = [] + mythic_encrypts = False + translation_container = None + agent_type = AgentType.Wrapper + agent_path = pathlib.Path(__file__).resolve().parent.parent + agent_icon_path = None + agent_code_path = agent_path / "agent_code" + semver = "0.4.0" + + # Mythic v4: conditional wrapper compatibility + wrapper_payload_requirements = [ + WrapperPayloadRequirement( + requires=WrapperPayloadRequirementRequires( + format=PayloadBuildMetadataFormat.Shellcode, + architecture=PayloadBuildMetadataArchitecture.X64, + os=SupportedOS.Windows, + ), + ), + WrapperPayloadRequirement( + requires=WrapperPayloadRequirementRequires( + format=PayloadBuildMetadataFormat.Shellcode, + architecture=PayloadBuildMetadataArchitecture.X86, + os=SupportedOS.Windows, + ), + ), + WrapperPayloadRequirement( + requires=WrapperPayloadRequirementRequires( + format=PayloadBuildMetadataFormat.Exe, + architecture=PayloadBuildMetadataArchitecture.X64, + os=SupportedOS.Windows, + ), + ), + WrapperPayloadRequirement( + requires=WrapperPayloadRequirementRequires( + format=PayloadBuildMetadataFormat.Exe, + architecture=PayloadBuildMetadataArchitecture.X86, + os=SupportedOS.Windows, + ), + ), + ] + + build_parameters = [ + BuildParameter( + name="filename", + parameter_type=BuildParameterType.String, + default_value="payload.bin", + description="Filename for the payload inside the archive", + ), + BuildParameter( + name="archive_format", + parameter_type=BuildParameterType.ChooseOne, + choices=["zip", "7z", "tar.gz"], + default_value="zip", + description="Archive format for the output container", + ), + ] + + build_steps = [ + BuildStep( + step_name="Wrapping", + step_description="Packaging the inner agent into an archive", + ), + ] + + async def build(self) -> BuildResponse: + resp = BuildResponse(status=BuildStatus.Success) + try: + agent_bytes = self.wrapped_payload + if agent_bytes is None: + resp.set_status(BuildStatus.Error) + resp.build_stderr = "No wrapped payload provided" + return resp + if isinstance(agent_bytes, str): + agent_bytes = base64.b64decode(agent_bytes) + + filename = "payload.bin" + archive_format = "zip" + for bp in self.build_parameters: + if bp.name == "filename": + filename = bp.value if bp.value else "payload.bin" + elif bp.name == "archive_format": + archive_format = bp.value if bp.value else "zip" + + buf = io.BytesIO() + + if archive_format == "zip": + with zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) as zf: + zf.writestr(filename, agent_bytes) + resp.file_extension = "zip" + + elif archive_format == "tar.gz": + with tarfile.open(fileobj=buf, mode="w:gz") as tf: + info = tarfile.TarInfo(name=filename) + info.size = len(agent_bytes) + tf.addfile(info, io.BytesIO(agent_bytes)) + resp.file_extension = "tar.gz" + + elif archive_format == "7z": + import py7zr + with py7zr.SevenZipFile(buf, "w") as sz: + sz.writestr(agent_bytes, filename) + resp.file_extension = "7z" + + else: + resp.set_status(BuildStatus.Error) + resp.build_stderr = f"Unknown archive format: {archive_format}" + return resp + + await SendMythicRPCPayloadUpdatebuildStep( + MythicRPCPayloadUpdateBuildStepMessage( + PayloadUUID=self.uuid, + StepName="Wrapping", + StepStdout=( + f"Packaged \'{filename}\' " + f"({len(agent_bytes)} bytes) into {archive_format}" + ), + StepSuccess=True, + ) + ) + + resp.payload = buf.getvalue() + resp.build_message = ( + f"Wrapped payload into {archive_format} " + f"({len(resp.payload)} bytes)" + ) + + except Exception as e: + resp.set_status(BuildStatus.Error) + resp.build_stderr = f"Error wrapping payload: {str(e)}" + + return resp diff --git a/Payload_Type/python_services/main.py b/Payload_Type/python_services/main.py index 83cdd10..20550dc 100644 --- a/Payload_Type/python_services/main.py +++ b/Payload_Type/python_services/main.py @@ -2,10 +2,11 @@ import mythic_container import asyncio import basic_python_agent +import basic_wrapper import websocket.mythic.c2_functions.websocket from translator.translator import * from my_logger import logger from basic_command_augment import * from basic_eventer.my_eventing import * -mythic_container.mythic_service.start_and_run_forever() \ No newline at end of file +mythic_container.mythic_service.start_and_run_forever() diff --git a/Payload_Type/python_services/requirements.txt b/Payload_Type/python_services/requirements.txt new file mode 100644 index 0000000..556328d --- /dev/null +++ b/Payload_Type/python_services/requirements.txt @@ -0,0 +1,2 @@ +mythic_container==0.7.0rc9 +py7zr diff --git a/Payload_Type/python_services/websocket/mythic/c2_functions/websocket.py b/Payload_Type/python_services/websocket/mythic/c2_functions/websocket.py index c626650..78d4e2c 100644 --- a/Payload_Type/python_services/websocket/mythic/c2_functions/websocket.py +++ b/Payload_Type/python_services/websocket/mythic/c2_functions/websocket.py @@ -8,6 +8,7 @@ class Websocket(C2Profile): author = "@xorrior" is_p2p = False is_server_routed = False + semver = "0.4.0" server_binary_path = pathlib.Path(".") / "websocket" / "c2_code" / "server" server_folder_path = pathlib.Path(".") / "websocket" / "c2_code" parameters = [