Skip to content

Commit

Permalink
securityd and trustd hook
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfugil committed Jan 11, 2024
1 parent dd9f82c commit 3425651
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/rootfulhooks/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define ROOTLESSHOOKS_HOOKS_H

void lsdInit(void);
void securitydInit(void);

#endif
1 change: 1 addition & 0 deletions include/rootlesshooks/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

void cfprefsdInit(void);
void sbInit(void);
void securitydInit(void);

#endif
1 change: 1 addition & 0 deletions src/rootfulhooks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ C_SRC = $(wildcard *.c)
OBJC_SRC = $(wildcard *.m)
OBJCFLAGS = -fobjc-arc
LIBS = -lobjc -framework Foundation -framework CoreFoundation ../libs/libellekit.tbd
LIBS += -framework Security
OBJS = $(patsubst %,$(OBJDIR)/%,$(OBJC_SRC:.m=.m.o) $(C_SRC:.c=.c.o))

ifeq ($(ASAN),1)
Expand Down
2 changes: 2 additions & 0 deletions src/rootfulhooks/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ __attribute__((constructor))void rootfulhooks_main(void) {
}

if (!strcmp(path, "/usr/libexec/lsd")) lsdInit();
else if (strcmp(path, "/usr/libexec/securityd") == 0
|| strcmp(path, "/usr/libexec/trustd") == 0) securitydInit();
}
1 change: 1 addition & 0 deletions src/rootfulhooks/securityd.c
1 change: 1 addition & 0 deletions src/rootlesshooks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ C_SRC = $(wildcard *.c)
OBJC_SRC = $(wildcard *.m)
OBJCFLAGS = -fobjc-arc
LIBS = -lobjc -framework Foundation -framework CoreFoundation ../libs/libellekit.tbd
LIBS += -framework Security
OBJS = $(patsubst %,$(OBJDIR)/%,$(OBJC_SRC:.m=.m.o) $(C_SRC:.c=.c.o))

ifeq ($(ASAN),1)
Expand Down
2 changes: 2 additions & 0 deletions src/rootlesshooks/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ __attribute__((constructor))void rootlesshooks_main(void) {

if (!strcmp(path, "/usr/sbin/cfprefsd")) cfprefsdInit();
else if (!strcmp(path, "/System/Library/CoreServices/SpringBoard.app/SpringBoard")) sbInit();
else if (strcmp(path, "/usr/libexec/securityd") == 0
|| strcmp(path, "/usr/libexec/trustd") == 0) securitydInit();
/*else if (!strcmp(path, "/usr/libexec/lsd")) lsdInit(); */
}
13 changes: 13 additions & 0 deletions src/rootlesshooks/securityd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <Security/Security.h>
#include <substrate.h>

bool SecIsInternalRelease(void);

bool (*orig_SecIsInternalRelease)(void);
bool new_SecIsInternalRelease(void) {
return true;
}

void securitydInit(void) {
MSHookFunction(SecIsInternalRelease, (void*)new_SecIsInternalRelease, (void**)&orig_SecIsInternalRelease);
}
11 changes: 7 additions & 4 deletions src/systemhook/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,11 @@ __attribute__((constructor)) static void initializer(void)
#endif

if (pflags & palerain_option_rootless) {
if (strcmp(gExecutablePath, "/usr/sbin/cfprefsd") == 0) {
dlopen_hook("/cores/binpack/usr/lib/rootlesshooks.dylib", RTLD_NOW);
} else if (strcmp(gExecutablePath, "/System/Library/CoreServices/SpringBoard.app/SpringBoard") == 0) {
if (
strcmp(gExecutablePath, "/usr/sbin/cfprefsd") == 0 ||
strcmp(gExecutablePath, "/System/Library/CoreServices/SpringBoard.app/SpringBoard") == 0 ||
strcmp(gExecutablePath, "/usr/libexec/securityd") == 0
) {
dlopen_hook("/cores/binpack/usr/lib/rootlesshooks.dylib", RTLD_NOW);
}
} else {
Expand All @@ -492,7 +494,8 @@ __attribute__((constructor)) static void initializer(void)
if (!ret) release = atoi(name.release);
}
if (release && atoi(name.release) >= 20) {
if (strcmp(gExecutablePath, "/usr/libexec/lsd") == 0) {
if (strcmp(gExecutablePath, "/usr/libexec/lsd") == 0 ||
strcmp(gExecutablePath, "/usr/libexec/securityd") == 0) {
dlopen_hook("/cores/binpack/usr/lib/rootfulhooks.dylib", RTLD_NOW);
}
}
Expand Down

0 comments on commit 3425651

Please sign in to comment.