60

I have just released my app for iOS, but I'm not sure how to make my app safe from being used by jailbrakers.

Can I do something to prevent my app working on jailbroken devices?

Wyetro
  • 8,439
  • 9
  • 46
  • 64
R. Dewi
  • 4,141
  • 9
  • 41
  • 66
  • 3
    Apps aren't jailbroken - iPhones and iPads are. – Michael Petrotta Jun 30 '11 at 05:37
  • There's no magical way to make apps pirating-proof. Otherwise, app piracy wouldn't exist. – zneak Jun 30 '11 at 05:37
  • For one thing, the title of the question is very poorly done grammatically, so I could not figure out what you where asking. May I suggest changing it to "How to keep my app from running on a jailbroken device?"? As for the question, Rahul Vyas' answer is very good. You may also want to find a way to contact Apple every time your app is opened on a jailbroken device. – Justin Jun 30 '11 at 22:16
  • Thank you for all your comment, I was wondering to make my app can not be running on a jailbroken device – R. Dewi Jul 01 '11 at 04:30
  • 45
    Poor grammar aside, I don't think assaulting his grammar or saying snide comments like "apps aren't jailbroken" and "there's no magical way to make apps pirate-proof." Sometimes, people don't know English well. Let that go :\ – 2rs2ts Jul 07 '11 at 12:15
  • 2
    @user529758 Jailbreaking itself is not piracy. Anyway it's also true that most jailbreaking is done for piracy. – eonil May 20 '14 at 03:33
  • Check these repos: [SecurityDetector](https://github.com/fiber-inc/SecurityDetector) [JailBreak-Detection](https://github.com/TheSwiftyCoder/JailBreak-Detection) [JBInspector](https://github.com/mofneko/JBInspector) I prefer the first one. – Nike Kov Mar 29 '19 at 16:11
  • I have no problem to understand his question. I can see no problem with his grammar. Perhaps you should enhance your reading skills. – Tom Mar 03 '22 at 21:59

11 Answers11

56

You can detect through code that if the app is running on a jail broken device or not. Through that way you can pop up an alert and close the app. You can do whatever you want to do. Here is a tutorial for it:

http://thwart-ipa-cracks.blogspot.com/2008/11/detection.html

and here is a Stack Overflow post:

How do I detect that an iOS app is running on a jailbroken phone?

Also, if you want a complete solution, you can see in tapjoy sdk code. They are detecting jailbroken iPhone. Here is tapjoy URL https://www.tapjoy.com/

Community
  • 1
  • 1
Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256
  • 2
    Just wanted to say thanks for the great answer, I will bookmark this because I'm going to be heading into iOS development and this is good to know! – 2rs2ts Jul 07 '11 at 12:16
  • Thanks @RahulVyas; it will help me in leading my ios development project team – Naved Nov 10 '11 at 09:09
10

Check for these paths

+ (BOOL)isJailBroken {
#ifdef TARGET_IPHONE_SIMULATOR
    return NO;
#endif

    NSArray *paths = @[@"/bin/bash",
                       @"/usr/sbin/sshd",
                       @"/etc/apt",
                       @"/private/var/lib/apt/",
                       @"/Applications/Cydia.app",
                       ];

    for (NSString *path in paths) {
        if ([self fileExistsAtPath:path]) {
            return YES;
        }
    }

    return NO;
}


+ (BOOL)fileExistsAtPath:(NSString *)path {
    FILE *pFile;
    pFile = fopen([path cStringUsingEncoding:[NSString defaultCStringEncoding]], "r");
    if (pFile == NULL) {
        return NO;
    }
    else
        fclose(pFile);
    return YES;
}

Additionally, you can take a look https://github.com/OneSignal/OneSignal-iOS-SDK/blob/master/iOS_SDK/OneSignalSDK/Source/OneSignalJailbreakDetection.m

Spidy
  • 1,137
  • 3
  • 28
  • 48
onmyway133
  • 45,645
  • 31
  • 257
  • 263
  • 1
    updated link: https://github.com/OneSignal/OneSignal-iOS-SDK/blob/master/iOS_SDK/OneSignalSDK/Source/OneSignalJailbreakDetection.m – Deryck Lucian Feb 21 '19 at 16:59
5

Try to find a file which cydia or jailbroken device create. Or try to write in a file outside the app's blackbox. If you succeed to do that, the device is compromised/jailbroken :)

- (BOOL)jailbroken
{
    NSFileManager * fileManager = [NSFileManager defaultManager];
    return [fileManager fileExistsAtPath:@"/private/var/lib/apt/"];
}
karim
  • 15,408
  • 7
  • 58
  • 96
5
/**
     Detect that the app is running on a jailbroken device or not

     - returns: bool value for jailbroken device or not
     */
    public class func isDeviceJailbroken() -> Bool {
        #if arch(i386) || arch(x86_64)
            return false
        #else
            let fileManager = FileManager.default

            if (fileManager.fileExists(atPath: "/bin/bash") ||
                fileManager.fileExists(atPath: "/usr/sbin/sshd") ||
                fileManager.fileExists(atPath: "/etc/apt") ||
                fileManager.fileExists(atPath: "/private/var/lib/apt/") ||
                fileManager.fileExists(atPath: "/Applications/Cydia.app") ||
                fileManager.fileExists(atPath: "/Library/MobileSubstrate/MobileSubstrate.dylib")) {
                return true
            } else {
                return false
            }
        #endif
    }
deanWombourne
  • 38,189
  • 13
  • 98
  • 110
CrazyPro007
  • 1,006
  • 9
  • 15
4

You can detect if a device is jailBroken or not by checking the following

  1. Cydia is installed
  2. Verify some of the system paths
  3. Can perform a sandbox integrity check
  4. Perform symlink verification
  5. Verify whether you create and write files outside your Sandbox

There is an open source library I created from various articles and books, try it out.

Jawa
  • 2,336
  • 6
  • 34
  • 39
user3088680
  • 301
  • 2
  • 3
4
-(BOOL) isJailbroken
{
#if TARGET_IPHONE_SIMULATOR
return NO;
#else
FILE *f = fopen("/bin/bash", "r");
if (errno == ENOENT)
{
    // device is NOT jailbroken
    fclose(f);
    NSLog(@"no");
    return NO;
}
else {
    // device IS jailbroken
    fclose(f);
    NSLog(@"yes");
    return YES;

}
#endif
}
sinh99
  • 3,909
  • 32
  • 32
4

Based off of @karim's answer heres a slightly modified swift version:

func hasJailbreak() -> Bool {
    #if arch(i386) || arch(x86_64)
        println("Simulator")
        return false    
    #else
        var fileManager = NSFileManager.defaultManager()
        if(fileManager.fileExistsAtPath("/private/var/lib/apt")) {
            println("Jailbroken Device")
            return true
        } else {
            println("Clean Device")
            return false
        }
    #endif
}
inVINCEable
  • 2,167
  • 3
  • 25
  • 49
2

Even if your device is jailbroken , ipa applications can only access their own sand boxes, so If device is either jailbroken or not your method will return NO :) Look for another way Also if you try to access somewhere but your sandbox publishing app on the appstore may head problems

user1846654
  • 79
  • 1
  • 4
2

There is no way to detect if device is jailbroken.

Consider that even if there was, the device has already been jailbroken, meaning arbitrary code execution is possible, and the jailbreaker would just modify whatever method of detection you would use to signal that the device has not been jailbroken.

reference: https://forums.developer.apple.com/thread/43073

credits go to Apple Staff who answered this same question

igrek
  • 1,415
  • 1
  • 12
  • 27
1

There are many ways to find the jailbroken devices. checking cydia technic will not be work if skilled hacker changes the application path.

A good way to check for it would be to see if we can modify a file in some other location outside the application bundle.

NSError *error;
NSString *stringToBeWritten = @"This is a test.";
[stringToBeWritten writeToFile:@"/private/jailbreak.txt" atomically:YES
         encoding:NSUTF8StringEncoding error:&error];
if(error==nil){
   //Device is jailbroken
   return YES;
 } else {
   //Device is not jailbroken
   [[NSFileManager defaultManager] removeItemAtPath:@"/private/jailbreak.txt" error:nil];
 }

Find more techniques in the below url

http://highaltitudehacks.com/2013/12/17/ios-application-security-part-24-jailbreak-detection-and-evasion/

Boobalan
  • 815
  • 11
  • 11
1

SWIFT 3:

func hasJailbreak() -> Bool {
        #if arch(i386) || arch(x86_64)
            print("Simulator")
            return false
        #else
            return FileManager.default.fileExistsAtPath("/private/var/lib/apt")
        #endif
    }
Yaroslav Dukal
  • 3,894
  • 29
  • 36