350 likes | 485 Views
Practical Crypto Attacks Against Web Applications Justin Clarke OWASP London Chapter Leader OWASP Global Connections Committee. Overview. IANAC Usage != security Pentesting ?. The Need for Cryptography.
E N D
Practical Crypto Attacks Against Web ApplicationsJustin ClarkeOWASP London Chapter LeaderOWASP Global Connections Committee
Overview • IANAC • Usage != security • Pentesting?
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
Scenarios • Symmetric Crypto Attacks • ECB Mode Usage • Padding-Based Attacks • Secure Random Number Generation (if we have time)
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
Why is ECB mode BAD? • Reason #1 ECB x • CONFIDENTIALITY
Why is ECB mode BAD? • Reason #2 UID:23909,Email:john@doe.com,NickName:JohnDoe2301,Role:3
Why is ECB mode BAD? • Reason #2 CIPHERTEXT UID:23909,Email:john@doe.com,NickName:JohnDoe2301,Role:3
Why is ECB mode BAD? • Reason #2 CIPHERTEXT UID:23909,Email:john@doe.com,NickName:JohnDoe2301,Role:3 CIPHERTEXT
Why is ECB mode BAD? • Reason #2 CIPHERTEXT UID:23909,Email:john@doe.com,NickName:JohnDoe2301,Role:3 CIPHERTEXT UID:23901,Role:39,Email:john@doe.com,NickName:JohnDoe230
Why is ECB mode BAD? • Reason #2 CIPHERTEXT UID:23909,Email:john@doe.com,NickName:JohnDoe2301,Role:3 CIPHERTEXT UID:23901,Role:39,Email:john@doe.com,NickName:JohnDoe230
DEMO ECB Mode Attack
What about CBC mode? CBC • CONFIDENTIALITY
CBC Decryption • Original Ciphertext BLOCK 1 BLOCK 2 BLOCK 3
CBC Decryption • Block Swapping will result in data corruption BLOCK 1 BLOCK 3 BLOCK 2
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
How Padding Works • 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
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 • Return the value CRITICAL
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
The Padding Oracle Attack Byte X == 0x00 Byte Y == ??? • Exception? YES • Byte Y is not valid padding
The Padding Oracle Attack Byte X == 0x01 Byte Y == ??? • Exception? YES • Byte Y is not valid padding
The Padding Oracle Attack Byte X == 0x02 Byte Y == ??? • Exception? YES • Byte Y IS valid padding (must be 0x01)
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
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
DEMO Padding Oracle Attack
What’s the solution? • As we’ve seen, encrypted data (while kept private) is still susceptible to tampering • We need to ensure PRIVACY and INTEGRITY Encryption Message
What’s the solution? • 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 Encryption Message
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
So to Summarize… • Crypto is hard to get right • Lots of ways to make mistakes • When in doubt, ask an expert
Justin Clarke justin.clarke@owasp.org justin@gdssecurity.com Twitter: @connectjunkie