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

后端 未结 17 1314
情书的邮戳
情书的邮戳 2020-11-22 10:48

If I want my app to behave differently on a jailbroken iPhone, how would I go about determining this?

相关标签:
17条回答
  • 2020-11-22 11:20

    Checking if the kernel is broken isn't THAT much more involved.

    Jailbreaking makes the kernel's signature check of signed code always report that code is signed correctly, unbroken phones cannot run code with a bad signature.

    So, include a separate executable in the app with a bad signature. It could just be a 3-line program that has main() and a return value. Compile the executable without code signing (turn it off in Project Settings->Build) and sign it with a different key using the "codesign" commandline utility.

    Have your app exec the separate executable. If your program can't get the return value when running the separate executable with the bad sig, it's definitely jailed. If the separate executable returns A-OK, the phone is definitely jailbroken.

    0 讨论(0)
  • 2020-11-22 11:21

    Try executing unsigned code through your application.

    A jailbroken devices usually has the following characteristics:

    • run unsigned code
    • has Cydia installed
    • has jailbreak files
    • full r/w access to the whole filesystem
    • some system files will have been modified (content and so sha1 doesn't match with original files)
    • stuck to specific version (jailbreakable version)

    Just checking file existence for jailbreak detection is doomed to fail. These checks are easy to bypass.

    0 讨论(0)
  • 2020-11-22 11:21

    Here's my solutions: Step 1

    extension UIDevice {
        func isJailBroken() -> Bool {
            let cydiaPath = "/Applications/Cydia.app"
            let aptPath = "/private/var/lib/apt/"
            if FileManager.default.fileExists(atPath: cydiaPath) || FileManager.default.fileExists(atPath: aptPath) {
                return true
            }
            return false
        }
    }
    

    Step 2: Call it inside viewDidLoad() inside your launch screen view controller(or whatever VC you are calling for the first time):

           // show a blank screen or some other view controller
           let viewController = UIDevice.current.isJailBroken() ? JailBrokenViewController() : NextViewController()
           self.navigationController?.present(viewController, animated: true, completion:nil)
    
    0 讨论(0)
  • 2020-11-22 11:21

    Try To Access /Application/Preferences.app/General.plist You should be able To do so on a jailbroken iPhone On non-Jb phone you won't Be able To Access it

    0 讨论(0)
  • 2020-11-22 11:22

    Some common files to check for: /Library/MobileSubstrate/MobileSubstrate.dylib

    /Applications/Cydia.app

    /var/cache/apt

    /var/lib/apt

    /var/lib/cydia

    /var/log/syslog

    /var/tmp/cydia.log

    /bin/bash

    /bin/sh

    /usr/sbin/sshd

    /usr/libexec/ssh-keysign

    /etc/ssh/sshd_config

    /etc/apt

    Most check for Cydia related files.

    0 讨论(0)
  • 2020-11-22 11:22

    What we did is, we already have an RSS feed to communicate with our users (Stocks Live), we put a news item that states something like this:

    Some jailbroken devices have problems bla bla bla, we made a hack to solve those issues but we need to know if this a jailbroken device or not, press here so the app fixes the issue. If you ever return to normal, ie removed the jailbreak, press here.

    Then you process the user interaction and do what is appropriate, like behaving different etc...

    0 讨论(0)
提交回复
热议问题