SlideShare a Scribd company logo
1 of 43
Download to read offline
macOS Vulnerabilities Hiding in
Plain Sight
Csaba Fitzl


Twitter: @theevilbit
whoami
• lead content developer of "macOS Control Bypasses" @
Offensive Security


• macOS bug hunter


• ex red/blue teamer


• husband, father


• hiking, trail running 🥾 🏔 🏃
Agenda
• Intro


• CVE-2021-1815 - macOS local privilege escalation via Preferences


• CVE-2021-30972 - TCC bypass


• CVE-2022-32780 - Sandbox escape via disk arbitration


• for each CVE:


• technical background


• original vulnerability and exploit


• new vulnerability and exploit
INTRO
• "can't see the forest for the trees"


• we are so focused on something, that we can easily miss some details


• rush in reading stuff online
INTRO
• I tend to read the same articles again and again


• I found three vulnerabilities in published writeups


• not for the
fi
rst read, but probably 10th, 20th or even 30th
CVE-2021-1815 - macOS local
privilege escalation via Preferences
cfprefsd
• core foundation preferences daemon


• sets/stores and retrieves preferences for apps


• 2 instances: user, system


• interact: Preferences API or direct XPC ()
original vulnerability
• pwn2own 2020 - 6 step exploit chain to
pwn macOS (Yonghwi Jin, Jungwon Lim,
Insu Yun, and Taesoo Kim)


• LPE via cfprefsd


• allowed change ownership of arbitrary
folder
original exploit
• race with symlink


• change ownership of /etc/pam.d


• update sudo pam con
fi
g


• get root without password
Apple's
fi
x
• reversed by the pwn2own team


• ensures symlinks are no longer
followed (O_NOFOLLOW)
the issue
• although the symlink issue is solved


• a directory is still created


• and ownership set


• ==> we can create a directory
anywhere and set the user as the
owner
exploit method #1
• periodic scripts: executed daily/weekly/
monthly


• con
fi
g: /etc/defaults/periodic.conf


• the "local" directory is empty by default


• won't work beyond 11.5 (see: https://
theevilbit.github.io/beyond/
beyond_0019/)


• slow :( getting root can take up to a day
demo
exploit method #2
• sysdiagnose runs as root


• it executes binaries from /usr/local/bin
(doesn't exists by default)


• some of these have been remediated
because of homebrew


• not perfect - depends on user trigger:


• Feedback Assistant


• manually invoke


• keyboard shortcut: Command + Option
+ Shift+ Control + Period (.)
CVE-2021-30972 - TCC
bypass
TCC
• security feature to control access to
privacy related resources


• sqlite3 database (except: private
entitlements, macl extended
attribute) - (~)/Library/Application
Support/com.apple.TCC/TCC.db


• for more: talk (20+ Ways to Bypass
Your macOS Privacy Mechanisms),
posts by Wojciech Regula and myself
CVE-2021-30713 - TCC bypass by XCSSET
Source: JAMF
• XCSSET malware TCC bypass 0day


• discovered by JAMF


• malicious app is hosted inside a
bundle, which has TCC
permissions


• macOS wrongly identi
fi
es the
bundle (hint!!!)
CVE-2021-30798 - TCC Bypass Again, Inspired By
XCSSET
• found by Mickey Jin


• TCC db contains only bundle
ID


• simply fake the bundle ID in
the app


• system performs code sign
check on the real bundle
(hint!!!)
problem?
• the TCC.db does store the csreq info


• none of the fake processes had proper code signature


• the bypass in both cases was possible because: binaries on disk were veri
fi
ed


• WUT????


• on macOS: you can modify app binaries on disk even when they run (unlike
in Windows)
elsewhere?
• in every other case*, code signature is veri
fi
ed in memory


• *except GateKeeper/am
fi
d when the app is launched, because there is no
process yet


• XPC / Mach connections


• should use audit token


• even PID is insecure


• on-disk? not even an option 🤣


• in-memory integrity check by AMFI
CVE-2021-30972 - TCC bypass again
1. Make a fake app with the same bundle ID
and name as the one we want to
impersonate, and place it in an arbitrary
location


2. Start the app


3. Copy the original app over the fake app


4. Initiate an action which requires privacy
permissions


5. TCC is bypassed, with inheriting the original
app's rights
CVE-2021-30972 - Wojciech's version
1. Make a fake app, and embed in a "donor" app (use the same team ID)


2. Start the app


3. Copy the donor app over the embedded app


4. Initiate an action which requires privacy permissions


5. TCC is bypassed, with inheriting the donor's rights
demo
fi
x
•
fi
nally dynamic code signature is veri
fi
ed
CVE-2022-32780 - Sandbox
escape via Disk Arbitration
diskarbitration - the basics
• system wide service, de
fi
ned in:


• /System/Library/LaunchDaemons/com.apple.diskarbitrationd.plist


• XPC: com.apple.DiskArbitration.diskarbitrationd


• manage disk mounting, unmounting


• calls mount/unmount system calls under the hood
diskarbitration - why we like it?
• runs as root


• unsandboxed


• XPC service accessible from
application sandbox


• opensource
CVE-2017-2533 - LPE via diskarbitrationd
• used by phoenhex team in pwn2own 2017


• DA:


• resolves path -> checks if the user has rights to
mount over directory


• no more checks later


• resolves path -> mounting


• TOCTOU bug, race condition


• exploit: mount the EFI (admin writeable) partition
over crontabs
CVE-2022-32780
• not exactly hidden


• Apple moved the check into
DAServer.c -
"_DAServerSessionQueueRequest"


• extra check for the sandbox
CVE-2022-32780 - old vs new
CVE-2022-32780 - Testing
CVE-2022-32780 - Testing
CVE-2022-32780 - exploitation
• what to mount?


• EFI won't work (can't mount + not
reachable from sandbox)


• custom dmg!


• how? DA works on /dev,
diskmanagementd (can map dmg into /
dev/) is not reachable from sandbox


• 💡use "open"


• we can unmount, /dev/ remains
CVE-2022-32780 - exploitation
• where to mount?


• Terminal Preferences


• ~/Library/Preferences/
com.apple.Terminal.plist


• "CommandString" executed upon
launch
CVE-2022-32780 - full exploit
1. Drops a `dmg`
fi
le


2. It will call `open` to open a `dmg`
fi
le


3. Then it will use the diskarbitration service to unmount it --> at this point we have a custom disk device we
can mount somewhere


4. It will start a thread to alternate the symlink and the directory


5. Then it will start a loop to call the mount operation of the DA service - due to the racer it will eventually
succeed


• we also always unmount the local directory, as we don't need that


6. It will check if we mounted over `Preferences`, and if yes stop


7. Open Terminal
demo
conclusion
conclusion
• it's worth to read write-ups carefully


• it's worth revisiting old docs, notes, code


• it's worth to slow down
Csaba Fitzl


Twitter: @theevilbit
Icons
•
fl
aticon.com


• xnimrodx


• Freepik

More Related Content

What's hot

Scalable and Available, Patterns for Success
Scalable and Available, Patterns for SuccessScalable and Available, Patterns for Success
Scalable and Available, Patterns for Success
Derek Collison
 
DerbyCon 8 - Attacking Azure Environments with PowerShell
DerbyCon 8 - Attacking Azure Environments with PowerShellDerbyCon 8 - Attacking Azure Environments with PowerShell
DerbyCon 8 - Attacking Azure Environments with PowerShell
Karl Fosaaen
 

What's hot (20)

An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
 
Reverse proxies & Inconsistency
Reverse proxies & InconsistencyReverse proxies & Inconsistency
Reverse proxies & Inconsistency
 
Jenkins를 활용한 Openshift CI/CD 구성
Jenkins를 활용한 Openshift CI/CD 구성 Jenkins를 활용한 Openshift CI/CD 구성
Jenkins를 활용한 Openshift CI/CD 구성
 
How fun of privilege escalation Red Pill2017
How fun of privilege escalation  Red Pill2017How fun of privilege escalation  Red Pill2017
How fun of privilege escalation Red Pill2017
 
Deep dive into ssrf
Deep dive into ssrfDeep dive into ssrf
Deep dive into ssrf
 
FAPI and beyond - よりよいセキュリティのために
FAPI and beyond - よりよいセキュリティのためにFAPI and beyond - よりよいセキュリティのために
FAPI and beyond - よりよいセキュリティのために
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
 
Intro to Pentesting Jenkins
Intro to Pentesting JenkinsIntro to Pentesting Jenkins
Intro to Pentesting Jenkins
 
FreeIPA - Attacking the Active Directory of Linux
FreeIPA - Attacking the Active Directory of LinuxFreeIPA - Attacking the Active Directory of Linux
FreeIPA - Attacking the Active Directory of Linux
 
From Zero to Docker
From Zero to DockerFrom Zero to Docker
From Zero to Docker
 
SSRF workshop
SSRF workshop SSRF workshop
SSRF workshop
 
Developer Tutorial: WebAuthn for Web & FIDO2 for Android
Developer Tutorial: WebAuthn for Web & FIDO2 for AndroidDeveloper Tutorial: WebAuthn for Web & FIDO2 for Android
Developer Tutorial: WebAuthn for Web & FIDO2 for Android
 
Vyatta 改造入門
Vyatta 改造入門Vyatta 改造入門
Vyatta 改造入門
 
Docker (Compose) 활용 - 개발 환경 구성하기
Docker (Compose) 활용 - 개발 환경 구성하기Docker (Compose) 활용 - 개발 환경 구성하기
Docker (Compose) 활용 - 개발 환경 구성하기
 
Transparent Encryption in HDFS
Transparent Encryption in HDFSTransparent Encryption in HDFS
Transparent Encryption in HDFS
 
鯨物語~Dockerコンテナとオーケストレーションの理解
鯨物語~Dockerコンテナとオーケストレーションの理解鯨物語~Dockerコンテナとオーケストレーションの理解
鯨物語~Dockerコンテナとオーケストレーションの理解
 
Scalable and Available, Patterns for Success
Scalable and Available, Patterns for SuccessScalable and Available, Patterns for Success
Scalable and Available, Patterns for Success
 
Command injection
Command injectionCommand injection
Command injection
 
Taller docker _es-cl
Taller docker _es-clTaller docker _es-cl
Taller docker _es-cl
 
DerbyCon 8 - Attacking Azure Environments with PowerShell
DerbyCon 8 - Attacking Azure Environments with PowerShellDerbyCon 8 - Attacking Azure Environments with PowerShell
DerbyCon 8 - Attacking Azure Environments with PowerShell
 

Similar to macOS Vulnerabilities Hiding in Plain Sight

20+ Ways to Bypass Your macOS Privacy Mechanisms
20+ Ways to Bypass Your macOS Privacy Mechanisms20+ Ways to Bypass Your macOS Privacy Mechanisms
20+ Ways to Bypass Your macOS Privacy Mechanisms
SecuRing
 
Esage on non-existent 0-days, stable binary exploits and user interaction
Esage   on non-existent 0-days, stable binary exploits and user interactionEsage   on non-existent 0-days, stable binary exploits and user interaction
Esage on non-existent 0-days, stable binary exploits and user interaction
DefconRussia
 
Project Malware AnalysisCS 6262 Project 3Agenda.docx
Project Malware AnalysisCS 6262 Project 3Agenda.docxProject Malware AnalysisCS 6262 Project 3Agenda.docx
Project Malware AnalysisCS 6262 Project 3Agenda.docx
briancrawford30935
 
Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]
RootedCON
 

Similar to macOS Vulnerabilities Hiding in Plain Sight (20)

[Hackersuli][HUN]MacOS - Going Down the Rabbit Hole
[Hackersuli][HUN]MacOS - Going Down the Rabbit Hole[Hackersuli][HUN]MacOS - Going Down the Rabbit Hole
[Hackersuli][HUN]MacOS - Going Down the Rabbit Hole
 
Getting root with benign app store apps vsecurityfest
Getting root with benign app store apps vsecurityfestGetting root with benign app store apps vsecurityfest
Getting root with benign app store apps vsecurityfest
 
20+ Ways to Bypass Your macOS Privacy Mechanisms
20+ Ways to Bypass Your macOS Privacy Mechanisms20+ Ways to Bypass Your macOS Privacy Mechanisms
20+ Ways to Bypass Your macOS Privacy Mechanisms
 
Owning computers without shell access 2
Owning computers without shell access 2Owning computers without shell access 2
Owning computers without shell access 2
 
Csaba fitzl - Mount(ain) of Bugs
Csaba fitzl - Mount(ain) of BugsCsaba fitzl - Mount(ain) of Bugs
Csaba fitzl - Mount(ain) of Bugs
 
On non existent 0-days, stable binary exploits and
On non existent 0-days, stable binary exploits andOn non existent 0-days, stable binary exploits and
On non existent 0-days, stable binary exploits and
 
Esage on non-existent 0-days, stable binary exploits and user interaction
Esage   on non-existent 0-days, stable binary exploits and user interactionEsage   on non-existent 0-days, stable binary exploits and user interaction
Esage on non-existent 0-days, stable binary exploits and user interaction
 
unit 2 confinement techniques.pdf
unit 2 confinement techniques.pdfunit 2 confinement techniques.pdf
unit 2 confinement techniques.pdf
 
Security research over Windows #defcon china
Security research over Windows #defcon chinaSecurity research over Windows #defcon china
Security research over Windows #defcon china
 
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the CoreNSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
 
Operating Docker
Operating DockerOperating Docker
Operating Docker
 
Project Malware AnalysisCS 6262 Project 3Agenda.docx
Project Malware AnalysisCS 6262 Project 3Agenda.docxProject Malware AnalysisCS 6262 Project 3Agenda.docx
Project Malware AnalysisCS 6262 Project 3Agenda.docx
 
Custom Tile Generation in PCF
Custom Tile Generation in PCFCustom Tile Generation in PCF
Custom Tile Generation in PCF
 
Road to Opscon (Pisa '15) - DevOoops
Road to Opscon (Pisa '15) - DevOoopsRoad to Opscon (Pisa '15) - DevOoops
Road to Opscon (Pisa '15) - DevOoops
 
Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)
 
Custom Tile Generation in PCF
Custom Tile Generation in PCFCustom Tile Generation in PCF
Custom Tile Generation in PCF
 
[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...
 
Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]
 
Continuous Delivery, Continuous Integration
Continuous Delivery, Continuous Integration Continuous Delivery, Continuous Integration
Continuous Delivery, Continuous Integration
 
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
 

More from Csaba Fitzl

More from Csaba Fitzl (9)

Launch and Environment Constraints Overview
Launch and Environment Constraints OverviewLaunch and Environment Constraints Overview
Launch and Environment Constraints Overview
 
SecurityFest-22-Fitzl-beyond.pdf
SecurityFest-22-Fitzl-beyond.pdfSecurityFest-22-Fitzl-beyond.pdf
SecurityFest-22-Fitzl-beyond.pdf
 
Exploiting Directory Permissions on macOS
Exploiting Directory Permissions on macOSExploiting Directory Permissions on macOS
Exploiting Directory Permissions on macOS
 
Exploiting XPC in AntiVirus
Exploiting XPC in AntiVirusExploiting XPC in AntiVirus
Exploiting XPC in AntiVirus
 
GateKeeper - bypass or not bypass?
GateKeeper - bypass or not bypass?GateKeeper - bypass or not bypass?
GateKeeper - bypass or not bypass?
 
Getting root with benign app store apps
Getting root with benign app store appsGetting root with benign app store apps
Getting root with benign app store apps
 
Exploit generation and javascript analysis automation with WinDBG lu
Exploit generation and javascript analysis automation with WinDBG luExploit generation and javascript analysis automation with WinDBG lu
Exploit generation and javascript analysis automation with WinDBG lu
 
Exploit generation automation with WinDBG (Hacktivity 2017)
Exploit generation automation with WinDBG (Hacktivity 2017)Exploit generation automation with WinDBG (Hacktivity 2017)
Exploit generation automation with WinDBG (Hacktivity 2017)
 
How to convince a malware to avoid us
How to convince a malware to avoid usHow to convince a malware to avoid us
How to convince a malware to avoid us
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptx
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 

macOS Vulnerabilities Hiding in Plain Sight

  • 1. macOS Vulnerabilities Hiding in Plain Sight Csaba Fitzl Twitter: @theevilbit
  • 2. whoami • lead content developer of "macOS Control Bypasses" @ Offensive Security • macOS bug hunter • ex red/blue teamer • husband, father • hiking, trail running 🥾 🏔 🏃
  • 3. Agenda • Intro • CVE-2021-1815 - macOS local privilege escalation via Preferences • CVE-2021-30972 - TCC bypass • CVE-2022-32780 - Sandbox escape via disk arbitration • for each CVE: • technical background • original vulnerability and exploit • new vulnerability and exploit
  • 4. INTRO • "can't see the forest for the trees" • we are so focused on something, that we can easily miss some details • rush in reading stuff online
  • 5. INTRO • I tend to read the same articles again and again • I found three vulnerabilities in published writeups • not for the fi rst read, but probably 10th, 20th or even 30th
  • 6. CVE-2021-1815 - macOS local privilege escalation via Preferences
  • 7. cfprefsd • core foundation preferences daemon • sets/stores and retrieves preferences for apps • 2 instances: user, system • interact: Preferences API or direct XPC ()
  • 8. original vulnerability • pwn2own 2020 - 6 step exploit chain to pwn macOS (Yonghwi Jin, Jungwon Lim, Insu Yun, and Taesoo Kim) • LPE via cfprefsd • allowed change ownership of arbitrary folder
  • 9. original exploit • race with symlink • change ownership of /etc/pam.d • update sudo pam con fi g • get root without password
  • 10. Apple's fi x • reversed by the pwn2own team • ensures symlinks are no longer followed (O_NOFOLLOW)
  • 11. the issue • although the symlink issue is solved • a directory is still created • and ownership set • ==> we can create a directory anywhere and set the user as the owner
  • 12. exploit method #1 • periodic scripts: executed daily/weekly/ monthly • con fi g: /etc/defaults/periodic.conf • the "local" directory is empty by default • won't work beyond 11.5 (see: https:// theevilbit.github.io/beyond/ beyond_0019/) • slow :( getting root can take up to a day
  • 13. demo
  • 14.
  • 15. exploit method #2 • sysdiagnose runs as root • it executes binaries from /usr/local/bin (doesn't exists by default) • some of these have been remediated because of homebrew • not perfect - depends on user trigger: • Feedback Assistant • manually invoke • keyboard shortcut: Command + Option + Shift+ Control + Period (.)
  • 17. TCC • security feature to control access to privacy related resources • sqlite3 database (except: private entitlements, macl extended attribute) - (~)/Library/Application Support/com.apple.TCC/TCC.db • for more: talk (20+ Ways to Bypass Your macOS Privacy Mechanisms), posts by Wojciech Regula and myself
  • 18. CVE-2021-30713 - TCC bypass by XCSSET Source: JAMF • XCSSET malware TCC bypass 0day • discovered by JAMF • malicious app is hosted inside a bundle, which has TCC permissions • macOS wrongly identi fi es the bundle (hint!!!)
  • 19. CVE-2021-30798 - TCC Bypass Again, Inspired By XCSSET • found by Mickey Jin • TCC db contains only bundle ID • simply fake the bundle ID in the app • system performs code sign check on the real bundle (hint!!!)
  • 20. problem? • the TCC.db does store the csreq info • none of the fake processes had proper code signature • the bypass in both cases was possible because: binaries on disk were veri fi ed • WUT???? • on macOS: you can modify app binaries on disk even when they run (unlike in Windows)
  • 21. elsewhere? • in every other case*, code signature is veri fi ed in memory • *except GateKeeper/am fi d when the app is launched, because there is no process yet • XPC / Mach connections • should use audit token • even PID is insecure • on-disk? not even an option 🤣 • in-memory integrity check by AMFI
  • 22. CVE-2021-30972 - TCC bypass again 1. Make a fake app with the same bundle ID and name as the one we want to impersonate, and place it in an arbitrary location 2. Start the app 3. Copy the original app over the fake app 4. Initiate an action which requires privacy permissions 5. TCC is bypassed, with inheriting the original app's rights
  • 23. CVE-2021-30972 - Wojciech's version 1. Make a fake app, and embed in a "donor" app (use the same team ID) 2. Start the app 3. Copy the donor app over the embedded app 4. Initiate an action which requires privacy permissions 5. TCC is bypassed, with inheriting the donor's rights
  • 24. demo
  • 25.
  • 26. fi x • fi nally dynamic code signature is veri fi ed
  • 27. CVE-2022-32780 - Sandbox escape via Disk Arbitration
  • 28. diskarbitration - the basics • system wide service, de fi ned in: • /System/Library/LaunchDaemons/com.apple.diskarbitrationd.plist • XPC: com.apple.DiskArbitration.diskarbitrationd • manage disk mounting, unmounting • calls mount/unmount system calls under the hood
  • 29. diskarbitration - why we like it? • runs as root • unsandboxed • XPC service accessible from application sandbox • opensource
  • 30. CVE-2017-2533 - LPE via diskarbitrationd • used by phoenhex team in pwn2own 2017 • DA: • resolves path -> checks if the user has rights to mount over directory • no more checks later • resolves path -> mounting • TOCTOU bug, race condition • exploit: mount the EFI (admin writeable) partition over crontabs
  • 31. CVE-2022-32780 • not exactly hidden • Apple moved the check into DAServer.c - "_DAServerSessionQueueRequest" • extra check for the sandbox
  • 35. CVE-2022-32780 - exploitation • what to mount? • EFI won't work (can't mount + not reachable from sandbox) • custom dmg! • how? DA works on /dev, diskmanagementd (can map dmg into / dev/) is not reachable from sandbox • 💡use "open" • we can unmount, /dev/ remains
  • 36. CVE-2022-32780 - exploitation • where to mount? • Terminal Preferences • ~/Library/Preferences/ com.apple.Terminal.plist • "CommandString" executed upon launch
  • 37. CVE-2022-32780 - full exploit 1. Drops a `dmg` fi le 2. It will call `open` to open a `dmg` fi le 3. Then it will use the diskarbitration service to unmount it --> at this point we have a custom disk device we can mount somewhere 4. It will start a thread to alternate the symlink and the directory 5. Then it will start a loop to call the mount operation of the DA service - due to the racer it will eventually succeed • we also always unmount the local directory, as we don't need that 6. It will check if we mounted over `Preferences`, and if yes stop 7. Open Terminal
  • 38. demo
  • 39.
  • 41. conclusion • it's worth to read write-ups carefully • it's worth revisiting old docs, notes, code • it's worth to slow down