繁体   English   中英

检测到Android root? 立即卸载应用程序

[英]Android root detected? Uninstall app immediately

我正在开发一个包含不应泄漏的敏感数据(加密密钥)的应用程序。 该应用程序应该能够在任何时候脱机工作,因此我无法将密钥存储在云中。

当用户拥有root设备时,他可以提取apk并获取密钥。 我想阻止这个。

一旦检测到root访问权限,有没有办法立即强制卸载我的应用程序而无需用户确认?

(或者是否有另一种方法可以防止密钥泄漏?)

我看了三星Knox,它对数据进行加密并使用硬件位来检测root访问权限,并在设备被篡改后使应用程序和数据无法访问。 它工作得很好,但我正在寻找适用于更广泛设备(不仅仅是三星设备)的解决方案。

编辑:那些你想要实现的东西(为加密密钥保存存储,......)并不是那么容易。 你应该阅读这篇文章 ,它可能对你有所帮助。

要卸载您的应用,您可以试试这个(未经过测试!):

Uri packageURI = Uri.parse("package:"+MyMainActivity.class.getPackage().getName());
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);

在根检测方面,不仅有“最佳”解决方案。 有各种方法,这里有一些东西可以帮助您入门:

/** @author Kevin Kowalewski */
public class RootUtil {
    public static boolean isDeviceRooted() {
        return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
    }

    private static boolean checkRootMethod1() {
        String buildTags = android.os.Build.TAGS;
        return buildTags != null && buildTags.contains("test-keys");
    }

    private static boolean checkRootMethod2() {
        String[] paths = { "/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 (String path : paths) {
            if (new File(path).exists()) return true;
        }
        return false;
    }

    private static boolean checkRootMethod3() {
        Process process = null;
        try {
            process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
            if (in.readLine() != null) return true;
            return false;
        } catch (Throwable t) {
            return false;
        } finally {
            if (process != null) process.destroy();
        }
    }
}

我认为卸载应用程序立即不是解决方案,您必须找出根目录的位置,并注意magisk管理器应用程序,可以绕过根检测,您可以尝试使用Rootbeer,roottools或创建根类进行根检测。 使用Rootbeer进行magisk管理器

//root example you can call this class.
public static boolean findBinary(String binaryName) {
    boolean found = false;
    if (!found) {
        String[] places = { "/sbin/", "/system/bin/", "/system/xbin/",
                "/data/local/xbin/", "/data/local/bin/",
                "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/",
                "/system/app/Superuser.apk", "/sbin/su", "/sbin/su/", "/system/bin/su","/system/bin/su/",
                "/system/xbin/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", "/su/",
                "/data/local/xbin/",
                "/system/bin/.ext/",
                "/system/bin/failsafe/",
                "/system/sd/xbin/",
                "/su/xbin/",
                "/su/bin/",
                "/magisk/.core/bin/",
                "/system/usr/we-need-root/",
                "/system/xbin/",
                "/system/su","/system/bin/.ext/.su","/system/usr/we-need-root/su-backup",
                "/system/xbin/mu",
                "/system/su/","/system/bin/.ext/.su/","/system/usr/we-need-root/su-backup/",
                "/system/xbin/mu/"};
        for (String where : places) {
            if (new File(where + binaryName).exists()) {
                found = true;
                break;
            }
        }
    }
    return found;
}
private static boolean isRooted() {
    return findBinary("su");
}

用于卸载应用程序(已测试)

Intent intent=new Intent(Intent.ACTION_DELETE);
String packageName = "yourpackagename";
intent.setData(Uri.parse("package:"+packageName));
startActivity(intent);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM