Simple Hypertext Transfer Protocol (HTTP) request processor.
示例#1
0
        /// <summary>
        /// The handler for HTTP POST requests.
        /// TODO: This code has not been tested. It should work, right? I mean, what could possibly go wrong?
        /// </summary>
        /// <param name="processor">The HTTP processor.</param>
        public void HttpPostHandler(HttpProcessor processor)
        {
            string data = string.Empty;

            do
            {
                int next = processor.StreamInput.ReadByte();
                if (next == -1) break;

                data += Convert.ToChar(next);
            }
            while (true);

            processor.WriteLine("<html>A post? Thank you. I needed that.</html>");
        }
示例#2
0
        /// <summary>
        /// Begin listening.
        /// </summary>
        public void Start()
        {
            this.listener = new TcpListener(this.Address, this.Port);
            this.listener.Start();
            this.Active = true;

            while (this.Active)
            {
                TcpClient s = this.listener.AcceptTcpClient();
                HttpProcessor processor = new HttpProcessor(s, this);
                Thread thread = new Thread(new ThreadStart(processor.Process));
                thread.Start();
                Thread.Sleep(1);
            }

            this.listener.Stop();
        }
示例#3
0
        /// <summary>
        /// The handler for HTTP GET requests.
        /// </summary>
        /// <param name="processor">The HTTP processor.</param>
        public void HttpGetHandler(HttpProcessor processor)
        {
            processor.WriteSuccess();

            Cryptkeeper myCrypt = new Cryptkeeper(this.passphrase);
            DerivedValue derived = new DerivedValue(this.passphrase);
            string result = derived.GetString(3, 10);

            // No result? No handshake. Done.
            if (processor.RequestURL.IndexOf(result) == -1) return;

            // Parse out the host name and fetch the next page.
            string hostname = string.Empty;
            string absolutePath = processor.RequestURL;

            string[] values = absolutePath.Split(new string[] { result }, StringSplitOptions.RemoveEmptyEntries);
            absolutePath = values[0].Trim();
            string hostBase64 = values[1].Trim();
            byte[] hostBytes = System.Convert.FromBase64String(hostBase64);
            hostname = Encoding.ASCII.GetString(hostBytes);

            Uri link = new Uri(string.Concat("http://", hostname, absolutePath));

            try
            {
                WebClient web = new WebClient();
                byte[] page = web.DownloadData(link);
                web.Dispose();

                WebPageSteganography stegopage = new WebPageSteganography(page, this.passphrase);
                string message = string.Empty;

                if (this.MessageQueue.Count > 0)
                {
                    message = (string)this.MessageQueue.Dequeue();
                }

                stegopage.WriteValue(message);
                page = stegopage.GetBytes();

                processor.StreamOutput.Write(page);
                processor.StreamOutput.Flush();
                processor.WriteSuccess();
            }
            catch (Exception ex)
            {
                processor.StreamOutput.Write("<html><p>Ping! Something odd happened while retrieving ... " + link.ToString() + "</p><p>" + ex.ToString() + "</p></html>");
            }
        }