Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation Practical Crypto Attacks Against Web Applications Justin Clarke OWASP London Chapter Leader OWASP Global Connections Committee
OWASP Foundation IANAC Usage != security Pentesting? Overview
OWASP Foundation Confidentiality – Prevent the disclosure of information to unauthorized individuals or systems Integrity – Ensure that data cannot be modified undetectably Authenticity - Validate that a party is who they claim they are The Need for Cryptography
OWASP Foundation Symmetric Crypto Attacks ECB Mode Usage Padding-Based Attacks Secure Random Number Generation (if we have time) Scenarios
OWASP Foundation Most block ciphers support multiple modes of operation The most common modes are : ECB – Electronic Code Book CBC – Cipher Block Chaining CFB - Cipher Feedback OFB - Output Feedback None provide integrity if used in isolation Symmetric Crypto Attacks
OWASP Foundation Why is ECB mode BAD?
OWASP Foundation Reason #1 Why is ECB mode BAD? ECB CONFIDENTIALITY
OWASP Foundation Reason #2 Why is ECB mode BAD?
OWASP Foundation Reason #2 Why is ECB mode BAD? Block 1Block 2Block 3Block 4Block 5Block 6Block dab1 d7f285ac 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 69e75f87 cf74ab6d CIPHERTEXT
OWASP Foundation Why is ECB mode BAD? Block 1Block 7Block 2Block 3Block 4Block 5Block dab1 d7f285ac 69e75f87 cf74ab6d 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 Block 1Block 2Block 3Block 4Block 5Block 6Block dab1 d7f285ac 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 69e75f87 cf74ab6d Reason #2 CIPHERTEXT
OWASP Foundation Why is ECB mode BAD? Block 1Block 7Block 2Block 3Block 4Block 5Block dab1 d7f285ac 69e75f87 cf74ab6d 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 Block 1Block 2Block 3Block 4Block 5Block 6Block dab1 d7f285ac 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 69e75f87 cf74ab6d Reason #2 CIPHERTEXT
OWASP Foundation Why is ECB mode BAD? Block 1Block 7Block 2Block 3Block 4Block 5Block dab1 d7f285ac 69e75f87 cf74ab6d 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 Block 1Block 2Block 3Block 4Block 5Block 6Block dab1 d7f285ac 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 69e75f87 cf74ab6d Reason #2 CIPHERTEXT
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation DEMO ECB Mode Attack
OWASP Foundation What about CBC mode?
OWASP Foundation What about CBC mode? CBC CONFIDENTIALITY
OWASP Foundation Original Ciphertext CBC Decryption BLOCK 1BLOCK 2BLOCK 3
OWASP Foundation Block Swapping will result in data corruption CBC Decryption BLOCK 1BLOCK 3BLOCK 2
OWASP Foundation “Padding Oracle” Attack Leverages byte flipping of ciphertext to generate invalid padding exceptions Data can be decrypted (and encrypted too) without knowledge of the secret key Attacking CBC Encrypted Data
OWASP Foundation How Padding Works
OWASP Foundation Assuming this scheme, then there are only 8 possible valid padding sequences: 0x01 0x02, 0x02 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 How Padding Works
OWASP Foundation Flipping Bytes in CBC Mode
OWASP Foundation Is the key the correct size? Invalid Key Exception Is the value (bytes) an even block multiple? Invalid Length Exception Is the decrypted block properly padded? Invalid Padding Exception Return the value The Decryption Process CRITICAL
OWASP Foundation The Padding Oracle Attack
OWASP Foundation The Padding Oracle Attack Call this “Byte X” Call this “Byte Y” Basic Premise: A change of Byte X (ciphertext) will change Byte Y (plaintext) There is a one-to-one correlation between Byte X values and Byte Y values Exception is thrown if plain-text does not end with a valid padding sequence
OWASP Foundation The Padding Oracle Attack Byte X == 0x00 Byte Y == ??? Exception? YES Byte Y is not valid padding
OWASP Foundation The Padding Oracle Attack Byte X == 0x01 Byte Y == ??? Exception? YES Byte Y is not valid padding
OWASP Foundation The Padding Oracle Attack Byte X == 0x02 Byte Y == ??? Exception? YES Byte Y IS valid padding (must be 0x01)
OWASP Foundation What does that tell us? The altered byte value produced valid padding when XOR’ed with the intermediate value The Padding Oracle Attack IF A ^ B = C THEN A ^ C = B AND C ^ B = A
OWASP Foundation What does that tell us? If the padding byte was 0x01: –Our Byte (0x02) ^ Intermediate Byte (??) == 0x01 –Intermediate Byte == Our Byte (0x02) ^ 0x01 The plain-text value is the intermediate value XOR’ed with the prior ciphertext byte The Padding Oracle Attack
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation DEMO Padding Oracle Attack
OWASP Foundation As we’ve seen, encrypted data (while kept private) is still susceptible to tampering We need to ensure PRIVACY and INTEGRITY What’s the solution? Encryption Message
OWASP Foundation Encrypt + Sign the Ciphertext HMAC: Combines a cryptographic hash function with a secret key Cannot be re-computed without the key Verifies the integrity and authenticity of a message SIGNATURE What’s the solution? Encryption Message
OWASP Foundation Another Lesson Learned Why not HMAC within the ciphertext? Does not prevent against side channel attacks during decryption Padding Oracle Attack in.NET Framework Discovered September 2010 Viewstate and Forms Authentication Cookies were affected even though an HMAC was included within the ciphertext Tampering was only be detected after decryption
OWASP Foundation Crypto is hard to get right Lots of ways to make mistakes When in doubt, ask an expert So to Summarize…
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP Foundation Justin Clarke