Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Note: the correct guesses calculation is not right for some reason
- """
- An ECB/CBC detection oracle
- Now that you have ECB and CBC working:
- Write a function to generate a random AES key; that's just 16 random bytes.
- Write a function that encrypts data under an unknown key --- that is, a function that generates a random key and encrypts under it.
- The function should look like:
- encryption_oracle(your-input)
- => [MEANINGLESS JIBBER JABBER]
- Under the hood, have the function append 5-10 bytes (count chosen randomly) before the plaintext and 5-10 bytes after the plaintext.
- Now, have the function choose to encrypt under ECB 1/2 the time, and under CBC the other half (just use random IVs each time for CBC). Use rand(2) to decide which to use.
- Detect the block cipher mode the function is using each time. You should end up with a piece of code that, pointed at a block box that might be encrypting ECB or CBC, tells you which one is happening.
- """
- [mouse@apiary set2]$ ./challenge11.py
- Trying 1000 test using string "Hi, I'm new here. a b c d e f g hs ksadjfkjask ajfiosdjfkjakjfsdijfisjfkasjfkljklfja kjsdfkja ".
- ////////////////////////////////////////
- CBC Statistics:
- 510 lines processed
- MIN V,D 425,0
- MAX V,D 529,0
- Mean V,D: 473, 0
- Variance: 1024, 0
- Standard deviation: 32, 0
- V: Correct guesses: 510 100%
- D: Correct guesses: 510 100%
- ////////////////////////////////////////
- ECB Statistics:
- 490 lines processed
- MIN V,D 356,0
- MAX V,D 471,0
- Mean V,D: 413, 0
- Variance: 1074, 0
- Standard deviation: 32, 0
- V: Correct guesses: 227 46%
- D: Correct guesses: 490 100%
- Trying 1000 test using string "Even out settle scores quick Our disaster recovery requires even more disks Put your bytes up, prove it or you forfeit Got my C64 and we blew it into orbit".
- ////////////////////////////////////////
- CBC Statistics:
- 500 lines processed
- MIN V,D 683,0
- MAX V,D 721,0
- Mean V,D: 704, 0
- Variance: 50, 0
- Standard deviation: 7, 0
- V: Correct guesses: 500 100%
- D: Correct guesses: 500 100%
- ////////////////////////////////////////
- ECB Statistics:
- 500 lines processed
- MIN V,D 617,0
- MAX V,D 659,0
- Mean V,D: 639, 0
- Variance: 55, 0
- Standard deviation: 7, 0
- V: Correct guesses: 500 100%
- D: Correct guesses: 500 100%
- Trying 1000 test using string "M. Bison with eight straight perfects Overvolt emotions make hate break circuits In case you heard, it's a named fake service Optimize our runtime to escape verdicts".
- ////////////////////////////////////////
- CBC Statistics:
- 502 lines processed
- MIN V,D 691,0
- MAX V,D 789,0
- Mean V,D: 765, 0
- Variance: 185, 0
- Standard deviation: 13, 0
- V: Correct guesses: 502 100%
- D: Correct guesses: 502 100%
- ////////////////////////////////////////
- ECB Statistics:
- 498 lines processed
- MIN V,D 620,0
- MAX V,D 720,0
- Mean V,D: 702, 0
- Variance: 152, 0
- Standard deviation: 12, 0
- V: Correct guesses: 498 100%
- D: Correct guesses: 498 100%
- Trying 1000 test using string "Got an integer scope flow That they can't sign Passing code, didn't sanitize Command lines; land mine".
- ////////////////////////////////////////
- CBC Statistics:
- 485 lines processed
- MIN V,D 431,0
- MAX V,D 533,0
- Mean V,D: 509, 0
- Variance: 172, 0
- Standard deviation: 13, 0
- V: Correct guesses: 485 100%
- D: Correct guesses: 485 100%
- ////////////////////////////////////////
- ECB Statistics:
- 515 lines processed
- MIN V,D 372,0
- MAX V,D 470,0
- Mean V,D: 446, 0
- Variance: 142, 0
- Standard deviation: 11, 0
- V: Correct guesses: 503 97%
- D: Correct guesses: 515 100%
- Trying 1000 test using string "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".
- ////////////////////////////////////////
- CBC Statistics:
- 520 lines processed
- MIN V,D 424,0
- MAX V,D 466,0
- Mean V,D: 447, 0
- Variance: 56, 0
- Standard deviation: 7, 0
- V: Correct guesses: 520 100%
- D: Correct guesses: 520 100%
- ////////////////////////////////////////
- ECB Statistics:
- 480 lines processed
- MIN V,D 168,12
- MAX V,D 297,20
- Mean V,D: 226, 17
- Variance: 1343, 14
- Standard deviation: 36, 3
- V: Correct guesses: 0 0%
- D: Correct guesses: 0 0%
- Trying 1000 test using string "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".
- ////////////////////////////////////////
- CBC Statistics:
- 489 lines processed
- MIN V,D 423,0
- MAX V,D 467,0
- Mean V,D: 448, 0
- Variance: 56, 0
- Standard deviation: 7, 0
- V: Correct guesses: 489 100%
- D: Correct guesses: 489 100%
- ////////////////////////////////////////
- ECB Statistics:
- 511 lines processed
- MIN V,D 170,12
- MAX V,D 302,20
- Mean V,D: 226, 17
- Variance: 1340, 14
- Standard deviation: 36, 3
- V: Correct guesses: 0 0%
- D: Correct guesses: 0 0%
- Trying 1000 test using string "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".
- ////////////////////////////////////////
- CBC Statistics:
- 480 lines processed
- MIN V,D 423,0
- MAX V,D 466,0
- Mean V,D: 447, 0
- Variance: 50, 0
- Standard deviation: 7, 0
- V: Correct guesses: 480 100%
- D: Correct guesses: 480 100%
- ////////////////////////////////////////
- ECB Statistics:
- 520 lines processed
- MIN V,D 313,2
- MAX V,D 387,8
- Mean V,D: 350, 3
- Variance: 133, 0
- Standard deviation: 11, 0
- V: Correct guesses: 0 0%
- D: Correct guesses: 0 0%
- ////////////////////////////////////////
- About the tests:
- V test: Value is the hamming distance for every
- block vs every block, divided by the count of blocks
- (including the block vs itsself
- V Threshhold: if V > 405 than guess CBC
- D test: raw count of the duplicate blocks
- D Threshhold: if D < 1 than guess CBC
Add Comment
Please, Sign In to add comment