Creating a New Task
Tasks fall under two categories: script only tasks, and atomic tasks.Script Only Tasks
Script only tasks orchestrate one or more tasks that are already built-in to Apollo. For example, think about apsexec command. This command would first want to perform an upload to a target, then issue an sc command to create a new service, then another sc command to start the service. All you should need to do is add a new python file under Payload_Type/apollo/mythic/agent_functions/ named mycommand.py. This file should be of the format:
dependencies that are defined under MyCommandCommand["attributes"]. To perform task delegation, see Mythic documentation, or other examples of script only commands in Apollo, such as pth, dcsync, mimikatz, and otherwise.
Atomic Tasks
Atomic tasks are defined as new tasks to be added in the core of the agent. These types of tasks have no dependencies and are discrete taskings in and of themselves. New atomic tasks should be created under theTasks project of the Apollo solution, as my_command.cs. This new file should contain a class, public class my_command, that inherits from the Tasking base class.
Tasking Base Class
TheTasking base class that all tasks inherit from have the following special variables:
IAgent _agent- Dependency resolver.Task _data- A .NET representation of the task data sent from MythicJsonSerializer _jsonSerializer- An object that can serialize .NET objects to JSON strings and deserialize JSON strings to .NET objects.
CreateTaskResponse function, which is defined as the following:
TaskResponse objects are what are added to the queue via the ITaskManager.AddTaskResponseToQueue function, which ultimately sends data from the executing task back to Mythic (discussed later). What you should know, as a user, is that:
userOutputis what is sent in theuser_outputfield of a task to Mythic.messagesis a list of additional typed messages Mythic can interpret and feed into various parts of it’s UI.
messages variable is a list of IMythicMessage types, which can be one of the following:
CommandInformation- Information about loaded commandsEdgeNode- Updating the P2P nodes this agent knows about or is connected toFileBrowser- Updating data in Mythic’s file browserCredential- Adding new credentials to the Mythic storeRemovedFileInformation- Tracking file deletions in MythicArtifact- Artifacts from task execution. Includes process creation events, logons, file deletions, etc.UploadMessage- A special message type telling Mythic you’re retrieving a file from it.DownloadMessage- A special message type telling Mythic you’re pushing a data to the Mythic serverProcessInformation- Updates information in Mythic’s process browserKeylogInformation- Information about a user’s keypresses.
Example my_command.cs File
IAgent Interface
The IAgent interface is a dependency leveraged heavily throughout the agent. More reading on the interface can be done in the “Available Interfaces” documentation (may or may not be complete at the time of writing). You can use this interface to perform the following:- Get the agent’s
IFileManagerinterface, responsible for storing, fetching, and sending files to Mythic. - Get the agent’s
IProcessManagerinterface, responsible for creating new child processes. - Get the agent’s
IInjectionManagerinterface, responsible for injecting shellcode into processes. - Get the agent’s
ITaskManagerinterface, responsible for loading commands, dispatching new tasks, and adding output from tasks to the sending queue.
IAgent presents nor is it meant as a full list of the capabilities of each of the aforementioned interfaces. The following are just what’s most frequently used during Task development.
IFileManager Interface
The IFileManager interface is used by tasking to perform the following.- Get a file from Mythic by its file ID. The result of this operation will yield the file from Mythic in the
fileBytesvariable shown below:
- Send a file to Mythic via the
PutFilecall:
- Retrieve a file from the agent’s cache. Some tasks use the file cache to fetch files required for execution, as it reduces latency from task issuance to task execution. Some examples are:
execute_assembly- Fetches assemblies previously registered viaregister_filefrom the file cache to execute in a sacrifical processpowershell- Fetches the currently loaded PowerShell script from the file cache.
IProcessManager
The IProcessManager interface is responsible for:- Spawning new child processes
- Setting the parent process ID of child processes (
ppid) - Blocking non-Microsoft DLL’s from being loaded into the process (
block_dlls) - Setting the default process to spawn used in fork and run tasks (
spawnto_*) - Retrieving default application startup arguments.
Spawning a Child Process
Spawning a new child process can be done via:Process object (defined in ApolloInterop) which is distinct from the traditional System.Diagnostics.Process object. You can subscribe to this process’s stdout and stderr by adding an event handler to the Process object’s OutputDataReceived and ErrorDataReceived. Once you have your event handlers configured, you can issue Process.Start() to start process execution, and similarily, WaitForExit if you wish to wait for the process to exit.
Should you need to inject shellcode into a process, the Process.Inject method will inject arbitrary shellcode into the process using the currently defined injection method in the IInjectionManager implementation in use.
IInjectionManager
This interface is responsible for retrieving the loaded injection techniques, changing which technique is in use for post-ex jobs, as well as giving callers the ability to inject into arbitrary processes. Namely,IInjectionManager.CreateInstance will allow the caller to create an instance of injection to a target process, then a separate call to InjectionTechnique.Inject will inject the shellcode.
ITaskManager
TheITaskManager interface is what Tasks will most heavily interface with. Notably, this interface will push output from tasks up to Mythic for the user to see, load new taskings, cancel running tasks, and otherwise.
As a Task developer, you’ll mostly look to use ITaskManager.AddTaskResponseToQueue, which adds a new TaskResponse message to be sent to Mythic. These TaskResponse objects should be created via the Tasking base class’s Tasking.CreateTaskResponse, which populates the requisite fields.