Skip to content

Commit 4f8bbfa

Browse files
Merge pull request #8 from viyatb/mythic_file_api
[mythic] Add a function to get uploaded file details by name
2 parents 7a505a6 + 76a840c commit 4f8bbfa

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

mythic/mythic.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,29 @@ async def get_all_uploaded_files(
15971597
break
15981598

15991599

1600+
async def get_latest_uploaded_file_by_name(
1601+
mythic: mythic_classes.Mythic, custom_return_attributes: str = None, filename: str = None,
1602+
) -> dict:
1603+
"""
1604+
Execute a query to get metadata about the uploaded file by name.
1605+
To download the contents of a file, use the `download_file` function with the agent_file_id.
1606+
The default set of attributes returned in the dictionary can be found at graphql_queries.file_data_fragment.
1607+
If you want to use your own `custom_return_attributes` string to identify what information you want back, you have to include the `id` field, everything else is optional.
1608+
"""
1609+
file_query = f"""
1610+
query uploaded_file_by_name($filename: String!){{
1611+
filemeta(where: {{is_screenshot: {{_eq: false}}, is_download_from_agent: {{_eq: false}}, is_payload: {{_eq: false}}, deleted: {{_eq: false}}, filename_utf8: {{_eq: $filename}}}}, order_by: {{id: desc}}, limit: 1){{
1612+
{custom_return_attributes if custom_return_attributes is not None else '...file_data_fragment'}
1613+
}}
1614+
}}
1615+
{graphql_queries.file_data_fragment if custom_return_attributes is None else ''}
1616+
"""
1617+
output = await mythic_utilities.graphql_post(
1618+
mythic=mythic, query=file_query,
1619+
)
1620+
return output["filemeta"][0] if output["filemeta"] else {}
1621+
1622+
16001623
async def update_file_comment(
16011624
mythic: mythic_classes.Mythic, file_uuid: str, comment: str
16021625
) -> dict:

0 commit comments

Comments
 (0)