iOS jailbreak (iOS jailbreaking) is a technical means to get the highest permissions on iOS for the Apple Portable device operating system, using this technology and software to gain maximum access to iOS and possibly even further unlock operator restrictions on cellular networks. Mobile phone jailbreak will face more security risks, it is not recommended to jailbreak iOS devices. In the development of the jailbreak device can be security guard.
You can try using Nsfilemanager to determine if the device has a jailbreak plugin installed.
#defineArray_size (a) sizeof (a)/sizeof (A[0])Const Char* jailbreak_tool_pathes[] = { "/applications/cydia.app", "/library/mobilesubstrate/mobilesubstrate.dylib", "/bin/bash", "/usr/sbin/sshd", "/etc/apt"};
#pragmaMark-Determine if the device is jailbroken +(BOOL) isjailbreak{ for(intI=0; I<array_size (jailbreak_tool_pathes); i++) { if([[[Nsfilemanager Defaultmanager] fileexistsatpath:[nsstring Stringwithutf8string:jailbreak_tool_pathes[i]]) { Xsdlog (@"The device is jail broken!"); returnYES; }} xsdlog (@"The device is not jail broken!"); returnNO;}
You can see if you have permissions by trying to read the list of apps:
if ([[Nsfilemanager Defaultmanager] Fileexistsatpath:@" /user/applications/ "" Span style= "COLOR: #000000" >) {NSLog ( @ " Device is jailbroken " ); Nsarray *applist = [[Nsfilemanager Defaultmanager] Contentsofdirectoryatpath:@ " /user/applications/ " Error:nil]; NSLog ( @ " applist =%@ " ,applist); }
The jailbroken device is unable to read the data, and the jailbreak device is able to get a list.
Use the Stat series function to detect tools such as Cydia:
#import <sys/stat.h>void checkcydia (void) { struct stat stat_info ; if (0 = = Stat ("/applications/cydia.app", &Stat_info)) { NSLog (@ "Device is jailbroken");} }
You can see if stat is out of the system library and has been replaced by an attacker:
#import <dlfcn.h> void checkinject ( void int ret; Dl_info Dylib_info; int (*func_stat) (const char *, struct stat *) = Stat if ((ret = DLADDR (func_stat, &dylib_ info)) {NSLog ( @ " lib:%s " The output is:
If the result is not/usr/lib/system/libsystem_kernel.dylib, then 100% is attacked.
If the libsystem_kernel.dylib are replaced by an attacker ...
Dynamic Library Detection:
#import <mach-o/dyld.h>void checkdylibs (void) { = _dyld_image_count (); for 0 ; I < count; + +i) {*name = [[NSString Alloc]initwithutf8string:_dyld_get_image_name (i)]; NSLog (@ " dynamic Library detection result--%@", name);} }
Typically, the output that will contain the jailbreak will contain the string: Library/mobilesubstrate/mobilesubstrate.dylib.
Results:
By detecting the environment that the program is currently running:
#include <stdlib.h>void printenv ( void ) { char *env = getenv ( " dyld_insert_libraries " @ " ===%s " 2017 -05 - 23 15 : 02 : 30.232140 +0800 Testsecurityadvance[16888 : 919836 ] = = = ( Span style= "COLOR: #0000ff" >null )
the non-jailbroken device returns NULL.
See also: Read the blog of Nancy.
iOS security attack jailbreak device detection