Reputation: 365
Used "https://github.com/leecrossley/cordova-plugin-jailbreak-detection" but still it didn't check the JAILBROKEN since Cydia and other options were bypassed in latest 11+ iOS versions
How to handle latest iOS using Cordova or in native code ?
Upvotes: 14
Views: 25017
Reputation: 693
import Foundation
func isJailbroken() -> Bool {
let fileManager = FileManager.default
// Check for common jailbroken files or directories
let jailbreakFilePaths = [
"/Applications/Cydia.app",
"/Library/MobileSubstrate/MobileSubstrate.dylib",
"/bin/bash",
"/usr/sbin/sshd",
"/etc/apt"
]
for path in jailbreakFilePaths {
if fileManager.fileExists(atPath: path) {
return true
}
}
// Check if Cydia app can be opened
if let cydiaURL = URL(string: "cydia://package/com.example.package") {
if UIApplication.shared.canOpenURL(cydiaURL) {
return true
}
}
// Check if the app is running in a sandboxed environment
if let sandboxedPath = fileManager.containerURL(forSecurityApplicationGroupIdentifier: nil)?.path {
if sandboxedPath.contains("Library/MobileSubstrate") {
return true
}
}
// Check if the app is being debugged
var info = kinfo_proc()
var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
var size = MemoryLayout<kinfo_proc>.stride
sysctl(&mib, 4, &info, &size, nil, 0)
if (info.kp_proc.p_flag & P_TRACED) != 0 {
return true
}
return false
}
// Usage
if isJailbroken() {
print("Running on a jailbroken device.")
} else {
print("Not running on a jailbroken device.")
}
Upvotes: 0
Reputation: 2513
Update 2021: You can use the extension on UIDevice from this article: https://developerinsider.co/best-way-to-check-if-your-ios-app-is-running-on-a-jailbroken-phone/
I copied all code in here.
You can find the latest version of code on Github here (author is @vineetchoudhary): https://github.com/developerinsider/isJailBroken/blob/master/IsJailBroken/Extension/UIDevice%2BJailBroken.swift
Whole code:
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 {
static func hasCydiaInstalled() -> Bool {
return UIApplication.shared.canOpenURL(URL(string: "cydia://")!)
}
static func isContainsSuspiciousApps() -> Bool {
for path in suspiciousAppsPathToCheck {
if FileManager.default.fileExists(atPath: path) {
return true
}
}
return false
}
static func isSuspiciousSystemPathsExists() -> Bool {
for path in suspiciousSystemPathsToCheck {
if FileManager.default.fileExists(atPath: path) {
return true
}
}
return false
}
static func canEditSystemFiles() -> Bool {
let jailBreakText = "Developer Insider"
do {
try jailBreakText.write(toFile: jailBreakText, atomically: true, encoding: .utf8)
return true
} catch {
return false
}
}
/**
Add more paths here to check for jail break
*/
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"
]
}
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, you need to add cydia
in LSApplicationQueriesSchemes
key inside Info.plist
. It's required for canOpenURL
to work.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>cydia</string>
</array>
Upvotes: 32
Reputation: 2010
In native code: You can use DTTJailbreakDetection, it is in Objective-C. If you use swift you need to use a bridging header.
Objective-C:
if ([DTTJailbreakDetection isJailbroken]) {
// your code
}
Swift:
if DTTJailbreakDetection.isJailbroken() {
// your code
}
Upvotes: 7