Skip to content

Commit

Permalink
v0.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
its-a-feature committed Jan 14, 2024
1 parent 6397e28 commit c9bb763
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

## [v0.4.4] - 2024-01-13

### Changed

- Updated the typedarray_parse_function to be called after parse_dictionary or parse_arguments is called
- Parsing dictionary and arguments should simply make sure that there's data in the typed array parameter
- The `typedarray_parse_function` will be called if the value after parse_dictionary or parse_arguments is `[ ["", "string"], ["", "value" ]]` or `[ "value", "value" ]` formats.
- The first format with the empty first value is how Mythic's UI parsing will interpret the arrays

## [v0.4.3] - 2024-01-13

### Changed
Expand Down
8 changes: 5 additions & 3 deletions mythic_container/MythicCommandBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class PTRPCTypedArrayParseFunctionMessageResponse:
def __init__(self,
Success: bool = False,
Error: str = None,
TypedArray: list[tuple] = []):
TypedArray: list[list] = []):
self.Success = Success
self.Error = Error
self.TypedArray = TypedArray
Expand Down Expand Up @@ -586,7 +586,7 @@ def validateCredentialJSON(self, val):
if isinstance(val, dict):
return val
else:
raise ValueError("value ins't a dictionary")
raise ValueError("value isn't a dictionary")

def validatePass(self, val):
return val
Expand All @@ -605,9 +605,10 @@ def validateAgentConnect(self, val):
return val
else:
raise ValueError("Not instance of dictionary")

def validateTypedArray(self, val):
if isinstance(val, list):
if len(val) > 0 and not isinstance(val[0], tuple):
if len(val) > 0 and (not isinstance(val[0], tuple) and not isinstance(val[0], list)):
raise ValueError("Value isn't a list of tuples")
return val
else:
Expand Down Expand Up @@ -791,6 +792,7 @@ def load_args_from_json_string(self, command_line: str, add_unknown_args: bool =
else:
self.add_arg(key=k, value=v, type=ParameterType.String)
except Exception as e:
logger.error(e)
logger.error("Tried parsing command line as JSON when it's not")
return

Expand Down
2 changes: 1 addition & 1 deletion mythic_container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

containerVersion = "v1.1.4"

PyPi_version = "0.4.3"
PyPi_version = "0.4.4"

RabbitmqConnection = rabbitmqConnectionClass()

Expand Down
51 changes: 51 additions & 0 deletions mythic_container/agent_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ async def initialize_task(
task.args.load_args_from_dictionary(dictionary, add_unknown_args=True)
except Exception as loadException:
pass
for arg in task.args.args:
if arg.type == MythicCommandBase.ParameterType.TypedArray and callable(arg.typedarray_parse_function):
if len(arg.value) > 0 and arg.value[0][0] == "":
resp = await arg.typedarray_parse_function(MythicCommandBase.PTRPCTypedArrayParseFunctionMessage(
command=command_class.cmd,
parameter_name=arg.name,
payload_type="",
callback=message_json["callback"]["id"],
input_array=arg.value
))
if not resp.Success:
raise Exception(resp.Error)
arg.value = resp.TypedArray
elif len(arg.value) > 0 and isinstance(arg.value[0], str):
resp = await arg.typedarray_parse_function(MythicCommandBase.PTRPCTypedArrayParseFunctionMessage(
command=command_class.cmd,
parameter_name=arg.name,
payload_type="",
callback=message_json["callback"]["id"],
input_array=arg.value
))
if not resp.Success:
raise Exception(resp.Error)
task.args.set_arg(arg.name, resp.TypedArray)

except Exception as pa:
message = {
"task_id": message_json["task"]["id"],
Expand Down Expand Up @@ -204,6 +229,32 @@ async def verifyTaskArgs(
except Exception as loadException:
# must be looking at a task that doesn't have JSON-based parameters
pass
for arg in task.args.args:
if arg.type == MythicCommandBase.ParameterType.TypedArray and callable(arg.typedarray_parse_function):
if len(arg.value) > 0 and arg.value[0][0] == "":
inputArray = [x[1] for x in arg.value]
resp = await arg.typedarray_parse_function(MythicCommandBase.PTRPCTypedArrayParseFunctionMessage(
command=task.Task.CommandName,
parameter_name=arg.name,
payload_type=task.PayloadType,
callback=task.Callback.ID,
input_array=inputArray
))
if not resp.Success:
raise Exception(resp.Error)
task.args.set_arg(arg.name, resp.TypedArray)
elif len(arg.value) > 0 and isinstance(arg.value[0], str):
resp = await arg.typedarray_parse_function(MythicCommandBase.PTRPCTypedArrayParseFunctionMessage(
command=task.Task.CommandName,
parameter_name=arg.name,
payload_type=task.PayloadType,
callback=task.Callback.ID,
input_array=arg.value
))
if not resp.Success:
raise Exception(resp.Error)
task.args.set_arg(arg.name, resp.TypedArray)

except Exception as pa:
message = {
"task_id": task.Task.ID,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# This call to setup() does all the work
setup(
name="mythic_container",
version="0.4.3",
version="0.4.4",
description="Functionality for Mythic Services",
long_description=README,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit c9bb763

Please sign in to comment.