示例#1
0
        private void HackMessage(IMessage message)
        {
            var redirectMessage = message as RedirectMessage;

            if (redirectMessage == null)
            {
                return;
            }
            while (true)
            {
                var keys = (Dictionary <IPEndPoint, ulong>)EncryptionManager.GetType()
                           .GetField("peerKeys", BindingFlags.Instance | BindingFlags.NonPublic)
                           .GetValue(EncryptionManager);
                var publicKey  = keys[((TcpAddress)redirectMessage.Destination).Endpoint];
                var privateKey = BluemeshEncryptor.GeneratePublicKey(publicKey);
                var bytes      = redirectMessage.Data.ToArray();
                BluemeshEncryptor.EncryptBytes(bytes, MessageContainer.HeaderSize, bytes.Length - MessageContainer.HeaderSize, privateKey);
                var newMessage = MessageContainer.ReadFromBuffer(bytes, 0, ConnectionManager.Utility).Message;
                if (newMessage is DataMessage)
                {
                    Console.WriteLine("FLAG: " + Encoding.UTF8.GetString(((DataMessage)newMessage).Data));
                    break;
                }
                redirectMessage = (RedirectMessage)newMessage;
            }
        }
示例#2
0
        public void Should_decode_encoded_text()
        {
            var privateKey = BluemeshEncryptor.GeneratePrivateKey(BitConverter.GetBytes(16742));
            var publicKey  = BluemeshEncryptor.GeneratePublicKey(privateKey);

            Console.WriteLine("e = {0}, d = {1}", publicKey, privateKey);

            var buffer = new byte[32];

            var message = "        ";

            Encoding.ASCII.GetBytes(message, 0, message.Length, buffer, 0);

            Console.WriteLine(BitConverter.ToString(buffer));
            Console.WriteLine(Encoding.ASCII.GetString(buffer));

            BluemeshEncryptor.EncryptBytes(buffer, 0, buffer.Length, publicKey);

            Console.WriteLine(BitConverter.ToString(buffer));
            Console.WriteLine(Encoding.ASCII.GetString(buffer));

            BluemeshEncryptor.EncryptBytes(buffer, 0, buffer.Length, privateKey);

            Console.WriteLine(BitConverter.ToString(buffer));
            Console.WriteLine(Encoding.ASCII.GetString(buffer));

            Encoding.ASCII.GetString(buffer).Should().StartWith(message);
        }