Best way to check if your iOS App is running on a Jailbroken Phone

Vineet Choudhary
developerinsider
Published in
3 min readFeb 23, 2020

Originally published on DeveloperInsider: Best way to check if your iOS App is running on a Jailbroken Phone

Sometimes, for security reasons, we need to check if our iOS app (like banking apps, OTT apps, etc) is running on a jailbroken phone or not. Most people suggest, check if “Cydia” is installed or not. But there might be some chances that the device doesn’t have “Cydia” installed or installed with an alternative name. But what is the most effective way to check it?

So, here an extension of UIDevice which can detect if an iOS device is jailbroken or not most effectively by checking for the following -

  • Check if Cydia is installed
  • Check if the app can edit system files
  • Check if the system contains suspicious files
  • Check if other suspicious apps (FakeCarrier, Icy, etc.) is installed
  • Check if Cydia is installed with alternative names (using URIScheme)

Also, none of these checks void the Apple App Store guidelines.

import Foundation
import UIKit
extension UIDevice {
var isSimulator: Bool {
return TARGET_OS_SIMULATOR != 0
}

var isJailBroken: Bool {
get {
if UIDevice.current.isSimulator { return false }
if JailBrokenHelper.hasCydiaInstalled() { return true }
if JailBrokenHelper.isContainsSuspiciousApps() { return true }
if JailBrokenHelper.isSuspiciousSystemPathsExists() { return true }
return JailBrokenHelper.canEditSystemFiles()
}
}
}
private struct JailBrokenHelper {
//check if cydia is installed (using URI Scheme)
static func hasCydiaInstalled() -> Bool {
return UIApplication.shared.canOpenURL(URL(string: "cydia://")!)
}

//Check if suspicious apps (Cydia, FakeCarrier, Icy etc.) is installed
static func isContainsSuspiciousApps() -> Bool {
for path in suspiciousAppsPathToCheck {
if FileManager.default.fileExists(atPath: path) {
return true
}
}
return false
}

//Check if system contains suspicious files
static func isSuspiciousSystemPathsExists() -> Bool {
for path in suspiciousSystemPathsToCheck {
if FileManager.default.fileExists(atPath: path) {
return true
}
}
return false
}

//Check if app can edit system files
static func canEditSystemFiles() -> Bool {
let jailBreakText = "Developer Insider"
do {
try jailBreakText.write(toFile: jailBreakText, atomically: true, encoding: .utf8)
return true
} catch {
return false
}
}

//suspicious apps path to check
static var suspiciousAppsPathToCheck: [String] {
return ["/Applications/Cydia.app",
"/Applications/blackra1n.app",
"/Applications/FakeCarrier.app",
"/Applications/Icy.app",
"/Applications/IntelliScreen.app",
"/Applications/MxTube.app",
"/Applications/RockApp.app",
"/Applications/SBSettings.app",
"/Applications/WinterBoard.app"
]
}

//suspicious system paths to check
static var suspiciousSystemPathsToCheck: [String] {
return ["/Library/MobileSubstrate/DynamicLibraries/LiveClock.plist",
"/Library/MobileSubstrate/DynamicLibraries/Veency.plist",
"/private/var/lib/apt",
"/private/var/lib/apt/",
"/private/var/lib/cydia",
"/private/var/mobile/Library/SBSettings/Themes",
"/private/var/stash",
"/private/var/tmp/cydia.log",
"/System/Library/LaunchDaemons/com.ikey.bbot.plist",
"/System/Library/LaunchDaemons/com.saurik.Cydia.Startup.plist",
"/usr/bin/sshd",
"/usr/libexec/sftp-server",
"/usr/sbin/sshd",
"/etc/apt",
"/bin/bash",
"/Library/MobileSubstrate/MobileSubstrate.dylib"
]
}
}

Also, don’t forget to add “Cydia” in LSApplicationQueriesSchemes key of info.plist. Otherwise canOpenURL will always return false.

<key>LSApplicationQueriesSchemes</key>
<array>
<string>cydia</string>
</array>

Here the sample project on Github.

Check out AppBox. AppBox is tool which build and deploy Development, Ad-Hoc and In-house (Enterprise) iOS applications directly to the devices from your Dropbox account. AppBox is a opensource software available on github https://github.com/vineetchoudhary/AppBox-iOSAppsWirelessInstallation .

--

--

Vineet Choudhary
developerinsider

iOS, macOS and Xamarin Developer | Creator of @DevsInsider amd @AppBoxHQ