SlideShare a Scribd company logo
1 of 70
Protect Your Payloads:
Modern Keying Techniques
Leo Loobeek
• Senior Consultant @ Protiviti
• Execute penetration testing, red teams, etc.
• Enjoy custom implant and tool development
• Casually blog at adapt-and-attack.com
• Not a crypto expert
About Me
• Current Landscape
• Keying Review and Advantages
• Keying With Remote Resources
• Tie It Together
Agenda
Defense is getting better…
Endpoint
Security (EDR)
Sandboxing
Innovative
Tooling
VirusTotal,
Clouds, ML
Threat
Hunting
Improved
Methodologies
Detection
Capabilities
Researchers
Eventually, you WILL get caught and your remote access code WILL be analyzed…
• Command And Control
• Method (HTTP, DNS)
• Server Addresses
• Initial Execution Behavior
• Launching another process?
• Using injection? Process hollowing?
• Endpoint telemetry may catch this, may not…
• Custom Implant
Attacker Crown Jewels
• VBA – Macros
• JScript/VBScript – HTA, SCT, XSL
• PowerShell – oneliner everywhere
• C# - MSBuild, DotNetToJScript , ClickOnce
• DLL/Shellcode injection typically executed from
above
Scripting Languages (and C#)
Ever think about *what* key data points you lose
control of the moment you send that phishing email?
Ever think about *who* will see those key data
points?
Find more on #DailyScriptlet
• Advantages
• Great technique to defeat automated solutions
• Can slow down defender analysis
• Disadvantages
• Can eventually be reversed once obfuscation is
understood
• Behavior analysis, sandboxing, etc. may reveal behaviors
• can be limited if anti-analysis is included before obfuscation
‘Obfus’ + ‘cation’
@danielhbohannon and @cobbr_io good people to follow for obfuscation-fu!
Enter Key Derivation
Functions (keying)
• Keying is the idea of encrypting your payloads and using
local and remote resources to build the decryption key.
• These "resources" could be environmental variables on
the victim's workstation, HTML source of a web page, or
a specific computer name in Active Directory.
When an attacker is using this strategy, they may need to
discover information in order to encrypt the payload
properly.
What Is Keying?
• Back in 2016, Josh Pitts (@midnite_runr) and Travis
Morrow (@wired33) presented about this technique
• They released a tool: https://github.com/Genetic-
Malware/Ebowla
• Discussed previous academic studies on the topic
dating back to 1998
• Discussed Gauss – a real world example of malware
using keying in 2012
This is not new
• It still works GREAT
• Encrypts your DLLs, EXEs, shellcode, Python,
PowerShell
• Gives you binaries created from Go/Python, or
PowerShell
• Thanks to Josh and Travis on pushing these
techniques forward to the industry
Ebowla Is Awesome
• Keying is needed now more than ever
• Share my experiences and use cases
• Common Responses:
• “Oh yeah, that technique sounds useful for bypassing
sandboxes”
• “It’s a cool idea but it seems like a lot of work”
• “I don’t get it”
• “Yeah we use it, we have [X] technique that works really
well for us”
So Why am I Here?
Check out the Genetic Malware talks by Josh and
Travis for more in-depth understanding...
Slides:
https://github.com/Genetic-Malware/Ebowla
Video of ekoparty12 presentation:
https://www.youtube.com/watch?v=WI8Y24jTTlw
Keying Review
• Attacker is targeting a specific VP of E-Corp
and through OSINT has discovered
• He uses Microsoft Project
C:Program FilesMicrosoft Officeoffice15winproj.exe
• His username is JDoe
• Attacker wants to encrypt his payload so it only
executes on target’s workstation
Keying Review
Create Encrypted Data -
1. Hash the key data
“C:Program FilesMicrosoft Officeoffice15winproj.exeJDoe”
2. Use first 32 characters as encryption key
3. Encrypt payload with key
Keying Review
Create Keyed Payload -
1. Create functions to retrieve key data
- Get environment variable for “USERNAME”
- Get all paths under “C:Program Files”
2. Loop through all key data and hash each possible key
3. Attempt to decrypt with each key hash
Keying Review
HashOf(“C:Program FilesApplication Verifier” + “JDoe”)
HashOf(“C:Program FilesApplication Verifiervrfauto.dll” + “JDoe”)
…
HashOf(“C:Program FilesMicrosoft Office” + “JDoe”)
HashOf(“C:Program FilesMicrosoft Officeoffice15” + “JDoe”)
HashOf(“C:Program FilesMicrosoft Officeoffice15excel.exe” + “JDoe”)
HashOf(“C:Program FilesMicrosoft Officeoffice15msproj.exe” + “JDoe”)
Keying Review
• The following data carries over to the payload:
• Method(s) to retrieve key values
• The following data does not carry over to the
payload:
• The actual values (“JDoe”, MS Project file path)
• Original payload
Information Disclosed In Final Payload
• This is payload is now target specific and should have
difficulty running on sandboxes, VirusTotal, and
incident responder’s analysis systems
• Difficult to determine the target if sent to all VPs at
E-Corp
Keying Review - Takeaways
• Ebowla outputs to a compiled binary generated from
Python or Go
• This is ideal: would require serious analysis and reversing
to determine that the payload is using keying techniques
• Keying use in text-based payloads are subject to
quicker analysis with direct access to source code
Compiled vs Scripting
• What does a responder do when they see the
following being used as a key:
[Environment]::GetEnvironmentVariable("USERNAME")
[Environment]::GetEnvironmentVariable(“COMPUTERNAME")
[Environment]::GetEnvironmentVariable(“USERDNSDOMAIN")
• Sent through phishing? Find all recipients of the
email, compile the list, and try each one until it
executes.
• Found as persistence? Well, we know where to get
the environment variables…
Scripting Downsides
• Get all possible combinations of those three
environment variables
• Upside of combinations: possible blank values!
• If USERNAME=leo, COMPUTERNAME=pc, and
USERDNSDOMAIN=ecorp
Combinations
leopcecorp
leopc
leoecorp
leo
pcecorp
pc
ecorp
• What if E-Corp saw this..?
combos = new array()
combos += GetEnvionVar(“COMPUTERNAME”)
combos += GetEnvironVar(“USERNAME”)
combos += GetTime()
combos += GetSIDOfUser()
combos += GetIPAddressOf(“intranet.tesla.com”)
combos = GenerateCombinations(combos)
Combinations
• What if E-Corp saw this..?
combos = new array()
combos += GetEnvionVar(“COMPUTERNAME”)
combos += GetEnvironVar(“USERNAME”)
combos += GetTime()
combos += GetSIDOfUser()
combos += GetIPAddressOf(“intranet.tesla.com”)
combos = GenerateCombinations(combos)
Combinations
• Builds on the Combinations idea
• Custom key derivation functions
• Allows attackers to come up with new and creative ways
to specifically target remote access code to endpoints
• Allows attackers to still use keying if they haven’t found
data that fits Ebowla
• Currently supports C#, JScript and PowerShell
• JScript does not use DotNetToJScript
Introducing KeyRing
• Combos (string)
• Keying functions that would return one string value
• Ex) environment variables, current time (HH:MM)
• Chains ([]string)
• Keying functions returning one or more strings
• Ex) directory listings, running processes, computer
names in active directory
• Currently supports one chain and unlimited combos
KeyRing Vocabulary
KeyRing Decryption Process
combos = new array()
chains = new array ()
combos += GetEnvionVar(“COMPUTERNAME”)
combos += GetEnvironVar(“USERNAME”)
combos += GetTime()
chains = GetRunningProcesses()
combos = GenerateCombinations(combos)
for chain in chains {
for combo in combos {
tryDecryption(path, user, payload, payloadHash)
}
}
• More combinations, larger chains…
Keying Considerations
Longer execution
CPU may spike
Fan noise
Hard to determine
final key
KeyRing Demo
We still don’t have much control...
Could This Be Better?
Keying Using Remote
Resources
• If the payload also went to retrieve remote
resources, we could control those resources
(ex: HTTP)
• If we can control the data on those remote
endpoints, we can effectively “turn on” and “turn
off” those resources
• This returns control to the attacker: YOU choose
when your payload executes and when it doesn’t
Adding Remote Resources to Your Keys
• Back in 2015, Alex Rymdeko-Harvey (@Killswitch_GUI)
and Chris Truncer (@christruncer) put together an HTTP
Key module for Veil
https://www.veil-framework.com/framework/veil-
evasion/
• This is no longer a part of the Veil project
• Alex’s original blog post is no longer up
https://web.archive.org/web/20161001104512/http://cybersyndicates.com
:80/2015/06/veil-evasion-aes-encrypted-httpkey-request-module/
This also is not new
HTTP Key
Key Server C2 Server
www.site1.com www.site2.com
GET /content/dashboard.html
HTTP Key
Key Server C2 Server
www.site1.com www.site2.com
Expected HTML returned…
HTTP Key
Key Server C2 Server
www.site1.com www.site2.com
C2 Session Established
HTTP Key
Key Server C2 Server
www.site1.com www.site2.com
Benign HTML returned…
HTTP Key
Key Server C2 Server
www.site1.com www.site2.com
Nothing Happens
DNS Key with TXT Record
• Use benign response, send phish, wait an hour,
replace benign response
• Replace expected page with benign page
immediately after execution
• May never be decrypted again
• Monitor logs for access attempts to the URL/DNS
record to detect incident response
Use Cases
• KeyServer is DNS and HTTP keying made easy
• Easily turn the keys “on” or “off”
• Greppable logs
• Alerts for Slack and Email
• Built to be behind Apache mod_rewrite
Introducing KeyServer
• Use Constraints to automate switching the key status
Turn key on between 09:59am and 10:01am
or
Turn key off after it has been accessed once
or
Turn key on once access has been attempted 20 times
or…
KeyServer Constraints
• KeyRing includes code to generate HTTP keying for
C#, PowerShell, and JScript
• KeyRing includes code to generate DNS keying for C#
• Uses Pinvoke for DNS queries
• Thanks to @Arno0x0x for
https://github.com/Arno0x/DNSExfiltrator
• DNS and HTTP keying are “Combos” in KeyRing
terms
KeyRing+KeyServer
KeyServer Demo
Phishin’ With HTTP Key
Payload + Key Server C2 Server (empire)
www.fakederbycon.com webmail.stealthyc2.com
GET /freetix
GET /dave/kennedy.html
1
2
IR Detection with DNS Key
Key Server C2 Server (empire)
keyserver.site webmail.stealthyc2.com
In-Memory w/High Delay
Persistence on
user workstation
AB
Using KeyServer in the “Wild”
Using KeyServer in the “Wild”
• I still lost my KeyServer domain
• How could it be better?
Original Payload
Encrypt with HTTP/DNS key
Encrypt with other keying
Could’ve Done Better…
If Blue Team blocks KeyServer IP/domain/URL, payload
won’t execute and you will lose access if you don’t
have other methods of persistence
Important Note
My Motivations and How I’ve
Used Keying
• Several detection techniques that continue to scare me…
• Improvements to in-memory detection capabilities
(CreateRemoteThread, etc.)
• Abnormal binaries initiating network connections – Sysmon
EID 3
• PowerShell and command line logging
And why are these finally getting the attention they
deserve?
Odds Are In Defenders Favor
All Tradecraft About In-Memory
• If I don’t feel 100% comfortable attempting to get
my payload directly into memory…
Let’s drop things to disk! With keying techniques, I feel
comfortable doing this again
Droppin’ Files To Disk
Obfuscate Original Payload
Encrypt with Keying Techniques
Obfuscate Encrypted Payload
Obfuscation Still Needed
• Prepare a C# dropper
• Implant will use InternetExplorer.Application COM object
for web requests to C2 server
• Get an HTA file onto disk
• Use DotNetToJScript to get C# over to JScript
• Use keying to encrypt DotNetToJScript output
• Embed inside HTA file
• Find a way to execute “mshta.exe
C:fullpathtofile.hta”
Here’s A Reliable Go-To…
• No network connections initiated from anywhere but
Internet Explorer or Edge
• Mshta.exe is a signed binary
• All interesting behaviors still occur in memory
• Everyone’s looking for “mshta.exe https://...”
• https://attack.mitre.org/wiki/Technique/T1170
• Bonus: Not a console application, fits nicely with scheduled
tasks
• Downside: Mshta.exe execution itself may set of alarms
The Advantages
Closing Thoughts
• Understand the whole file’s behaviors
• Look for encryption/decryption functions
• Be careful interacting with attacker infrastructure
• Be careful running a file to analyze
• Avoid VirusTotal uploads if possible
Defense
• Highly recommend implementing forms of Keying
throughout your offensive operations
• Please Key Responsibly…
Hide your remote access code and behaviors as much
as possible during the exercise, but share your
behaviors and IoCs after the exercise.
Conclusion
• KeyRing
https://github.com/leoloobeek/KeyRing
• KeyServer
https://github.com/leoloobeek/KeyServer
• Let me know if you have questions or problems on
GitHub or @leoloobeek
Tools
Questions?

More Related Content

What's hot

Windows Operating System Archaeology
Windows Operating System ArchaeologyWindows Operating System Archaeology
Windows Operating System Archaeologyenigma0x3
 
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourWAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourSoroush Dalili
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程Weber Tsai
 
PowerShell for Practical Purple Teaming
PowerShell for Practical Purple TeamingPowerShell for Practical Purple Teaming
PowerShell for Practical Purple TeamingNikhil Mittal
 
(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory PwnagePetros Koutroumpis
 
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...Daniel Bohannon
 
.NET Core 3.0時代のメモリ管理
.NET Core 3.0時代のメモリ管理.NET Core 3.0時代のメモリ管理
.NET Core 3.0時代のメモリ管理KageShiron
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.Mikhail Egorov
 
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback흥배 최
 
C# Game Server
C# Game ServerC# Game Server
C# Game Serverlactrious
 
Hunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows EnvironmentHunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows EnvironmentTeymur Kheirkhabarov
 
Integration testing with spring @snow one
Integration testing with spring @snow oneIntegration testing with spring @snow one
Integration testing with spring @snow oneVictor Rentea
 
xv6のコンテキストスイッチを読む
xv6のコンテキストスイッチを読むxv6のコンテキストスイッチを読む
xv6のコンテキストスイッチを読むmfumi
 
Reverse proxies & Inconsistency
Reverse proxies & InconsistencyReverse proxies & Inconsistency
Reverse proxies & InconsistencyGreenD0g
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심흥배 최
 
Lightweight static code analysis with semgrep
Lightweight static code analysis with semgrepLightweight static code analysis with semgrep
Lightweight static code analysis with semgrepNull Bhubaneswar
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by defaultSecuRing
 
Vault - Secret and Key Management
Vault - Secret and Key ManagementVault - Secret and Key Management
Vault - Secret and Key ManagementAnthony Ikeda
 

What's hot (20)

Windows Operating System Archaeology
Windows Operating System ArchaeologyWindows Operating System Archaeology
Windows Operating System Archaeology
 
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ BehaviourWAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
 
TDOH x 台科 pwn課程
TDOH x 台科 pwn課程TDOH x 台科 pwn課程
TDOH x 台科 pwn課程
 
PowerShell for Practical Purple Teaming
PowerShell for Practical Purple TeamingPowerShell for Practical Purple Teaming
PowerShell for Practical Purple Teaming
 
(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage
 
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
Invoke-CradleCrafter: Moar PowerShell obFUsk8tion & Detection (@('Tech','niqu...
 
Pentesting ReST API
Pentesting ReST APIPentesting ReST API
Pentesting ReST API
 
.NET Core 3.0時代のメモリ管理
.NET Core 3.0時代のメモリ管理.NET Core 3.0時代のメモリ管理
.NET Core 3.0時代のメモリ管理
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
 
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback
잘 알려지지 않은 숨은 진주, Winsock API - WSAPoll, Fast Loopback
 
C# Game Server
C# Game ServerC# Game Server
C# Game Server
 
SSRF workshop
SSRF workshop SSRF workshop
SSRF workshop
 
Hunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows EnvironmentHunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows Environment
 
Integration testing with spring @snow one
Integration testing with spring @snow oneIntegration testing with spring @snow one
Integration testing with spring @snow one
 
xv6のコンテキストスイッチを読む
xv6のコンテキストスイッチを読むxv6のコンテキストスイッチを読む
xv6のコンテキストスイッチを読む
 
Reverse proxies & Inconsistency
Reverse proxies & InconsistencyReverse proxies & Inconsistency
Reverse proxies & Inconsistency
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심
 
Lightweight static code analysis with semgrep
Lightweight static code analysis with semgrepLightweight static code analysis with semgrep
Lightweight static code analysis with semgrep
 
Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
 
Vault - Secret and Key Management
Vault - Secret and Key ManagementVault - Secret and Key Management
Vault - Secret and Key Management
 

Similar to Protect Your Payloads: Modern Keying Techniques

Python and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementPython and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementLaurent Leturgez
 
13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applicationsKarthik Gaekwad
 
The Web Application Hackers Toolchain
The Web Application Hackers ToolchainThe Web Application Hackers Toolchain
The Web Application Hackers Toolchainjasonhaddix
 
Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Daniel Bohannon
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Jim Manico
 
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malwareDefcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malwarePriyanka Aash
 
OWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript ApplicationsOWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript ApplicationsLewis Ardern
 
[CB16] Invoke-Obfuscation: PowerShell obFUsk8tion Techniques & How To (Try To...
[CB16] Invoke-Obfuscation: PowerShell obFUsk8tion Techniques & How To (Try To...[CB16] Invoke-Obfuscation: PowerShell obFUsk8tion Techniques & How To (Try To...
[CB16] Invoke-Obfuscation: PowerShell obFUsk8tion Techniques & How To (Try To...CODE BLUE
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...Hackito Ergo Sum
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchMats Bryntse
 
Android lessons you won't learn in school
Android lessons you won't learn in schoolAndroid lessons you won't learn in school
Android lessons you won't learn in schoolMichael Galpin
 
Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...Sysdig
 
Road to Opscon (Pisa '15) - DevOoops
Road to Opscon (Pisa '15) - DevOoopsRoad to Opscon (Pisa '15) - DevOoops
Road to Opscon (Pisa '15) - DevOoopsGianluca Varisco
 
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Scott Keck-Warren
 
How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)Larry Cashdollar
 
Open source security
Open source securityOpen source security
Open source securitylrigknat
 
BSIDES-PR Keynote Hunting for Bad Guys
BSIDES-PR Keynote Hunting for Bad GuysBSIDES-PR Keynote Hunting for Bad Guys
BSIDES-PR Keynote Hunting for Bad GuysJoff Thyer
 
Learn Electron for Web Developers
Learn Electron for Web DevelopersLearn Electron for Web Developers
Learn Electron for Web DevelopersKyle Cearley
 

Similar to Protect Your Payloads: Modern Keying Techniques (20)

Python and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementPython and Oracle : allies for best of data management
Python and Oracle : allies for best of data management
 
13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications
 
The Web Application Hackers Toolchain
The Web Application Hackers ToolchainThe Web Application Hackers Toolchain
The Web Application Hackers Toolchain
 
Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017
 
Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2
 
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malwareDefcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
 
OWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript ApplicationsOWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript Applications
 
[CB16] Invoke-Obfuscation: PowerShell obFUsk8tion Techniques & How To (Try To...
[CB16] Invoke-Obfuscation: PowerShell obFUsk8tion Techniques & How To (Try To...[CB16] Invoke-Obfuscation: PowerShell obFUsk8tion Techniques & How To (Try To...
[CB16] Invoke-Obfuscation: PowerShell obFUsk8tion Techniques & How To (Try To...
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
Android lessons you won't learn in school
Android lessons you won't learn in schoolAndroid lessons you won't learn in school
Android lessons you won't learn in school
 
Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...
 
Road to Opscon (Pisa '15) - DevOoops
Road to Opscon (Pisa '15) - DevOoopsRoad to Opscon (Pisa '15) - DevOoops
Road to Opscon (Pisa '15) - DevOoops
 
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023
 
How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)
 
Open source security
Open source securityOpen source security
Open source security
 
BSIDES-PR Keynote Hunting for Bad Guys
BSIDES-PR Keynote Hunting for Bad GuysBSIDES-PR Keynote Hunting for Bad Guys
BSIDES-PR Keynote Hunting for Bad Guys
 
Learn Electron for Web Developers
Learn Electron for Web DevelopersLearn Electron for Web Developers
Learn Electron for Web Developers
 

Recently uploaded

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Protect Your Payloads: Modern Keying Techniques

  • 1. Protect Your Payloads: Modern Keying Techniques Leo Loobeek
  • 2. • Senior Consultant @ Protiviti • Execute penetration testing, red teams, etc. • Enjoy custom implant and tool development • Casually blog at adapt-and-attack.com • Not a crypto expert About Me
  • 3. • Current Landscape • Keying Review and Advantages • Keying With Remote Resources • Tie It Together Agenda
  • 4. Defense is getting better… Endpoint Security (EDR) Sandboxing Innovative Tooling VirusTotal, Clouds, ML Threat Hunting Improved Methodologies Detection Capabilities Researchers Eventually, you WILL get caught and your remote access code WILL be analyzed…
  • 5. • Command And Control • Method (HTTP, DNS) • Server Addresses • Initial Execution Behavior • Launching another process? • Using injection? Process hollowing? • Endpoint telemetry may catch this, may not… • Custom Implant Attacker Crown Jewels
  • 6. • VBA – Macros • JScript/VBScript – HTA, SCT, XSL • PowerShell – oneliner everywhere • C# - MSBuild, DotNetToJScript , ClickOnce • DLL/Shellcode injection typically executed from above Scripting Languages (and C#)
  • 7. Ever think about *what* key data points you lose control of the moment you send that phishing email? Ever think about *who* will see those key data points?
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. Find more on #DailyScriptlet
  • 13. • Advantages • Great technique to defeat automated solutions • Can slow down defender analysis • Disadvantages • Can eventually be reversed once obfuscation is understood • Behavior analysis, sandboxing, etc. may reveal behaviors • can be limited if anti-analysis is included before obfuscation ‘Obfus’ + ‘cation’ @danielhbohannon and @cobbr_io good people to follow for obfuscation-fu!
  • 15. • Keying is the idea of encrypting your payloads and using local and remote resources to build the decryption key. • These "resources" could be environmental variables on the victim's workstation, HTML source of a web page, or a specific computer name in Active Directory. When an attacker is using this strategy, they may need to discover information in order to encrypt the payload properly. What Is Keying?
  • 16. • Back in 2016, Josh Pitts (@midnite_runr) and Travis Morrow (@wired33) presented about this technique • They released a tool: https://github.com/Genetic- Malware/Ebowla • Discussed previous academic studies on the topic dating back to 1998 • Discussed Gauss – a real world example of malware using keying in 2012 This is not new
  • 17. • It still works GREAT • Encrypts your DLLs, EXEs, shellcode, Python, PowerShell • Gives you binaries created from Go/Python, or PowerShell • Thanks to Josh and Travis on pushing these techniques forward to the industry Ebowla Is Awesome
  • 18. • Keying is needed now more than ever • Share my experiences and use cases • Common Responses: • “Oh yeah, that technique sounds useful for bypassing sandboxes” • “It’s a cool idea but it seems like a lot of work” • “I don’t get it” • “Yeah we use it, we have [X] technique that works really well for us” So Why am I Here?
  • 19. Check out the Genetic Malware talks by Josh and Travis for more in-depth understanding... Slides: https://github.com/Genetic-Malware/Ebowla Video of ekoparty12 presentation: https://www.youtube.com/watch?v=WI8Y24jTTlw Keying Review
  • 20. • Attacker is targeting a specific VP of E-Corp and through OSINT has discovered • He uses Microsoft Project C:Program FilesMicrosoft Officeoffice15winproj.exe • His username is JDoe • Attacker wants to encrypt his payload so it only executes on target’s workstation Keying Review
  • 21. Create Encrypted Data - 1. Hash the key data “C:Program FilesMicrosoft Officeoffice15winproj.exeJDoe” 2. Use first 32 characters as encryption key 3. Encrypt payload with key Keying Review
  • 22. Create Keyed Payload - 1. Create functions to retrieve key data - Get environment variable for “USERNAME” - Get all paths under “C:Program Files” 2. Loop through all key data and hash each possible key 3. Attempt to decrypt with each key hash Keying Review
  • 23. HashOf(“C:Program FilesApplication Verifier” + “JDoe”) HashOf(“C:Program FilesApplication Verifiervrfauto.dll” + “JDoe”) … HashOf(“C:Program FilesMicrosoft Office” + “JDoe”) HashOf(“C:Program FilesMicrosoft Officeoffice15” + “JDoe”) HashOf(“C:Program FilesMicrosoft Officeoffice15excel.exe” + “JDoe”) HashOf(“C:Program FilesMicrosoft Officeoffice15msproj.exe” + “JDoe”) Keying Review
  • 24. • The following data carries over to the payload: • Method(s) to retrieve key values • The following data does not carry over to the payload: • The actual values (“JDoe”, MS Project file path) • Original payload Information Disclosed In Final Payload
  • 25. • This is payload is now target specific and should have difficulty running on sandboxes, VirusTotal, and incident responder’s analysis systems • Difficult to determine the target if sent to all VPs at E-Corp Keying Review - Takeaways
  • 26. • Ebowla outputs to a compiled binary generated from Python or Go • This is ideal: would require serious analysis and reversing to determine that the payload is using keying techniques • Keying use in text-based payloads are subject to quicker analysis with direct access to source code Compiled vs Scripting
  • 27. • What does a responder do when they see the following being used as a key: [Environment]::GetEnvironmentVariable("USERNAME") [Environment]::GetEnvironmentVariable(“COMPUTERNAME") [Environment]::GetEnvironmentVariable(“USERDNSDOMAIN") • Sent through phishing? Find all recipients of the email, compile the list, and try each one until it executes. • Found as persistence? Well, we know where to get the environment variables… Scripting Downsides
  • 28. • Get all possible combinations of those three environment variables • Upside of combinations: possible blank values! • If USERNAME=leo, COMPUTERNAME=pc, and USERDNSDOMAIN=ecorp Combinations leopcecorp leopc leoecorp leo pcecorp pc ecorp
  • 29. • What if E-Corp saw this..? combos = new array() combos += GetEnvionVar(“COMPUTERNAME”) combos += GetEnvironVar(“USERNAME”) combos += GetTime() combos += GetSIDOfUser() combos += GetIPAddressOf(“intranet.tesla.com”) combos = GenerateCombinations(combos) Combinations
  • 30. • What if E-Corp saw this..? combos = new array() combos += GetEnvionVar(“COMPUTERNAME”) combos += GetEnvironVar(“USERNAME”) combos += GetTime() combos += GetSIDOfUser() combos += GetIPAddressOf(“intranet.tesla.com”) combos = GenerateCombinations(combos) Combinations
  • 31. • Builds on the Combinations idea • Custom key derivation functions • Allows attackers to come up with new and creative ways to specifically target remote access code to endpoints • Allows attackers to still use keying if they haven’t found data that fits Ebowla • Currently supports C#, JScript and PowerShell • JScript does not use DotNetToJScript Introducing KeyRing
  • 32. • Combos (string) • Keying functions that would return one string value • Ex) environment variables, current time (HH:MM) • Chains ([]string) • Keying functions returning one or more strings • Ex) directory listings, running processes, computer names in active directory • Currently supports one chain and unlimited combos KeyRing Vocabulary
  • 33. KeyRing Decryption Process combos = new array() chains = new array () combos += GetEnvionVar(“COMPUTERNAME”) combos += GetEnvironVar(“USERNAME”) combos += GetTime() chains = GetRunningProcesses() combos = GenerateCombinations(combos) for chain in chains { for combo in combos { tryDecryption(path, user, payload, payloadHash) } }
  • 34. • More combinations, larger chains… Keying Considerations Longer execution CPU may spike Fan noise Hard to determine final key
  • 36. We still don’t have much control... Could This Be Better?
  • 38. • If the payload also went to retrieve remote resources, we could control those resources (ex: HTTP) • If we can control the data on those remote endpoints, we can effectively “turn on” and “turn off” those resources • This returns control to the attacker: YOU choose when your payload executes and when it doesn’t Adding Remote Resources to Your Keys
  • 39. • Back in 2015, Alex Rymdeko-Harvey (@Killswitch_GUI) and Chris Truncer (@christruncer) put together an HTTP Key module for Veil https://www.veil-framework.com/framework/veil- evasion/ • This is no longer a part of the Veil project • Alex’s original blog post is no longer up https://web.archive.org/web/20161001104512/http://cybersyndicates.com :80/2015/06/veil-evasion-aes-encrypted-httpkey-request-module/ This also is not new
  • 40. HTTP Key Key Server C2 Server www.site1.com www.site2.com GET /content/dashboard.html
  • 41. HTTP Key Key Server C2 Server www.site1.com www.site2.com Expected HTML returned…
  • 42. HTTP Key Key Server C2 Server www.site1.com www.site2.com C2 Session Established
  • 43. HTTP Key Key Server C2 Server www.site1.com www.site2.com Benign HTML returned…
  • 44. HTTP Key Key Server C2 Server www.site1.com www.site2.com Nothing Happens
  • 45. DNS Key with TXT Record
  • 46. • Use benign response, send phish, wait an hour, replace benign response • Replace expected page with benign page immediately after execution • May never be decrypted again • Monitor logs for access attempts to the URL/DNS record to detect incident response Use Cases
  • 47. • KeyServer is DNS and HTTP keying made easy • Easily turn the keys “on” or “off” • Greppable logs • Alerts for Slack and Email • Built to be behind Apache mod_rewrite Introducing KeyServer
  • 48. • Use Constraints to automate switching the key status Turn key on between 09:59am and 10:01am or Turn key off after it has been accessed once or Turn key on once access has been attempted 20 times or… KeyServer Constraints
  • 49. • KeyRing includes code to generate HTTP keying for C#, PowerShell, and JScript • KeyRing includes code to generate DNS keying for C# • Uses Pinvoke for DNS queries • Thanks to @Arno0x0x for https://github.com/Arno0x/DNSExfiltrator • DNS and HTTP keying are “Combos” in KeyRing terms KeyRing+KeyServer
  • 51. Phishin’ With HTTP Key Payload + Key Server C2 Server (empire) www.fakederbycon.com webmail.stealthyc2.com GET /freetix GET /dave/kennedy.html 1 2
  • 52. IR Detection with DNS Key Key Server C2 Server (empire) keyserver.site webmail.stealthyc2.com In-Memory w/High Delay Persistence on user workstation AB
  • 53. Using KeyServer in the “Wild”
  • 54. Using KeyServer in the “Wild”
  • 55. • I still lost my KeyServer domain • How could it be better? Original Payload Encrypt with HTTP/DNS key Encrypt with other keying Could’ve Done Better…
  • 56.
  • 57.
  • 58. If Blue Team blocks KeyServer IP/domain/URL, payload won’t execute and you will lose access if you don’t have other methods of persistence Important Note
  • 59. My Motivations and How I’ve Used Keying
  • 60. • Several detection techniques that continue to scare me… • Improvements to in-memory detection capabilities (CreateRemoteThread, etc.) • Abnormal binaries initiating network connections – Sysmon EID 3 • PowerShell and command line logging And why are these finally getting the attention they deserve? Odds Are In Defenders Favor
  • 61. All Tradecraft About In-Memory
  • 62. • If I don’t feel 100% comfortable attempting to get my payload directly into memory… Let’s drop things to disk! With keying techniques, I feel comfortable doing this again Droppin’ Files To Disk
  • 63. Obfuscate Original Payload Encrypt with Keying Techniques Obfuscate Encrypted Payload Obfuscation Still Needed
  • 64. • Prepare a C# dropper • Implant will use InternetExplorer.Application COM object for web requests to C2 server • Get an HTA file onto disk • Use DotNetToJScript to get C# over to JScript • Use keying to encrypt DotNetToJScript output • Embed inside HTA file • Find a way to execute “mshta.exe C:fullpathtofile.hta” Here’s A Reliable Go-To…
  • 65. • No network connections initiated from anywhere but Internet Explorer or Edge • Mshta.exe is a signed binary • All interesting behaviors still occur in memory • Everyone’s looking for “mshta.exe https://...” • https://attack.mitre.org/wiki/Technique/T1170 • Bonus: Not a console application, fits nicely with scheduled tasks • Downside: Mshta.exe execution itself may set of alarms The Advantages
  • 67. • Understand the whole file’s behaviors • Look for encryption/decryption functions • Be careful interacting with attacker infrastructure • Be careful running a file to analyze • Avoid VirusTotal uploads if possible Defense
  • 68. • Highly recommend implementing forms of Keying throughout your offensive operations • Please Key Responsibly… Hide your remote access code and behaviors as much as possible during the exercise, but share your behaviors and IoCs after the exercise. Conclusion
  • 69. • KeyRing https://github.com/leoloobeek/KeyRing • KeyServer https://github.com/leoloobeek/KeyServer • Let me know if you have questions or problems on GitHub or @leoloobeek Tools

Editor's Notes

  1. Warning: I’m not a crypto expert so you don’t have to expect any crazy math in this talk, but what is on the docket is...
  2. I think we can all agree that defense is getting better...
  3. As attackers, we have crown jewels too. Command and control – this one is the most obvious and applies to everyone. Defenders finding your C2 method and C2 servers is worst case scenario. Yes, red team infrastructure deployments with long haul and different C2s can help, but still not ideal. Execution behavior – In more advanced techniques, you may be using a more complex execution behavior rather than just executing an empire stager with powershell.exe. This information could help the targeted organization find other infections or this could burn your latest evasion method. Endpoint telemetry may already reveal all of this, with Carbon Black and others. It may not, or it may not reveal the “how” Custom Implant – More and more places are moving towards custom implants and c2 frameworks. This was actually my own personal motivator. Losing our custom remote access code, even if its just a dropper, is a concern. Real attackers agree.
  4. Phishing is the most common method to get remote access code executed on a remote victim, so most of this presentation will come from that point of view.
  5. Two questions that I frankly didn’t really think about my first few years as a pentester.
  6. Key data points lost here…. C2 server Using PowerShell Empire (the payload structure is obviously from Empire) The macro wrote out a file to the user’s temp folder called And this isn’t just PowerShell.
  7. Lets talk about obfuscation…
  8. This idea I’m about to present about is not new, its actually quite “old”. Its been around for a few years, and actually the presenters showed some academic research from back in 1998.
  9. Ebowla is pretty awesome, and still works great. If you’ve used it at all in the past few years, you’ll notice AVs still have a really hard time putting a signature on what they’re doing.
  10. With heightened defense awareness, improving tools, and the number of prying eyes these days, keying is needed now more than ever. Especially with a constant push and discussion around custom implants and new techniques to bypass these improving defensive tools.
  11. I think a necessary discussion with keying is around compiled vs scripting payloads....
  12. Combinations can help us here mask what exactly are being used as the key Using ordered combinations, not permutations, we can generate more key values to test with A big upside to combinations, is when generating it will try each with a blank value as well
  13. The code here we start with creating a chain and combo array Then we add to the combos and chain arrays by calling various functions Getting environment variables and time for combos And getting all running processes on the system into chains We then generate all combinations of all the combo values Finally, we loop through each chain, and for each chain we tack on each combo
  14. Now that we have all these chains and combos to choose from, we need to talk a bit about keying considerations
  15. The HTTP key module essentially allowed veil to encrypt a payload based on specific HTML, then you host the HTML on a website. The payload would then reach out to the website, take the HTML, hash it, and try and decrypt.
  16. REMOVE THE A RECORD STUFF
  17. REPLACE SERVER WITH ‘A’ Add dotted line from ‘2’ to C2 server
  18. Obfuscation definitely still needed.. Especially if KeyRing code gets used eventually it will get signatured and obfuscation will be required. AMSI and scriptblock logging some other reasons why its still needed, for example, if using PowerShell the decrypted code will hit the
  19. So, here’s an example of how I’ve applied this new line of thinking and using keying techniques, by burning one of my go to techniques I’ve used here and there for the past 18 months or so.
  20. Even on MITRE ATT&CK, it only shows example detections that include mshta execution using an HTA on an HTTP server. This was the case with regsvr32 executions.
  21. There’s no specific appliance or technique that will detect keyed payloads, obviously, but here’s some ideas for the defense nonetheless…