Exemplo n.º 1
0
        public static byte[] AESEncryptionOracle(byte[] input, out bool isECB)
        {
            var randomPrefixLength = random.Next(5, 11);
            var randomPrefixBuffer = new byte[randomPrefixLength];

            random.NextBytes(randomPrefixBuffer);

            var randomSuffixLength = random.Next(5, 11);
            var randomSuffixBuffer = new byte[randomSuffixLength];

            random.NextBytes(randomSuffixBuffer);

            var paddedInput = new byte[randomPrefixLength + input.Length + randomSuffixLength];

            Array.Copy(randomPrefixBuffer, 0, paddedInput, 0, randomPrefixLength);
            Array.Copy(input, 0, paddedInput, randomPrefixLength, input.Length);
            Array.Copy(randomSuffixBuffer, 0, paddedInput, randomPrefixLength + input.Length, randomSuffixLength);

            if (paddedInput.Length % 16 != 0)
            {
                paddedInput = BlockPad(paddedInput, paddedInput.Length + (16 - paddedInput.Length % 16));
            }

            isECB = random.Next(0, 2) == 1;

            if (isECB)
            {
                return(AES128.EncryptECB(paddedInput, randomKey));
            }
            else
            {
                var iv = RandomAES128Key();
                return(AES128.EncryptCBC(paddedInput, randomKey, iv));
            }
        }
Exemplo n.º 2
0
        public static byte[] CBCBitflipOracle(string payload)
        {
            var prefix = "comment1=cooking%20MCs;userdata=";
            var suffix = ";comment2=%20like%20a%20pound%20of%20bacon";

            //note that if you Escape all values you can't bitflip attack
            //payload = Uri.EscapeDataString(payload)
            payload = payload.Replace(";", "%3b").Replace("=", "%3d");
            var newSource    = string.Concat(prefix, payload, suffix);
            var paddedSource = Pad16(Encoding.UTF8.GetBytes(newSource));
            var iv           = Encoding.UTF8.GetBytes("YELLOW SUBMARINE");

            return(AES128.EncryptCBC(paddedSource, randomKey, iv));
        }