CBC Mode is Malleable. Don’t trust it for Authentication — Arxum Path Security (2024)

On a recent pentest, I encountered an authentication system that used a block cipher in CBC mode, which I was able to break using a Padding Oracle. The vulnerability required access to valid ciphertext, which limited the scope of the attack, but it was possible to decrypt a full authentication token in about an hour even though the token was encrypted with AES-256.

Cryptography is difficult to implement securely due to the fact that it is complicated and requires many moving parts, and if any of these components are not handled properly, the entire system can be compromised.

The problem with CBC mode is that it is malleable. Recently, researchers broke PDF encryption using CBC Gadgets to inject content into an encrypted document (https://pdf-insecurity.org/encryption/cbc-malleability.html). The notion that simply because something is encrypted it can be trusted is false. Here are some reasons why.

Bit Flipping Attacks

In CBC mode, each block of plaintext is XOR’d against the previous block of ciphertext BEFORE encryption (the first block of plaintext is XOR’d against a block known as the Initialization Vector). This makes the value that is encrypted completely dependent on the prior ciphertext block.

During decryption the process is in reverse. A block is decrypted to an intermediate value, and then this intermediate value is XOR’d against the previous ciphertext block to return to the original plaintext.

XOR, or Exclusive OR, is a commutative operation, much like addition. For example,

This example is simple, because anything XOR’d by itself is 0, so when the plaintext decrypts to 0 here, we know that

Under such an attack, the attacker’s previous block will decrypt to garbage, so for this to work, that garbage needs to be discarded by the application (think of tokens that are split on &, for example). If an attacker can safely get the application to ignore the garbage, then the target block would decrypt to a forged authenticated token.

Note, CTR mode is also vulnerable to an attack like this, but in an even more direct fashion, as previous blocks don’t need to be tampered with.

Padding Oracles

While Padding Oracles do not recover the encryption key, a ciphertext encrypted with that key can be decrypted with 256 guesses per byte. The reason the vulnerability exists is because block ciphers must have valid padding, and encryption algorithms will handle the padding for developers during encryption. Consequently, during development and testing, valid ciphertexts are used and developers may never even be aware padding exists. This is dangerous because not handling padding errors safely can compromise the system.

So what is padding and why is it necessary?

A block cipher deals with fixed sizes of data, or blocks. In AES, the block size is 16 bytes, or 128 bits. A ciphertext block will always be 16 bytes, and so plaintext must also always be in blocks of 16 bytes. Real world scenarios don’t conform to such requirements, however. If the plaintext is 20 bytes in length, the first 16 bytes will form a block, and the remaining 4 bytes will be 12 bytes short of the 16 byte block size. Those remaining 12 bytes will get filled with padding.

The PKCS#7 standard defines how this padding is constructed, and it is quite simple. The number of padding bytes will be filled with the value of how much padding is necessary. To demonstrate, here we have 13 bytes of plaintext, and 3 bytes of padding. So we pad the 13 bytes with 3 bytes of \x03.

Padding can be anywhere from 1 to 16 bytes. The reason 16 bytes of padding would exist is if the plaintext evenly falls into 16 byte blocks. An additional block of only padding would then be required so that the algorithm knows the padding is valid.

During decryption, a ciphertext is first decrypted and then the padding is discarded. If the ciphertext was not tampered with, then the padding will be valid. But if the padding can’t be found and the application errors, then an attacker can leverage this error as an oracle.

Using techniques similar to those in the bit flipping attack, an attacker can force decryption of a block to one that has valid padding if the application provides information when the padding is invalid. This is because for each byte in the target block, there will be an 8bit value in the previous block that XORs the intermediate value into valid padding. For instance, for the last byte of the block, we are looking for a padding of \x01. So a valid equation would look like this:

Using XORs commutative property, and the original previous block, we can then decrypt the last byte of the target block

Knowing the last byte of plaintext, the attacker would then need to find a block that decrypts to intermediate values that end in \x02\x02, \x03\x03\x03, \x04\x04\x04\x04, etc. This allows for an efficient decryption of a ciphertext without ever knowing the key, simply because the application didn’t handle an error.

Recommendations

Just because something is encrypted, doesn’t make it trustworthy. To ensure the integrity of ciphertexts, sign them with a Message Authentication Code (MAC), or consider using a block cipher mode that provides authentication, such as GCM. For authentication tokens, using an HMAC with SHA-256 is advisable.

CBC Mode is Malleable. Don’t trust it for Authentication — Arxum Path Security (2024)
Top Articles
Tradelines for Sale: Is it a Best Practice or Fake Shortcut? | Nav
How to Transfer Money Online to Friends and Family
Swimgs Yuzzle Wuzzle Yups Wits Sadie Plant Tune 3 Tabs Winnie The Pooh Halloween Bob The Builder Christmas Autumns Cow Dog Pig Tim Cook’s Birthday Buff Work It Out Wombats Pineview Playtime Chronicles Day Of The Dead The Alpha Baa Baa Twinkle
Craigslist Pets Longview Tx
Amtrust Bank Cd Rates
Merlot Aero Crew Portal
Owatc Canvas
Stolen Touches Neva Altaj Read Online Free
Graveguard Set Bloodborne
Hardly Antonyms
Derpixon Kemono
Jcpenney At Home Associate Kiosk
อพาร์ทเมนต์ 2 ห้องนอนในเกาะโคเปนเฮเกน
Truck Trader Pennsylvania
State HOF Adds 25 More Players
De beste uitvaartdiensten die goede rituele diensten aanbieden voor de laatste rituelen
Ally Joann
Bing Chilling Words Romanized
[Cheryll Glotfelty, Harold Fromm] The Ecocriticism(z-lib.org)
Milanka Kudel Telegram
Juicy Deal D-Art
Plaza Bonita Sycuan Bus Schedule
Nsa Panama City Mwr
Craigslist Roseburg Oregon Free Stuff
2487872771
Violent Night Showtimes Near Johnstown Movieplex
Craftsman Yt3000 Oil Capacity
Winterset Rants And Raves
Kiddie Jungle Parma
Purdue Timeforge
Microsoftlicentiespecialist.nl - Microcenter - ICT voor het MKB
Car Crash On 5 Freeway Today
Soulstone Survivors Igg
Compare Plans and Pricing - MEGA
Armageddon Time Showtimes Near Cmx Daytona 12
Nid Lcms
Who Is Responsible for Writing Obituaries After Death? | Pottstown Funeral Home & Crematory
Brother Bear Tattoo Ideas
Spurs Basketball Reference
Darkglass Electronics The Exponent 500 Test
What is a lifetime maximum benefit? | healthinsurance.org
Sinai Sdn 2023
Aurora Southeast Recreation Center And Fieldhouse Reviews
8 4 Study Guide And Intervention Trigonometry
Take Me To The Closest Ups
Wrentham Outlets Hours Sunday
Tyrone Unblocked Games Bitlife
303-615-0055
Otter Bustr
Southwind Village, Southend Village, Southwood Village, Supervision Of Alcohol Sales In Church And Village Halls
Competitive Comparison
How To Find Reliable Health Information Online
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 6381

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.