196 lines
13 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.

# React Native Application Analysis
{{#include ../../banners/hacktricks-training.md}}
애플리케이션이 React Native 프레임워크로 구축되었는지 확인하려면 다음 단계를 따르세요:
1. APK 파일의 이름을 zip 확장자로 변경하고 `cp com.example.apk example-apk.zip``unzip -qq example-apk.zip -d ReactNative` 명령을 사용하여 새 폴더에 추출합니다.
2. 새로 생성된 ReactNative 폴더로 이동하여 assets 폴더를 찾습니다. 이 폴더 안에는 minified 형식의 React JavaScript가 포함된 `index.android.bundle` 파일이 있어야 합니다.
3. `find . -print | grep -i ".bundle$"` 명령을 사용하여 JavaScript 파일을 검색합니다.
참고: APK 대신 Android App Bundle (.aab)을 받았다면, 먼저 유니버설 APK를 생성한 다음 번들을 추출하세요:
```bash
# Get bundletool.jar and generate a universal APK set
java -jar bundletool.jar build-apks \
--bundle=app-release.aab \
--output=app.apks \
--mode=universal \
--overwrite
# Extract the APK and then unzip it to find assets/index.android.bundle
unzip -p app.apks universal.apk > universal.apk
unzip -qq universal.apk -d ReactNative
ls ReactNative/assets/
```
## Javascript Code
`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. `index.html` 파일을 Google Chrome에서 엽니다.
3. **OS X의 경우 Command+Option+J** 또는 **Windows의 경우 Control+Shift+J**를 눌러 개발자 도구를 엽니다.
4. 개발자 도구에서 "Sources"를 클릭합니다. 폴더와 파일로 나뉘어진 JavaScript 파일이 보일 것입니다. 이는 주요 번들을 구성합니다.
`index.android.bundle.map`이라는 파일을 찾으면, 비축소화된 형식으로 소스 코드를 분석할 수 있습니다. 맵 파일은 소스 매핑을 포함하고 있어, 축소된 식별자를 매핑할 수 있게 해줍니다.
민감한 자격 증명 및 엔드포인트를 검색하려면 다음 단계를 따르세요:
1. JavaScript 코드를 분석할 민감한 키워드를 식별합니다. React Native 애플리케이션은 종종 Firebase, AWS S3 서비스 엔드포인트, 개인 키 등과 같은 서드파티 서비스를 사용합니다.
2. 이 특정 경우에 애플리케이션이 Dialogflow 서비스를 사용하고 있는 것으로 관찰되었습니다. 그 구성과 관련된 패턴을 검색합니다.
3. 재콘 과정 중에 JavaScript 코드에서 민감한 하드코딩된 자격 증명이 발견된 것은 다행이었습니다.
### 번들에서 빠른 비밀/엔드포인트 탐색
이 간단한 grep은 축소된 JS에서도 흥미로운 지표를 드러내는 경우가 많습니다:
```bash
# Common backends and crash reporters
strings -n 6 index.android.bundle | grep -Ei "(api\.|graphql|/v1/|/v2/|socket|wss://|sentry\.io|bugsnag|appcenter|codepush|firebaseio\.com|amplify|aws)"
# Firebase / Google keys (heuristics)
strings -n 6 index.android.bundle | grep -Ei "(AIza[0-9A-Za-z_-]{35}|AIzaSy[0-9A-Za-z_-]{33})"
# AWS access key id heuristic
strings -n 6 index.android.bundle | grep -E "AKIA[0-9A-Z]{16}"
# Expo/CodePush deployment keys
strings -n 6 index.android.bundle | grep -Ei "(CodePush|codepush:\\/\\/|DeploymentKey)"
# Sentry DSN
strings -n 6 index.android.bundle | grep -Ei "(Sentry\.init|dsn\s*:)"
```
Over-The-Air 업데이트 프레임워크가 의심되는 경우, 다음을 찾아보세요:
- Microsoft App Center / CodePush 배포 키
- Expo EAS Updates 구성 (`expo-updates`, `expo\.io`, 서명 인증서)
### 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)**, 최신 바이트코드 버전을 지원하는 hbctool의 업데이트된 포크, **[hasmer](https://github.com/lucasbaizer2/hasmer)**, **[hermes_rs](https://github.com/Pilfer/hermes_rs)** (Rust 라이브러리/APIs) 또는 **[hermes-dec](https://github.com/P1sec/hermes-dec)**를 사용하여 **바이트코드를 분해**하고 **일부 의사 JS 코드로 디컴파일**할 수 있습니다. 예를 들어:
```bash
# Disassemble and re-assemble with hbctool (works only for supported HBC versions)
hbctool disasm ./index.android.bundle ./hasm_out
# ...edit ./hasm_out/**/*.hasm (e.g., change comparisons, constants, feature flags)...
hbctool asm ./hasm_out ./index.android.bundle
# Using hasmer (focus on disassembly; assembler/decompiler are WIP)
hasmer disasm ./index.android.bundle -o hasm_out
# Using hermes-dec to produce pseudo-JS
hbc-disassembler ./index.android.bundle /tmp/my_output_file.hasm
hbc-decompiler ./index.android.bundle /tmp/my_output_file.js
```
Tip: 오픈 소스 Hermes 프로젝트는 특정 Hermes 릴리스에서 `hbcdump`와 같은 개발자 도구도 제공합니다. 번들을 생성하는 데 사용된 Hermes 버전을 빌드하면, `hbcdump`는 함수, 문자열 테이블 및 바이트코드를 덤프하여 더 깊은 분석을 할 수 있습니다.
### 코드 변경 및 재빌드 (Hermes)
이상적으로는 분해된 코드를 수정할 수 있어야 합니다(비교, 값 또는 수정해야 할 기타 사항 변경) 그리고 **바이트코드를 재빌드**하고 앱을 재빌드해야 합니다.
- 원래 **[hbctool](https://github.com/bongtrop/hbctool)**은 번들을 분해하고 변경 후 다시 빌드하는 것을 지원하지만, 역사적으로는 오래된 바이트코드 버전만 지원했습니다. 커뮤니티에서 유지 관리하는 포크는 최신 Hermes 버전(중반 80s96 포함)에 대한 지원을 확장하며, 현대 RN 앱을 패치하는 데 가장 실용적인 옵션인 경우가 많습니다.
- 도구 **[hermes-dec](https://github.com/P1sec/hermes-dec)**는 바이트코드를 재빌드하는 것을 지원하지 않지만(디컴파일러/분해기만), 논리를 탐색하고 문자열을 덤프하는 데 매우 유용합니다.
- 도구 **[hasmer](https://github.com/lucasbaizer2/hasmer)**는 여러 Hermes 버전의 분해 및 조립을 지원하는 것을 목표로 합니다; 조립은 아직 성숙해 가고 있지만 최근 바이트코드에서 시도해 볼 가치가 있습니다.
hbctool과 유사한 조립기를 사용한 최소한의 워크플로우:
```bash
# 1) Disassemble to HASM directories
hbctool disasm assets/index.android.bundle ./hasm
# 2) Edit a guard or feature flag (example: force boolean true)
# In the relevant .hasm, replace a LoadConstUInt8 0 with 1
# or change a conditional jump target to bypass a check.
# 3) Reassemble into a new bundle
hbctool asm ./hasm assets/index.android.bundle
# 4) Repack the APK and resign
zip -r ../patched.apk *
# Align/sign as usual (see Android signing section in HackTricks)
```
Hermes 바이트코드 형식은 버전이 있으며, 어셈블러는 정확한 디스크 형식과 일치해야 합니다. 형식 오류가 발생하면 업데이트된 포크/대안으로 전환하거나 일치하는 Hermes 도구를 재구성해야 합니다.
## 동적 분석
앱을 동적으로 분석하려면 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/)에서 확인할 수 있습니다.
### Frida를 사용하여 릴리스에서 Dev Support 활성화 (주의사항)
일부 앱은 실수로 Dev Support를 전환할 수 있는 클래스를 포함하여 배포됩니다. 존재하는 경우, `getUseDeveloperSupport()`가 true를 반환하도록 강제할 수 있습니다:
```javascript
// frida -U -f com.target.app -l enable-dev.js
Java.perform(function(){
try {
var Host = Java.use('com.facebook.react.ReactNativeHost');
Host.getUseDeveloperSupport.implementation = function(){
return true; // force dev support
};
console.log('[+] Patched ReactNativeHost.getUseDeveloperSupport');
} catch (e) {
console.log('[-] Could not patch: ' + e);
}
});
```
경고: 제대로 구축된 릴리스 빌드에서는 `DevSupportManagerImpl` 및 관련 디버그 전용 클래스가 제거되며, 이 플래그를 전환하면 앱이 충돌하거나 아무런 효과가 없을 수 있습니다. 이 기능이 작동하면 일반적으로 개발자 메뉴를 노출하고 디버거/검사기를 연결할 수 있습니다.
### RN 앱에서의 네트워크 가로채기
React Native Android는 일반적으로 내부에서 OkHttp에 의존합니다( `Networking` 네이티브 모듈을 통해). 비루팅된 장치에서 동적 테스트 중에 트래픽을 가로채거나 관찰하려면:
- 시스템 프록시 사용 + 사용자 CA 신뢰 또는 다른 일반 Android TLS 우회 기술 사용.
- RN 전용 팁: 앱이 실수로 릴리스에서 Flipper를 번들에 포함한 경우(디버그 도구), Flipper 네트워크 플러그인이 요청/응답을 노출할 수 있습니다.
일반 Android 가로채기 및 핀 고정 우회 기술에 대한 참조:
{{#ref}}
make-apk-accept-ca-certificate.md
{{#endref}}
{{#ref}}
frida-tutorial/objection-tutorial.md
{{#endref}}
## 인기 RN 라이브러리의 최근 문제(확인할 사항)
JS 번들 또는 네이티브 라이브에서 볼 수 있는 서드파티 모듈을 감사할 때, 알려진 취약점을 확인하고 `package.json`/`yarn.lock`에서 버전을 검증하십시오.
- react-native-mmkv (Android): 2.11.0 이전 버전은 선택적 암호화 키를 Android 로그에 기록했습니다. ADB/logcat이 사용 가능하면 비밀이 복구될 수 있습니다. >= 2.11.0을 보장하십시오. 지표: `react-native-mmkv` 사용, 암호화와 함께 MMKV 초기화를 언급하는 로그 문구. CVE-2024-21668.
- react-native-document-picker: 9.1.1 이전 버전은 Android에서 경로 탐색에 취약했습니다(파일 선택), 9.1.1에서 수정되었습니다. 입력 및 라이브러리 버전을 검증하십시오.
빠른 점검:
```bash
grep -R "react-native-mmkv" -n {index.android.bundle,*.map} 2>/dev/null || true
grep -R "react-native-document-picker" -n {index.android.bundle,*.map} 2>/dev/null || true
# If you also have the node_modules (rare on release): grep -R in package.json / yarn.lock
```
## References
- [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)
- CVE-2024-21668: react-native-mmkv logs encryption key on Android, fixed in v2.11.0 (NVD): https://nvd.nist.gov/vuln/detail/CVE-2024-21668
- hbctool (and forks) for Hermes assemble/disassemble: https://github.com/bongtrop/hbctool
{{#include ../../banners/hacktricks-training.md}}