Skip to content

Commit d41c638

Browse files
committed
Include sandbox check in the new Jailbreak detection code
1 parent 0a7fc31 commit d41c638

File tree

1 file changed

+56
-47
lines changed

1 file changed

+56
-47
lines changed

Sources/KSCrashRecordingCore/include/KSJailbreak.h

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -164,53 +164,62 @@ static inline bool ksj_local_is_insert_libraries_env_var(const char *str)
164164
* Note: Implemented as a macro to force it inline always.
165165
*/
166166
#if !TARGET_OS_SIMULATOR && !TARGET_OS_OSX && KSCRASH_HAS_SYSCALL
167-
#define get_jailbreak_status(pIsJailbroken) \
168-
do { \
169-
int fd = 0; \
170-
\
171-
bool tmp_file_is_accessible = false; \
172-
bool mobile_substrate_exists = false; \
173-
bool etc_apt_exists = false; \
174-
bool has_insert_libraries = false; \
175-
\
176-
const char *test_write_file = "/tmp/bugsnag-check.txt"; \
177-
remove(test_write_file); \
178-
ksj_syscall_open(test_write_file, O_CREAT, 0644, &fd); \
179-
if (fd > 0) { \
180-
close(fd); \
181-
tmp_file_is_accessible = true; \
182-
} else { \
183-
ksj_syscall_open(test_write_file, O_RDONLY, 0, &fd); \
184-
if (fd > 0) { \
185-
close(fd); \
186-
tmp_file_is_accessible = true; \
187-
} \
188-
} \
189-
remove(test_write_file); \
190-
\
191-
const char *mobile_substrate_path = "/Library/MobileSubstrate/MobileSubstrate.dylib"; \
192-
ksj_syscall_open(mobile_substrate_path, O_RDONLY, 0, &fd); \
193-
if (fd > 0) { \
194-
close(fd); \
195-
mobile_substrate_exists = true; \
196-
} \
197-
\
198-
const char *etc_apt_path = "/etc/apt"; \
199-
DIR *dirp = opendir(etc_apt_path); \
200-
if (dirp) { \
201-
etc_apt_exists = true; \
202-
closedir(dirp); \
203-
} \
204-
\
205-
for (int i = 0; environ[i] != NULL; i++) { \
206-
if (ksj_local_is_insert_libraries_env_var(environ[i])) { \
207-
has_insert_libraries = true; \
208-
break; \
209-
} \
210-
} \
211-
\
212-
*(pIsJailbroken) = \
213-
tmp_file_is_accessible || mobile_substrate_exists || etc_apt_exists || has_insert_libraries; \
167+
#define get_jailbreak_status(pIsJailbroken) \
168+
do { \
169+
int fd = 0; \
170+
\
171+
bool tmp_file_is_accessible = false; \
172+
bool mobile_substrate_exists = false; \
173+
bool etc_apt_exists = false; \
174+
bool has_insert_libraries = false; \
175+
bool broken_sandbox = false; \
176+
\
177+
const char *test_write_file = "/tmp/file-check.txt"; \
178+
remove(test_write_file); \
179+
ksj_syscall_open(test_write_file, O_CREAT, 0644, &fd); \
180+
if (fd > 0) { \
181+
close(fd); \
182+
tmp_file_is_accessible = true; \
183+
} else { \
184+
ksj_syscall_open(test_write_file, O_RDONLY, 0, &fd); \
185+
if (fd > 0) { \
186+
close(fd); \
187+
tmp_file_is_accessible = true; \
188+
} \
189+
} \
190+
remove(test_write_file); \
191+
\
192+
const char *mobile_substrate_path = "/Library/MobileSubstrate/MobileSubstrate.dylib"; \
193+
ksj_syscall_open(mobile_substrate_path, O_RDONLY, 0, &fd); \
194+
if (fd > 0) { \
195+
close(fd); \
196+
mobile_substrate_exists = true; \
197+
} \
198+
\
199+
const char *etc_apt_path = "/etc/apt"; \
200+
DIR *dirp = opendir(etc_apt_path); \
201+
if (dirp) { \
202+
etc_apt_exists = true; \
203+
closedir(dirp); \
204+
} \
205+
\
206+
for (int i = 0; environ[i] != NULL; i++) { \
207+
if (ksj_local_is_insert_libraries_env_var(environ[i])) { \
208+
has_insert_libraries = true; \
209+
break; \
210+
} \
211+
} \
212+
\
213+
const char *sandboxpath = "/private/kscrash_jailbreak_test"; \
214+
ksj_syscall_open(sandboxpath, O_WRONLY | O_CREAT | O_TRUNC, 0644, &fd); \
215+
if (fd > 0) { \
216+
close(fd); \
217+
broken_sandbox = true; \
218+
remove(sandboxpath); \
219+
} \
220+
\
221+
*(pIsJailbroken) = tmp_file_is_accessible || mobile_substrate_exists || etc_apt_exists || \
222+
has_insert_libraries || broken_sandbox; \
214223
} while (0)
215224

216225
#else

0 commit comments

Comments
 (0)