SlideShare a Scribd company logo
1 of 34
Download to read offline
Applied Cryptanalysis:
Stream ciphers
Vladimir Garbuz
Intro
•Why do I need to learn about Crypto generally?
• It’s often used to create Cookies, hidden parameters
• To do TLS the right way
• For hashes and data integrity checks
• Password and sensitive info storage
• To have more marketable skills during an interview
•To whom is this useful?
• Devs, QA, anyone interested in security and crypto
•What do I need to understand this?
• School math knowledge
• Desire to learn
Overview
•Symmetric encryption
• Stream ciphers
• Block ciphers
• Modes of operation
•Cryptographic hash
• Key derivation
• Authenticated Encryption, AEAD
•Asymmetric encryption
•Conclusions and best practices
Symmetric Crypto basics
Jean-Phillipe
Aumasson
Symmetric Crypto basics
•To Encrypt is to take Plaintext, key and convert
them into Ciphertext: C = E(P, k)
•To Decrypt is to take Ciphertext, key and convert
them back into Plaintext: P = D(C, k)
•An attacker must, ideally, try (bruteforce) all
possible keys – for 256 bit key – 1077 combinations
Symmetric Crypto basics
•What’s an attack?
Symmetric Crypto basics
•OK, what’s a cryptographic attack?
• Anything better than bruteforce
•What’s a practical attack?
• Any attack an adversary with best technology available
can conduct in “reasonable” amount of time
• “reasonable” is determined based on how long the plaintext keeps it’s
value
• Normally, due to exponential nature of cryptanalytic difficulty, attacks
are either impossible or very much possible
Symmetric Crypto basics
Main cryptanalytic methods, at a glance
•Known plaintext
•Chosen plaintext (encryption oracles)
•Chosen ciphertext (decryption oracles, bit
flipping)
•Statistical cryptanalysis
•Differential cryptanalysis
•Side-channel attacks
Symmetric Crypto basics
http://www.washingtonpost.com/wp-srv/politics/special/clinton/stories/pizza121998.htm
Symmetric Crypto basics
XOR ⊕ Refresher
•Basically a bit flipping machine
•A ⊕ A = 0
Symmetric Crypto basics
XOR ⊕ Refresher
1. A ⊕ A = 0
2. A ⊕ 0 = A
3. A ⊕ B = B ⊕ A (commutativity)
4. A ⊕ ( B ⊕ C ) = ( A ⊕ B) ⊕ C (associativity)
5. Let K ⊕ M = C , then:
C ⊕ K = K ⊕ M ⊕ K = K ⊕ K ⊕ M = 0 ⊕ M = M
Stream ciphers
•Historic stream cipher example – One-time Pads
• Sender and Receiver must have identical Pads
• Pads fully filled with random data
• Sender computes Message ⊕ Pad and sends result
• Receiver does Ciphertext ⊕ Pad to get Message
•One-time Pads are mathematically proven to be
unbreakable! YAY! VICTORY! Let’s all go home now.
THE END
QUESTIONS?
Stream ciphers
•Historic stream cipher example – One-time Pads
• Sender and Receiver must have identical Pads
• Pads fully filled with random data
• Sender computes Message ⊕ Pad and sends result
• Receiver does Ciphertext ⊕ Pad to get Message
•One-time Pads are mathematically proven to be
unbreakable! YAY! VICTORY! Let’s all go home now.
•Cons? One-time Pads are horribly impractical 
• And unbreakable, well… Only as long as Pads’ data is
truly random and they are never used twice
Stream ciphers
•Modern electronic Stream Ciphers
• Were inspired by One-time pads
• Have almost all of their problems + some more!
• Derive high entropy Key from Passphrase
• Generate Keystream via a PRNG algorithm from Key
• It’s output is effectively used instead of one-time pads
• Employ Initialization Vectors - transmitted in cleartext
• They are mixed with the Key to avoid key reuse (pad reuse)
Stream ciphers
Basic vulnerabilities: bit flipping
•With Steam Ciphers, a flipped bit in the Ciphertext
ALWAYS results in a flipped bit in the Plaintext
•Having only a Ciphertext, an attacker can make it
say ANYTHING when decrypted!
• Needs to know the target position in the plaintext
• How? E.g. via reverse engineering the app or Crib-dragging
•Requires no knowledge of the encryption key
•Every stream cipher is vulnerable to it!
Stream ciphers
Basic vulnerabilities: bit flipping example
•Given: an encrypted cookie with data like
…&user=john.doe&admin=0&…
•Whose encrypted bytes in binary look like
…10010011 11011001 01101000…
•A flip of only 1 bit of ciphertext is necessary
…10010011 11011000 01101000…
•To make the decrypted plaintext say
…&user=john.doe&admin=1&…
Stream ciphers
Basic vulnerabilities: key reuse
What’s so terrible about key (pad) reuse?
•So we have 2 plaintexts P1 and P2, and we encrypt
them separately under the same Key, IV pair:
C1=P1⊕F(Key,IV)
C2=P2⊕F(Key,IV)
When attacker intercepts them, he can then
compute:
C1⊕C2=P1⊕P2
•“Oh, please! How bad could that possibly be?..”
Stream ciphers
Basic vulnerabilities: key reuse
Stream ciphers
Basic vulnerabilities: key reuse
•Edge case: if one of the plaintexts, e.g. P1, is known,
restoring the other one is trivial
C1⊕C2⊕P1 = (P1⊕K)⊕(P2⊕K)⊕P1 = 0⊕P2 = P2
•Edge case: if a portion of Plaintext is known, the
Keystream in corresponding position is revealed
C = P⊕E(Key,IV)  C⊕P = E(Key,IV)
• Now, having the Keystream at some position, we can
decrypt data at that position from ALL other ciphertexts
• We can also change and re-encrypt any data there
Stream ciphers
Basic vulnerabilities: Why does key reuse happen?
•No IV is used
•Static IV
• For example, the encryption key itself
• Or a hash of the password – good entropy, still useless
•Very short IV
• E.g. WEP had a 24 bit IV == 16777216 values
• Birthday paradox - in 4096 packets IV is reused with P=0.5
• Birthday paradox??
Stream ciphers
Birthday paradox
• For what number of people, the chances that two of them
share a birthday are 50-50?
• 𝑛 ≈ 2𝑚 × 𝑝 𝑛 → 2 × 224 × 0.5 = 212
= 4096
Stream ciphers
Basic vulnerabilities: Why does key reuse happen?
•Bad IV
• Caused by bad random
• Specifically, where a PRNG is used instead of CSPRNG
• “Oh please, what’s the difference?”
Stream ciphers: random
•Popular PRNG named RANDU
•Dots as (x,y) and (x,y,z) – all fall in 15 3D planes!
Stream ciphers: random
•CSPRNG sequence attractor analysis
Stream ciphers: random
•Windows 98 PRNG attractor analysis
Stream ciphers: random
Hacking Java’s Random(): predicting the future
•Linear Congruential PRNG:
seed = (seed * multiplier + addend) mod (2 ^ precision)
• Has 48 bits of state, but discloses only 32 at a time e.g. nextInt()
• The remaining 16 bits are easily bruteforcible on modern PCs:
Stream ciphers: random
Hacking Java’s Random(): peeking into the past
• Long story short, one bit at a time we unwind the changes a
previous seed would’ve had on the current number
• And can do so recursively as far back as we wish
Stream ciphers
Case-study
•Used a circular XOR cipher
• Meaning, “keystream”, the passphrase, was reused
• Well, not exactly XOR operation but close enough
•With a hardcoded key 
• That had barely any entropy
•Without an IV
•All this made it vulnerable to every kind of attack
Stream ciphers
Case-study
Differential Cryptanalysis via chosen plaintext attack
1. ‘aaaaa’ user session cookie, first 10 “bytes” :
131!167!208!205!204!194!184!192!164!124!...
2. ‘bbbbb’ user session cookie:
131!167!209!206!205!195!185!192!164!124!...
3. This is basically an “encryption” oracle
4. From this, we can already deduce the
“keystream”
5. But it’s revealed clearly if we use ‘0’ for
username
6. But what if we couldn’t control the plaintext?..
Stream ciphers
Case-study
Statistical analysis
• Only the end part of cookies changed between sessions
• We can already see what’s encrypted here
• Now just bruteforce 1 byte for each column
• Voila! We have our keystream symbol!
Stream ciphers
So, how to do it right?
•NEVER be clever and invent your own crypto!
•Use well-known Crypto suits, e.g. Bouncy Castle
•Never use a vulnerable cipher! E.g., RC4
• Instead, go for ChaCha20 – no known attacks
•When you’re asked for an IV, get it from CSPRNG!
• And make it LOOOOONG
•Never use the Passphrase as the Key!
• Instead, google how to use PBKDF2 from RFC 2898
goo.gl/tuKku7
Applied cryptanalysis - stream ciphers

More Related Content

What's hot

Bitcoin Keys, Addresses & Wallets
Bitcoin Keys, Addresses & WalletsBitcoin Keys, Addresses & Wallets
Bitcoin Keys, Addresses & WalletsChristopher Allen
 
Practical rsa padding oracle attacks
Practical rsa padding oracle attacksPractical rsa padding oracle attacks
Practical rsa padding oracle attacksAlexandre Moneger
 
The Cryptography has YOU
The Cryptography has YOUThe Cryptography has YOU
The Cryptography has YOUYurii Bilyk
 
Cryptography for Penetration Testers (PDF version)
Cryptography for Penetration Testers (PDF version)Cryptography for Penetration Testers (PDF version)
Cryptography for Penetration Testers (PDF version)ceng
 
CNIT 141: 10. RSA
CNIT 141: 10. RSACNIT 141: 10. RSA
CNIT 141: 10. RSASam Bowne
 
Strong cryptography in PHP
Strong cryptography in PHPStrong cryptography in PHP
Strong cryptography in PHPEnrico Zimuel
 
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...Moabi.com
 
How-to crack 43kk passwords while drinking your juice/smoozie in the Hood
How-to crack 43kk passwords  while drinking your  juice/smoozie in the HoodHow-to crack 43kk passwords  while drinking your  juice/smoozie in the Hood
How-to crack 43kk passwords while drinking your juice/smoozie in the HoodYurii Bilyk
 
Rust Intro @ Roma Rust meetup
Rust Intro @ Roma Rust meetup Rust Intro @ Roma Rust meetup
Rust Intro @ Roma Rust meetup Claudio Capobianco
 
Collision vulnerability for hash data structures in web platforms
Collision vulnerability for hash data structures in web platformsCollision vulnerability for hash data structures in web platforms
Collision vulnerability for hash data structures in web platformsBerescu Ionut
 
Pushing a camel through the eye of a needle
Pushing a camel through the eye of a needlePushing a camel through the eye of a needle
Pushing a camel through the eye of a needleSensePost
 
Cryptography for developers
Cryptography for developersCryptography for developers
Cryptography for developersKai Koenig
 
Message Authentication using Message Digests and the MD5 Algorithm
Message Authentication using Message Digests and the MD5 AlgorithmMessage Authentication using Message Digests and the MD5 Algorithm
Message Authentication using Message Digests and the MD5 AlgorithmAjay Karri
 

What's hot (20)

Bitcoin Keys, Addresses & Wallets
Bitcoin Keys, Addresses & WalletsBitcoin Keys, Addresses & Wallets
Bitcoin Keys, Addresses & Wallets
 
Practical rsa padding oracle attacks
Practical rsa padding oracle attacksPractical rsa padding oracle attacks
Practical rsa padding oracle attacks
 
rspamd-fosdem
rspamd-fosdemrspamd-fosdem
rspamd-fosdem
 
The Cryptography has YOU
The Cryptography has YOUThe Cryptography has YOU
The Cryptography has YOU
 
Cryptography for Penetration Testers (PDF version)
Cryptography for Penetration Testers (PDF version)Cryptography for Penetration Testers (PDF version)
Cryptography for Penetration Testers (PDF version)
 
CNIT 141: 10. RSA
CNIT 141: 10. RSACNIT 141: 10. RSA
CNIT 141: 10. RSA
 
Strong cryptography in PHP
Strong cryptography in PHPStrong cryptography in PHP
Strong cryptography in PHP
 
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
 
Encryption
EncryptionEncryption
Encryption
 
rspamd-hyperscan
rspamd-hyperscanrspamd-hyperscan
rspamd-hyperscan
 
rspamd-slides
rspamd-slidesrspamd-slides
rspamd-slides
 
How-to crack 43kk passwords while drinking your juice/smoozie in the Hood
How-to crack 43kk passwords  while drinking your  juice/smoozie in the HoodHow-to crack 43kk passwords  while drinking your  juice/smoozie in the Hood
How-to crack 43kk passwords while drinking your juice/smoozie in the Hood
 
Rust Intro @ Roma Rust meetup
Rust Intro @ Roma Rust meetup Rust Intro @ Roma Rust meetup
Rust Intro @ Roma Rust meetup
 
Collision vulnerability for hash data structures in web platforms
Collision vulnerability for hash data structures in web platformsCollision vulnerability for hash data structures in web platforms
Collision vulnerability for hash data structures in web platforms
 
Cryptography
CryptographyCryptography
Cryptography
 
Pushing a camel through the eye of a needle
Pushing a camel through the eye of a needlePushing a camel through the eye of a needle
Pushing a camel through the eye of a needle
 
Cryptography for developers
Cryptography for developersCryptography for developers
Cryptography for developers
 
Message Authentication using Message Digests and the MD5 Algorithm
Message Authentication using Message Digests and the MD5 AlgorithmMessage Authentication using Message Digests and the MD5 Algorithm
Message Authentication using Message Digests and the MD5 Algorithm
 
Proof of x
Proof of xProof of x
Proof of x
 
IPv6 for Pentester
IPv6 for PentesterIPv6 for Pentester
IPv6 for Pentester
 

Similar to Applied cryptanalysis - stream ciphers

CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. EncryptionSam Bowne
 
CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. EncryptionSam Bowne
 
CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. EncryptionSam Bowne
 
CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. EncryptionSam Bowne
 
Cns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption TechniquesCns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption Techniquesbabak danyal
 
Classical Encryption Techniques in Network Security
Classical Encryption Techniques in Network SecurityClassical Encryption Techniques in Network Security
Classical Encryption Techniques in Network Securitybabak danyal
 
CNIT 125 Ch 4. Security Engineering (Part 2)
CNIT 125 Ch 4. Security Engineering (Part 2)CNIT 125 Ch 4. Security Engineering (Part 2)
CNIT 125 Ch 4. Security Engineering (Part 2)Sam Bowne
 
Chapter# 3 modified.pptx
Chapter# 3 modified.pptxChapter# 3 modified.pptx
Chapter# 3 modified.pptxMaryam522887
 
CISSP Prep: Ch 4. Security Engineering (Part 2)
CISSP Prep: Ch 4. Security Engineering (Part 2)CISSP Prep: Ch 4. Security Engineering (Part 2)
CISSP Prep: Ch 4. Security Engineering (Part 2)Sam Bowne
 
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersCNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersSam Bowne
 
overview of cryptographic techniques
overview of cryptographic techniquesoverview of cryptographic techniques
overview of cryptographic techniquesShubham Jain
 
Blockchain Technology Introduction and Basics
Blockchain Technology  Introduction and BasicsBlockchain Technology  Introduction and Basics
Blockchain Technology Introduction and Basicsjayasris2023
 
Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Cloudflare
 
4. Block Ciphers
4. Block Ciphers 4. Block Ciphers
4. Block Ciphers Sam Bowne
 
CNIT 126 13: Data Encoding
CNIT 126 13: Data EncodingCNIT 126 13: Data Encoding
CNIT 126 13: Data EncodingSam Bowne
 

Similar to Applied cryptanalysis - stream ciphers (20)

CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. Encryption
 
CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. Encryption
 
CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. Encryption
 
CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. Encryption
 
Block Ciphers Modes of Operation
Block Ciphers Modes of OperationBlock Ciphers Modes of Operation
Block Ciphers Modes of Operation
 
Cns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption TechniquesCns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption Techniques
 
Classical Encryption Techniques in Network Security
Classical Encryption Techniques in Network SecurityClassical Encryption Techniques in Network Security
Classical Encryption Techniques in Network Security
 
Cryptography
CryptographyCryptography
Cryptography
 
Cryptography.ppt
Cryptography.pptCryptography.ppt
Cryptography.ppt
 
Symmetric encryption
Symmetric encryptionSymmetric encryption
Symmetric encryption
 
CNIT 125 Ch 4. Security Engineering (Part 2)
CNIT 125 Ch 4. Security Engineering (Part 2)CNIT 125 Ch 4. Security Engineering (Part 2)
CNIT 125 Ch 4. Security Engineering (Part 2)
 
Chapter# 3 modified.pptx
Chapter# 3 modified.pptxChapter# 3 modified.pptx
Chapter# 3 modified.pptx
 
CISSP Prep: Ch 4. Security Engineering (Part 2)
CISSP Prep: Ch 4. Security Engineering (Part 2)CISSP Prep: Ch 4. Security Engineering (Part 2)
CISSP Prep: Ch 4. Security Engineering (Part 2)
 
CNIT 141: 4. Block Ciphers
CNIT 141: 4. Block CiphersCNIT 141: 4. Block Ciphers
CNIT 141: 4. Block Ciphers
 
overview of cryptographic techniques
overview of cryptographic techniquesoverview of cryptographic techniques
overview of cryptographic techniques
 
Blockchain Technology Introduction and Basics
Blockchain Technology  Introduction and BasicsBlockchain Technology  Introduction and Basics
Blockchain Technology Introduction and Basics
 
Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014
 
4. Block Ciphers
4. Block Ciphers 4. Block Ciphers
4. Block Ciphers
 
Modern Cryptography
Modern CryptographyModern Cryptography
Modern Cryptography
 
CNIT 126 13: Data Encoding
CNIT 126 13: Data EncodingCNIT 126 13: Data Encoding
CNIT 126 13: Data Encoding
 

Recently uploaded

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Recently uploaded (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

Applied cryptanalysis - stream ciphers

  • 2. Intro •Why do I need to learn about Crypto generally? • It’s often used to create Cookies, hidden parameters • To do TLS the right way • For hashes and data integrity checks • Password and sensitive info storage • To have more marketable skills during an interview •To whom is this useful? • Devs, QA, anyone interested in security and crypto •What do I need to understand this? • School math knowledge • Desire to learn
  • 3. Overview •Symmetric encryption • Stream ciphers • Block ciphers • Modes of operation •Cryptographic hash • Key derivation • Authenticated Encryption, AEAD •Asymmetric encryption •Conclusions and best practices
  • 5. Symmetric Crypto basics •To Encrypt is to take Plaintext, key and convert them into Ciphertext: C = E(P, k) •To Decrypt is to take Ciphertext, key and convert them back into Plaintext: P = D(C, k) •An attacker must, ideally, try (bruteforce) all possible keys – for 256 bit key – 1077 combinations
  • 7. Symmetric Crypto basics •OK, what’s a cryptographic attack? • Anything better than bruteforce •What’s a practical attack? • Any attack an adversary with best technology available can conduct in “reasonable” amount of time • “reasonable” is determined based on how long the plaintext keeps it’s value • Normally, due to exponential nature of cryptanalytic difficulty, attacks are either impossible or very much possible
  • 8. Symmetric Crypto basics Main cryptanalytic methods, at a glance •Known plaintext •Chosen plaintext (encryption oracles) •Chosen ciphertext (decryption oracles, bit flipping) •Statistical cryptanalysis •Differential cryptanalysis •Side-channel attacks
  • 10. Symmetric Crypto basics XOR ⊕ Refresher •Basically a bit flipping machine •A ⊕ A = 0
  • 11. Symmetric Crypto basics XOR ⊕ Refresher 1. A ⊕ A = 0 2. A ⊕ 0 = A 3. A ⊕ B = B ⊕ A (commutativity) 4. A ⊕ ( B ⊕ C ) = ( A ⊕ B) ⊕ C (associativity) 5. Let K ⊕ M = C , then: C ⊕ K = K ⊕ M ⊕ K = K ⊕ K ⊕ M = 0 ⊕ M = M
  • 12. Stream ciphers •Historic stream cipher example – One-time Pads • Sender and Receiver must have identical Pads • Pads fully filled with random data • Sender computes Message ⊕ Pad and sends result • Receiver does Ciphertext ⊕ Pad to get Message •One-time Pads are mathematically proven to be unbreakable! YAY! VICTORY! Let’s all go home now.
  • 14. Stream ciphers •Historic stream cipher example – One-time Pads • Sender and Receiver must have identical Pads • Pads fully filled with random data • Sender computes Message ⊕ Pad and sends result • Receiver does Ciphertext ⊕ Pad to get Message •One-time Pads are mathematically proven to be unbreakable! YAY! VICTORY! Let’s all go home now. •Cons? One-time Pads are horribly impractical  • And unbreakable, well… Only as long as Pads’ data is truly random and they are never used twice
  • 15. Stream ciphers •Modern electronic Stream Ciphers • Were inspired by One-time pads • Have almost all of their problems + some more! • Derive high entropy Key from Passphrase • Generate Keystream via a PRNG algorithm from Key • It’s output is effectively used instead of one-time pads • Employ Initialization Vectors - transmitted in cleartext • They are mixed with the Key to avoid key reuse (pad reuse)
  • 16. Stream ciphers Basic vulnerabilities: bit flipping •With Steam Ciphers, a flipped bit in the Ciphertext ALWAYS results in a flipped bit in the Plaintext •Having only a Ciphertext, an attacker can make it say ANYTHING when decrypted! • Needs to know the target position in the plaintext • How? E.g. via reverse engineering the app or Crib-dragging •Requires no knowledge of the encryption key •Every stream cipher is vulnerable to it!
  • 17. Stream ciphers Basic vulnerabilities: bit flipping example •Given: an encrypted cookie with data like …&user=john.doe&admin=0&… •Whose encrypted bytes in binary look like …10010011 11011001 01101000… •A flip of only 1 bit of ciphertext is necessary …10010011 11011000 01101000… •To make the decrypted plaintext say …&user=john.doe&admin=1&…
  • 18. Stream ciphers Basic vulnerabilities: key reuse What’s so terrible about key (pad) reuse? •So we have 2 plaintexts P1 and P2, and we encrypt them separately under the same Key, IV pair: C1=P1⊕F(Key,IV) C2=P2⊕F(Key,IV) When attacker intercepts them, he can then compute: C1⊕C2=P1⊕P2 •“Oh, please! How bad could that possibly be?..”
  • 20. Stream ciphers Basic vulnerabilities: key reuse •Edge case: if one of the plaintexts, e.g. P1, is known, restoring the other one is trivial C1⊕C2⊕P1 = (P1⊕K)⊕(P2⊕K)⊕P1 = 0⊕P2 = P2 •Edge case: if a portion of Plaintext is known, the Keystream in corresponding position is revealed C = P⊕E(Key,IV)  C⊕P = E(Key,IV) • Now, having the Keystream at some position, we can decrypt data at that position from ALL other ciphertexts • We can also change and re-encrypt any data there
  • 21. Stream ciphers Basic vulnerabilities: Why does key reuse happen? •No IV is used •Static IV • For example, the encryption key itself • Or a hash of the password – good entropy, still useless •Very short IV • E.g. WEP had a 24 bit IV == 16777216 values • Birthday paradox - in 4096 packets IV is reused with P=0.5 • Birthday paradox??
  • 22. Stream ciphers Birthday paradox • For what number of people, the chances that two of them share a birthday are 50-50? • 𝑛 ≈ 2𝑚 × 𝑝 𝑛 → 2 × 224 × 0.5 = 212 = 4096
  • 23. Stream ciphers Basic vulnerabilities: Why does key reuse happen? •Bad IV • Caused by bad random • Specifically, where a PRNG is used instead of CSPRNG • “Oh please, what’s the difference?”
  • 24. Stream ciphers: random •Popular PRNG named RANDU •Dots as (x,y) and (x,y,z) – all fall in 15 3D planes!
  • 25. Stream ciphers: random •CSPRNG sequence attractor analysis
  • 26. Stream ciphers: random •Windows 98 PRNG attractor analysis
  • 27. Stream ciphers: random Hacking Java’s Random(): predicting the future •Linear Congruential PRNG: seed = (seed * multiplier + addend) mod (2 ^ precision) • Has 48 bits of state, but discloses only 32 at a time e.g. nextInt() • The remaining 16 bits are easily bruteforcible on modern PCs:
  • 28. Stream ciphers: random Hacking Java’s Random(): peeking into the past • Long story short, one bit at a time we unwind the changes a previous seed would’ve had on the current number • And can do so recursively as far back as we wish
  • 29. Stream ciphers Case-study •Used a circular XOR cipher • Meaning, “keystream”, the passphrase, was reused • Well, not exactly XOR operation but close enough •With a hardcoded key  • That had barely any entropy •Without an IV •All this made it vulnerable to every kind of attack
  • 30. Stream ciphers Case-study Differential Cryptanalysis via chosen plaintext attack 1. ‘aaaaa’ user session cookie, first 10 “bytes” : 131!167!208!205!204!194!184!192!164!124!... 2. ‘bbbbb’ user session cookie: 131!167!209!206!205!195!185!192!164!124!... 3. This is basically an “encryption” oracle 4. From this, we can already deduce the “keystream” 5. But it’s revealed clearly if we use ‘0’ for username 6. But what if we couldn’t control the plaintext?..
  • 31. Stream ciphers Case-study Statistical analysis • Only the end part of cookies changed between sessions • We can already see what’s encrypted here • Now just bruteforce 1 byte for each column • Voila! We have our keystream symbol!
  • 32. Stream ciphers So, how to do it right? •NEVER be clever and invent your own crypto! •Use well-known Crypto suits, e.g. Bouncy Castle •Never use a vulnerable cipher! E.g., RC4 • Instead, go for ChaCha20 – no known attacks •When you’re asked for an IV, get it from CSPRNG! • And make it LOOOOONG •Never use the Passphrase as the Key! • Instead, google how to use PBKDF2 from RFC 2898