crypto 101 - lateral security - cryptopreso.pdf · – security testing (design & architecture,...

29
Crypto 101 A “no crazy maths” guide to breaking crypto Benjamin Kearns – Technical Team Leader Event – OWASP Day 2015 Date – 27 th February 2015

Upload: others

Post on 29-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Crypto 101A “no crazy maths” guide to breaking crypto

Benjamin Kearns – Technical Team LeaderEvent – OWASP Day 2015Date – 27th February 2015

Page 2: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Company Overview

Company– Lateral Security (IT) Services Limited– Founded in April 2008 by Nick von Dadelszen and Ratu Mason (Both Directors)– Auckland, Wellington Melbourne: ~20 highly specialised security consultants

Services– Security testing (design & architecture, penetration testing, configuration, code

reviews, security devices & controls, mobile apps) – Security advisory (Lifecycle compliance & audit – ISO, PCI-DSS, NZISM, policy

process development, threat modeling and risk assessment) process development, threat modeling and risk assessment) – Regular ongoing technical testing and assurance programs

Page 3: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Me

Page 4: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Overview

• Introduction• XOR• Stream ciphers• Block cipher modes

• Electronic Codebook (ECB)• Cipher Block Chaining (CBC)

• HMAC• HMAC

Page 5: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

XOR (Exclusive Or)

0100 1011 (P)1100 1110 (K)

1000 0101 (C)0 XOR 0 = 0

1000 0101 (C)1100 1110 (K)

0100 1011 (P)

1 XOR 0 = 10 XOR 1 = 11 XOR 1 = 0

Page 6: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

XOR – Example

Plain text: Secret String

Key: a

Secret String XOR aaaaaaaaaaaa

0101 0011 0110 0101 0110 0011 ..

Secret String XOR aaaaaaaaaaaa

0101 0011 0110 0101 0110 0011 ..0101 0011 0110 0101 0110 0011 ..

0110 0001 0110 0001 0110 0001 ..

0011 0010 0000 0100 0000 0010 ..

32 04 02 13 04 15 41 32 15 13 08 0f 0632 04 02 13 04 15 41 32 15 13 08 0f 06

0101 0011 0110 0101 0110 0011 ..

0110 0001 0110 0001 0110 0001 ..

0011 0010 0000 0100 0000 0010 ..

Page 7: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Stream ciphers

Key

Stream cipher

Keystream

Plaintext

Page 8: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Stream Ciphers

“Secret Session Key” → Stream Cipher → 492485C29AF129B…

492485C29AF129B...492485C29AF129B...

uid=4;cart_items=[502,388,590,4]

Page 9: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile
Page 10: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

But you’re safe, right?

WEP

Page 11: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Block ciphers

Plaintext

Block cipherKey

Ciphertext

Page 12: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Electronic Codebook (ECB)

Page 13: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

ECB example

AAAAAAAABBBBBBBBAAAAAAAA

AAAAAAAA | BBBBBBBB | AAAAAAAA

a49e184729a65b18 | 38f9c215972c28e3 | a49e184729a65b18

Page 14: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

ECB Example

Page 15: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Exploiting ECB

SITE_ID=1;ADMIN=92;LOGIN0;USER=4_TIMESTAMP=1375861043;SITE_ID=1;ADMIN=0;USER=492;LOGIN_TIMESTAMP=1375861043;

SITE_ID=

1;ADMIN=

0;USER=4

92;LOGIN

_TIMESTA

0358f292249283bc

49f28b20a3c3051d

5c382dd38f9526f5

48a84d294c128a46

193b48cff29ac493

function process_session_cookie() {

session_cookie = decrypt_cookie(COOKIES['Session'])

variables = session_cookie.split(';')

foreach(session_variable in variables) {

key_value_array = session_variable.split('=')

session[key_value_array.first] = key_value_array.second;

SITE_ID=

1;ADMIN=

92;LOGIN

0;USER=4

_TIMESTA

0358f292249283bc

49f28b20a3c3051d

48a84d294c128a46

5c382dd38f9526f5

193b48cff29ac493

SITE_ID=

1;ADMIN=

0;USER=4

92;LOGIN

_TIMESTA

0358f292249283bc

49f28b20a3c3051d

5c382dd38f9526f5

48a84d294c128a46

193b48cff29ac493

SITE_ID=1;ADMIN=0;USER=492;LOGIN_TIMESTAMP=1375861043;

_TIMESTA

MP=13758

61043;

193b48cff29ac493

104d210c20a04882

294859ac4980a5dd

session[key_value_array.first] = key_value_array.second;

}

}

//...

if(session['ADMIN'] != 0) {

// Unlock awesome admin powers

}

SESSION=0358f292249283bc49f28b20a3c3051d5c382dd38f9526f548a84d29

4c128a46193b48cff29ac493104d210c20a04882294859ac4980a5dd

_TIMESTA

MP=13758

61043;

193b48cff29ac493

104d210c20a04882

294859ac4980a5dd

SESSION=0358f292249283bc49f28b20a3c3051d48a84d294c128a465c382dd3

8f9526f5193b48cff29ac493104d210c20a04882294859ac4980a5dd

_TIMESTA

MP=13758

61043;

193b48cff29ac493

104d210c20a04882

294859ac4980a5dd

SESSION=0358f292249283bc49f28b20a3c3051d5c382dd38f9526f548a84d29

4c128a46193b48cff29ac493104d210c20a04882294859ac4980a5dd

Page 16: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile
Page 17: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

But you’re safe, right?

Cipher cipher = Cipher.getInstance(“AES”);

Cipher.init(…)

Page 18: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

CBC

Page 19: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

CBC

Page 20: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile
Page 21: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

But you’re safe, right?

CVE-2005-0039

Page 22: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

HMAC

HMAC

Message

Key

Signature

{user_id=3,timestamp=1376773912};BA842C380DD11204BF

Page 23: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile
Page 24: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

But you’re safe, right?

B1347247976a6c5fba55f3f81faba1c8b6777e55

6015824405f06b4dbcea65b433535f7ad747ce36

0a38e9a40ca5d66d7002a6ade0ed0f8b71058c82

0163f66cf65d91521ab55255ff708b9909b13800

8a7f13d68fec575def1dc3ff7200cd72b0658963

15e0bed2

Page 25: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Cracking crypto

Page 26: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Top Secret

Page 27: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Computers are hard

Page 28: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

More crypto fun

http://www.matasano.com/articles/crypto-challenges/

Page 29: Crypto 101 - Lateral Security - CryptoPreso.pdf · – Security testing (design & architecture, penetrati on testing, configuration, code reviews, security devices & controls, mobile

Questions and Contacts

Lateral Security (IT) Services Limited

Wellington38-42 Waring Taylor Street (level 7, Petherick Tower)PO Box 8093, Wellington 6143, New ZealandPhone: +64 4 4999 756Email: [email protected]

Auckland187 Queen Street (level 8, Landmark House)187 Queen Street (level 8, Landmark House)PO Box 7706, Auckland, New ZealandPhone: +64 9 3770 700Email: [email protected]

Melbourne200 Queen Street (level 13)Melbourne, VIC 3000, AustraliaPhone: +61 1300 554745Email: [email protected]

Presentation Downloadwww.lateralsecurity.com/

presentations