+ All Categories
Home > Documents > PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining),...

PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining),...

Date post: 25-Sep-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
64
1 PADDING ORACLE FOR THE MASSES
Transcript
Page 1: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

1

PADDING ORACLE FOR THEMASSES

Page 2: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

2

What is this presentation about?

● This presentation is a scrap book from our experience developing a reliable exploit against ASP.Net● It tooks 2 people working full time to create a reliable and working exploit for this vulnerabilities● All the kudos to Juliano Rizzo and Thai Duong for finding such a clever technique and teaching the world about the risks

Page 3: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

3

Page 4: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

4

Padding Oracle:it’s not a vulnerabilityit's an *Attack*

Page 5: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

5

What is the vulnerability?

● The vulnerability is a bad crypto implementation when using cbc mode of operation● A block cipher by itself allows encryption of only a single data block of the cipher lengths● IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on all the preceding ciphertext blocks (ie. If you encrypt again the same block, the ciphertext will be different.)

Page 6: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

6

I AM PROTECTED.IM USING AES

CONFIDENCIALITY !=

AUTHENTICITY

Page 7: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

7

HOW DOES CBCWORKS?

Page 8: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

8

IMV0

+

IV

P0

C0

Decryption process

dk(C0)

Page 9: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

9

IMV0

+

IV

P0

C0

IMV1

+

P1

C1

Decryption process

dk(C0) dk(C1)

Page 10: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

10

HOW DOES PADDINGWORKS?

Page 11: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

11

AAAAAAA

PKCS7

AAAAAAA1

Seven bytes data, padded with one \x01 byte

AAAAAA AAAAAA22

Six bytes data, padded with two \x02 bytes

Page 12: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

12

AAAAAAAA

PKCS7

AAAAAAAA

Eight bytes data, padded with eight \x08 bytes

88888888

Page 13: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

13

PADDINGORACLES

101

Page 14: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

14Evil Hacker

QWERTYBLAHBLAH

CORRECT DECRYPTIO

N

WRONG PADDING

Page 15: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

15

WRONG PADDING

The difference between a correct decryption or a wrong padding came in different flavours:

● Time difference● Error Code● Stack trace● HTML length● Strawberry

Page 16: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

16

ABCDEFGH IJKLMNOPcaptcha.php?val=IV

Encrypted Data

Page 17: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

17

X1X

2X

3X

4X

5X

6X

7X

8

+

ABCDEFGH

PYWTL333

IJKLMNOP

captcha.php?val=ABCDEFGHIJKLMNOP

dk(...)

Page 18: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

18

X1X

2X

3X

4X

5X

6X

7X

8

+

ABCDEFGH

PYWTL333

IJKLMNOP

dk(...)

Controlled DATA

Page 19: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

19

X1X

2X

3X

4X

5X

6X

7X

8 + ABCDEFGH PYWTL333

IJKLMNOP

dk(...)

=

IMV IV Plaintext

Page 20: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

20

So, if by some means we can know the IMV for a specific block, we

can forge custom captchas

Page 21: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

21

HOW DOES THE ATTACKWORKS?

Page 22: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

22

X1X

2X

3X

4X

5X

6X

7X

8

+

ABCDEFGI

PYWTL33Z

IJKLMNOP

dk(...)

We modify the last byte from the IVWe leave the enc block Fixed

Fixed

Page 23: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

23

X1X

2X

3X

4X

5X

6X

7X

8

+

ABCDEFGI

PYWTL33Z

IJKLMNOP

dk(...)

Wrong Padding

This will make the final result workor fail, in this case we can see that 33Zis not a valid padding

Page 24: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

24

X1X

2X

3X

4X

5X

6X

7X

8

+

ABCDEFGT

PYWTL331

IJKLMNOP

dk(...)

Padding Ok!

We keep changing the iv's last characteruntil we find the correct padding (theweb will behave differently)

Page 25: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

25

X8+T 1=

Page 26: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

26

X8 1= + T = 0x55

Page 27: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

27

Now that we know the 8th byte of the IMV, we go for the 7th

Page 28: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

28

X1X

2X

3X

4X

5X

6X

7X

8

+

ABCDEFH\x57

PYWTL332

IJKLMNOP

dk(...)

First we set the last IV byte such as the last decryted byte is a 2

X8=0x55 2+ = 0x57

Page 29: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

29

X1X

2X

3X

4X

5X

6X

7X

8

+

ABCDEFH\x57

PYWTL372

IJKLMNOP

dk(...)

Now we try to find the 7th IMV byte bykeep changing the 7th IV byte

Fixed

Wrong Padding

Page 30: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

30

X1X

2X

3X

4X

5X

6X

7X

8

+

ABCDEFJ\x57

PYWTL322

IJKLMNOP

dk(...)Fixed

Padding Ok!

Page 31: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

31

If you want to make your encrypted buf say something, you already have the pieces!

Page 32: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

32

2b 1a 51 00 f1 20 4f 55

+

68 5b 1f 5e b0 73 4d 57

CANVAS22

IJKLMNOP

dk(...)

IMV found using padding oracle

Message

We calculate an IV in order to produceour message :)

Page 33: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

33

ASP.NET

Page 34: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

34

IMV0

+

IV

P0

C0

IMV1

+

P1

C1

It's Fixed on the Server

dk(C0) dk(C1)

Page 35: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

35

Your target is ScriptResource.axd, this will allow you to download any file on the www root, including web.config (machine password, etc) It has its own “protocol” for doing stuffs

Page 36: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

36

R|~/web.config

Page 37: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

37

R#XXXXXXXX|||~/web.config

Page 38: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

38

● After a lot of brain cells burning, we came out with the following:

RANDOM IV for next IV for next ABCDEFGHI

R#xxxxxx TRASHED |||~/web .config

Page 39: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

39

RANDOM IV for next IV for next ABCDEFGHI

R#xxxxxx TRASHED |||~/web .config

Obtained via Padding Oracle.Around 2k request.

Obtained via randomly modifying the block12k to 100k average (could be more).

Page 40: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

40

Workarounds

● They don’t work, the only way to fix the bug is the patch● Examples:

● Redirecting all the logs to the same web● Adding a random sleep to each request

Page 41: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

41

MAGIC

“T”BLOCK

Page 42: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

42

RANDOM ORIGINAL1 ORIGINAL2 ORIGINAL3

Txxxxxx UNENCRYPTED UNENCRYPTED UNENCRYPTED

Randomly change a block, to obtain a T. This will decrypt all the other blocks.50­1000 hits

Page 43: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on
Page 44: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

44

MAGIC “T” Block

● The magic “T” Block will replace padding oracle● It will also allow you to do CBC-R● This will bypass all types of workarounds● Can speed up the QR-Block lookup!!

Page 45: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

45

First objetive: find a QRBlock

Page 46: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

Bruteforce!!!

Page 47: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

47

T-BLOCK random1 random2 Paddingblocks

Txxxxxx trashhh trashhhTrash + padding

RandomN

trashhh

...

...

Send a lot of random blocks

Page 48: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

48

T-BLOCK random1randomX

Txxxxxx

R#.....

...

...trashhh

Until we find our QR-Block

random2

trashhh

randomN

trashhh

Paddingblocks

Trash + padding

Page 49: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

49

Life it's no so easy...We need to set a correct IV for each bruteforce block

Page 50: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

50

blahrandomX

$$.....

blah

We need to mimic the first block

Paddingblocks

Trash + padding

IMV

+

IVblah

blah

Page 51: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

51

Simplification: default IV =

“\x00\x00\x00\x00\x00\x00\x00\x00”

Page 52: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

52

If instead of sending 8 random bytes you send \x00\x00 + 6 random bytes everything is

simpler!

Page 53: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

53

T-BLOCK random1randomX

Txxxxxx

R#.....

...

...trashhh

Life is easy again :)

random2

trashhh

randomN

trashhh

Paddingblocks

Trash + padding

R#.....

+

\x00\x00 + random

Page 54: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

54

but...

Page 55: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

55

T-BLOCK random1randomX

Txxxxxx

#......

...

...trashhh

we can be out of phase

random2

trashR#

randomN

ashhhtr

Paddingblocks

Trash + padding

����R.

False negative

Page 56: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

56

The encoding “eat” some characters

Page 57: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

57

random1

trashhh

random2

trashhh

random3

trashhh

random1

trashhh

random2

trashhh

random3

trashhh

Solution:Every n blocks we send a mark

xxxxxxxx immunity

mark-iv mark

xxxxxxxx

mark-iv

Page 58: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

58

The Padding Oracle attack took 35.000

requests in avg.

Page 59: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

59

The Magic-T takes 700 request(tblock: 400, qrblock: 300)

Page 60: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

60

DEMO

Page 61: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

61

Is that all?

● ASP.net is just one wrong implementation, there are more.● As a consultant you should be looking for:

● Session keys that looks like base64 (ASP.NET Uses UrlEncoded base64, it is a bit different)

● Encrypted cookies● Persisted information such as viewstate● “Any encrypted information that is stored client-side and returned to the server”

Page 62: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

62

Conclusion

● Workarounds are useless. PATCH!● Exploits once again show themselves to be a necessary tool to prove server risks● This is a error of implementation, even if you fix asp.net, your own developers’ software could have made their own crypto and be vulnerable

Page 63: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

63

More information

● Security Flaws Induced by CBC Padding – S. Vaudenay● Padding Oracle Attacks on the ISO CBC Mode Padding Standard - K.G. Paterson and A. Yau● Practical Padding Oracle Attacks – J. Rizzo and T. Duong

Page 64: PADDING ORACLE - Immunity Inc · 2020. 1. 23. · IBM came out with CBC (Cipher Block chaining), this mode of operation causes the decryption of a block of ciphertext to depend on

64

THANKS NICO [email protected]@nicowaisman

Matias Soler (@gnuler)Agustin Gianni (@agustingianni)


Recommended