Most Common Cryptography Mistakes 3/8/2016 You fell vic+m to one - - PowerPoint PPT Presentation

most common cryptography mistakes
SMART_READER_LITE
LIVE PREVIEW

Most Common Cryptography Mistakes 3/8/2016 You fell vic+m to one - - PowerPoint PPT Presentation

Most Common Cryptography Mistakes 3/8/2016 You fell vic+m to one of the classic blunders! #8: Key Re-use Dont use same key for both direcEons. Risk: replay aHacks Dont re-use same key for both encrypEon and authenEcaEon. #7:


slide-1
SLIDE 1

Most Common Cryptography Mistakes

3/8/2016

slide-2
SLIDE 2
slide-3
SLIDE 3

You fell vic+m to one of the classic blunders!

slide-4
SLIDE 4

#8: Key Re-use

  • Don’t use same key for both direcEons.

– Risk: replay aHacks

  • Don’t re-use same key for both encrypEon and

authenEcaEon.

slide-5
SLIDE 5

#7: Careful with ConcatenaEon

  • Common mistake: Hash(S||T)

– “builEn” || “securely” = “built” || “insecurely”

slide-6
SLIDE 6

Amazon Web Services

hHp://amazon.com/set?u=daw&n=David&t=U&m=… MAC(K,”udawnDavidtU”)

slide-7
SLIDE 7

Amazon Web Services

hHp://amazon.com/set?u=daw&n=DavidtAq&t=U&m=… MAC(K,”udawnDavidtAqtU”) hHp://amazon.com/set?u=daw&n=David&t=A&qt=U&m=…

slide-8
SLIDE 8
slide-9
SLIDE 9

#7: Careful with ConcatenaEon

  • Common mistake: Hash(S||T)

– “builEn” || “securely” = “built” || “insecurely”

  • Fix: Hash(len(S) || S || T)
  • Make sure inputs to hash/MAC are uniquely

decodable

slide-10
SLIDE 10

#5: Don’t Encrypt without Auth

  • Common mistake: encrypt, but no authenEcaEon

– A checksum does not provide authenEcaEon

  • If you’re encrypEng, you probably want

authenEcated encrypEon

– Encrypt-then-authenEcate: Ek1(M), Fk2(Ek1(M)) – Or, use a dedicated AE mode: GCM, EAX, …

slide-11
SLIDE 11

Encrypt without Auth Hall of Shame

  • ASP.NET (x2)
  • XML encrypEon
  • Amazon EC2
  • JavaServer Faces
  • Ruby on Rails
  • OWASP ESAPI
  • IPSEC
  • WEP
  • SSH2
slide-12
SLIDE 12

#4: Be Careful with Randomness

  • Common mistake: use predictable random

number generator (e.g., to generate keys)

  • SoluEon: Use a crypto-quality PRNG.

– /dev/urandom, CryptGenRandom, …

slide-13
SLIDE 13

Netscape Navigator

char chall[16], k[16]; srand(getpid() + time(NULL) + getppid()); for (int i=0; i<16; i++) chal[i] = rand(); for (int i=0; i<16; i++) chal[i] = rand();

slide-14
SLIDE 14

Netscape Navigator 1.1

R, {K}KS , {M}K, … certS

Client Server

where (R, K) = hash(microseconds, x) x = seconds + pid + (ppid << 12)

slide-15
SLIDE 15

Netscape Navigator 1.1

R, {K}KS , {M}K, … certS

Client Server

where (R, K) = hash(microseconds, x) x = seconds + pid + (ppid << 12)

A7ack: Eavesdropper can guess x (≈ 10 bits) and microseconds (20 bits), and use R to check guess.

slide-16
SLIDE 16
slide-17
SLIDE 17

Bad PRNGs = broken crypto

  • Netscape server’s private keys (≈ 32 bits)
  • Kerberos v4’s session keys (≈ 20 bits)
  • X11 MIT-MAGIC-COOKIE1 (8 bits)
  • Linux vtun (≈ 1 bit)
  • PlanetPoker site (≈ 18 bits)
  • Debian OpenSSL (15 bits)
  • CryptoAG – NSA spiked their PRNG
  • Dual_EC_DRBG – backdoor that only NSA can use
slide-18
SLIDE 18

#3: Passphrases Make Poor Keys

  • Common mistake: Generate crypto key as

Hash(passphrase)

  • Problem: ≈ 20 bits of entropy; even with a slow

hash, this is not nearly enough. Human- generated secrets just don’t have enough entropy.

  • Example: Bitcoin brainwallets
  • SoluEon: Crypto keys should be random.
slide-19
SLIDE 19

#2: Be Secure By Default

  • Common mistake: Security is opEonal, or

configurable, or negoEable

  • Fix: There is one mode of operaEon, and it is
  • secure. No human configuraEon needed.

– e.g., Skype

slide-20
SLIDE 20
slide-21
SLIDE 21
slide-22
SLIDE 22

#2: Beware Rollback AHacks

  • Common mistake: Security is negoEable, and

aHacker can persuade you to fall back to insecure crypto

slide-23
SLIDE 23

A CASE STUDY

slide-24
SLIDE 24

M ⊕ RC4(K) So do I. Here’s a nonce: R I support 128-bit crypto

MS Point-to-Point EncrypEon (MPPE)

Client Server

If both endpoints support 128-bit crypto:

where K = hash(password || R)

slide-25
SLIDE 25

M ⊕ RC4(K) So do I. Here’s a nonce: R I support 128-bit crypto

MS Point-to-Point EncrypEon (MPPE)

Client Server

If both endpoints support 128-bit crypto:

where K = hash(password || R)

A7ack 1: Eavesdropper can try dic+onary search

  • n password, given some known plaintext.
slide-26
SLIDE 26

M ⊕ RC4(K) So do I. Here’s a nonce: R I support 128-bit crypto

MS Point-to-Point EncrypEon (MPPE)

Client Server

If both endpoints support 128-bit crypto:

where K = hash(password || R)

A7ack 2: Ac+ve a7acker can tamper with packets by flipping bits, since there is no MAC.

slide-27
SLIDE 27

M ⊕ RC4(K) So do I. Here’s a nonce: R I support 128-bit crypto

Client Server

where K = hash(password || R)

A7ack 3: Bad guy can replay a prior session, since client doesn’t contribute a nonce.

M ⊕ RC4(K) So do I. Here’s a nonce: R I support 128-bit crypto

Client Bad Guy

slide-28
SLIDE 28

M ⊕ RC4(K) So do I. Here’s a nonce: R I support 128-bit crypto

Client Server

where K = hash(password || R)

A7ack 4: Bad guy can replay and reverse message direc+on, since same key used in both direc+ons.

M ⊕ RC4(K) So do I. Here’s a nonce: R I support 128-bit crypto

Client Bad Guy

slide-29
SLIDE 29

M ⊕ RC4(K) I don’t. Use 40-bit crypto I support 128-bit crypto

MS Point-to-Point EncrypEon (MPPE)

Client Server

If one endpoint doesn’t support 128-bit crypto:

where K = hash(uppercase(password))

slide-30
SLIDE 30

M ⊕ RC4(K) I don’t. Use 40-bit crypto I support 128-bit crypto

MS Point-to-Point EncrypEon (MPPE)

Client Server

If one endpoint doesn’t support 128-bit crypto:

where K = hash(uppercase(password))

A7ack 1: Eavesdropper can try dic+onary search

  • n password, given some known plaintext.
slide-31
SLIDE 31

M ⊕ RC4(K) I don’t. Use 40-bit crypto I support 128-bit crypto

MS Point-to-Point EncrypEon (MPPE)

Client Server

If one endpoint doesn’t support 128-bit crypto:

where K = hash(uppercase(password))

A7ack 2: Dic+onary search can be sped up with precomputed table (given known plaintext).

slide-32
SLIDE 32

M ⊕ RC4(K) I don’t. Use 40-bit crypto I support 128-bit crypto

MS Point-to-Point EncrypEon (MPPE)

Client

where K = hash(uppercase(password))

A7ack 3: Imposter server can downgrade client to 40-bit crypto, then crack password.

Bad Guy

slide-33
SLIDE 33

M ⊕ RC4(K) I don’t. Use 40-bit I support 128-bit

MS Point-to-Point EncrypEon (MPPE)

Client Server

where K = hash(uppercase(password)), K’ = hash(password || R)

A7ack 4: Man-in-the-middle can downgrade crypto strength even if both client + server support 128-bit crypto, then crack password.

Bad Guy M’ ⊕ RC4(K’) So do I. Nonce: R I support 128-bit

slide-34
SLIDE 34

#1: Don’t Roll Your Own

  • Don’t design your own crypto algorithm
  • Use a Eme-honored, well-tested system

– For data in transit: TLS, SSH, IPSEC – For data at rest: GnuPG

slide-35
SLIDE 35

#0: Crypto Ain’t Magic

“If you think cryptography is the soluEon to your problem, then you don’t understand cryptography and you don’t understand your problem.” – Roger Needham

slide-36
SLIDE 36

Meta-Lessons

  • Cryptography is hard.
  • Hire an expert, or use an exisEng system

(e.g., SSL, SSH, GnuPG).

  • But: Most vulnerabiliEes are in applicaEons and

sovware, not in crypto algorithms.

slide-37
SLIDE 37

BONUS MATERIAL

slide-38
SLIDE 38

#8: Traffic Analysis is SEll Possible

  • EncrypEon doesn’t hide sender, recipient, length,
  • r Eme of message. (“meta-data”)
slide-39
SLIDE 39

SSH

{l}K (handshake; key exchange)

Client Server

{l}K’ {s}K {s}K’ {\n}K {\nfoo bar \n$}K’

slide-40
SLIDE 40

SSH

{\n}K

Client Server

{\nPassword: }K’ {q}K {p}K {l}K {e}K {4}K {\n}K {\nLast login: …\n $\n}K’

slide-41
SLIDE 41

SSH

{\n}K

Client Server

{\nPassword: }K’ {q}K {p}K {l}K {e}K {4}K {\n}K {\nLast login: …\n $\n}K’

Reveals length of password. Reveals +me between keystrokes. This leaks par+al informa+on about the password!

slide-42
SLIDE 42

Lessons Summarized

  • Don’t design your own crypto algorithm.
  • Use authenEcated encrypEon (don’t encrypt

without authenEcaEng).

  • Use crypto-quality random numbers.
  • Don’t derive crypto keys from passphrases.
  • Be secure by default.
  • Be careful with concatenaEon.
  • Don’t re-use nonces/IVs. Don’t re-use keys for

mulEple purposes.

  • EncrypEon doesn’t prevent traffic analysis

(“metadata”).

slide-43
SLIDE 43

#7: Don’t re-use nonces/IVs

  • Re-using a nonce or IV leads to catastrophic

security failure.

slide-44
SLIDE 44

Credit card numbers in a database

slide-45
SLIDE 45

Aver Base64 decoding

slide-46
SLIDE 46

Encrypted credit card numbers

slide-47
SLIDE 47

Encrypted credit card numbers

ASCII: …, ‘3’ = 0x33, ‘4’ = 0x34, ‘5’ = 0x35, …

slide-48
SLIDE 48

Encrypted credit card numbers

ASCII: ‘0’ = 0x30, …, ‘7’ = 0x37, ‘8’ = 0x38, ‘9’ = 0x39

slide-49
SLIDE 49

#7: Don’t re-use nonces/IVs

  • Re-using a nonce or IV leads to catastrophic

security failure.

slide-50
SLIDE 50

WEP

  • Early method for encrypEng Wifi: WEP (Wired Equivalent Privacy)

– Share a single cryptographic key among all devices – Encrypt all packets sent over the air, using the shared key – Use a checksum to prevent injecEon of spoofed packets (encrypted traffic)

slide-51
SLIDE 51

WEP - A LiHle More Detail

  • WEP uses the RC4 stream cipher to encrypt a TCP/IP

packet (P) by xor-ing it with keystream (RC4(K, IV))

IV, P ⊕ RC4(K, IV)

slide-52
SLIDE 52

A Risk of Keystream Reuse

  • In some implementaEons, IVs repeat.

– If we send two ciphertexts (C, C’) using the same IV, then the xor of plaintexts leaks (P ⊕ P’ = C ⊕ C’), which might reveal both plaintexts

† Lesson: Don’t re-use nonces/IVs

IV, P ⊕ RC4(K, IV) IV, P’ ⊕ RC4(K, IV)

slide-53
SLIDE 53

WEP -- Even More Detail

IV RC4 key IV encrypted packet

  • riginal unencrypted packet

checksum

slide-54
SLIDE 54

AHack #2: Spoofed Packets

  • AHackers can inject forged 802.11 traffic

– Learn Z = RC4(K, IV) using previous aHack – Since the CRC checksum is unkeyed, you can then create valid ciphertexts that will be accepted by the receiver

IV, (P, CRC(P)) ⊕ Z

slide-55
SLIDE 55

AHack #3: Packet ModificaEon

  • CRC is linear

⇒ CRC(P ⊕ Δ) = CRC(P) ⊕ CRC(Δ) ⇒ the modified packet (P ⊕ Δ) has a valid checksum † AHacker can tamper with packet (P) without breaking RC4 (P, CRC(P)) ⊕ RC4(K) (P, CRC(P)) ⊕ RC4(K) ⊕ (Δ, CRC(Δ))

slide-56
SLIDE 56

AHack #4: InducEve Learning

  • Learn Z1..n = RC4(K, IV)1..n using previous aHack
  • Then guess Zn+1; verify guess by sending a ping packet ((P,

CRC(P))) of length n+1 and watching for a response

  • Repeat, for n=1,2,…, unEl all of RC4(K, IV) is known

(P, CRC(P)) ⊕ (Z1..n, 0) (P, CRC(P)) ⊕ (Z1..n, 1) (P, CRC(P)) ⊕ (Z1..n, 255)

:

(pong) Credits: Arbaugh, et al.

slide-57
SLIDE 57

AHack #5: ReacEon AHacks

  • TCP ACKnowledgement returned by recipient

⇔ TCP checksum on modified packet (P ⊕ 0x00010001) is valid ⇔ wt(P & 0x00010001) = 1 † AHacker can recover plaintext (P) without breaking RC4

P ⊕ RC4(K) P ⊕ RC4(K) ⊕ 0x00010001 (ACK)