Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key...

57
Most Common Cryptography Mistakes 3/8/2016

Transcript of Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key...

Page 1: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

MostCommonCryptographyMistakes

3/8/2016

Page 2: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this
Page 3: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

Youfellvic+mtooneoftheclassicblunders!

Page 4: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#8:KeyRe-use

•  Don’tusesamekeyforbothdirecEons.– Risk:replayaHacks

•  Don’tre-usesamekeyforbothencrypEonandauthenEcaEon.

Page 5: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#7:CarefulwithConcatenaEon

•  Commonmistake:Hash(S||T)– “builEn”||“securely”=“built”||“insecurely”

Page 6: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

AmazonWebServices

hHp://amazon.com/set?u=daw&n=David&t=U&m=…

MAC(K,”udawnDavidtU”)

Page 7: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

AmazonWebServices

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=…

Page 8: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this
Page 9: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#7:CarefulwithConcatenaEon

•  Commonmistake:Hash(S||T)– “builEn”||“securely”=“built”||“insecurely”

•  Fix:Hash(len(S)||S||T)•  Makesureinputstohash/MACareuniquelydecodable

Page 10: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#5:Don’tEncryptwithoutAuth

•  Commonmistake:encrypt,butnoauthenEcaEon– AchecksumdoesnotprovideauthenEcaEon

•  Ifyou’reencrypEng,youprobablywantauthenEcatedencrypEon– Encrypt-then-authenEcate:Ek1(M),Fk2(Ek1(M))– Or,useadedicatedAEmode:GCM,EAX,…

Page 11: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

EncryptwithoutAuthHallofShame

•  ASP.NET(x2)•  XMLencrypEon•  AmazonEC2•  JavaServerFaces•  RubyonRails•  OWASPESAPI•  IPSEC•  WEP•  SSH2

Page 12: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#4:BeCarefulwithRandomness

•  Commonmistake:usepredictablerandomnumbergenerator(e.g.,togeneratekeys)

•  SoluEon:Useacrypto-qualityPRNG.– /dev/urandom,CryptGenRandom,…

Page 13: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

NetscapeNavigator

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

Page 14: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

NetscapeNavigator1.1

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

certSClient Server

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

Page 15: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

NetscapeNavigator1.1

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

certSClient Server

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

A7ack:Eavesdroppercanguessx(≈10bits)andmicroseconds(20bits),anduseRtocheckguess.

Page 16: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this
Page 17: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

BadPRNGs=brokencrypto

•  Netscapeserver’sprivatekeys(≈32bits)•  Kerberosv4’ssessionkeys(≈20bits)•  X11MIT-MAGIC-COOKIE1(8bits)•  Linuxvtun(≈1bit)•  PlanetPokersite(≈18bits)•  DebianOpenSSL(15bits)•  CryptoAG–NSAspikedtheirPRNG•  Dual_EC_DRBG–backdoorthatonlyNSAcanuse

Page 18: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#3:PassphrasesMakePoorKeys

•  Commonmistake:GeneratecryptokeyasHash(passphrase)

•  Problem:≈20bitsofentropy;evenwithaslowhash,thisisnotnearlyenough.Human-generatedsecretsjustdon’thaveenoughentropy.

•  Example:Bitcoinbrainwallets•  SoluEon:Cryptokeysshouldberandom.

Page 19: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#2:BeSecureByDefault

•  Commonmistake:SecurityisopEonal,orconfigurable,ornegoEable

•  Fix:ThereisonemodeofoperaEon,anditissecure.NohumanconfiguraEonneeded.– e.g.,Skype

Page 20: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this
Page 21: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this
Page 22: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#2:BewareRollbackAHacks

•  Commonmistake:SecurityisnegoEable,andaHackercanpersuadeyoutofallbacktoinsecurecrypto

Page 23: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

ACASESTUDY

Page 24: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

M⊕RC4(K)

SodoI.Here’sanonce:R

Isupport128-bitcrypto

MSPoint-to-PointEncrypEon(MPPE)

Client Server

Ifbothendpointssupport128-bitcrypto:

whereK=hash(password||R)

Page 25: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

M⊕RC4(K)

SodoI.Here’sanonce:R

Isupport128-bitcrypto

MSPoint-to-PointEncrypEon(MPPE)

Client Server

Ifbothendpointssupport128-bitcrypto:

whereK=hash(password||R)

A7ack1:Eavesdroppercantrydic+onarysearchonpassword,givensomeknownplaintext.

Page 26: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

M⊕RC4(K)

SodoI.Here’sanonce:R

Isupport128-bitcrypto

MSPoint-to-PointEncrypEon(MPPE)

Client Server

Ifbothendpointssupport128-bitcrypto:

whereK=hash(password||R)

A7ack2:Ac+vea7ackercantamperwithpacketsbyflippingbits,sincethereisnoMAC.

Page 27: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

M⊕RC4(K)

SodoI.Here’sanonce:R

Isupport128-bitcrypto

Client Server

whereK=hash(password||R)

A7ack3:Badguycanreplayapriorsession,sinceclientdoesn’tcontributeanonce.

M⊕RC4(K)

SodoI.Here’sanonce:R

Isupport128-bitcrypto

Client BadGuy

Page 28: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

M⊕RC4(K)

SodoI.Here’sanonce:R

Isupport128-bitcrypto

Client Server

whereK=hash(password||R)

A7ack4:Badguycanreplayandreversemessagedirec+on,sincesamekeyusedinbothdirec+ons.

M⊕RC4(K)

SodoI.Here’sanonce:R

Isupport128-bitcrypto

Client BadGuy

Page 29: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

M⊕RC4(K)

Idon’t.Use40-bitcrypto

Isupport128-bitcrypto

MSPoint-to-PointEncrypEon(MPPE)

Client Server

Ifoneendpointdoesn’tsupport128-bitcrypto:

whereK=hash(uppercase(password))

Page 30: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

M⊕RC4(K)

Idon’t.Use40-bitcrypto

Isupport128-bitcrypto

MSPoint-to-PointEncrypEon(MPPE)

Client Server

Ifoneendpointdoesn’tsupport128-bitcrypto:

whereK=hash(uppercase(password))

A7ack1:Eavesdroppercantrydic+onarysearchonpassword,givensomeknownplaintext.

Page 31: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

M⊕RC4(K)

Idon’t.Use40-bitcrypto

Isupport128-bitcrypto

MSPoint-to-PointEncrypEon(MPPE)

Client Server

Ifoneendpointdoesn’tsupport128-bitcrypto:

whereK=hash(uppercase(password))

A7ack2:Dic+onarysearchcanbespedupwithprecomputedtable(givenknownplaintext).

Page 32: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

M⊕RC4(K)

Idon’t.Use40-bitcrypto

Isupport128-bitcrypto

MSPoint-to-PointEncrypEon(MPPE)

Client

whereK=hash(uppercase(password))

A7ack3:Imposterservercandowngradeclientto40-bitcrypto,thencrackpassword.

BadGuy

Page 33: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

M⊕RC4(K)Idon’t.Use40-bit

Isupport128-bit

MSPoint-to-PointEncrypEon(MPPE)

Client Server

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

A7ack4:Man-in-the-middlecandowngradecryptostrengthevenifbothclient+serversupport128-bitcrypto,thencrackpassword.

BadGuy

M’⊕RC4(K’)

SodoI.Nonce:RIsupport128-bit

Page 34: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#1:Don’tRollYourOwn

•  Don’tdesignyourowncryptoalgorithm•  UseaEme-honored,well-testedsystem– Fordataintransit:TLS,SSH,IPSEC– Fordataatrest:GnuPG

Page 35: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#0:CryptoAin’tMagic

“IfyouthinkcryptographyisthesoluEontoyourproblem,thenyoudon’tunderstandcryptographyandyoudon’tunderstandyourproblem.”

–RogerNeedham

Page 36: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

Meta-Lessons

•  Cryptographyishard.•  Hireanexpert,oruseanexisEngsystem(e.g.,SSL,SSH,GnuPG).

•  But:MostvulnerabiliEesareinapplicaEonsandsovware,notincryptoalgorithms.

Page 37: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

BONUSMATERIAL

Page 38: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#8:TrafficAnalysisisSEllPossible

•  EncrypEondoesn’thidesender,recipient,length,orEmeofmessage.(“meta-data”)

Page 39: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

SSH

{l}K

(handshake;keyexchange)Client Server

{l}K’{s}K{s}K’

{\n}K{\nfoobar\n$}K’

Page 40: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

SSH{\n}K

Client Server

{\nPassword:}K’{q}K{p}K

{l}K

{e}K

{4}K{\n}K

{\nLastlogin:…\n$\n}K’

Page 41: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

SSH{\n}K

Client Server

{\nPassword:}K’{q}K{p}K

{l}K

{e}K

{4}K{\n}K

{\nLastlogin:…\n$\n}K’

Revealslengthofpassword.

Reveals+mebetweenkeystrokes.Thisleakspar+alinforma+onaboutthepassword!

Page 42: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

LessonsSummarized

•  Don’tdesignyourowncryptoalgorithm.•  UseauthenEcatedencrypEon(don’tencryptwithoutauthenEcaEng).

•  Usecrypto-qualityrandomnumbers.•  Don’tderivecryptokeysfrompassphrases.•  Besecurebydefault.•  BecarefulwithconcatenaEon.•  Don’tre-usenonces/IVs.Don’tre-usekeysformulEplepurposes.

•  EncrypEondoesn’tpreventtrafficanalysis(“metadata”).

Page 43: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#7:Don’tre-usenonces/IVs

•  Re-usinganonceorIVleadstocatastrophicsecurityfailure.

Page 44: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

Creditcardnumbersinadatabase

Page 45: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

AverBase64decoding

Page 46: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

Encryptedcreditcardnumbers

Page 47: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

Encryptedcreditcardnumbers

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

Page 48: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

Encryptedcreditcardnumbers

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

Page 49: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

#7:Don’tre-usenonces/IVs

•  Re-usinganonceorIVleadstocatastrophicsecurityfailure.

Page 50: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

WEP

•  EarlymethodforencrypEngWifi:WEP(WiredEquivalentPrivacy)–  Shareasinglecryptographickeyamongalldevices–  Encryptallpacketssentovertheair,usingthesharedkey–  UseachecksumtopreventinjecEonofspoofedpackets

(encrypted traffic)

Page 51: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

WEP-ALiHleMoreDetail

•  WEPusestheRC4streamciphertoencryptaTCP/IPpacket(P)byxor-ingitwithkeystream(RC4(K,IV))

IV,P⊕RC4(K,IV)

Page 52: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

ARiskofKeystreamReuse

•  InsomeimplementaEons,IVsrepeat.–  Ifwesendtwociphertexts(C,C’)usingthesameIV,thenthexorof

plaintextsleaks(P⊕P’=C⊕C’),whichmightrevealbothplaintexts

�Lesson:Don’tre-usenonces/IVs

IV,P⊕RC4(K,IV)

IV,P’⊕RC4(K,IV)

Page 53: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

WEP--EvenMoreDetail

IV

RC4 key

IV encrypted packet

original unencrypted packet checksum

Page 54: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

AHack#2:SpoofedPackets

•  AHackerscaninjectforged802.11traffic–  LearnZ=RC4(K,IV)usingpreviousaHack–  SincetheCRCchecksumisunkeyed,youcanthencreatevalid

ciphertextsthatwillbeacceptedbythereceiver

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

Page 55: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

AHack#3:PacketModificaEon

•  CRCislinear⇒CRC(P⊕Δ)=CRC(P)⊕CRC(Δ)⇒themodifiedpacket(P⊕Δ)hasavalidchecksum

�AHackercantamperwithpacket(P)withoutbreakingRC4

(P,CRC(P))⊕RC4(K)

(P,CRC(P))⊕RC4(K)⊕(Δ,CRC(Δ))

Page 56: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

AHack#4:InducEveLearning

•  LearnZ1..n=RC4(K,IV)1..nusingpreviousaHack•  ThenguessZn+1;verifyguessbysendingapingpacket((P,

CRC(P)))oflengthn+1andwatchingforaresponse•  Repeat,forn=1,2,…,unElallofRC4(K,IV)isknown

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

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

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

:

(pong)

Credits:Arbaugh,etal.

Page 57: Most Common Cryptography Mistakescs161/sp16/slides/... · • Common mistake: Generate crypto key as Hash(passphrase) • Problem: ≈ 20 bits of entropy; even with a slow hash, this

AHack#5:ReacEonAHacks

•  TCPACKnowledgementreturnedbyrecipient⇔TCPchecksumonmodifiedpacket(P⊕0x00010001)isvalid⇔wt(P&0x00010001)=1

�AHackercanrecoverplaintext(P)withoutbreakingRC4

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

(ACK)