Skip to content

Instantly share code, notes, and snippets.

@mmdock
Created July 12, 2019 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmdock/530f9dfc6f169bb2938329f11cce81a2 to your computer and use it in GitHub Desktop.
Save mmdock/530f9dfc6f169bb2938329f11cce81a2 to your computer and use it in GitHub Desktop.
iOS Simple Jailbroken Test
///Discussion:
///In theory, if app is able to have visibility of a file outside the app's environment then it is jailbroken.
///For this test, we will be checking for common files found from various ways of jailbreaking an iOS device.
///As a final test: try writing outside of the app's sandbox.
func isJailbroken() -> Bool{
#if targetEnvironment(simulator)
return false
#else
let fm = FileManager.default
var isJailbroken: Bool = false
isJailbroken = fm.fileExists(atPath: "/private/var/lib/apt") || fm.fileExists(atPath: "/etc/apt") || fm.fileExists(atPath: "/usr/sbin/sshd") || fm.fileExists(atPath: "/bin/bash") || fm.fileExists(atPath: "/Library/MobileSubstrate/MobileSubstrate.dylib") || fm.fileExists(atPath: "/Applications/Cydia.app")
let stringToWrite = "Jailbreak Test”"
do {
try stringToWrite.write(toFile:"/private/JailbreakTest.txt", atomically:true, encoding: String.Encoding.utf8)
return true
} catch {
isJailbroken = isJailbroken || false
}
return isJailbroken
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment