Incog Pipe Stream defines the data protocol for reading and writing strings on our stream.
Ejemplo n.º 1
0
        /// <summary>
        /// Interactive Mode allows the user to key in message after message, and have the message sent over the covert channel.
        /// </summary>
        private void InteractiveMode()
        {
            // Update the screen with the parameters of the chat session
            this.PrintInteractiveMode(ChannelTools.CommunicationMode.Alice);

            // Wait for the client connection
            this.WriteVerbose("Waiting for client connect . . .");

            NamedPipeServerStream pipeServer = new NamedPipeServerStream(
                this.CmdletGuid,
                PipeDirection.InOut);

            DerivedValue derived = new DerivedValue(this.Passphrase);
            string handshake = derived.GetString(3, 12);
            this.WriteVerbose(string.Format("Handshaking with {0}.", handshake));

            pipeServer.WaitForConnection();
            this.WriteVerbose("Connected. Ready to send chat messages.");

            try
            {
                // Read the request from the client
                IncogStream stream = new IncogStream(pipeServer, this.Passphrase, this.TargetEntropy);

                // Verify our identity to the connected client using a handshake string
                stream.WriteString(handshake);

                do
                {
                    Console.Write("{0}> ", this.CmdletName);
                    string line = Console.ReadLine();
                    if (line == string.Empty) continue;
                    stream.WriteString(line);
                    if (line.ToLower() == "exit") break;
                }
                while (true);
            }
            catch (System.IO.IOException e)
            {
                // Catch the IOException that is raised if the pipe is broken or disconnected.
                this.WriteWarning(e.Message);
            }

            pipeServer.Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Provides a one-time, preprocessing functionality for the cmdlet.
        /// </summary>
        protected override void BeginProcessing()
        {
            // Initialize parameters and base Incog cmdlet components
            this.InitializeComponent();

            // Invoke Interative Mode if selected
            if (this.Interactive) this.InteractiveMode();

            // Start the connection
            this.WriteVerbose("Connecting to server . . .");

            NamedPipeClientStream pipeClient = new NamedPipeClientStream(
                    this.RemoteAddress.ToString(),
                    this.CmdletGuid,
                    PipeDirection.InOut,
                    PipeOptions.None,
                    System.Security.Principal.TokenImpersonationLevel.Impersonation);

            DerivedValue derived = new DerivedValue(this.Passphrase);
            string handshake = derived.GetString(3, 12);
            this.WriteVerbose(string.Format("Handshaking with {0}.", handshake));

            pipeClient.Connect();
            IncogStream stream = new IncogStream(pipeClient, this.Passphrase);

            // Validate the server's signature string
            if (stream.ReadString() == handshake)
            {
                // The client security token is sent with the first write.
                // Print the file to the screen.
                this.WriteVerbose("Connected. Incoming chat messages.");

                do
                {
                    string message = stream.ReadString();

                    if (message == string.Empty)
                    {
                        Thread.Sleep(250);
                        continue;
                    }

                    if (message.Trim().ToLower() == "exit")
                    {
                        break;
                    }

                    if (this.Interactive)
                    {
                        Console.WriteLine("{0} > {1}", this.RemoteAddress.ToString(), message);
                    }
                    else
                    {
                        this.WriteObject(message);
                    }
                }
                while (true);
            }
            else
            {
                this.WriteVerbose("The connected failed because of an invalid server handshake.");
            }

            pipeClient.Close();

            // Give the client process some time to display results before exiting.
            Thread.Sleep(2000);
        }