* Travaillez-vous dans une **entreprise de cybersécurité** ? Voulez-vous voir votre **entreprise annoncée dans HackTricks** ? ou voulez-vous avoir accès à la **dernière version de PEASS ou télécharger HackTricks en PDF** ? Consultez les [**PLANS D'ABONNEMENT**](https://github.com/sponsors/carlospolop) !
* Découvrez [**The PEASS Family**](https://opensea.io/collection/the-peass-family), notre collection exclusive de [**NFTs**](https://opensea.io/collection/the-peass-family)
* Obtenez le [**swag officiel PEASS & HackTricks**](https://peass.creator-spring.com)
* **Rejoignez le** [**💬**](https://emojipedia.org/speech-balloon/) [**groupe Discord**](https://discord.gg/hRep4RUj7f) ou le [**groupe telegram**](https://t.me/peass) ou **suivez** moi sur **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Partagez vos astuces de piratage en soumettant des PR au** [**repo hacktricks**](https://github.com/carlospolop/hacktricks) **et au** [**repo hacktricks-cloud**](https://github.com/carlospolop/hacktricks-cloud).
<figure><imgsrc="../../../../.gitbook/assets/image (2).png"alt=""><figcaption><p>Image de <ahref="http://newosxbook.com/files/HITSB.pdf">http://newosxbook.com/files/HITSB.pdf</a></p></figcaption></figure>
Dans l'image précédente, il est possible d'observer **comment la Sandbox sera chargée** lorsqu'une application avec l'entitlement **`com.apple.security.app-sandbox`** est exécutée.
Ensuite, **`libSystem.B`** appellera d'autres fonctions jusqu'à ce que **`xpc_pipe_routine`** envoie les entitlements de l'application à **`securityd`**. Securityd vérifie si le processus doit être mis en quarantaine à l'intérieur de la Sandbox, et si c'est le cas, il sera mis en quarantaine.\
Enfin, la Sandbox sera activée par un appel à **`__sandbox_ms`** qui appellera **`__mac_syscall`**.
The macOS sandbox is a powerful security feature that restricts the actions that a process can perform on a system. However, like any security feature, it is not perfect and can be bypassed or debugged in certain situations.
Debugging the macOS sandbox can be useful for understanding how it works and for finding vulnerabilities that can be exploited to bypass it. There are several tools and techniques that can be used to debug the macOS sandbox, including:
The `sandbox-exec` command can be used to run a process in a sandbox and to print out information about the sandbox as the process runs. This can be useful for understanding how the sandbox works and for identifying any issues that may be present.
The `sandboxd` daemon is responsible for enforcing the macOS sandbox. It can be run in debug mode using the `-d` flag, which will cause it to print out information about the sandbox as it enforces it. This can be useful for understanding how the sandbox works and for identifying any issues that may be present.
The `DYLD_INSERT_LIBRARIES` environment variable can be used to inject a dynamic library into a process. This can be used to intercept and modify system calls made by the process, including those related to the sandbox. By intercepting and modifying these calls, it may be possible to bypass the sandbox.
Bypassing the macOS sandbox can be difficult, but it is not impossible. There are several techniques that can be used to bypass the sandbox, including:
Like any software, the macOS sandbox is not perfect and may contain vulnerabilities that can be exploited to bypass it. Finding and exploiting these vulnerabilities can be difficult, but it is a viable option for bypassing the sandbox.
The `task_for_pid` API can be used to gain elevated privileges on a system. By using this API, it may be possible to bypass the sandbox and perform actions that would otherwise be restricted.
As mentioned earlier, the `DYLD_INSERT_LIBRARIES` environment variable can be used to inject a dynamic library into a process. By doing so, it may be possible to bypass the sandbox by intercepting and modifying system calls made by the process.
The macOS sandbox is a powerful security feature that can help protect a system from malicious activity. However, it is not perfect and can be bypassed or debugged in certain situations. By understanding how the sandbox works and by using the appropriate tools and techniques, it may be possible to bypass or debug the sandbox and perform actions that would otherwise be restricted.
The macOS sandbox is a powerful security feature that restricts the access of applications to sensitive system resources. However, it is not foolproof and can be bypassed by attackers with the right knowledge and tools.
Debugging a sandboxed application can be challenging due to the restrictions placed on it. However, there are a few techniques that can be used to debug a sandboxed application:
One way to debug a sandboxed application is to attach to a running process. This can be done using a debugger such as `lldb` or `gdb`. To attach to a running process, you will need to know the process ID (PID) of the application. This can be obtained using the `ps` command in the Terminal.
Another way to debug a sandboxed application is to inject a debugger into the process. This can be done using a tool such as `ptrace` or `mach_inject`. Once the debugger is injected, you can use it to debug the application as you would with any other process.
One way to bypass a sandboxed application is to exploit a vulnerability in the application or in the system itself. This can allow an attacker to gain elevated privileges and bypass the sandbox.
Another way to bypass a sandboxed application is to use a known exploit. This can be a vulnerability that has already been discovered and publicly disclosed, or it can be a tool or technique that is commonly used to bypass sandboxes.
Finally, an attacker can attempt to reverse engineer the sandbox itself to find weaknesses or vulnerabilities that can be exploited. This can be a time-consuming process, but it can be very effective if done correctly.
The macOS sandbox is a powerful security feature that can help protect your system from malicious applications. However, it is not foolproof and can be bypassed by attackers with the right knowledge and tools. As a developer or security professional, it is important to be aware of these techniques and to take steps to mitigate the risks they pose.
Si à partir du processus Sandbox, vous êtes capable de **compromettre d'autres processus** fonctionnant dans des Sandbox moins restrictives (ou sans Sandbox), vous pourrez vous échapper vers leurs Sandbox :
[Cette recherche](https://saagarjha.com/blog/2020/05/20/mac-app-store-sandbox-escape/) a découvert deux façons de contourner le bac à sable. Étant donné que le bac à sable est appliqué depuis l'espace utilisateur lorsque la bibliothèque **libSystem** est chargée, si un binaire pouvait éviter de la charger, il ne serait jamais mis en bac à sable :
* Si le binaire était **complètement compilé de manière statique**, il pourrait éviter de charger cette bibliothèque.
* Si le **binaire n'avait pas besoin de charger de bibliothèques** (car le lien est également dans libSystem), il n'aurait pas besoin de charger libSystem.
Si un processus sandboxé peut **écrire** dans un endroit où **plus tard une application non sandboxée va exécuter le binaire**, il pourra **s'échapper simplement en y plaçant** le binaire. Un bon exemple de ce type d'emplacements sont `~/Library/LaunchAgents` ou `/System/Library/LaunchDaemons`.
Pour cela, vous pourriez même avoir besoin de **2 étapes** : faire en sorte qu'un processus avec un sandbox **plus permissif** (`file-read*`, `file-write*`) exécute votre code qui écrira effectivement dans un endroit où il sera **exécuté sans sandbox**.
* Travaillez-vous dans une **entreprise de cybersécurité** ? Voulez-vous voir votre **entreprise annoncée dans HackTricks** ? ou voulez-vous avoir accès à la **dernière version de PEASS ou télécharger HackTricks en PDF** ? Consultez les [**PLANS D'ABONNEMENT**](https://github.com/sponsors/carlospolop) !
* Obtenez le [**swag officiel PEASS & HackTricks**](https://peass.creator-spring.com)
* **Rejoignez le** [**💬**](https://emojipedia.org/speech-balloon/) [**groupe Discord**](https://discord.gg/hRep4RUj7f) ou le [**groupe telegram**](https://t.me/peass) ou **suivez** moi sur **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Partagez vos astuces de piratage en soumettant des PR au** [**repo hacktricks**](https://github.com/carlospolop/hacktricks) **et au** [**repo hacktricks-cloud**](https://github.com/carlospolop/hacktricks-cloud).