@@ -2172,6 +2172,72 @@ async def send_custom_webhook_message(
21722172 "webhook_type" : webhook_type })
21732173
21742174
2175+ # ####### C2 Functions #############
2176+
2177+ async def start_stop_c2_profile (
2178+ mythic : mythic_classes .Mythic ,
2179+ c2_profile_name : str ,
2180+ action : str = "start"
2181+ ):
2182+ query = """
2183+ query getC2IdFromName($c2_name: String!) {
2184+ c2profile(where: {name: {_eq: $c2_name}}){
2185+ id
2186+ }
2187+ }
2188+ """
2189+ resp = await mythic_utilities .graphql_post (mythic = mythic , query = query , variables = {
2190+ "c2_name" : c2_profile_name ,
2191+ })
2192+ if len (resp ["c2profile" ]) == 0 :
2193+ raise Exception (f"Failed to find c2 profile { c2_profile_name } " )
2194+ start_stop = """
2195+ mutation startStopC2Profile($id: Int!, $action: String!){
2196+ startStopProfile(id: $id, action: $action){
2197+ status
2198+ error
2199+ output
2200+ }
2201+ }
2202+ """
2203+ resp = await mythic_utilities .graphql_post (mythic = mythic , query = start_stop , variables = {
2204+ "id" : resp ["c2profile" ][0 ]["id" ], "action" : action ,
2205+ })
2206+ return resp ["startStopProfile" ]
2207+
2208+
2209+ async def create_saved_c2_instance (
2210+ mythic : mythic_classes .Mythic ,
2211+ instance_name : str ,
2212+ c2_profile_name : str ,
2213+ c2_parameters : dict
2214+ ):
2215+ query = """
2216+ query getC2IdFromName($c2_name: String!) {
2217+ c2profile(where: {name: {_eq: $c2_name}}){
2218+ id
2219+ }
2220+ }
2221+ """
2222+ resp = await mythic_utilities .graphql_post (mythic = mythic , query = query , variables = {
2223+ "c2_name" : c2_profile_name ,
2224+ })
2225+ if len (resp ["c2profile" ]) == 0 :
2226+ raise Exception (f"Failed to find c2 profile { c2_profile_name } " )
2227+ mutation = """
2228+ mutation createNewC2Instance($instance_name: String!, $c2_instance: String!, $c2profile_id: Int!){
2229+ create_c2_instance(c2_instance: $c2_instance, instance_name: $instance_name, c2profile_id: $c2profile_id){
2230+ status
2231+ error
2232+ }
2233+ }
2234+ """
2235+ resp = await mythic_utilities .graphql_post (mythic = mythic , query = mutation , variables = {
2236+ "instance_name" : instance_name , "c2profile_id" : resp ["c2profile" ][0 ]["id" ], "c2_instance" : json .dumps (c2_parameters )
2237+ })
2238+ return resp ["create_c2_instance" ]
2239+
2240+
21752241# ####### Tag Functions ############
21762242
21772243
0 commit comments