-1

由于无系统 root 可以使用几年,因此检测设备是否已 root 变得“更难”。我开始寻找一种可能的解决方案来检测设备是否无系统地植根,但我仍然无法找出解决方案。检查文件是否存在于给定路径(在 /system 中)是没有意义的,因为如果设备无系统地植根,它就不会存在。同样寻找管理 root 访问的应用程序可能没有意义,因为用户可能没有安装它们/或者只是使用其他的,不如 Magisk、SuperSu 等流行。

所以,我的想法是执行“su”命令,然后检查 shell 是否在 root 模式下运行(“#”)或不(“$”)。但是我如何检查它以哪种模式运行?据我所知,在简单地执行命令后:

       Runtime.getRuntime().exec("su");

由于不再使用“SU 用户”(?),进程被终止。

简单查看我对 adb 用法的含义:

user@user:~$ adb shell
device:/ $ su

如果执行此命令后变为:

device:/ #

将知道设备是否已植根,如果返回“权限被拒绝”将知道设备未植根。我可以在 Android 应用程序中实现类似的功能吗?

4

3 回答 3

0

最好只使用 SafetyNet api。虽然它不能具体告诉 root,但它会让你知道该设备是不可信的。代码也很简单。

val nonce = ByteArray(20)
SecureRandom().nextBytes(nonce)
SafetyNet.getClient(context).attest(nonce, API_KEY)
        .addOnSuccessListener(this) { response ->
            // Indicates communication with the service was successful.
            // Use response.jwsResult to get the result data.
            val resultParts = result.jwsResult.split(".")
            if (resultParts.size == 3) {
                val bytes = Base64Utils.decode(resultParts[1])
                val newString = String(bytes)
                val json = JSONObject(newString)
                    // Check json fields to see if device is secure
                    // NOTE best practice is to send this to server instead of handling locally.
                }
        }
        .addOnFailureListener(this) { e: Exception ->
            // An error occurred while communicating with the service.
            if (e is ApiException) {
                // An error with the Google Play services API contains some
                // additional details.
                // You can retrieve the status code using the
                // e.statusCode property.
            } else {
                // A different, unknown type of error occurred.
                Log.d(TAG, "Error: ${e.message}")
            }

        }

以下是不同的检查场景。请查看安卓文档 场景

于 2019-01-18T15:45:07.793 回答
0

没有真正的方法可以确定设备没有植根。甚至您的测试以查看 su 是否存在 - 他们总是可以将应用程序重命名为“super”而不是 su。或“foobar”。或者使用自定义版本的 AOSP 隐藏您正在寻找的任何内容。您要做的是在您无法控制的不受信任的环境中运行,并询问它是否可以信任。那永远行不通。你可以证明一个环境是不可信的,但你永远无法证明它是可信的。

于 2019-01-18T15:36:22.940 回答
0

加上 Gabe Sechan 的回答,始终检测无系统根几乎是不可能的,因为根权限可以修改执行检查的软件。

话虽如此,对 rootbeer提出了 pull request,它应该能够使用 Unix Domain Sockets 检测 Magisk,至少在该方法被修补之前。

于 2019-01-28T20:55:55.970 回答