4

An Infosec team wanted to know if our app was executable on rooted Android devices. We developed a solution for it and now want to test our app. Are we able to replicate rooted devices online? If not, can anyone provide other ways to test our app?

Thanks in advance!

Ridcully
  • 23,362
  • 7
  • 71
  • 86
kiri
  • 1,977
  • 5
  • 27
  • 55
  • Note: The question is asking for "how to create a rooted device for testing app", not for "how to test if an app is running on a rooted device". – Geno Chen Mar 11 '19 at 05:15

2 Answers2

2

I have written a few util functions to help me with determining if my app is running in root environment:

private fun isDeviceRooted(): Boolean {
    return checkRootMethod1() || checkRootMethod2() || checkRootMethod3()
}

private fun checkRootMethod1(): Boolean {
    val buildTags = android.os.Build.TAGS
    return buildTags != null && buildTags.contains("test-keys")
}

private fun checkRootMethod2(): Boolean {
    val paths = arrayOf("/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su", "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su")
    for (path in paths) {
        if (File(path).exists()) return true
    }
    return false
}

private fun checkRootMethod3(): Boolean {
    var process: Process? = null
    return try {
        process = Runtime.getRuntime().exec(arrayOf("/system/xbin/which", "su"))
        val `in` = BufferedReader(InputStreamReader(process!!.inputStream))
        `in`.readLine() != null
    } catch (t: Throwable) {
        false
    } finally {
        process?.destroy()
    }
}
seyed Jafari
  • 1,235
  • 10
  • 20
2

I think the best idea is to use the rooted/ rootable android emulator. Here are few android emulators that you can download for windows pc.

Links for rootable emulators

If you want to use the emulator provided by the android studio then i think you would have to create a new android emulator with API 22 (LOLLIPOP) or above using android studio and try rooting it with help of Kingroot app. This app helps you to root your device by directly installing on your device like an normal application. This solution must work as it works on normal real devices. I have myself tried on the real devices but not on android emulator.

Hope this solves your query

Paul P Joby
  • 713
  • 7
  • 17