Crypto Strikes Back! (Google 2009)

Nate Lawson
Nate LawsonEngineer at Root Labs
ack!
    to St rikes B
Cryp



      Nate Lawson
       August 5, 2009
      Google Tech Talk
My background
• Root Labs founder
  – Design and analyze systems
     • Embedded and kernel security
     • Software protection, DRM
     • Crypto and protocols


• Cryptography Research
  – Reviewed numerous products that use crypto
  – Co-designed Blu-ray disc content protection layer
• Infogard Labs
  – Reviewed crypto products for the FIPS 140 program
• IBM/ISS
  – Original developer of RealSecure IDS


                                                        2
Crypto is deceptively simple and attractive
• Block ciphers, public key, etc. make sense
  conceptually
• Books like Applied Cryptography made it accessible
• Proofs of security, brute-force strength claims are
  appealing




               +               =


                                                        3
No one implements their own ciphers
• Developers got the message that custom ciphers
  are bad
• Many low-level crypto libraries to choose from
  – Java JCE, BouncyCastle
  – Microsoft CryptoAPI, .NET Cryptography
  – OpenSSL, Crypto++
• Pressing question: 128 or 256-bit keys?




                                                   4
Crypto strikes back!
•   Crypto is strong but extremely fragile
•   Requires review 2-10x the development cost
•   Can’t be secured by testing
•   When it fails, you get to change out root keys




                                                     5
Don’t implement your own crypto
• Instead use…
   – SSL for transport
   – GPG for data at rest
• If your design doesn’t seem to fit that model,
  rework it until it does
• If you can’t, use a high-level crypto library
   – Gutmann cryptlib (GPL/commercial)
   – GPGME
   – Keyczar
• Don’t use low-level libraries directly
   – OpenSSL, CryptoAPI, JCE, etc.




                                                   6
Warning signs: bad crypto ahead
• Obvious confusion of terms
  –   “Decrypting” a signature to verify it
  –   Multiple names/terms for the same field/operation
  –   Overly focused on salts as a key security feature
  –   The words “rainbow tables”
• Arguments why non-standard usage is ok,
  based on…
  – Key size
  – Lack of attacker knowledge
  – A blog post

                In its defense, ECB does have valid uses:
                Whole disk encryption, for example.
                Nick Johnson on May 18, 2009 8:10 AM
                              Actually, scratch my earlier - even for whole
                              disk encryption you should be using CTR
                              instead of ECB. :)
                              Nick Johnson on May 18, 2009 9:11 AM
                                                                              7
Warning signs: bad crypto ahead
• Encrypting multiple blocks with RSA
• Insistence that the IV must be kept secret
• Spec diagrams from Wikipedia




                 http://en.wikipedia.org/wiki/HMAC

                                                     8
How to fix Javascript crypto
• Don’t do it; it makes no sense
  – Where did the browser get the code from?
     • The webserver
  – Over?
     • SSL (we hope)
  – And the keys that the Javascript uses?
     • Um, the same webserver


• You have SSL on the client and server, use it
  – Anything you roll yourself is going to be worse
  – Remove the words “Javascript crypto” from your
    vocabulary




                                                      9
System-wide flaws
Upgrading encryption on-the-fly
• Fixing an old, broken cookie scheme
  – Old: CBC-encrypted cookie but no integrity protection
  – New: + HMAC protection of encrypted cookie


• Bright idea: “We’ll upgrade user cookies!”
  –   Decrypt the data, check length of result
  –   Detect old cookie based on version field
  –   Set new version, encrypt with new key, add HMAC
  –   Return it to the user




                                                            11
Bad PRNG or no seeding
• Default “random” PRNGs not a good choice
  – Cryptographic generator has different requirements
     • Constantly re-seeded with new entropy
     • Impossible to guess or even perturb internal state
  – Don’t use:
     • Python random (use random.SystemRandom)
     • java.util.Random (use java.security.SecureRandom)
     • .NET System.Random (use System.Security.Cryptography.
       RandomNumberGenerator)
• Cold boot case
  – Server just rebooted and you’re already getting requests
     • Is there enough entropy?
     • Are you replaying IVs, challenge values, etc.?
  – Wait, who in your company is responsible for this?


                                                               12
Side channel attacks
• Crypto does not operate in a true “black box”
  – Measurability
       • CPU retains state in the form of caches, branch prediction
         buffer, stack data
  – Control
       • Interaction with users and network influences resource usage,
         page protections, scheduling
• Ability to influence and/or measure crypto behavior
  can compromise your keys
  –   Timing
  –   Power analysis
  –   EM radiation
  –   Heat, sound, disk access patterns, etc.




                                                                      13
Encryption flaws
Block cipher modes of operation
• If you know ECB from CBC, give yourself a hand
• Now the following
  – OFB, CFB, CTR
     • Stream cipher constructions
     • Bitwise malleability
     • Fatal if counter or output reused
  – CCM, EAX, GCM, OCB
     • Authenticated encryption
     • Provide integrity protection + encryption
     • Fatal if IV reused
• Decipher this one
  – “TDEA Electronic Code Book (TECB) Mode”




                                                   15
Counter duplication in CTR mode
• You painstakingly made sure to not duplicate the
  counter on the client
  – Using a counter and saving its state in a variable
  – Forcing a key renegotiation if rebooted
     • Or even persisted it to disk


• But what about the server?
  – If using a shared key, you have keystream reuse if the
    server’s counter overlaps the client's



                 1af2                    1ae9

                  KA                      KA


                                                             16
Integrity protection flaws
Custom hash constructions
• Goal: prevent modification of a cookie
• Solution
  – Send SHA1(key || data)
  – User can’t forge the result because they don’t know the
    secret, right?
• Length extension attack
  – See SHA1 init and final operations below:
• Use HMAC instead
                                     Initialize variables:
  – Other ad-hoc constructions       h0 = 0x67452301
    also vulnerable                  h1 = 0xEFCDAB89
                                     h2 = 0x98BADCFE
                                     h3 = 0x10325476
                                     h4 = 0xC3D2E1F0
                                     …
                                     Produce the final hash value:
                                     return (h0 || h1 || h2 || h3 || h4)


                                                                           18
Too much left up to the implementer
• HMAC integrity check with XMLDsig

            <SignatureMethod Algorithm="…xmldsig#hmac-sha1">
                 <HMACOutputLength>160</HMACOutputLength>
            </SignatureMethod>




• Questions…
  – What is wrong with a length of 0 (or 1)?
  – What if an implementer allowed other algorithm selections?
• Why does this field even exist?
  – Saves 10 bytes for SHA-1 but adds 38 bytes of tag
    overhead
  – No backwards-compatibility excuse
  – Yet another field to validate for N implementers

                                                               19
Padding error oracle with CBC encryption
• Plaintext is HMACed, padded to block size, CBC-
  encrypted
  – Example for AES, message length 14 bytes
     Block = p[0], … p[13], 0x01, 0x01
• Server returns two different errors
  – Padding_Incorrect: pad byte was wrong value for specified
    total length
  – Integrity_Failure: padding valid but message modified
• Now you can decrypt bytes
  – Set a block with different guesses for last byte
  – If correct guess, you’ll get Integrity_Failure error
  – Repeat for other bytes




                                                            20
Signature flaws
Incorrectly comparing hash value
• Verifying an RSA signature
  – RSA-Exp(PubKey, SigData)
  – Verify all the padding data as you should
  – return (0 == strncmp(userHash, myHash, 20));
• Attack
  – Create 256 messages, each slightly different
  – Once SHA-1(message) == {00, …}, you win!

             for i in range(256):
                 s = 'The magic number is: ' + i
                 a = sha1(s).hexdigest()
                 if a[:2] == '00':
                     break

             >> The magic number is: 26
                006c60dde4bc…




                                                   22
Lack of structure in signed data
• You have to know exactly what you’re signing!
  – Think of signed data as a command, typed into a global
    root shell, on every cluster in your company
• Amazon Web Services v1
  – Allowed the client to sign a URL
     1. Split the query string using '&' and '=' delimiters
     2. Concatenate all the key/value pairs into a single string
        (key1 || value1 || key2 || value2)
     3. Protect it with HMAC-SHA1(key, data)
• No structure in data means the following are
  equivalent
     …?GoodKey1=GoodValue1BadKey2BadValue2
     …?GoodKey1=GoodValue1&BadKey2=BadValue2




                                                                   23
Bare (no padding) signatures
• Just use RSA directly, why hash first?
• Attack
  – Choose some primes as your messages
  – Get each one signed
  – Now forge any message composed of a combination of
    those primes, their inverses, etc.

                 mA = 3
                 mB = 7
                 sig(3 * 7) = sigA * sigB mod n


• Fun fact: same property that allows blinding




                                                         24
Padding is not something to ignore
• PKCS#1 pads messages to be signed as follows
  – SigData = 00 01 FF … FF 00 <SHA1-OID> <SHA1-HASH>
  – Then, signature is RSA-Exp(PrivKey, SigData)
• Signature verification seems simple
  – Process the sig with RSA-Exp(PubKey, SigData)
  – Strip off padding, find the hash, and compare to the hash
    of the message
• Now attacker can create forgeries
  – For 2048 bit key and 160-bit SHA hash, there are 21888
    inputs that will match
  – With small public exponent, straightforward algebra to
    calculate a colliding signature
• Every bit of padding data must be strictly checked


                                                                25
Public key flaws
DSA fails if random value known
• If the random challenge value k is known, it reveals
  your entire private key
• DSA signature (r, s) is:
    r = gk mod p mod q
    s = k-1 (H(m) + x*r) mod q
• If you know k, you can calculate x as follows:
    x = ((s * k) – H(m)) * r-1 mod q
• Remember that Debian PRNG bug?
  – Every DSA key used on a vulnerable system for a single
    signature is forever compromised
• Surprise!
  – Knowledge of only a few bits of k and multiple signatures is
    sufficient
  – Hidden number problem (Boneh, others)

                                                              27
“Encrypting” with RSA private key
• Example
  – Device has an RSA public key to verify signature on
    firmware updates
  – Idea: keep the public key secret and use it to decrypt the
    updates also
• RSA is incompatible with block cipher thinking
  – You can’t “encrypt” with a private key and keep the public
    key secret
  – An attacker can always figure out the public key (e, n)
    from observing two signatures
            for e in [3, 5, 7, … 65537]:
                n ~= GCD(sig1e – m1, sig2e – m2)
                if m1e mod n == sig1:
                     break



                                                                 28
SRP parameter validation
• SRP gives secure password-based key agreement
• Seems easy, right?




• Like all public-key crypto, very sensitive to choice
  of values


                                                         29
SRP parameter validation bug
• What if client sends A=0?




• Hmm, server does (A * foobar)baz = 0
  – And there are other bad parameters with similar results




                                                              30
But wait, there’s more!
• DH small subgroup confinement attack (Tor, IKE)
  – Sending magic values lets you choose the server’s key
    (similar to SRP attack)
• Encrypting a CRC for an integrity check (SSH v1)
• Fault injection during RSA signing (Pay TV smart
  card glitching)




                                                            31
Conclusion
• Crypto is brittle (easy to mess up)
   – And when it fails, the results are spectacular
• So don’t build your own crypto
   – SSL for transport
   – GPG for data at rest
• If your design doesn’t seem to fit that model,
  rework it until it does
• If you can’t, use a high-level library
   – cryptlib or Keyczar
• Always get a third-party review of any crypto code
   – If you had to design your own, much more extensive
     review required



                                                          32
Contact info



      For more detailed articles on these topics, please see
      my blog linked at: http://rootlabs.com


      Questions?


      Nate Lawson
      nate@rootlabs.com




                                                               33
1 of 33

Recommended

Building the ZoomFloppy (ECCC 2010) by
Building the ZoomFloppy (ECCC 2010)Building the ZoomFloppy (ECCC 2010)
Building the ZoomFloppy (ECCC 2010)Nate Lawson
3.1K views22 slides
When Crypto Attacks! (Yahoo 2009) by
When Crypto Attacks! (Yahoo 2009)When Crypto Attacks! (Yahoo 2009)
When Crypto Attacks! (Yahoo 2009)Nate Lawson
3K views26 slides
Scalable Architecture 101 by
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101ConFoo
4K views59 slides
BlueHat v18 || A mitigation for kernel toctou vulnerabilities by
BlueHat v18 || A mitigation for kernel toctou vulnerabilitiesBlueHat v18 || A mitigation for kernel toctou vulnerabilities
BlueHat v18 || A mitigation for kernel toctou vulnerabilitiesBlueHat Security Conference
262 views35 slides
Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies) by
Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)
Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)Ontico
1.2K views45 slides
Abusing Microsoft Kerberos - Sorry you guys don’t get it by
Abusing Microsoft Kerberos - Sorry you guys don’t get itAbusing Microsoft Kerberos - Sorry you guys don’t get it
Abusing Microsoft Kerberos - Sorry you guys don’t get itE Hacking
1.1K views53 slides

More Related Content

What's hot

Introduction to memcached by
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
70.9K views77 slides
PostgreSQL: Welcome To Total Security by
PostgreSQL: Welcome To Total SecurityPostgreSQL: Welcome To Total Security
PostgreSQL: Welcome To Total SecurityRobert Bernier
717 views38 slides
Kerberos, NTLM and LM-Hash by
Kerberos, NTLM and LM-HashKerberos, NTLM and LM-Hash
Kerberos, NTLM and LM-HashAnkit Mehta
6.3K views25 slides
Gwc3 by
Gwc3Gwc3
Gwc3Dan Kaminsky
796 views33 slides
Introduction to Redis by
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
121.1K views24 slides
QEMU Disk IO Which performs Better: Native or threads? by
QEMU Disk IO Which performs Better: Native or threads?QEMU Disk IO Which performs Better: Native or threads?
QEMU Disk IO Which performs Better: Native or threads?Pradeep Kumar
34.2K views66 slides

What's hot(20)

PostgreSQL: Welcome To Total Security by Robert Bernier
PostgreSQL: Welcome To Total SecurityPostgreSQL: Welcome To Total Security
PostgreSQL: Welcome To Total Security
Robert Bernier717 views
Kerberos, NTLM and LM-Hash by Ankit Mehta
Kerberos, NTLM and LM-HashKerberos, NTLM and LM-Hash
Kerberos, NTLM and LM-Hash
Ankit Mehta6.3K views
Introduction to Redis by Dvir Volk
Introduction to RedisIntroduction to Redis
Introduction to Redis
Dvir Volk121.1K views
QEMU Disk IO Which performs Better: Native or threads? by Pradeep Kumar
QEMU Disk IO Which performs Better: Native or threads?QEMU Disk IO Which performs Better: Native or threads?
QEMU Disk IO Which performs Better: Native or threads?
Pradeep Kumar34.2K views
A memcached implementation in Java by elliando dias
A memcached implementation in JavaA memcached implementation in Java
A memcached implementation in Java
elliando dias2.1K views
Usenix LISA 2012 - Choosing a Proxy by Leif Hedstrom
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a Proxy
Leif Hedstrom7.7K views
How To Set Up SQL Load Balancing with HAProxy - Slides by Severalnines
How To Set Up SQL Load Balancing with HAProxy - SlidesHow To Set Up SQL Load Balancing with HAProxy - Slides
How To Set Up SQL Load Balancing with HAProxy - Slides
Severalnines21.3K views
Infinit filesystem, Reactor reloaded by Infinit
Infinit filesystem, Reactor reloadedInfinit filesystem, Reactor reloaded
Infinit filesystem, Reactor reloaded
Infinit789 views
DeathNote of Microsoft Windows Kernel by Peter Hlavaty
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows Kernel
Peter Hlavaty9.4K views
Linux-HA with Pacemaker by Kris Buytaert
Linux-HA with PacemakerLinux-HA with Pacemaker
Linux-HA with Pacemaker
Kris Buytaert17.5K views
Content Caching with NGINX and NGINX Plus by Kevin Jones
Content Caching with NGINX and NGINX PlusContent Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX Plus
Kevin Jones1.5K views
Common technique in Bypassing Stuff in Python. by Shahriman .
Common technique in Bypassing Stuff in Python.Common technique in Bypassing Stuff in Python.
Common technique in Bypassing Stuff in Python.
Shahriman .19.6K views

Viewers also liked

Using FreeBSD to Design a Secure Digital Cinema Server (Usenix 2004) by
Using FreeBSD to Design a Secure Digital Cinema Server (Usenix 2004)Using FreeBSD to Design a Secure Digital Cinema Server (Usenix 2004)
Using FreeBSD to Design a Secure Digital Cinema Server (Usenix 2004)Nate Lawson
862 views30 slides
Foundations of Platform Security by
Foundations of Platform SecurityFoundations of Platform Security
Foundations of Platform SecurityNate Lawson
830 views22 slides
ACPI and FreeBSD (Part 2) by
ACPI and FreeBSD (Part 2)ACPI and FreeBSD (Part 2)
ACPI and FreeBSD (Part 2)Nate Lawson
3.5K views15 slides
ACPI and FreeBSD (Part 1) by
ACPI and FreeBSD (Part 1)ACPI and FreeBSD (Part 1)
ACPI and FreeBSD (Part 1)Nate Lawson
1.6K views16 slides
Copy Protection Wars: Analyzing Retro and Modern Schemes (RSA 2007) by
Copy Protection Wars: Analyzing Retro and Modern Schemes (RSA 2007)Copy Protection Wars: Analyzing Retro and Modern Schemes (RSA 2007)
Copy Protection Wars: Analyzing Retro and Modern Schemes (RSA 2007)Nate Lawson
3K views30 slides
Highway to Hell: Hacking Toll Systems (Blackhat 2008) by
Highway to Hell: Hacking Toll Systems (Blackhat 2008)Highway to Hell: Hacking Toll Systems (Blackhat 2008)
Highway to Hell: Hacking Toll Systems (Blackhat 2008)Nate Lawson
3.1K views44 slides

Viewers also liked(12)

Using FreeBSD to Design a Secure Digital Cinema Server (Usenix 2004) by Nate Lawson
Using FreeBSD to Design a Secure Digital Cinema Server (Usenix 2004)Using FreeBSD to Design a Secure Digital Cinema Server (Usenix 2004)
Using FreeBSD to Design a Secure Digital Cinema Server (Usenix 2004)
Nate Lawson862 views
Foundations of Platform Security by Nate Lawson
Foundations of Platform SecurityFoundations of Platform Security
Foundations of Platform Security
Nate Lawson830 views
ACPI and FreeBSD (Part 2) by Nate Lawson
ACPI and FreeBSD (Part 2)ACPI and FreeBSD (Part 2)
ACPI and FreeBSD (Part 2)
Nate Lawson3.5K views
ACPI and FreeBSD (Part 1) by Nate Lawson
ACPI and FreeBSD (Part 1)ACPI and FreeBSD (Part 1)
ACPI and FreeBSD (Part 1)
Nate Lawson1.6K views
Copy Protection Wars: Analyzing Retro and Modern Schemes (RSA 2007) by Nate Lawson
Copy Protection Wars: Analyzing Retro and Modern Schemes (RSA 2007)Copy Protection Wars: Analyzing Retro and Modern Schemes (RSA 2007)
Copy Protection Wars: Analyzing Retro and Modern Schemes (RSA 2007)
Nate Lawson3K views
Highway to Hell: Hacking Toll Systems (Blackhat 2008) by Nate Lawson
Highway to Hell: Hacking Toll Systems (Blackhat 2008)Highway to Hell: Hacking Toll Systems (Blackhat 2008)
Highway to Hell: Hacking Toll Systems (Blackhat 2008)
Nate Lawson3.1K views
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007) by Nate Lawson
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
Nate Lawson1.8K views
Designing and Attacking DRM (RSA 2008) by Nate Lawson
Designing and Attacking DRM (RSA 2008)Designing and Attacking DRM (RSA 2008)
Designing and Attacking DRM (RSA 2008)
Nate Lawson3.5K views
TLS Optimization by Nate Lawson
TLS OptimizationTLS Optimization
TLS Optimization
Nate Lawson7.7K views
TLS/SSL MAC security flaw by Nate Lawson
TLS/SSL MAC security flawTLS/SSL MAC security flaw
TLS/SSL MAC security flaw
Nate Lawson1.5K views
TLS/SSL Protocol Design 201006 by Nate Lawson
TLS/SSL Protocol Design 201006TLS/SSL Protocol Design 201006
TLS/SSL Protocol Design 201006
Nate Lawson3K views
TLS/SSL Protocol Design by Nate Lawson
TLS/SSL Protocol DesignTLS/SSL Protocol Design
TLS/SSL Protocol Design
Nate Lawson8.4K views

Similar to Crypto Strikes Back! (Google 2009)

Fixing twitter by
Fixing twitterFixing twitter
Fixing twitterRoger Xia
546 views49 slides
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ... by
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...xlight
444 views49 slides
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ... by
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...smallerror
1.4K views49 slides
Fixing_Twitter by
Fixing_TwitterFixing_Twitter
Fixing_Twitterliujianrong
562 views49 slides
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for... by
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...Alexandre Moneger
892 views44 slides
ASRG SOS 2022 Encrypted messaging on CAN bus by
ASRG SOS 2022 Encrypted messaging on CAN busASRG SOS 2022 Encrypted messaging on CAN bus
ASRG SOS 2022 Encrypted messaging on CAN busKenTindell
731 views23 slides

Similar to Crypto Strikes Back! (Google 2009)(20)

Fixing twitter by Roger Xia
Fixing twitterFixing twitter
Fixing twitter
Roger Xia546 views
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ... by xlight
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
xlight444 views
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ... by smallerror
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
smallerror1.4K views
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for... by Alexandre Moneger
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
Alexandre Moneger892 views
ASRG SOS 2022 Encrypted messaging on CAN bus by KenTindell
ASRG SOS 2022 Encrypted messaging on CAN busASRG SOS 2022 Encrypted messaging on CAN bus
ASRG SOS 2022 Encrypted messaging on CAN bus
KenTindell731 views
High Scalability Toronto: Meetup #2 by ScribbleLive
High Scalability Toronto: Meetup #2High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2
ScribbleLive1.3K views
Where Django Caching Bust at the Seams by Concentric Sky
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
Concentric Sky16.4K views
7. Key-Value Databases: In Depth by Fabio Fumarola
7. Key-Value Databases: In Depth7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth
Fabio Fumarola13.1K views
Open source security by lrigknat
Open source securityOpen source security
Open source security
lrigknat1.6K views
Applied cryptanalysis - everything else by Vlad Garbuz
Applied cryptanalysis - everything elseApplied cryptanalysis - everything else
Applied cryptanalysis - everything else
Vlad Garbuz697 views
SpecterOps Webinar Week - Kerberoasting Revisisted by Will Schroeder
SpecterOps Webinar Week - Kerberoasting RevisistedSpecterOps Webinar Week - Kerberoasting Revisisted
SpecterOps Webinar Week - Kerberoasting Revisisted
Will Schroeder3.7K views
10 application security fundamentals - part 2 - security mechanisms - encry... by appsec
10   application security fundamentals - part 2 - security mechanisms - encry...10   application security fundamentals - part 2 - security mechanisms - encry...
10 application security fundamentals - part 2 - security mechanisms - encry...
appsec334 views
When the internet bleeded : RootConf 2014 by Anant Shrivastava
When the internet bleeded : RootConf 2014When the internet bleeded : RootConf 2014
When the internet bleeded : RootConf 2014
Anant Shrivastava2.3K views
Walking the Bifrost: An Operator's Guide to Heimdal & Kerberos on macOS by Cody Thomas
Walking the Bifrost: An Operator's Guide to Heimdal & Kerberos on macOSWalking the Bifrost: An Operator's Guide to Heimdal & Kerberos on macOS
Walking the Bifrost: An Operator's Guide to Heimdal & Kerberos on macOS
Cody Thomas1.3K views
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn by LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
LinkedIn3.7K views
Continuous Deployment with Cassandra by Michael Kjellman
Continuous Deployment with CassandraContinuous Deployment with Cassandra
Continuous Deployment with Cassandra
Michael Kjellman955 views
Continuous Deployment with Cassandra by DataStax Academy
Continuous Deployment with CassandraContinuous Deployment with Cassandra
Continuous Deployment with Cassandra
DataStax Academy2.6K views
What's inside the black box? Using ML to tune and manage Kafka. (Matthew Stum... by confluent
What's inside the black box? Using ML to tune and manage Kafka. (Matthew Stum...What's inside the black box? Using ML to tune and manage Kafka. (Matthew Stum...
What's inside the black box? Using ML to tune and manage Kafka. (Matthew Stum...
confluent890 views

Recently uploaded

"Running students' code in isolation. The hard way", Yurii Holiuk by
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk Fwdays
36 views34 slides
The Power of Generative AI in Accelerating No Code Adoption.pdf by
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdfSaeed Al Dhaheri
39 views18 slides
Business Analyst Series 2023 - Week 4 Session 8 by
Business Analyst Series 2023 -  Week 4 Session 8Business Analyst Series 2023 -  Week 4 Session 8
Business Analyst Series 2023 - Week 4 Session 8DianaGray10
145 views13 slides
Future of AR - Facebook Presentation by
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook PresentationRob McCarty
65 views27 slides
MVP and prioritization.pdf by
MVP and prioritization.pdfMVP and prioritization.pdf
MVP and prioritization.pdfrahuldharwal141
39 views8 slides
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...ShapeBlue
196 views62 slides

Recently uploaded(20)

"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays36 views
The Power of Generative AI in Accelerating No Code Adoption.pdf by Saeed Al Dhaheri
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdf
Saeed Al Dhaheri39 views
Business Analyst Series 2023 - Week 4 Session 8 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 8Business Analyst Series 2023 -  Week 4 Session 8
Business Analyst Series 2023 - Week 4 Session 8
DianaGray10145 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty65 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue196 views
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 by BookNet Canada
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
BookNet Canada44 views
"Package management in monorepos", Zoltan Kochan by Fwdays
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan Kochan
Fwdays34 views
Transcript: Redefining the book supply chain: A glimpse into the future - Tec... by BookNet Canada
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
BookNet Canada41 views
Optimizing Communication to Optimize Human Behavior - LCBM by Yaman Kumar
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBM
Yaman Kumar38 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue208 views
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading... by The Digital Insurer
Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...Webinar : Desperately Seeking Transformation - Part 2:  Insights from leading...
Webinar : Desperately Seeking Transformation - Part 2: Insights from leading...
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu437 views
"Node.js Development in 2024: trends and tools", Nikita Galkin by Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays33 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue162 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue139 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue164 views

Crypto Strikes Back! (Google 2009)

  • 1. ack! to St rikes B Cryp Nate Lawson August 5, 2009 Google Tech Talk
  • 2. My background • Root Labs founder – Design and analyze systems • Embedded and kernel security • Software protection, DRM • Crypto and protocols • Cryptography Research – Reviewed numerous products that use crypto – Co-designed Blu-ray disc content protection layer • Infogard Labs – Reviewed crypto products for the FIPS 140 program • IBM/ISS – Original developer of RealSecure IDS 2
  • 3. Crypto is deceptively simple and attractive • Block ciphers, public key, etc. make sense conceptually • Books like Applied Cryptography made it accessible • Proofs of security, brute-force strength claims are appealing + = 3
  • 4. No one implements their own ciphers • Developers got the message that custom ciphers are bad • Many low-level crypto libraries to choose from – Java JCE, BouncyCastle – Microsoft CryptoAPI, .NET Cryptography – OpenSSL, Crypto++ • Pressing question: 128 or 256-bit keys? 4
  • 5. Crypto strikes back! • Crypto is strong but extremely fragile • Requires review 2-10x the development cost • Can’t be secured by testing • When it fails, you get to change out root keys 5
  • 6. Don’t implement your own crypto • Instead use… – SSL for transport – GPG for data at rest • If your design doesn’t seem to fit that model, rework it until it does • If you can’t, use a high-level crypto library – Gutmann cryptlib (GPL/commercial) – GPGME – Keyczar • Don’t use low-level libraries directly – OpenSSL, CryptoAPI, JCE, etc. 6
  • 7. Warning signs: bad crypto ahead • Obvious confusion of terms – “Decrypting” a signature to verify it – Multiple names/terms for the same field/operation – Overly focused on salts as a key security feature – The words “rainbow tables” • Arguments why non-standard usage is ok, based on… – Key size – Lack of attacker knowledge – A blog post In its defense, ECB does have valid uses: Whole disk encryption, for example. Nick Johnson on May 18, 2009 8:10 AM Actually, scratch my earlier - even for whole disk encryption you should be using CTR instead of ECB. :) Nick Johnson on May 18, 2009 9:11 AM 7
  • 8. Warning signs: bad crypto ahead • Encrypting multiple blocks with RSA • Insistence that the IV must be kept secret • Spec diagrams from Wikipedia http://en.wikipedia.org/wiki/HMAC 8
  • 9. How to fix Javascript crypto • Don’t do it; it makes no sense – Where did the browser get the code from? • The webserver – Over? • SSL (we hope) – And the keys that the Javascript uses? • Um, the same webserver • You have SSL on the client and server, use it – Anything you roll yourself is going to be worse – Remove the words “Javascript crypto” from your vocabulary 9
  • 11. Upgrading encryption on-the-fly • Fixing an old, broken cookie scheme – Old: CBC-encrypted cookie but no integrity protection – New: + HMAC protection of encrypted cookie • Bright idea: “We’ll upgrade user cookies!” – Decrypt the data, check length of result – Detect old cookie based on version field – Set new version, encrypt with new key, add HMAC – Return it to the user 11
  • 12. Bad PRNG or no seeding • Default “random” PRNGs not a good choice – Cryptographic generator has different requirements • Constantly re-seeded with new entropy • Impossible to guess or even perturb internal state – Don’t use: • Python random (use random.SystemRandom) • java.util.Random (use java.security.SecureRandom) • .NET System.Random (use System.Security.Cryptography. RandomNumberGenerator) • Cold boot case – Server just rebooted and you’re already getting requests • Is there enough entropy? • Are you replaying IVs, challenge values, etc.? – Wait, who in your company is responsible for this? 12
  • 13. Side channel attacks • Crypto does not operate in a true “black box” – Measurability • CPU retains state in the form of caches, branch prediction buffer, stack data – Control • Interaction with users and network influences resource usage, page protections, scheduling • Ability to influence and/or measure crypto behavior can compromise your keys – Timing – Power analysis – EM radiation – Heat, sound, disk access patterns, etc. 13
  • 15. Block cipher modes of operation • If you know ECB from CBC, give yourself a hand • Now the following – OFB, CFB, CTR • Stream cipher constructions • Bitwise malleability • Fatal if counter or output reused – CCM, EAX, GCM, OCB • Authenticated encryption • Provide integrity protection + encryption • Fatal if IV reused • Decipher this one – “TDEA Electronic Code Book (TECB) Mode” 15
  • 16. Counter duplication in CTR mode • You painstakingly made sure to not duplicate the counter on the client – Using a counter and saving its state in a variable – Forcing a key renegotiation if rebooted • Or even persisted it to disk • But what about the server? – If using a shared key, you have keystream reuse if the server’s counter overlaps the client's 1af2 1ae9 KA KA 16
  • 18. Custom hash constructions • Goal: prevent modification of a cookie • Solution – Send SHA1(key || data) – User can’t forge the result because they don’t know the secret, right? • Length extension attack – See SHA1 init and final operations below: • Use HMAC instead Initialize variables: – Other ad-hoc constructions h0 = 0x67452301 also vulnerable h1 = 0xEFCDAB89 h2 = 0x98BADCFE h3 = 0x10325476 h4 = 0xC3D2E1F0 … Produce the final hash value: return (h0 || h1 || h2 || h3 || h4) 18
  • 19. Too much left up to the implementer • HMAC integrity check with XMLDsig <SignatureMethod Algorithm="…xmldsig#hmac-sha1"> <HMACOutputLength>160</HMACOutputLength> </SignatureMethod> • Questions… – What is wrong with a length of 0 (or 1)? – What if an implementer allowed other algorithm selections? • Why does this field even exist? – Saves 10 bytes for SHA-1 but adds 38 bytes of tag overhead – No backwards-compatibility excuse – Yet another field to validate for N implementers 19
  • 20. Padding error oracle with CBC encryption • Plaintext is HMACed, padded to block size, CBC- encrypted – Example for AES, message length 14 bytes Block = p[0], … p[13], 0x01, 0x01 • Server returns two different errors – Padding_Incorrect: pad byte was wrong value for specified total length – Integrity_Failure: padding valid but message modified • Now you can decrypt bytes – Set a block with different guesses for last byte – If correct guess, you’ll get Integrity_Failure error – Repeat for other bytes 20
  • 22. Incorrectly comparing hash value • Verifying an RSA signature – RSA-Exp(PubKey, SigData) – Verify all the padding data as you should – return (0 == strncmp(userHash, myHash, 20)); • Attack – Create 256 messages, each slightly different – Once SHA-1(message) == {00, …}, you win! for i in range(256): s = 'The magic number is: ' + i a = sha1(s).hexdigest() if a[:2] == '00': break >> The magic number is: 26 006c60dde4bc… 22
  • 23. Lack of structure in signed data • You have to know exactly what you’re signing! – Think of signed data as a command, typed into a global root shell, on every cluster in your company • Amazon Web Services v1 – Allowed the client to sign a URL 1. Split the query string using '&' and '=' delimiters 2. Concatenate all the key/value pairs into a single string (key1 || value1 || key2 || value2) 3. Protect it with HMAC-SHA1(key, data) • No structure in data means the following are equivalent …?GoodKey1=GoodValue1BadKey2BadValue2 …?GoodKey1=GoodValue1&BadKey2=BadValue2 23
  • 24. Bare (no padding) signatures • Just use RSA directly, why hash first? • Attack – Choose some primes as your messages – Get each one signed – Now forge any message composed of a combination of those primes, their inverses, etc. mA = 3 mB = 7 sig(3 * 7) = sigA * sigB mod n • Fun fact: same property that allows blinding 24
  • 25. Padding is not something to ignore • PKCS#1 pads messages to be signed as follows – SigData = 00 01 FF … FF 00 <SHA1-OID> <SHA1-HASH> – Then, signature is RSA-Exp(PrivKey, SigData) • Signature verification seems simple – Process the sig with RSA-Exp(PubKey, SigData) – Strip off padding, find the hash, and compare to the hash of the message • Now attacker can create forgeries – For 2048 bit key and 160-bit SHA hash, there are 21888 inputs that will match – With small public exponent, straightforward algebra to calculate a colliding signature • Every bit of padding data must be strictly checked 25
  • 27. DSA fails if random value known • If the random challenge value k is known, it reveals your entire private key • DSA signature (r, s) is: r = gk mod p mod q s = k-1 (H(m) + x*r) mod q • If you know k, you can calculate x as follows: x = ((s * k) – H(m)) * r-1 mod q • Remember that Debian PRNG bug? – Every DSA key used on a vulnerable system for a single signature is forever compromised • Surprise! – Knowledge of only a few bits of k and multiple signatures is sufficient – Hidden number problem (Boneh, others) 27
  • 28. “Encrypting” with RSA private key • Example – Device has an RSA public key to verify signature on firmware updates – Idea: keep the public key secret and use it to decrypt the updates also • RSA is incompatible with block cipher thinking – You can’t “encrypt” with a private key and keep the public key secret – An attacker can always figure out the public key (e, n) from observing two signatures for e in [3, 5, 7, … 65537]: n ~= GCD(sig1e – m1, sig2e – m2) if m1e mod n == sig1: break 28
  • 29. SRP parameter validation • SRP gives secure password-based key agreement • Seems easy, right? • Like all public-key crypto, very sensitive to choice of values 29
  • 30. SRP parameter validation bug • What if client sends A=0? • Hmm, server does (A * foobar)baz = 0 – And there are other bad parameters with similar results 30
  • 31. But wait, there’s more! • DH small subgroup confinement attack (Tor, IKE) – Sending magic values lets you choose the server’s key (similar to SRP attack) • Encrypting a CRC for an integrity check (SSH v1) • Fault injection during RSA signing (Pay TV smart card glitching) 31
  • 32. Conclusion • Crypto is brittle (easy to mess up) – And when it fails, the results are spectacular • So don’t build your own crypto – SSL for transport – GPG for data at rest • If your design doesn’t seem to fit that model, rework it until it does • If you can’t, use a high-level library – cryptlib or Keyczar • Always get a third-party review of any crypto code – If you had to design your own, much more extensive review required 32
  • 33. Contact info For more detailed articles on these topics, please see my blog linked at: http://rootlabs.com Questions? Nate Lawson nate@rootlabs.com 33