mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
82 lines
5.1 KiB
Markdown
82 lines
5.1 KiB
Markdown
{{#include ../../banners/hacktricks-training.md}}
|
||
|
||
# React Native 应用程序分析
|
||
|
||
要确认应用程序是否基于 React Native 框架构建,请按照以下步骤操作:
|
||
|
||
1. 将 APK 文件重命名为 zip 扩展名,并使用命令 `cp com.example.apk example-apk.zip` 和 `unzip -qq example-apk.zip -d ReactNative` 将其提取到新文件夹中。
|
||
|
||
2. 导航到新创建的 ReactNative 文件夹,找到 assets 文件夹。在此文件夹中,您应该找到文件 `index.android.bundle`,该文件以压缩格式包含 React JavaScript。
|
||
|
||
3. 使用命令 `find . -print | grep -i ".bundle$"` 搜索 JavaScript 文件。
|
||
|
||
## Javascript 代码
|
||
|
||
如果检查 `index.android.bundle` 的内容时发现应用程序的 JavaScript 代码(即使是压缩的),您可以 **分析它以查找敏感信息和漏洞**。
|
||
|
||
由于该包实际上包含了应用程序的所有 JS 代码,因此可以 **将其分割成不同的文件**(可能使其逆向工程更容易),使用 **工具 [react-native-decompiler](https://github.com/numandev1/react-native-decompiler)**。
|
||
|
||
### Webpack
|
||
|
||
要进一步分析 JavaScript 代码,您可以将文件上传到 [https://spaceraccoon.github.io/webpack-exploder/](https://spaceraccoon.github.io/webpack-exploder/) 或按照以下步骤操作:
|
||
|
||
1. 在同一目录中创建一个名为 `index.html` 的文件,内容如下:
|
||
```html
|
||
<script src="./index.android.bundle"></script>
|
||
```
|
||
2. 在 Google Chrome 中打开 `index.html` 文件。
|
||
|
||
3. 通过按 **Command+Option+J for OS X** 或 **Control+Shift+J for Windows** 打开开发者工具栏。
|
||
|
||
4. 在开发者工具栏中点击 "Sources"。你应该会看到一个 JavaScript 文件,它被分成文件夹和文件,构成了主包。
|
||
|
||
如果你找到一个名为 `index.android.bundle.map` 的文件,你将能够以未压缩的格式分析源代码。映射文件包含源映射,这允许你映射压缩的标识符。
|
||
|
||
要搜索敏感凭证和端点,请按照以下步骤操作:
|
||
|
||
1. 确定敏感关键词以分析 JavaScript 代码。React Native 应用程序通常使用第三方服务,如 Firebase、AWS S3 服务端点、私钥等。
|
||
|
||
2. 在这个特定案例中,观察到该应用程序使用了 Dialogflow 服务。搜索与其配置相关的模式。
|
||
|
||
3. 幸运的是,在侦查过程中在 JavaScript 代码中发现了敏感的硬编码凭证。
|
||
|
||
### 更改 JS 代码并重建
|
||
|
||
在这种情况下,更改代码很简单。你只需将应用程序重命名为使用扩展名 `.zip` 并提取它。然后你可以 **修改这个包中的 JS 代码并重建应用程序**。这应该足以让你 **注入代码** 以进行测试。
|
||
|
||
## Hermes 字节码
|
||
|
||
如果包包含 **Hermes 字节码**,你 **将无法访问应用程序的 JavaScript 代码**(甚至无法访问压缩版本)。
|
||
|
||
你可以通过运行以下命令检查包是否包含 Hermes 字节码:
|
||
```bash
|
||
file index.android.bundle
|
||
index.android.bundle: Hermes JavaScript bytecode, version 96
|
||
```
|
||
然而,您可以使用工具 **[hbctool](https://github.com/bongtrop/hbctool)**、**[hermes-dec](https://github.com/P1sec/hermes-dec)** 或 **[hermes_rs](https://github.com/Pilfer/hermes_rs)** 来 **反汇编字节码**,并且还可以 **将其反编译为一些伪 JS 代码**。要做到这一点,例如可以使用以下命令:
|
||
```bash
|
||
hbc-disassembler ./index.android.bundle /tmp/my_output_file.hasm
|
||
hbc-decompiler ./index.android.bundle /tmp/my_output_file.js
|
||
```
|
||
### 修改代码并重建
|
||
|
||
理想情况下,您应该能够修改反汇编的代码(更改比较、值或您需要修改的任何内容),然后**重建字节码**,再重建应用程序。
|
||
|
||
工具**[hbctool](https://github.com/bongtrop/hbctool)**支持反汇编包并在进行更改后重新构建,但它**仅支持旧版本**的Hermes字节码。
|
||
|
||
工具**[hermes-dec](https://github.com/P1sec/hermes-dec)**不支持重建字节码。
|
||
|
||
工具**[hermes_rs](https://github.com/Pilfer/hermes_rs)**支持重建字节码,但它实际上是一个库,而不是CLI工具。
|
||
|
||
## 动态分析
|
||
|
||
您可以尝试动态分析应用程序,使用Frida启用React应用的开发者模式,并使用**`react-native-debugger`**进行附加。然而,显然您需要应用程序的源代码。您可以在[https://newsroom.bedefended.com/hooking-react-native-applications-with-frida/](https://newsroom.bedefended.com/hooking-react-native-applications-with-frida/)找到更多信息。
|
||
|
||
## 参考文献
|
||
|
||
- [https://medium.com/bugbountywriteup/lets-know-how-i-have-explored-the-buried-secrets-in-react-native-application-6236728198f7](https://medium.com/bugbountywriteup/lets-know-how-i-have-explored-the-buried-secrets-in-react-native-application-6236728198f7)
|
||
- [https://www.assetnote.io/resources/research/expanding-the-attack-surface-react-native-android-applications](https://www.assetnote.io/resources/research/expanding-the-attack-surface-react-native-android-applications)
|
||
- [https://payatu.com/wp-content/uploads/2023/02/Mastering-React-Native-Application-Pentesting-A-Practical-Guide-2.pdf](https://payatu.com/wp-content/uploads/2023/02/Mastering-React-Native-Application-Pentesting-A-Practical-Guide-2.pdf)
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|