SlideShare a Scribd company logo
Cryptanalysis in the
Time of Ransomware
July 28th 2017
DEF CON 25 Crypto Village
Mark Mager
2
 Senior Malware Researcher at
Endgame
 Reverse engineer and software dev
 Please note: I am NOT a cryptographer
 Washington, DC area
 Previously at
 US-CERT
 CYBERCOM
 Lockheed Martin
 Battelle
 Twitter - @magerbomb
About Me
3
Agenda  Ransomware Execution Flow
 Cryptanalysis Workflow
 Walkthroughs
• Powerware
• Nemucod
• TorrentLocker
• Apocalypse
 Research in the Field
 Conclusion
 Questions
4
Ransomware
Execution
Flow
 Payload written disk and executed
 Key generation / retrieval
• Exchange with C2 (optional)
 Enumeration / directory traversal
• Files are individually encrypted
• Ransom note in each directory (optional)
5
Cryptanalysis
Workflow
 Dynamic analysis
• Observe network communications
• Analyze encrypted files
∙ Magic byte sequences / watermarks
∙ Whole vs. partial encryption
• Forensic artifacts on disk
∙ Reg keys, dropped files, event logs
• Repeat tests multiple times
∙ Adjust environment as needed
∙ Known / chosen plaintext attacks
 Reverse engineering
• Identify crypto algorithm(s) used
∙ Implementation mistakes that may
potentially weaken the crypto
• Key generation, storage, transmission
 Apply lessons learned to decrypter dev
6
Walkthroughs  Walk through ransomware encryption schemes
that can be defeated
 Older variants that are no longer in circulation
 High level reverse engineering
 Crypto implementation details
• Note any differences b/w note and reality
 Focus on devising POC for decrypting
Powerware
Enumeration
Crypto setup
File
write
File Cleanup
10
Let’s deobfuscate this a little bit…
11
Much better! Now what sticks out?
 Symmetric encryption
• RijndaelManaged class (AES)
 256 bit (32 byte) key
 Initialization vector
 Padding with zero
 Cipher block chaining (CBC) mode
 Only the first 2048 bytes of the file are to be read in and encrypted
 Files less than 2048 bytes are ignored
 No further modifications made to the crypto object before CreateEncryptor()
Deobfuscated file transformation code block
13
Back to the crypto setup…
 Symmetric encryption
• RijndaelManaged class (AES)
 256 bit (32 byte) key
 Initialization vector
 Padding with zero
 Cipher block chaining (CBC) mode
Let’s build our own decrypter!
16
Nemucod
2048 bytes max
XOR static key
20
Nemucod  Asymmetric crypto
• RSA-1024
 XOR
 Unique key generation
 255 byte key
• Hard-coded
• Same for every file
 Only the first 2048 bytes
 Simple encrypter binary
How can we decrypt our files?
22
TorrentLocker
Decompiled view of ctr_encrypt
libtomcrypt source code
Decompiled view of aes_encrypt
libtomcrypt source code
30
TorrentLocker  From limited reverse engineering we know…
• AES
• Counter (CTR) mode
• libtomcrypt
 Could this potentially be vulnerable?
• Implementation flaws
Source: “Counter Mode Security: Analysis and Recommendations”
31
TorrentLocker  A = large plaintext file of NULL bytes
• Exhaust keystream (if file size limitation)
 B = non-NULL plaintext (arbitrary size < than A)
 ENCRYPT(A) = A’
 A’ XOR A = KEYSTREAM
• A = NULL bytes
∙ XOR A is redundant
・ A’ = KEYSTREAM
 ENCRYPT(B) = B’
 B’ XOR KEYSTREAM = B
How can we test
for a flawed
AES-CTR
implementation?
Let’s see if this holds true…
33
34
TorrentLocker  AES
 Counter (CTR) mode
 Static key
 Static IV / nonce
 2 MB file size limit
 No padding
• Need to consider byte alignment and
determine block size to cover edge cases
Apocalypse
 After viewing ciphertexts spanning multiple file types, a magic byte sequence
reveals itself
• 77 2A 3C D0
 After encrypting a chosen plaintext
containing solely null bytes
• Appears to be some repetition
39
Apocalypse  Magic byte sequence
 Repetition in ciphertext
• Produced from NULL byte plaintext
 Ransom note doesn’t mention encryption type
 Let’s proceed with reverse engineering…
 Text search in IDA Pro for XOR operations
• Most XORs just clearing out registers, but two stick out in sub_40108
• Good place to start, but it’s not always this easy
 The two XORs of interest are looped over
 Appears that the previously identified magic byte
sequence is written by the first WriteFile call
 Second WriteFile writes out the transformed buffer
containing the presumably encrypted data
Let’s test out the script…
45
46
Research in
the Field
 Tracking and reverse engineering new variants
 Developing and releasing decrypters for free
 BleepingComputer forums
• BloodDolly
 @malwarehunterteam
• http://id-ransomware.malwarehunterteam.com
 @malwaretech
• WannaCry killswitch
• https://www.malwaretech.com
 @demonslay335
 … and many others!
Despite
proliferation,
researchers have
kept pace
47
Conclusion  Crypto implementation issues prevalent
• “Crypto is hard”
 Ransom notes are not trustworthy for technical
specs
• Don’t believe the hype
 RE and cryptanalysis / decrypter dev are not
linear processes
• Known / chosen plaintext attacks
• Trial and error
• Focus on sections where modifications
occur, then dig deeper for more clues
• Build out POC, then stress test and harden
as needed to cover all edge cases
Thanks!
Twitter - @magerbomb
E-mail - mager@endgame.com

More Related Content

What's hot

CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. Encryption
Sam Bowne
 
Find the Hacker
Find the HackerFind the Hacker
Find the Hacker
Sysdig
 
Introduction to Dynamic Malware Analysis ...Or am I "Cuckoo for Malware?"
Introduction to Dynamic Malware Analysis   ...Or am I "Cuckoo for Malware?"Introduction to Dynamic Malware Analysis   ...Or am I "Cuckoo for Malware?"
Introduction to Dynamic Malware Analysis ...Or am I "Cuckoo for Malware?"
Lane Huff
 
Block Cipher Modes of Operation And Cmac For Authentication
Block Cipher Modes of Operation And Cmac For AuthenticationBlock Cipher Modes of Operation And Cmac For Authentication
Block Cipher Modes of Operation And Cmac For Authentication
Vittorio Giovara
 
Sysdig Open Source Intro
Sysdig Open Source IntroSysdig Open Source Intro
Sysdig Open Source Intro
Michael Ducy
 
4055-841_Project_ShailendraSadh
4055-841_Project_ShailendraSadh4055-841_Project_ShailendraSadh
4055-841_Project_ShailendraSadh
Shailendra Sadh - CISSP
 
Authenticated Encryption Gcm Ccm
Authenticated Encryption Gcm CcmAuthenticated Encryption Gcm Ccm
Authenticated Encryption Gcm Ccm
Vittorio Giovara
 
CNIT 141 6. Hash Functions
CNIT 141 6. Hash FunctionsCNIT 141 6. Hash Functions
CNIT 141 6. Hash Functions
Sam Bowne
 
Software Security
Software SecuritySoftware Security
Software Security
Roman Oliynykov
 
Block Cipher
Block CipherBlock Cipher
Block Cipher
Brandon Byungyong Jo
 
Block Ciphers Modes of Operation
Block Ciphers Modes of OperationBlock Ciphers Modes of Operation
Block Ciphers Modes of Operation
Shafaan Khaliq Bhatti
 
Sheila Ayelen Berta - The Art of Persistence: "Mr. Windows… I don’t wanna go ...
Sheila Ayelen Berta - The Art of Persistence: "Mr. Windows… I don’t wanna go ...Sheila Ayelen Berta - The Art of Persistence: "Mr. Windows… I don’t wanna go ...
Sheila Ayelen Berta - The Art of Persistence: "Mr. Windows… I don’t wanna go ...
RootedCON
 
RC4&RC5
RC4&RC5RC4&RC5
RC4&RC5
guestff64339
 
Malware analysis using volatility
Malware analysis using volatilityMalware analysis using volatility
Malware analysis using volatility
Yashashree Gund
 
Unpack your troubles*: .NET packer tricks and countermeasures
Unpack your troubles*: .NET packer tricks and countermeasuresUnpack your troubles*: .NET packer tricks and countermeasures
Unpack your troubles*: .NET packer tricks and countermeasures
ESET
 
Sysdig Tokyo Meetup 2018 02-27
Sysdig Tokyo Meetup 2018 02-27Sysdig Tokyo Meetup 2018 02-27
Sysdig Tokyo Meetup 2018 02-27
Michael Ducy
 
13528 l8
13528 l813528 l8
13528 l8
ridhika_gulati
 
I mage encryption using rc5
I mage encryption using rc5I mage encryption using rc5
I mage encryption using rc5
Suramrit Singh
 
Bootkits: Past, Present & Future - Virus Bulletin
Bootkits: Past, Present & Future - Virus BulletinBootkits: Past, Present & Future - Virus Bulletin
Bootkits: Past, Present & Future - Virus Bulletin
ESET
 
Kalyna block cipher presentation in English
Kalyna block cipher presentation in EnglishKalyna block cipher presentation in English
Kalyna block cipher presentation in English
Roman Oliynykov
 

What's hot (20)

CNIT 141: 1. Encryption
CNIT 141: 1. EncryptionCNIT 141: 1. Encryption
CNIT 141: 1. Encryption
 
Find the Hacker
Find the HackerFind the Hacker
Find the Hacker
 
Introduction to Dynamic Malware Analysis ...Or am I "Cuckoo for Malware?"
Introduction to Dynamic Malware Analysis   ...Or am I "Cuckoo for Malware?"Introduction to Dynamic Malware Analysis   ...Or am I "Cuckoo for Malware?"
Introduction to Dynamic Malware Analysis ...Or am I "Cuckoo for Malware?"
 
Block Cipher Modes of Operation And Cmac For Authentication
Block Cipher Modes of Operation And Cmac For AuthenticationBlock Cipher Modes of Operation And Cmac For Authentication
Block Cipher Modes of Operation And Cmac For Authentication
 
Sysdig Open Source Intro
Sysdig Open Source IntroSysdig Open Source Intro
Sysdig Open Source Intro
 
4055-841_Project_ShailendraSadh
4055-841_Project_ShailendraSadh4055-841_Project_ShailendraSadh
4055-841_Project_ShailendraSadh
 
Authenticated Encryption Gcm Ccm
Authenticated Encryption Gcm CcmAuthenticated Encryption Gcm Ccm
Authenticated Encryption Gcm Ccm
 
CNIT 141 6. Hash Functions
CNIT 141 6. Hash FunctionsCNIT 141 6. Hash Functions
CNIT 141 6. Hash Functions
 
Software Security
Software SecuritySoftware Security
Software Security
 
Block Cipher
Block CipherBlock Cipher
Block Cipher
 
Block Ciphers Modes of Operation
Block Ciphers Modes of OperationBlock Ciphers Modes of Operation
Block Ciphers Modes of Operation
 
Sheila Ayelen Berta - The Art of Persistence: "Mr. Windows… I don’t wanna go ...
Sheila Ayelen Berta - The Art of Persistence: "Mr. Windows… I don’t wanna go ...Sheila Ayelen Berta - The Art of Persistence: "Mr. Windows… I don’t wanna go ...
Sheila Ayelen Berta - The Art of Persistence: "Mr. Windows… I don’t wanna go ...
 
RC4&RC5
RC4&RC5RC4&RC5
RC4&RC5
 
Malware analysis using volatility
Malware analysis using volatilityMalware analysis using volatility
Malware analysis using volatility
 
Unpack your troubles*: .NET packer tricks and countermeasures
Unpack your troubles*: .NET packer tricks and countermeasuresUnpack your troubles*: .NET packer tricks and countermeasures
Unpack your troubles*: .NET packer tricks and countermeasures
 
Sysdig Tokyo Meetup 2018 02-27
Sysdig Tokyo Meetup 2018 02-27Sysdig Tokyo Meetup 2018 02-27
Sysdig Tokyo Meetup 2018 02-27
 
13528 l8
13528 l813528 l8
13528 l8
 
I mage encryption using rc5
I mage encryption using rc5I mage encryption using rc5
I mage encryption using rc5
 
Bootkits: Past, Present & Future - Virus Bulletin
Bootkits: Past, Present & Future - Virus BulletinBootkits: Past, Present & Future - Virus Bulletin
Bootkits: Past, Present & Future - Virus Bulletin
 
Kalyna block cipher presentation in English
Kalyna block cipher presentation in EnglishKalyna block cipher presentation in English
Kalyna block cipher presentation in English
 

Similar to Cryptanalysis in the Time of Ransomware

PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
CODE BLUE
 
Crypto Miners in the Cloud
Crypto Miners in the CloudCrypto Miners in the Cloud
Crypto Miners in the Cloud
Teri Radichel
 
Sullivan white boxcrypto-baythreat-2013
Sullivan white boxcrypto-baythreat-2013Sullivan white boxcrypto-baythreat-2013
Sullivan white boxcrypto-baythreat-2013
Cloudflare
 
nabdullin_brcrdu_dark
nabdullin_brcrdu_darknabdullin_brcrdu_dark
nabdullin_brcrdu_dark
Nikita Abdullin
 
Eusecwest
EusecwestEusecwest
Eusecwest
zynamics GmbH
 
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
 
Breaking Smart [Bank] Statements – Hacker Halted 2019 – Manuel Nader
Breaking Smart [Bank] Statements – Hacker Halted 2019 – Manuel NaderBreaking Smart [Bank] Statements – Hacker Halted 2019 – Manuel Nader
Breaking Smart [Bank] Statements – Hacker Halted 2019 – Manuel Nader
EC-Council
 
CNIT 126: 13: Data Encoding
CNIT 126: 13: Data EncodingCNIT 126: 13: Data Encoding
CNIT 126: 13: Data Encoding
Sam Bowne
 
Is That A Penguin In My Windows?
Is That A Penguin In My Windows?Is That A Penguin In My Windows?
Is That A Penguin In My Windows?
zeroSteiner
 
Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014
Cloudflare
 
CNIT 126 13: Data Encoding
CNIT 126 13: Data EncodingCNIT 126 13: Data Encoding
CNIT 126 13: Data Encoding
Sam Bowne
 
Analysing Ransomware
Analysing RansomwareAnalysing Ransomware
Analysing Ransomware
Napier University
 
Practical Malware Analysis Ch13
Practical Malware Analysis Ch13Practical Malware Analysis Ch13
Practical Malware Analysis Ch13
Sam Bowne
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCON
Lyon Yang
 
White-box Cryptography -BayThreat 2013
White-box Cryptography -BayThreat 2013White-box Cryptography -BayThreat 2013
White-box Cryptography -BayThreat 2013
Nick Sullivan
 
Cryptography and steganography lesson and discription.pptx
Cryptography and steganography lesson and discription.pptxCryptography and steganography lesson and discription.pptx
Cryptography and steganography lesson and discription.pptx
RobertCarreonBula
 
DEFCON 23 - Eijah - crypto for hackers
DEFCON 23 - Eijah - crypto for hackersDEFCON 23 - Eijah - crypto for hackers
DEFCON 23 - Eijah - crypto for hackers
Felipe Prado
 
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't driveDEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
Felipe Prado
 
Peter Gutmann Presentation - CSO Perspectives Roadshow Auckland 9th Mar 2015
Peter Gutmann Presentation - CSO Perspectives Roadshow Auckland 9th Mar 2015Peter Gutmann Presentation - CSO Perspectives Roadshow Auckland 9th Mar 2015
Peter Gutmann Presentation - CSO Perspectives Roadshow Auckland 9th Mar 2015
CSO_Presentations
 
You suck at Memory Analysis
You suck at Memory AnalysisYou suck at Memory Analysis
You suck at Memory Analysis
Francisco Ribeiro
 

Similar to Cryptanalysis in the Time of Ransomware (20)

PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
PANDEMONIUM: Automated Identification of Cryptographic Algorithms using Dynam...
 
Crypto Miners in the Cloud
Crypto Miners in the CloudCrypto Miners in the Cloud
Crypto Miners in the Cloud
 
Sullivan white boxcrypto-baythreat-2013
Sullivan white boxcrypto-baythreat-2013Sullivan white boxcrypto-baythreat-2013
Sullivan white boxcrypto-baythreat-2013
 
nabdullin_brcrdu_dark
nabdullin_brcrdu_darknabdullin_brcrdu_dark
nabdullin_brcrdu_dark
 
Eusecwest
EusecwestEusecwest
Eusecwest
 
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)
 
Breaking Smart [Bank] Statements – Hacker Halted 2019 – Manuel Nader
Breaking Smart [Bank] Statements – Hacker Halted 2019 – Manuel NaderBreaking Smart [Bank] Statements – Hacker Halted 2019 – Manuel Nader
Breaking Smart [Bank] Statements – Hacker Halted 2019 – Manuel Nader
 
CNIT 126: 13: Data Encoding
CNIT 126: 13: Data EncodingCNIT 126: 13: Data Encoding
CNIT 126: 13: Data Encoding
 
Is That A Penguin In My Windows?
Is That A Penguin In My Windows?Is That A Penguin In My Windows?
Is That A Penguin In My Windows?
 
Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014
 
CNIT 126 13: Data Encoding
CNIT 126 13: Data EncodingCNIT 126 13: Data Encoding
CNIT 126 13: Data Encoding
 
Analysing Ransomware
Analysing RansomwareAnalysing Ransomware
Analysing Ransomware
 
Practical Malware Analysis Ch13
Practical Malware Analysis Ch13Practical Malware Analysis Ch13
Practical Malware Analysis Ch13
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCON
 
White-box Cryptography -BayThreat 2013
White-box Cryptography -BayThreat 2013White-box Cryptography -BayThreat 2013
White-box Cryptography -BayThreat 2013
 
Cryptography and steganography lesson and discription.pptx
Cryptography and steganography lesson and discription.pptxCryptography and steganography lesson and discription.pptx
Cryptography and steganography lesson and discription.pptx
 
DEFCON 23 - Eijah - crypto for hackers
DEFCON 23 - Eijah - crypto for hackersDEFCON 23 - Eijah - crypto for hackers
DEFCON 23 - Eijah - crypto for hackers
 
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't driveDEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
 
Peter Gutmann Presentation - CSO Perspectives Roadshow Auckland 9th Mar 2015
Peter Gutmann Presentation - CSO Perspectives Roadshow Auckland 9th Mar 2015Peter Gutmann Presentation - CSO Perspectives Roadshow Auckland 9th Mar 2015
Peter Gutmann Presentation - CSO Perspectives Roadshow Auckland 9th Mar 2015
 
You suck at Memory Analysis
You suck at Memory AnalysisYou suck at Memory Analysis
You suck at Memory Analysis
 

Recently uploaded

Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
zubairahmad848137
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 

Recently uploaded (20)

Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 

Cryptanalysis in the Time of Ransomware

  • 1. Cryptanalysis in the Time of Ransomware July 28th 2017 DEF CON 25 Crypto Village Mark Mager
  • 2. 2  Senior Malware Researcher at Endgame  Reverse engineer and software dev  Please note: I am NOT a cryptographer  Washington, DC area  Previously at  US-CERT  CYBERCOM  Lockheed Martin  Battelle  Twitter - @magerbomb About Me
  • 3. 3 Agenda  Ransomware Execution Flow  Cryptanalysis Workflow  Walkthroughs • Powerware • Nemucod • TorrentLocker • Apocalypse  Research in the Field  Conclusion  Questions
  • 4. 4 Ransomware Execution Flow  Payload written disk and executed  Key generation / retrieval • Exchange with C2 (optional)  Enumeration / directory traversal • Files are individually encrypted • Ransom note in each directory (optional)
  • 5. 5 Cryptanalysis Workflow  Dynamic analysis • Observe network communications • Analyze encrypted files ∙ Magic byte sequences / watermarks ∙ Whole vs. partial encryption • Forensic artifacts on disk ∙ Reg keys, dropped files, event logs • Repeat tests multiple times ∙ Adjust environment as needed ∙ Known / chosen plaintext attacks  Reverse engineering • Identify crypto algorithm(s) used ∙ Implementation mistakes that may potentially weaken the crypto • Key generation, storage, transmission  Apply lessons learned to decrypter dev
  • 6. 6 Walkthroughs  Walk through ransomware encryption schemes that can be defeated  Older variants that are no longer in circulation  High level reverse engineering  Crypto implementation details • Note any differences b/w note and reality  Focus on devising POC for decrypting
  • 8.
  • 10. 10 Let’s deobfuscate this a little bit…
  • 11. 11 Much better! Now what sticks out?  Symmetric encryption • RijndaelManaged class (AES)  256 bit (32 byte) key  Initialization vector  Padding with zero  Cipher block chaining (CBC) mode
  • 12.  Only the first 2048 bytes of the file are to be read in and encrypted  Files less than 2048 bytes are ignored  No further modifications made to the crypto object before CreateEncryptor() Deobfuscated file transformation code block
  • 13. 13 Back to the crypto setup…  Symmetric encryption • RijndaelManaged class (AES)  256 bit (32 byte) key  Initialization vector  Padding with zero  Cipher block chaining (CBC) mode
  • 14.
  • 15. Let’s build our own decrypter!
  • 16. 16
  • 18.
  • 19. 2048 bytes max XOR static key
  • 20. 20 Nemucod  Asymmetric crypto • RSA-1024  XOR  Unique key generation  255 byte key • Hard-coded • Same for every file  Only the first 2048 bytes  Simple encrypter binary
  • 21. How can we decrypt our files?
  • 22. 22
  • 24.
  • 25.
  • 26. Decompiled view of ctr_encrypt
  • 28. Decompiled view of aes_encrypt
  • 30. 30 TorrentLocker  From limited reverse engineering we know… • AES • Counter (CTR) mode • libtomcrypt  Could this potentially be vulnerable? • Implementation flaws Source: “Counter Mode Security: Analysis and Recommendations”
  • 31. 31 TorrentLocker  A = large plaintext file of NULL bytes • Exhaust keystream (if file size limitation)  B = non-NULL plaintext (arbitrary size < than A)  ENCRYPT(A) = A’  A’ XOR A = KEYSTREAM • A = NULL bytes ∙ XOR A is redundant ・ A’ = KEYSTREAM  ENCRYPT(B) = B’  B’ XOR KEYSTREAM = B How can we test for a flawed AES-CTR implementation?
  • 32. Let’s see if this holds true…
  • 33. 33
  • 34. 34 TorrentLocker  AES  Counter (CTR) mode  Static key  Static IV / nonce  2 MB file size limit  No padding • Need to consider byte alignment and determine block size to cover edge cases
  • 36.
  • 37.  After viewing ciphertexts spanning multiple file types, a magic byte sequence reveals itself • 77 2A 3C D0
  • 38.  After encrypting a chosen plaintext containing solely null bytes • Appears to be some repetition
  • 39. 39 Apocalypse  Magic byte sequence  Repetition in ciphertext • Produced from NULL byte plaintext  Ransom note doesn’t mention encryption type  Let’s proceed with reverse engineering…
  • 40.  Text search in IDA Pro for XOR operations • Most XORs just clearing out registers, but two stick out in sub_40108 • Good place to start, but it’s not always this easy
  • 41.  The two XORs of interest are looped over  Appears that the previously identified magic byte sequence is written by the first WriteFile call  Second WriteFile writes out the transformed buffer containing the presumably encrypted data
  • 42.
  • 43.
  • 44. Let’s test out the script…
  • 45. 45
  • 46. 46 Research in the Field  Tracking and reverse engineering new variants  Developing and releasing decrypters for free  BleepingComputer forums • BloodDolly  @malwarehunterteam • http://id-ransomware.malwarehunterteam.com  @malwaretech • WannaCry killswitch • https://www.malwaretech.com  @demonslay335  … and many others! Despite proliferation, researchers have kept pace
  • 47. 47 Conclusion  Crypto implementation issues prevalent • “Crypto is hard”  Ransom notes are not trustworthy for technical specs • Don’t believe the hype  RE and cryptanalysis / decrypter dev are not linear processes • Known / chosen plaintext attacks • Trial and error • Focus on sections where modifications occur, then dig deeper for more clues • Build out POC, then stress test and harden as needed to cover all edge cases
  • 48. Thanks! Twitter - @magerbomb E-mail - mager@endgame.com