hacktricks/src/mobile-pentesting/android-app-pentesting/reversing-native-libraries.md

45 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 反向工程本地库
{{#include ../../banners/hacktricks-training.md}}
**更多信息请查看:** [**https://maddiestone.github.io/AndroidAppRE/reversing_native_libs.html**](https://maddiestone.github.io/AndroidAppRE/reversing_native_libs.html)
Android 应用可以使用本地库,通常用 C 或 C++ 编写,以满足性能关键任务的需求。恶意软件创建者也使用这些库,因为它们比 DEX 字节码更难以反向工程。本节强调针对 Android 的反向工程技能,而不是教授汇编语言。提供了 ARM 和 x86 版本的库以确保兼容性。
### 关键点:
- **Android 应用中的本地库:**
- 用于性能密集型任务。
- 用 C 或 C++ 编写,使反向工程具有挑战性。
-`.so`(共享对象)格式存在,类似于 Linux 二进制文件。
- 恶意软件创建者更喜欢本地代码以增加分析难度。
- **Java 本地接口JNI和 Android NDK**
- JNI 允许在本地代码中实现 Java 方法。
- NDK 是一组特定于 Android 的工具,用于编写本地代码。
- JNI 和 NDK 将 Java或 Kotlin代码与本地库连接起来。
- **库加载与执行:**
- 使用 `System.loadLibrary``System.load` 将库加载到内存中。
- 在库加载时执行 JNI_OnLoad。
- Java 声明的本地方法链接到本地函数,从而实现执行。
- **将 Java 方法链接到本地函数:**
- **动态链接:** 本地库中的函数名称匹配特定模式,允许自动链接。
- **静态链接:** 使用 `RegisterNatives` 进行链接,提供函数命名和结构的灵活性。
- **反向工程工具和技术:**
- Ghidra 和 IDA Pro 等工具有助于分析本地库。
- `JNIEnv` 对理解 JNI 函数和交互至关重要。
- 提供练习以实践加载库、链接方法和识别本地函数。
### 资源:
- **学习 ARM 汇编:**
- 建议深入了解底层架构。
- 推荐来自 Azeria Labs 的 [ARM Assembly Basics](https://azeria-labs.com/writing-arm-assembly-part-1/)。
- **JNI 和 NDK 文档:**
- [Oracle 的 JNI 规范](https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html)
- [Android 的 JNI 提示](https://developer.android.com/training/articles/perf-jni)
- [开始使用 NDK](https://developer.android.com/ndk/guides/)
- **调试本地库:**
- [使用 JEB 反编译器调试 Android 本地库](https://medium.com/@shubhamsonani/how-to-debug-android-native-libraries-using-jeb-decompiler-eec681a22cf3)
{{#include ../../banners/hacktricks-training.md}}