我正在研究一种静态分析工具,以帮助检测 Android 应用程序中的恶意软件。我想知道是否可以在不使用类加载器的情况下在 Android 上执行代码注入。我知道可以使用 Dex 类加载器在运行时加载字节码,但我想知道是否可以在不使用类加载器的情况下执行此操作。我发现了像https://github.com/miktam/Disabler这样的项目,它们使用 AspectJ 之类的东西在运行时添加日志记录和跟踪。如果我错了,请纠正我,但我认为这可能在 AspectJ 库的某个深处使用了类加载器。
我正在考虑更多关于在运行时使用已经加载的类的任意字节码覆盖/实现方法,以便下次调用它时,它会从原始源实现中执行一些恶意/未声明的操作。这可能吗?如果是这样,人们将如何去做呢?
更新:试图进一步澄清我的问题。
我对直接调用本机代码或使用 Runtime.exec 不感兴趣。我已经在我的工具中检查了那些 Java API。让我对我在想的事情给出一个粗略的代码想法。
public static void main(String[] args){
hello(); // BENIGN
evil("hello", getFile("com.blah.MyClass"));
hello(); // MALWARE, or alternatively since it might not be loaded also BENIGN until next time application is run.
}
public static void hello(){System.out.println("Hi!");}
public static void evil(String methodName, File classFile){
byte[] evilMethodImplementation = {0x...}; // some crafted byte code to replace the body of a method in a class file
RandomAccessFile raf = new RandomAccessFile(classFile, "rw");
raf.seek(findMethodBody(methodName, classFile)); // seek to the body contents of the method
raf.write(evilMethodImplementation); // overwrite the current implementation with malicious implementation
raf.close();
}
这只是我正在考虑看看是否可能的想法。基本上我想知道它是否可能在不使用反射接口的情况下进行反射,因为它会绕过我的检测。