Skip to content
Open
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
2 changes: 1 addition & 1 deletion Payload_Type/go_services/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
12 changes: 10 additions & 2 deletions Payload_Type/python_services/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions Payload_Type/python_services/basic_wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -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))
Empty file.
Empty file.
156 changes: 156 additions & 0 deletions Payload_Type/python_services/basic_wrapper/agent_functions/builder.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion Payload_Type/python_services/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
mythic_container.mythic_service.start_and_run_forever()
2 changes: 2 additions & 0 deletions Payload_Type/python_services/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mythic_container==0.7.0rc9
py7zr
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down