/// <summary> /// Provides a record-by-record processing functionality for the cmdlet. /// </summary> protected override void ProcessRecord() { WebPageSteganography stegoPage = new WebPageSteganography(this.Path, this.Passphrase); string text = stegoPage.ReadValue(); this.WriteObject(text); this.WriteVerbose("Message retrieved."); }
/// <summary> /// Provides a record-by-record processing functionality for the cmdlet. /// </summary> protected override void ProcessRecord() { WebPageSteganography stegoPage = new WebPageSteganography(this.Path, this.Passphrase); stegoPage.WriteValue(this.Message); string check = stegoPage.ReadValue(); this.WriteVerbose(check); this.WriteObject("Message saved."); }
/// <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>"); } }
/// <summary> /// Provides a one-time, preprocessing functionality for the cmdlet. /// </summary> protected override void BeginProcessing() { // Initialize parameters and base Incog cmdlet components this.InitializeComponent(); // Verify the browser history file path this.BrowserHistoryFile = ConsoleTools.ExpandAndVerifyPath(this, this.BrowserHistoryFile); StreamReader history = new StreamReader(this.BrowserHistoryFile.FullName); string text = history.ReadToEnd(); string[] lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); this.links = new Uri[lines.Length]; for (int i = 0; i < this.links.Length; i++) { this.links[i] = new Uri(lines[i]); this.WriteVerbose(string.Format("Loading ... {0}", this.links[i].ToString())); } // Invoke Interative Mode if selected if (this.Interactive) this.InteractiveMode(); // Set the default TCP port if (this.TCP == 0) this.TCP = 80; // Get a derived value to indicate where the path and host split DerivedValue derived = new DerivedValue(this.Passphrase); string split = derived.GetString(3, 10); int linkIndex = 0; do { // Get the host and path of the next URL string host = this.links[linkIndex].Host; string absolutePath = this.links[linkIndex].AbsolutePath; // Get the host as a base64 encoded string byte[] hostBytes = System.Text.Encoding.ASCII.GetBytes(host); string hostBase64 = System.Convert.ToBase64String(hostBytes); // Get the resulting link -- absolute path and host in base 64 Uri resultingLink = new Uri(string.Concat( "http://", this.RemoteAddress.ToString(), ":", this.TCP.ToString(), absolutePath, split, hostBase64)); try { // Create a request for the URL and set the timeout WebRequest request = WebRequest.Create(resultingLink); request.Timeout = request.Timeout * 2; // Get the response WebResponse response = request.GetResponse(); // Display the status this.WriteVerbose(resultingLink.ToString()); this.WriteVerbose(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server Stream dataStream = response.GetResponseStream(); // Read in the stream into a buffer int growBufferBy = 1024; byte[] buffer = new byte[10240]; byte[] page; int index = 0; do { int i = dataStream.ReadByte(); if (i == -1) { page = new byte[index]; Array.Copy(buffer, page, index); break; } buffer[index] = Convert.ToByte(i); index++; if (index == buffer.Length) { byte[] temp = new byte[buffer.Length + growBufferBy]; Array.Copy(buffer, temp, buffer.Length); buffer = new byte[temp.Length]; Array.Copy(temp, buffer, temp.Length); } } while (true); response.Close(); // Feed the bytes into a stego page and test WebPageSteganography stegoPage = new WebPageSteganography(page, this.Passphrase); string message = stegoPage.ReadValue(); // Break on exit if (message.Trim().ToLower() == "exit") break; if (message != string.Empty) { if (this.Interactive) { Console.WriteLine("{0} > {1}", this.RemoteAddress.ToString(), message); } else { this.WriteObject(message); } } } catch (System.Net.Sockets.SocketException ex) { this.WriteVerbose(ex.InnerException.ToString()); break; } catch (Exception ex) { if (ex.InnerException != null) { if (ex.InnerException.GetType() == typeof(System.Net.Sockets.SocketException)) { this.WriteWarning(ex.InnerException.Message); break; } } this.WriteWarning(ex.ToString()); } linkIndex++; if (linkIndex == this.links.Length) linkIndex = 0; System.Threading.Thread.Sleep(500); } while (true); }