MythicRPC

MythicRPC in 2.2.7+

The RPC functionality within Mythic as of 2.2.7 is more dynamic, allowing more functionality to be added to the back-end and automatically usable by the Payload Type containers without requiring new PyPi packages or new Docker images. To facilitate this, you can always get the latest RPC available functionality within your tasking via:
1
from mythic_payloadtype_container.MythicRPC import *
2
import sys
3
4
async def create_tasking(self, task: MythicTask) -> MythicTask:
5
resp = await MythicRPC().get_functions()
6
print(resp.response)
7
sys.stdout.flush()
8
return task
Copied!
That will print out all of the information for the available functions if you're ever in doubt about what's available or how to call the functions. When you find a function you want to call, you do it as follows:
1
file_resp = await MythicRPC().execute("create_file", task_id=task.id,
2
file=base64.b64encode(task.args.get_arg("file_id")).decode(),
3
saved_file_name=original_file_name,
4
delete_after_fetch=False,
5
)
Copied!
where you always call await MythicRPC().execute with the first parameter being the name of the function to call and all of the other arguments being passed in like normal function arguments.

2.3.0+ Functions

The function set is moving towards a standard nomenclature - create_* for when you want to create/register/add something to the database, get_* for when you want to fetch something from the database, and delete_* when you want to remove something from the database or mark it as deleted. The current set of functionality for 2.2.8 is as follows:
1
create_file(task_id: int, file: str, delete_after_fetch: bool = True, saved_file_name: str = None, is_screenshot: bool = False, is_download: bool = False, remote_path: str = None, host: str = None) -> dict
2
Creates a FileMeta object in Mythic's database and writes contents to disk with a random UUID filename.
3
This file can then be fetched via the returned file UUID.
4
:param task_id: The ID number of the task performing this action (task.id)
5
:param file: The base64 contents of the file to register
6
:param delete_after_fetch: Should Mythic delete the file from disk after the agent fetches it. This also marks the file as deleted in the UI. This is useful if the file is a temporary file that doesn't necessarily need long-term tracking within Mythic.
7
:param saved_file_name: The name of the file (if none supplied, a random UUID4 value will be used)
8
:param is_screenshot: Is this file a screenshot reported by the agent? If so, this will cause it to show up in the screenshots page.
9
:param is_download: Is this file the result of downloading something from the agent? If so, this will cause it to show up in the Files page under Downloads
10
:param remote_path: Does this file exist on target? If so, provide the full remote path here
11
:param host: If this file exists on a target host, indicate it here in conjunction with the remote_path argument
12
:return: Dict of a FileMeta object
13
Example: this takes two arguments - ParameterType.String for `remote_path` and ParameterType.File for `file`
14
async def create_tasking(self, task: MythicTask) -> MythicTask:
15
try:
16
original_file_name = json.loads(task.original_params)["file"]
17
if len(task.args.get_arg("remote_path")) == 0:
18
task.args.add_arg("remote_path", original_file_name)
19
elif task.args.get_arg("remote_path")[-1] == "/":
20
task.args.add_arg("remote_path", task.args.get_arg("remote_path") + original_file_name)
21
file_resp = await MythicRPC().execute("create_file", task_id=task.id,
22
file=base64.b64encode(task.args.get_arg("file")).decode(),
23
saved_file_name=original_file_name,
24
delete_after_fetch=False,
25
)
26
if file_resp.status == MythicStatus.Success:
27
task.args.add_arg("file", file_resp.response["agent_file_id"])
28
task.display_params = f"{original_file_name} to {task.args.get_arg('remote_path')}"
29
else:
30
raise Exception("Error from Mythic: " + str(file_resp.error))
31
except Exception as e:
32
raise Exception("Error from Mythic: " + str(sys.exc_info()[-1].tb_lineno) + str(e))
33
return task
Copied!
1
get_file(task_id: int = None, callback_id: int = None, filename: str = None, limit_by_callback: bool = True, max_results: int = 1, file_id: str = None, get_contents: bool = True) -> dict
2
Get file data and contents by name (ex: from create_file and a specified saved_file_name parameter).
3
The search can be limited to just this callback (or the entire operation) and return just the latest or some number of matching results.
4
:param task_id: The ID number of the task performing this action (task.id) - if this isn't provided, the callback id must be provided
5
:param callback_id: The ID number of the callback for this action - if this isn't provided, the task_id must be provided
6
:param filename: The name of the file to search for (Case sensitive)
7
:param file_id: If no filename specified, then can search for a specific file by this UUID
8
:param limit_by_callback: Set this to True if you only want to search for files that are tied to this callback. This is useful if you're doing this as part of another command that previously loaded files into this callback's memory.
9
:param max_results: The number of results you want back. 1 will be the latest file uploaded with that name, -1 will be all results.
10
:param get_contents: Boolean of if you want to fetch file contents or just metadata
11
:return: An array of dictionaries representing the FileMeta objects of all matching files. When "get_contents" is True, each entry in this array will also have a "contents" key with the base64 representation of the associated file if it hasn't been deleted, or None if it has.
12
For an example-
13
resp = await MythicRPC().execute("get_file", task_id=task.id, filename="myAssembly.exe")
14
resp.response <--- this is an array
15
resp.response[0] <--- this is the most recently registered matching file where filename="myAssembly.exe"
16
resp.response[0]["filename"] <-- the filename of that first result
17
resp.response[0]["contents"] <--- the base64 representation of that file
18
All of the possible dictionary keys are available at https://github.com/its-a-feature/Mythic/blob/master/mythic-docker/app/database_models/model.py for the FileMeta class
Copied!
1
update_file(file_id: str, comment: str = None, delete_after_fetch: bool = None,
2
contents: bytes = None, filename: str = None) -> dict:
3
Given a file identifier, update certain attributes of the file.
4
:param file_id: This is the string UUID identifier for the file
5
:param comment: If you want to update the comment on the file, supply the text here
6
:param delete_after_fetch: If you want this file to be deleted after an agent fetches it, set this to True. It's false by default.
7
:param contents: Supply the raw bytes of the file if you want to update the contents.
8
:param filename: Supply a new filename for the file
9
:return: Success or error code
Copied!
1
get_payload(payload_uuid: str, get_contents: bool = True) -> dict
2
Get information about a payload and its contents
3
:param payload_uuid: The UUID for the payload you're interested in
4
:param get_contents: Whether or not you want to fetch the contents of the file or just the metadata
5
:return: dictionary representation of the Payload object
6
Example:
7
async def create_tasking(self, task: MythicTask) -> MythicTask:
8
try:
9
gen_resp = await MythicRPC().execute("create_payload_from_uuid", task_id=task.id,
10
payload_uuid=task.args.get_arg("template"))
11
if gen_resp.status == MythicStatus.Success:
12
# we know a payload is building, now we want it
13
while True:
14
resp = await MythicRPC().execute("get_payload", payload_uuid=gen_resp.response["uuid"])
15
if resp.status == MythicStatus.Success:
16
if resp.response["build_phase"] == "success":
17
task.args.add_arg("template", resp.response["file"]["agent_file_id"])
18
task.display_params = f"new Apfell payload ({resp.response['uuid']}) with description {resp.response['tag']}"
19
break
20
elif resp.response["build_phase"] == "error":
21
raise Exception(
22
"Failed to build new payload: " + str(resp.error)
23
)
24
else:
25
await asyncio.sleep(1)
26
if resp.status == MythicStatus.Error:
27
raise Exception("Failed to get information about new payload:\n" + resp.error)
28
else:
29
raise Exception("Failed to generate new payload:\n" + gen_resp.error)
30
except Exception as e:
31
raise Exception("Error trying to call RPC:\n" + str(e))
32
return task
Copied!
1
search_payloads(callback_id: int, payload_types: [str] = None, include_auto_generated: bool = False, description: str = "",
2
filename: str = "", build_parameters: dict = None) -> dict:
3
"""
4
Search payloads based on payload type, if it was auto generated, the description, the filename, or build parameter values.
5
Note: This does not search payloads that have been deleted.
6
:param callback_id: The ID of the callback this search is for, this is what's used to limit your search to the right operation.
7
:param payload_types: The names of the associated payload type if you want to restrict results
8
:param include_auto_generated: Boolean if you want to include payloads that were automatically generated as part of tasking
9
:param description: If you want to search for payloads with certain information in their description, this functions like an igrep search
10
:param filename: If you want to search for payloads with certain filenames, this functions like an igrep search
11
:param build_parameters: If you want to limit your search based on certain build parameters (maybe shellcode for example),
12
then you can specify this dictionary of {"agent name": {"build_param_name": "build_param_value"}}
13
:return: An array of dictionaries where each entry is one matching payload. Each dictionary entry contains the following:
14
uuid - string
15
description -string
16
operator - string
17
creation_time - string
18
payload_type - string
19
operation - string
20
wrapped_payload - boolean (true if this payload wraps another payload)
21
deleted - boolean
22
build_container - string
23
build_phase - string
24
build_message - string
25
build_stderr - string
26
build_stdout - string
27
callback_alert - boolean (true if this payload will attempt to hit the operation's webhook when a new callback is generated)
28
auto_generated - boolean (true if this payload is auto generated by a task)
29
task - dictionary of information about the associated task
30
file - dictionary of information about the associated file
31
os - string
32
"""
Copied!
1
encrypt_message(message: dict, target_uuid: str, c2_profile_name: str):
2
Given a dictionary agent message, submit it to Mythic to encrypt with a target callback/payload's encryption keys
3
:param message: the dictionary message
4
:param target_uuid: the UUID of the payload/stager/callback that will receive the encrypted message
5
:param c2_profile_name: the name of the c2 profile that this message will be sent over
6
:return: The final base64 and encrypted message
Copied!
1
decrypt_message(message: str, c2_profile_name: str):
2
Given an encrypted message from an agent, decrypt it based on the C2 profile that received it
3
:param message: The base64 of the message from an agent
4
:param c2_profile_name: the name of the c2 profile where this message came from
5
:return: the dictionary representation of the message for Mythic
Copied!
1
get_commands(callback_id: int = None, loaded_only: bool = False,
2
payload_type_name: str = None, commands: [str] = None, os: str = None):
3
Get an array of dictionaries of all the possible commands for the specified callback or payload type
4
:param callback_id: the id of the callback in question
5
:param loaded_only: specify this as True to only include commands currently loaded into this callback
6
:param payload_type_name: specify this to fetch all possible commands for a specific payload type
7
:param commands: specify an array of command names along with the payload_type_name to fetch information
8
about only the listed commands for the specified payload type
9
:param os: Specify the OS that's associated with the payload_type_name so that commands can be filtered
10
:return: an array of dictionaries representing all of the requested commands for that payload type.
11
When returning all possible commands for this callback, commands are still filtered by their supported_os attributes
Copied!
1
add_commands_to_payload(payload_uuid: str, commands: [str]):
2
Register additional commands that are in the payload. This is useful if a user selects command X to include in a payload, but command X needs command Y.
3
A common example would be if command X is a script_only command or will end up delegating additional commands.
4
:param payload_uuid: The UUID of the payload that you're adding commands to.
5
:param commands: An array of command names that should be added to this payload.
6
:return: Success or Error
Copied!
1
get_tasks(task_id: int, host: str = None) -> dict
2
Get all of the currently running tasks on the current host or on a specific host
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param host: The name of the host to check for running tasks
5
:return: An array of dictionaries representing the tasks running
Copied!
1
get_responses(task_id: int) -> dict
2
For a given Task, get all of the user_output, artifacts, files, and credentials that task as created within Mythic
3
:param task_id: The TaskID you're interested in (i.e. task.id)
4
:return: A dictionary of the following format:
5
{
6
"user_output": array of dictionaries where each dictionary is user_output message for the task,
7
"artifacts": array of dictionaries where each dictionary is an artifact created for the task,
8
"files": array of dictionaries where each dictionary is a file registered as part of the task,
9
"credentials": array of dictionaries where each dictionary is a credential created as part of the task.
10
}
Copied!
1
create_payload_from_uuid(task_id: int, payload_uuid: str, generate_new_random_values: bool = True, new_description: str = None, remote_host: str = None, filename: str = None) -> dict
2
Given an existing Payload UUID, generate a new copy with a potentially new description, new filename, new random values, and specify that it'll exist on a certain host. This is useful for spawn or lateral movement tasks where you want to potentially change up IOCs and provide new, more informative, descriptions for callbacks.
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param payload_uuid: The UUID of the payload we're interested in
5
:param generate_new_random_values: Set this to True to generate new random values for C2 Profile parameters that are flagged as randomized
6
:param new_description: Provide a custom new description for the payload and callbacks associated from it. If you don't provide one, a generic one will be generated
7
:param remote_host: Indicate the hostname of the host this new payload is deployed to. If one isn't specified, you won't be able to link to it without first telling Mythic that this payload exists on a certain host via the Popup Modals.
8
:param filename: New filename for the payload. If one isn't supplied, a random UUID will be generated
9
:return: dictionary representation of the payload that was created
10
Example:
11
async def create_tasking(self, task: MythicTask) -> MythicTask:
12
try:
13
gen_resp = await MythicRPC().execute("create_payload_from_uuid", task_id=task.id,
14
payload_uuid=task.args.get_arg("template"))
15
if gen_resp.status == MythicStatus.Success:
16
# we know a payload is building, now we want it
17
while True:
18
resp = await MythicRPC().execute("get_payload", payload_uuid=gen_resp.response["uuid"])
19
if resp.status == MythicStatus.Success:
20
if resp.response["build_phase"] == "success":
21
task.args.add_arg("template", resp.response["file"]["agent_file_id"])
22
task.display_params = f"new Apfell payload ({resp.response['uuid']}) with description {resp.response['tag']}"
23
break
24
elif resp.response["build_phase"] == "error":
25
raise Exception(
26
"Failed to build new payload: " + str(resp.error)
27
)
28
else:
29
await asyncio.sleep(1)
30
if resp.status == MythicStatus.Error:
31
raise Exception("Failed to get information about new payload:\n" + resp.error)
32
else:
33
raise Exception("Failed to generate new payload:\n" + gen_resp.error)
34
except Exception as e:
35
raise Exception("Error trying to call RPC:\n" + str(e))
36
return task
Copied!
1
create_processes(task_id: int, processes: dict) -> dict
2
Create processes in bulk. The parameters in the "processes" dictionary are the same as those in the `create_process` RPC call.
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param processes: Dictionary of the processes you want to create - the key value pairs are the same as the parameters to the `create_process` RPC call.
5
:return: Success or Error (nothing in the `response` attribute)
Copied!
1
create_process(task_id: int, host: str, process_id: int, parent_process_id: int = None, architecture: str = None, name: str = None, bin_path: str = None, user: str = None, command_line: str = None, integrity_level: int = None, start_time: str = None, description: str = None, signer: str = None) -> dict
2
Create a new process within Mythic.
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param host: The host where this process exists
5
:param process_id: The process ID
6
:param parent_process_id: The process's parent process ID
7
:param architecture: The architecture for the process (x86, x64, arm, etc)
8
:param name: The name of the process
9
:param bin_path: The path to the binary that's executed
10
:param user: The user context that the process is executing
11
:param command_line: The command line that's spawned with the process
12
:param integrity_level: The integrity level of the process
13
:param start_time: When the process started
14
:param description: The description of the process
15
:param signer: The process' signing information
16
:return: Success or Error (nothing in the `response` attribute)
Copied!
1
create_artifact(task_id: int, artifact_type: str, artifact: str, host: str = None) -> dict
2
Create a new artifact for a certain task on a host
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param artifact_type: What kind of artifact is this (Process Create, File Write, etc). If the type specified doesn't exist, it will be created
5
:param artifact: The actual artifact that was created
6
:param host: Which host the artifact was created on. If none is provided, the current task's host is used
7
:return: Success or error (nothing in the `response` attribute)
Copied!
1
create_keylog(task_id: int, keystrokes: str, user: str = None, window_title: str = None) -> dict
2
Create a new keylog entry in Mythic.
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param keystrokes: The keys that are being registered
5
:param user: The user that performed the keystrokes. If you don't supply this, "UNKNOWN" will be used.
6
:param window_title: The title of the window where the keystrokes came from. If you don't supply this, "UNKNOWN" will be used.
7
:return: Success or Error (nothing in the `response` attribute)
Copied!
1
create_output(task_id: int, output: str) -> dict
2
Add a message to the output for a task that the operator can see
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param output: The message you want to send.
5
:return: Status of if you successfully posted or not (nothing in the `response` attribute)
6
Example:
7
async def create_tasking(self, task: MythicTask) -> MythicTask:
8
resp = await MythicRPC().execute("create_output", task_id=task.id, output="hello")
9
if resp.status != MythicStatus.Success:
10
task.status = MythicStatus.Error
11
raise Exception(resp.error)
12
return task
Copied!
1
create_event_message(task_id: int, message: str, warning: bool = False) -> dict
2
Create a message in the Event feed within the UI as an info message or as a warning
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param message: The message you want to send
5
:param warning: If this is True, the message will be a "warning" message
6
:return: success or error (nothing in the `response` attribute)
Copied!
1
create_credential(task_id: int, credential_type: str, account: str, realm: str, credential: str, metadata: str = '', comment: str = None) -> dict
2
Create a new credential within Mythic to be leveraged in future tasks
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param credential_type: The type of credential we're storing (plaintext, hash, ticket, certificate, token)
5
:param account: The account associated with the credential
6
:param realm: The realm for the credential (sometimes called the domain)
7
:param credential: The credential value itself
8
:param metadata: Any additional metadata you want to store about the credential
9
:param comment: Any comment you want to store about it the credential
10
:return: Success or Error (nothing in the `response` attribute)
Copied!
1
create_file_browser(task_id: int, host: str, name: str, full_path: str, permissions: dict = None, access_time: str = '', modify_time: str = '', comment: str = '', is_file: bool = True, size: str = '', success: bool = True, files: [<class 'dict'>] = None, update_deleted: bool = False) -> dict
2
Add file browser content to the file browser user interface.
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param host: Which host this data is from (useful for remote file listings)
5
:param name: Name of the file/folder that was listed
6
:param full_path: Full path of the file/folder that was listed (useful in case the operator said to ls `.` or a relative path)
7
:param permissions: Dictionary of permissions. The key/values here are completely up to you and are displayed as key/value pairs in the UI
8
:param access_time: String representation of when the file/folder was last accessed
9
:param modify_time: String representation of when the file/folder was last modified
10
:param comment: Any comment you might want to add to this file/folder
11
:param is_file: Is this a file?
12
:param size: Size of the file (can be an int or something human readable, like 10MB)
13
:param success: True/False if you successfully listed this file. A False value (like from an access denied) will appear as a red X in the UI
14
:param files: Array of dictionaries of information for all of the files in this folder (or an empty array of this is a file). Each dictionary has all of the same pieces of information as the main folder itself.
15
:param update_deleted: True or False indicating if this file browser data should be used to automatically update deleted files for the listed folder. This defaults to false, but if set to true and there are files that Mythic knows about for this folder that the passed-in data doesn't include, it will be marked as deleted.
16
:return: success or error (nothing in the `response` attribute)
Copied!
1
create_payload_on_host(task_id: int, payload_uuid: str, host: str) -> dict
2
Register within Mythic that the specified payload exists on the specified host as a result of this tasking
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param payload_uuid: The payload that will be associated with the host
5
:param host: The host that will have the payload on it
6
:return: success or error (nothing in the `response` attribute)
Copied!
1
create_logon_session(task_id: int, LogonId: int, host: str = None, **kwargs) -> dict
2
Create a new logon session for this host
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param LogonId: The integer logon identifier value that uniquely identifies this logon session on this host
5
:param host: The host where this logon session exists
6
:param kwargs: The `Mythic/mythic-docker/app/database_models/model.py` LogonSession class has all of the possible values you can set when creating/updating logon sessions. There are too many to list here individually, so a generic kwargs is specified.
7
:return: Success or Error (nothing in the `response` attribute)
Copied!
1
create_callback_token(task_id: int, TokenId: int, host: str = None) -> dict
2
Associate a token with a callback for usage in further tasking.
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param TokenId: The token you want to associate with this callback
5
:param host: The host where the token exists
6
:return: Success or Error (nothing in the `response` attribute)
Copied!
1
create_token(task_id: int, TokenId: int, host: str = None, **kwargs) -> dict
2
Create or update a token on a host. The `TokenId` is a unique identifier for the token on the host and is how Mythic identifies tokens as well. A token's `AuthenticationId` is used to link a Token to a LogonSession per Windows documentation, so when setting that value, if the associated LogonSession object doesnt' exist, Mythic will make it.
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param TokenId: The integer token identifier value that uniquely identifies this token on this host
5
:param host: The host where the token exists
6
:param kwargs: The `Mythic/mythic-docker/app/database_models/model.py` Token class has all of the possible values you can set when creating/updating tokens. There are too many to list here individually, so a generic kwargs is specified.
7
:return: Dictionary representation of the token created
Copied!
1
delete_token(TokenId: int, host: str) -> dict
2
Mark a specific token as "deleted" on a specific host.
3
:param TokenId: The token that should be deleted
4
:param host: The host where this token exists
5
:return: success or error (nothing in the `response` attribute)
Copied!
1
create_agentstorage(unique_id: str, data: bytes):
2
Allow Payload Types and Translation containers to store arbitrary data within the database that doesn't fit
3
somewhere else in Mythic's current schema
4
:param unique_id: A unique string identifier
5
:param data:
6
:return: {"unique_id": "unique id here", "data": "base64 of data here"}
Copied!
1
get_agentstorage(unique_id: str):
2
Allow Payload Types and Translation containers to fetch arbitrary data within the database that doesn't fit
3
somewhere else in Mythic's current schema
4
:param unique_id: A unique string identifier
5
:return: {"unique_id": "unique id here", "data": "base64 of data here"}
Copied!
1
delete_agentstorage(unique_id: str):
2
Allow Payload Types and Translation containers to delete arbitrary data within the database that doesn't fit
3
somewhere else in Mythic's current schema
4
:param unique_id: A unique string identifier
5
:return: Success or Error
Copied!
1
delete_file_browser(task_id: int, file_path: str, host: str = None) -> dict
2
Mark a file in the file browser as deleted (typically as part of a manual removal via a task)
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param file_path: The full path to the file that's being removed
5
:param host: The host where the file existed. If you don't specify a host, the callback's host is used
6
:return: Success or Error (nothing in the `response` attribute)
Copied!
1
delete_logon_session(LogonId: int, host: str) -> dict
2
Mark a specified logon session as "deleted" on a specific host
3
:param LogonId: The Logon Session that should be deleted
4
:param host: The host where the logon session used to be
5
:return: Success or Error (nothing in the `response` attribute)
Copied!
1
delete_callback_token(task_id: int, TokenId: int, host: str = None) -> dict
2
Mark a callback token as no longer being associated
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param TokenId: The Token you want to disassociate from the task's callback
5
:param host: The host where the token exists
6
:return: Success or Error (nothing in the `response` attribute)
Copied!
1
update_callback(task_id: int, user: str = None, host: str = None, pid: int = None, ip: str = None, external_ip: str = None, description: str = None, integrity_level: int = None, os: str = None, architecture: str = None, domain: str = None, extra_info: str = None, sleep_info: str = None) -> dict
2
Update this task's associated callback data.
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param user: The new username
5
:param host: The new hostname
6
:param pid: The new process identifier
7
:param ip: The new IP address
8
:param external_ip: The new external IP address
9
:param description: The new description
10
:param integrity_level: The new integrity level
11
:param os: The new operating system information
12
:param architecture: The new architecture
13
:param domain: The new domain
14
:param extra_info: The new "extra info" you want to store
15
:param sleep_info: The new sleep information for the callback
16
:return: Success or error (nothing in the `response` attribute)
Copied!
1
update_task_status(task_id: int, status: str, completed: bool = None):
2
Update a task's status to a custom value and optionally mark a task as completed
3
:param task_id: The task you want to update (i.e. task.id in you create_tasking)
4
:param status: The string value of the status you want to set
5
:param completed: Optional boolean value to mark the task as completed
6
:return: Status indicating success or error on if the task was updated or not.
Copied!
1
search_database(table: str, task_id: int = None, callback_id: int = None, **kwargs) -> dict
2
Search the Mythic database for some data. Data is searched by regular expression for the fields specified. Because the available fields depends on the table you're searching, that argument is a generic python "kwargs" value.
3
:param task_id: The ID number of the task performing this action (task.id) - if this isn't supplied, callback_id must be supplied
4
:param callback_id: The ID number of the callback performing this action - if this isn't supplied, task_id must be supplied
5
:param table: The name of the table you want to query. Currently only options are: process, token, file_browser. To search files (uploads/downloads/hosted), use `get_file`
6
:param kwargs: These are the key=value pairs for how you're going to search the table specified. For example, searching processes where the name of "bob" and host that starts with "spooky" would have kwargs of: name="bob", host="spooky*"
7
:return: an array of dictionaries that represent your search. If your search had no results, you'll get back an empty array
Copied!
1
control_socks(task_id: int, port: int, start: bool = False, stop: bool = False) -> dict
2
Start or stop SOCKS 5 on a specific port for this task's callback
3
:param task_id: The ID number of the task performing this action (task.id)
4
:param port: The port to open for SOCKS 5
5
:param start: Boolean for if SOCKS should start
6
:param stop: Boolean for if SOCKS should stop
7
:return: Status message of if it completed successfully (nothing in the `response` attribute)
8
Example:
9
async def create_tasking(self, task: MythicTask) -> MythicTask:
10
if task.args.get_arg("action") == "start":
11
resp = await MythicRPC().execute("control_socks", task_id=task.id, start=True, port=task.args.get_arg("port"))
12
if resp.status != MythicStatus.Success:
13
task.status = MythicStatus.Error
14
raise Exception(resp.error)
15
else:
16
resp = await MythicRPC().execute("control_socks", task_id=task.id, stop=True, port=task.args.get_arg("port"))
17
if resp.status != MythicStatus.Success:
18
task.status = MythicStatus.Error
19
raise Exception(resp.error)
20
return task
Copied!
1
update_loaded_commands(task_id: int, commands: [str], add: bool = None, remove: bool = None):
2
Add or Remove loaded commands for the callback associated with task_id
3
:param task_id: The task doing the modifications
4
:param commands: The list of command names to add/remove
5
:param add: Boolean set to True if you want to add the commands to the callback associated with task_id
6
:param remove: Boolean set to True if you want to remove teh commands from the callback assocaited with task_id
7
:return: Status for success or error
Copied!
1
create_subtask(parent_task_id: int, command: str, params_string: str = None, params_dict: dict = None, files: dict = None,
2
subtask_callback_function: str = None, subtask_group_name: str = None, tags: [str] = None,
3
group_callback_function: str = None) -> dict:
4
Issue a new task to the current callback as a child of the current task.
5
You can use the "subtask_callback_function" to provide the name of the function you want to call when this new task enters a "completed=True" state.
6
If you issue create_subtask_group, the group name and group callback functions are propagated here.
7
You MUST provide params_string or params_dict to this function, but you don't provide both.
8
:param parent_task_id: The id of the current task (task.id)
9
:param command: The name of the command you want to use
10
:param params_string: The string parameters you want to issue to that command (this gets passed to the command's parse_arguments function)
11
:param params_dict: THe dictionary of parameters you want to issue to that command (this will get converted into a string and passed to that command's parse_arguments function)
12
:param files: If you want to pass along a file to the task, provide it here (example provided)
13
:param subtask_callback_function: The name of the function to call on the _parent_ task when this function exits
14
:param subtask_group_name: An optional name of a group so that tasks can share a single callback function
15
:param tags: A list of strings of tags you want to apply to this new task
16
:param group_callback_function: If you're grouping tasks together, this is the name of the shared callback function for when they're all in a "completed=True" state
17
:return: Information about the task you just created
18
If the command for your subtask normally takes a parameter of type File, then we need to do something a little bit differently for you to pass that along to the subtask.
19
Let's say you want to call the "upload" command which takes a `path` argument which is a string and a `file` argument which is a type of File.
20
To call this as a subtask you'd need to pass in:
21
MythicRPC().execute("create_subtask", parent_task_id=task.id, command="upload", params_dict={"path": "/wherever", "file": "filename"}, files={"file": "base64 file contents"})
22
Notice here that in the parameters piece, the "file" value is the filename and in the "files" parameter, we associated it with the file contents.
23
This allows us to save off the filename in the task's "original_params" while still getting access to the contents in the "params" value.
24
"""
25
26
create_subtask_group(parent_task_id: int, tasks: [<class 'dict'>], subtask_group_name: str = None, tags: [<class 'str'>] = None, group_callback_function: str = None) -> dict
27
Create a group of subtasks at once and register a single callback function when the entire group is done executing.
28
:param parent_task_id: The id of the parent task (i.e. task.id)
29
:param tasks: An array of dictionaries representing the tasks to create. An example is shown below.
30
:param subtask_group_name: The name for the group. If one isn't provided, a random UUID will be used instead
31
:param tags: An optional list of tags to apply to all of the subtasks created.
32
:param group_callback_function: The name of the function to call in the _parent_ task when all of these subtasks are done.
33
:return: An array of dictionaries representing information about all of the subtasks created.
Copied!

Calling C2 RPC Functions

Your Payload Type container can actually call RPC functions defined within your C2 profile as well. You must have Mythic 2.2.8 and a PayloadType container version of at least 9 to leverage this functionality. These just have a slightly different format:
1
resp = await MythicRPC().execute_c2rpc(c2_profile="http", function_name="test", task_id=task.id,
2
message="hi")
Copied!
The key things to notice here are:
  1. 1.
    the function you execute is called execute_c2rpc instead of just execute
  2. 2.
    The message parameter is always a string. If you need to send a dictionary to your C2 profile, use json.dumps({dictionary here}) (make sure you import json at the top)
  3. 3.
    Your response back will have the same status , response, and error as the other kind of RPC functions.

Defining your own C2 RPC Functions

If you are creating your own C2, you can create your own C2 RPC functions! Inside of your mythic/c2_functions folder for your C2 Profile, create a file called C2_RPC_functions.py (it might already exist for you). This is where you can create as many RPC function endpoints as you want! They just have the following format:
1
from mythic_c2_container.C2ProfileBase import *
2
import sys
3
4
# request is a dictionary: {"action": func_name, "message": "the input", "task_id": task id num}
5
# must return an RPCResponse() object and set .status to an instance of RPCStatus and response to str of message
6
async def test(request):
7
response = RPCResponse()
8
response.status = RPCStatus.Success
9
response.response = "hello"
10
return response
Copied!