Skip to content

Commit cc25def

Browse files
committed
add new detection
1 parent 1d8514d commit cc25def

2 files changed

Lines changed: 66 additions & 57 deletions

File tree

jbsigs_generator.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ void writeMachOFileSig(NSString* path)
138138
processMachO(path.fileSystemRepresentation, ^(int fd,uint64_t offset,size_t size, void* header) {
139139
gSilces++;
140140
findCodeSignature(header, ^(void* data, size_t size) {
141-
uint8_t cdhash[20]={0};
142-
CC_SHA1(data, (CC_LONG)size, cdhash);
143-
char hashstr[sizeof(cdhash)*2 + 1] = {0};
144-
for(int i=0; i<sizeof(cdhash)/sizeof(cdhash[0]); i++) {
145-
sprintf(hashstr+i*2, "%02x", cdhash[i]);
141+
uint8_t hash[CC_SHA1_DIGEST_LENGTH]={0};
142+
CC_SHA1(data, (CC_LONG)size, hash);
143+
char hashstr[sizeof(hash)*2 + 1] = {0};
144+
for(int i=0; i<sizeof(hash)/sizeof(hash[0]); i++) {
145+
sprintf(hashstr+i*2, "%02x", hash[i]);
146146
}
147147
LOG("\tslice(%llx) hash: %s\n", offset, hashstr);
148148

main.m

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void detect_exception_port()
231231

232232
for (int i = 0; i<count; i++)
233233
{
234-
//NSLog(@"index[%d] mask=%08X port=%08X behavior=%08X flavor=%08X\n", i, masks[i], ports[i], behaviors[i], flavors[i]);
234+
//NSLog(@"detect_exception_port: index[%d] mask=%08X port=%08X behavior=%08X flavor=%08X\n", i, masks[i], ports[i], behaviors[i], flavors[i]);
235235
if(ports[i] || behaviors[i] || flavors[i]) {
236236
LOG("unexept exception record [%d] mask=%08X port=%08X behavior=%08X flavor=%08X\n", i, masks[i], ports[i], behaviors[i], flavors[i]);
237237
}
@@ -257,7 +257,12 @@ void detect_jb_preboot()
257257
strncpy(boothash, s.f_mntfromname+prefixlen, p-(s.f_mntfromname+prefixlen));
258258

259259
char path[PATH_MAX];
260-
snprintf(path, sizeof(path), "/private/preboot/%s/procursus", s.f_mntfromname);
260+
snprintf(path, sizeof(path), "/private/preboot/%s/procursus", boothash);
261+
if(access(path, F_OK)==0) {
262+
LOG("jb files in preboot!\n");
263+
}
264+
265+
snprintf(path, sizeof(path), "/private/preboot/%s/jb", boothash);
261266
if(access(path, F_OK)==0) {
262267
LOG("jb files in preboot!\n");
263268
}
@@ -331,7 +336,7 @@ void detect_removed_varjb()
331336
{
332337
NSString* saved = [NSUserDefaults.standardUserDefaults stringForKey:@"/var/jb"];
333338
if(access(saved.UTF8String, F_OK)==0) {
334-
LOG("removed /var/jb found: %s\n", saved.UTF8String);
339+
LOG("removed /var/jb found:\n%s\n\n", saved.UTF8String);
335340
}
336341
}
337342
}
@@ -481,32 +486,7 @@ void detect_jailbreak_port()
481486

482487
void detect_launchd_jbserver()
483488
{
484-
struct xpc_global_data* globalData = NULL;
485-
if (_os_alloc_once_table[1].once == -1) {
486-
globalData = _os_alloc_once_table[1].ptr;
487-
}
488-
else {
489-
globalData = _os_alloc_once(&_os_alloc_once_table[1], 472, NULL);
490-
if (!globalData) _os_alloc_once_table[1].once = -1;
491-
}
492-
if (!globalData) {
493-
LOG("invalid globalData!\n");
494-
return;
495-
}
496-
497-
if (!globalData->xpc_bootstrap_pipe) {
498-
mach_port_t *initPorts;
499-
mach_msg_type_number_t initPortsCount = 0;
500-
if (mach_ports_lookup(mach_task_self(), &initPorts, &initPortsCount) == 0) {
501-
globalData->task_bootstrap_port = initPorts[0];
502-
globalData->xpc_bootstrap_pipe = xpc_pipe_create_from_port(globalData->task_bootstrap_port, 0);
503-
}
504-
}
505-
if (!globalData->xpc_bootstrap_pipe) {
506-
LOG("invalid xpc_bootstrap_pipe!\n");
507-
return;
508-
}
509-
xpc_object_t xpipe = globalData->xpc_bootstrap_pipe;
489+
xpc_object_t bootstrap_pipe = ((struct xpc_global_data *)_os_alloc_once_table[1].ptr)->xpc_bootstrap_pipe;
510490

511491
xpc_object_t xdict = xpc_dictionary_create_empty();
512492

@@ -515,7 +495,7 @@ void detect_launchd_jbserver()
515495

516496
xpc_object_t xreply = NULL;
517497

518-
int err = xpc_pipe_routine_with_flags(xpipe, xdict, &xreply, 0);
498+
int err = xpc_pipe_routine_with_flags(bootstrap_pipe, xdict, &xreply, 0);
519499
//LOG("xpc_pipe_routine_with_flags error=%d xreply=%p\n", err, xreply);
520500

521501
if (err != 0) {
@@ -616,25 +596,6 @@ void detect_launchd_jb_mach_server()
616596
}
617597
}
618598

619-
//works on ios14.0 ~ 15.1.1
620-
void detect_trollstpre_app()
621-
{
622-
xpc_connection_t connection = xpc_connection_create_mach_service("com.apple.nehelper", nil, 2);
623-
xpc_connection_set_event_handler(connection, ^(xpc_object_t object){});
624-
xpc_connection_resume(connection);
625-
xpc_object_t xdict = xpc_dictionary_create(nil, nil, 0);
626-
xpc_dictionary_set_uint64(xdict, "delegate-class-id", 1);
627-
xpc_dictionary_set_uint64(xdict, "cache-command", 3);
628-
xpc_dictionary_set_string(xdict, "cache-signing-identifier", "com.opa334.TrollStore");
629-
xpc_object_t reply = xpc_connection_send_message_with_reply_sync(connection, xdict);
630-
// NSLog(@"reply=%s", xpc_copy_description(reply));
631-
xpc_object_t resultData = xpc_dictionary_get_value(reply, "result-data");
632-
if(xpc_dictionary_get_value(resultData, "cache-app-uuid") != nil) {
633-
LOG("trollstore app installed!\n");
634-
}
635-
}
636-
637-
638599
#import <Security/Security.h>
639600
#import <LocalAuthentication/LocalAuthentication.h>
640601
void detect_passcode_status()
@@ -827,6 +788,51 @@ void detect_launchd_ipchook()
827788
}
828789
}
829790

791+
void detect_bind_mounts()
792+
{
793+
char* defaultBindMounts[] = {
794+
"/usr/standalone/firmware",
795+
"/System/Library/Pearl/ReferenceFrames",
796+
"/System/Library/Caches/com.apple.factorydata",
797+
};
798+
799+
struct statfs * ss=NULL;
800+
int n = getmntinfo(&ss, 0);
801+
for(int i=0; i<n; i++) {
802+
//LOG("mount %s %s : %s : %x,%x\n", ss[i].f_fstypename, ss[i].f_mntonname, ss[i].f_mntfromname, ss[i].f_flags, ss[i].f_flags_ext);
803+
if(strcmp(ss[i].f_fstypename,"bindfs")==0) {
804+
bool known=false;
805+
for(int j=0; j<sizeof(defaultBindMounts)/sizeof(defaultBindMounts[0]); j++) {
806+
if(strcmp(ss[i].f_mntonname, defaultBindMounts[j])==0) {
807+
known = true;
808+
break;
809+
}
810+
}
811+
//if(!known)
812+
{
813+
LOG("unknown bind mount found: %s : %s\n", ss[i].f_mntonname, ss[i].f_mntfromname);
814+
}
815+
}
816+
}
817+
}
818+
819+
void detect_launchd_deplatformized()
820+
{
821+
xpc_object_t bootstrap_pipe = ((struct xpc_global_data *)_os_alloc_once_table[1].ptr)->xpc_bootstrap_pipe;
822+
823+
xpc_object_t dict = xpc_dictionary_create(NULL, NULL, 0);
824+
xpc_dictionary_set_uint64(dict, "subsystem", 3);
825+
xpc_dictionary_set_uint64(dict, "routine", 815);
826+
xpc_dictionary_set_uint64(dict, "handle", 0);
827+
xpc_dictionary_set_uint64(dict, "type", 1);
828+
829+
xpc_object_t reply = NULL;
830+
int rc = xpc_pipe_routine(bootstrap_pipe, dict, &reply);
831+
if(rc != 154) {
832+
LOG("launchd deplatformized: %s\n", xpc_copy_description(reply));
833+
}
834+
}
835+
830836
/* bypass all jb-bypass: FlyJB,Shadow,A-Bypass etc... */
831837
@interface NSObject(JBDetect15) + (void)initialize; @end
832838
@implementation NSObject(JBDetect15)
@@ -854,18 +860,21 @@ + (void)initialize
854860
detect_fugu15Max();
855861
detect_jailbreak_sigs();
856862
detect_jailbreak_port();
863+
detect_launchd_ipchook();
857864
detect_launchd_jbserver();
858865
detect_launchd_jb_mach_server();
859-
detect_trollstpre_app();
860-
detect_launchd_ipchook();
866+
detect_launchd_deplatformized();
867+
detect_bind_mounts();
861868

862869
// wait for NS Foundation to initialize.
863870
dispatch_async(dispatch_get_main_queue(), ^{
864871
detect_passcode_status();
865872
detect_removed_varjb();
866873
detect_url_schemes();
867874
detect_cfprefsd_hook();
868-
detect_jbapp_plugins();
875+
dispatch_async(dispatch_get_main_queue(), ^{
876+
detect_jbapp_plugins(); //super slow
877+
});
869878
});
870879
}
871880
}

0 commit comments

Comments
 (0)