Practical Crypto Attacks Against Web Applications Justin Clarke OWASP London Chapter Leader OWASP Global Connections Committee Copyright © The OWASP Foundation Permission is granted to copy,
Download ReportTranscript Practical Crypto Attacks Against Web Applications Justin Clarke OWASP London Chapter Leader OWASP Global Connections Committee Copyright © The OWASP Foundation Permission is granted to copy,
Practical Crypto Attacks Against Web Applications Justin Clarke OWASP London Chapter Leader OWASP Global Connections Committee 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 http://www.owasp.org/ Overview IANAC Usage != security Pentesting? OWASP Foundation The Need for Cryptography 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 OWASP Foundation Scenarios Symmetric Crypto Attacks ECB Mode Usage Padding-Based Attacks Secure Random Number Generation (if we have time) OWASP Foundation Symmetric Crypto Attacks 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 OWASP Foundation Why is ECB mode BAD? OWASP Foundation Why is ECB mode BAD? Reason #1 ECB CONFIDENTIALITY OWASP Foundation Why is ECB mode BAD? Reason #2 UID:23909,Email:[email protected],NickName:JohnDoe2301,Role:3 OWASP Foundation Why is ECB mode BAD? Reason #2 CIPHERTEXT Block 1 Block 2 Block 3 Block 4 Block 5 Block 6 Block 7 UID:2390 9,Email: john@doe .com,Nic kName:Jo hnDoe230 1,Role:3 9648dab1 d7f285ac 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 69e75f87 cf74ab6d UID:23909,Email:[email protected],NickName:JohnDoe2301,Role:3 OWASP Foundation Why is ECB mode BAD? Reason #2 CIPHERTEXT Block 1 Block 2 Block 3 Block 4 Block 5 Block 6 Block 7 UID:2390 9,Email: john@doe .com,Nic kName:Jo hnDoe230 1,Role:3 9648dab1 d7f285ac 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 69e75f87 cf74ab6d UID:23909,Email:[email protected],NickName:JohnDoe2301,Role:3 CIPHERTEXT Block 1 Block 7 Block 2 Block 3 Block 4 Block 5 Block 6 9648dab1 d7f285ac 69e75f87 cf74ab6d 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 OWASP Foundation Why is ECB mode BAD? Reason #2 CIPHERTEXT Block 1 Block 2 Block 3 Block 4 Block 5 Block 6 Block 7 UID:2390 9,Email: john@doe .com,Nic kName:Jo hnDoe230 1,Role:3 9648dab1 d7f285ac 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 69e75f87 cf74ab6d UID:23909,Email:[email protected],NickName:JohnDoe2301,Role:3 CIPHERTEXT Block 1 Block 7 Block 2 Block 3 Block 4 Block 5 Block 6 9648dab1 d7f285ac 69e75f87 cf74ab6d 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 UID:2390 1,Role:3 9,Email: john@doe .com,Nic kName:Jo hnDoe230 UID:23901,Role:39,Email:[email protected],NickName:JohnDoe230 OWASP Foundation Why is ECB mode BAD? Reason #2 CIPHERTEXT Block 1 Block 2 Block 3 Block 4 Block 5 Block 6 Block 7 UID:2390 9,Email: john@doe .com,Nic kName:Jo hnDoe230 1,Role:3 9648dab1 d7f285ac 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 69e75f87 cf74ab6d UID:23909,Email:[email protected],NickName:JohnDoe2301,Role:3 CIPHERTEXT Block 1 Block 7 Block 2 Block 3 Block 4 Block 5 Block 6 9648dab1 d7f285ac 69e75f87 cf74ab6d 22a1eaee db7aabbb 0f5a7a2a 1f8de75f 86adfcf6 17abcbcf 6adb7872 7ab9dd8e 96bdc238 5fa70ba2 UID:2390 1,Role:3 9,Email: john@doe .com,Nic kName:Jo hnDoe230 UID:23901,Role:39,Email:[email protected],NickName:JohnDoe230 OWASP Foundation DEMO ECB Mode 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 http://www.owasp.org/ What about CBC mode? OWASP Foundation What about CBC mode? CBC CONFIDENTIALITY OWASP Foundation CBC Decryption Original Ciphertext BLOCK 1 BLOCK 2 BLOCK 3 OWASP Foundation CBC Decryption Block Swapping will result in data corruption BLOCK 1 BLOCK 3 BLOCK 2 OWASP Foundation Attacking CBC Encrypted Data “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 OWASP Foundation How Padding Works OWASP Foundation How Padding Works Assuming this scheme, then there are only 8 possible valid padding sequences: 0x01 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x02 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x04 0x05, 0x06, 0x07, 0x08, 0x05, 0x06, 0x06 0x07, 0x07, 0x07 0x08, 0x08, 0x08, 0x08 OWASP Foundation Flipping Bytes in CBC Mode OWASP Foundation The Decryption Process 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 CRITICAL Return the value 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 The Padding Oracle Attack What does that tell us? The altered byte value produced valid padding when XOR’ed with the intermediate value IF A ^ B = C THEN A ^ C = B AND C ^ B = A OWASP Foundation The Padding Oracle Attack 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 OWASP Foundation DEMO 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 http://www.owasp.org/ What’s the solution? As we’ve seen, encrypted data (while kept private) is still susceptible to tampering Message Encryption We need to ensure PRIVACY and INTEGRITY OWASP Foundation What’s the solution? Encrypt + Sign the Ciphertext Message SIGNATURE Encryption 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 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 So to Summarize… Crypto is hard to get right Lots of ways to make mistakes When in doubt, ask an expert OWASP Foundation Justin Clarke [email protected] [email protected] Twitter: @connectjunkie 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 http://www.owasp.org/