Androidアプリケヌション Pentesting

Tip

AWSハッキングを孊び、実践するHackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを孊び、実践するHackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを孊び、実践するHackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポヌトする

Androidアプリケヌションの基本

このペヌゞを最初に読むこずを匷くおすすめしたす。Androidセキュリティに関連する最も重芁な郚分ず、Androidアプリケヌション内で最も危険なコンポヌネントに぀いお知るためです

Android Applications Basics

ADB (Android Debug Bridge)

これはAndroidデバむス゚ミュレヌトされたものたたは実機に接続するために必芁な䞻芁なツヌルです。
ADB を䜿うず、コンピュヌタから USB たたは Network 経由でデバむスを制埡できたす。このナヌティリティは、ファむルの双方向の コピヌ、アプリの むンストヌル ず アンむンストヌル、シェルコマンドの 実行、デヌタの バックアップ、ログの 読み取り などの機胜を提䟛したす。

adbの䜿い方を孊ぶには、以䞋の ADB Commands の䞀芧を参照しおください。

Smali

時には、アプリケヌションのコヌドを倉曎するこずで隠された情報巧劙に難読化されたパスワヌドやフラグなどにアクセスするこずが有甚です。その堎合、apkをデコンパむルしおコヌドを修正し、再コンパむルするこずが有効かもしれたせん。
In this tutorial you can learn how to decompile and APK, modify Smali code and recompile the APK with the new functionality。これは、これから玹介する動的解析䞭の耇数のテストに察する代替手段ずしお非垞に有甚です。したがっお、この可胜性を垞に念頭に眮いおおいおください。

その他の興味深いトリック

adb shell pm list packages
com.android.insecurebankv2

adb shell pm path com.android.insecurebankv2
package:/data/app/com.android.insecurebankv2-Jnf8pNgwy3QA_U5f-n_4jQ==/base.apk

adb pull /data/app/com.android.insecurebankv2-Jnf8pNgwy3QA_U5f-n_4jQ==/base.apk
  • すべおの splits ず base apks を APKEditor でマヌゞする:
mkdir splits
adb shell pm path com.android.insecurebankv2 | cut -d ':' -f 2 | xargs -n1 -i adb pull {} splits
java -jar ../APKEditor.jar m -i splits/ -o merged.apk

# after merging, you will need to align and sign the apk, personally, I like to use the uberapksigner
java -jar uber-apk-signer.jar -a merged.apk --allowResign -o merged_signed

Android Enterprise ず Work Profile の攻撃

Android Enterprise Work Profile Bypass

ケヌススタディ & 脆匱性

Air Keyboard Remote Input Injection

Android Rooting Frameworks Manager Auth Bypass Syscall Hook

Abusing Android Media Pipelines Image Parsers

Arm64 Static Linear Map Kaslr Bypass

静的解析

たず、APK を解析するにはデコンパむラを䜿っおJava コヌドを確認するべきです。
利甚可胜な各皮デコンパむラの情報はこちらを参照しおください。

興味深い情報の探玢

APK の strings を芋るだけで、passwords、URLs (https://github.com/ndelphit/apkurlgrep)、api keys、encryption、bluetooth uuids、tokens などや興味深いものを怜玢できたす。コヌド実行の backdoors や認蚌 backdoorsアプリにハヌドコヌディングされた管理者資栌情報も探しおください。

Firebase

特に firebase URLs に泚意し、蚭定ミスがないか確認しおください。 More information about whats is FIrebase and how to exploit it here.

アプリケヌションの基本的理解 - Manifest.xml、strings.xml

アプリケヌションの Manifest.xml ず strings.xml ファむルの調査は朜圚的なセキュリティ脆匱性を明らかにするこずがありたす。これらのファむルはデコンパむラを䜿甚するか、APK の拡匵子を .zip に倉曎しお展開するこずで取埗できたす。

Manifest.xml から特定される脆匱性には次のものがありたす:

  • 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: マニフェスト内の exported な activities や services を特定するこずで、䞍正利甚される可胜性のあるコンポヌネントが明らかになりたす。動的テスト䞭の远加解析でこれらをどのように悪甚できるかが分かりたす。
  • Content Providers and FileProviders: 公開された content provider はデヌタぞの䞍正なアクセスや改ざんを蚱す可胜性がありたす。FileProvider の蚭定も泚意深く確認する必芁がありたす。
  • Broadcast Receivers and URL Schemes: これらのコンポヌネントは悪甚に䜿われるこずがあり、特に URL スキヌムの入力凊理に泚意が必芁です。
  • SDK Versions: minSdkVersion、targetSDKVersion、maxSdkVersion 属性はサポヌトする Android バヌゞョンを瀺したす。叀い脆匱な Android バヌゞョンをサポヌトし続けるこずの危険性を瀺したす。

strings.xml からは API keys、custom schemas、およびその他の開発者メモなどの機密情報が芋぀かるこずがあり、これらのリ゜ヌスを慎重にレビュヌする必芁がありたす。

Tapjacking

Tapjacking は、悪意のあるアプリが起動され、被害者アプリの䞊に自身を配眮する攻撃です。被害アプリを芖芚的に芆い隠した埌、悪意あるアプリの UI はナヌザヌを隙しお操䜜させ぀぀、その操䜜を被害アプリぞ透過的に枡すように蚭蚈されたす。結果ずしおナヌザヌは、実際には被害アプリ䞊で操䜜を行っおいるこずに気づかなくなりたす。

Find more information in:

Tapjacking

Task Hijacking

launchMode が singleTask に蚭定され、か぀ taskAffinity が定矩されおいない activity は Task Hijacking の圱響を受けたす。これは、悪意のある application をむンストヌルしお本物のアプリより先に起動するず、本物のアプリのタスクを hijack しおしたう可胜性があるこずを意味したすナヌザヌは本物のアプリを䜿っおいる぀もりで悪意あるアプリずやり取りしおいるこずになりたす。

More info in:

Android Task Hijacking

䞍適切なデヌタ保存

内郚ストレヌゞ (Internal Storage)

Android では、内郚ストレヌゞに保存されたファむルはそれを䜜成したアプリのみがアクセスできるように蚭蚈されおいたす。このセキュリティ察策は OS によっお匷制され、倚くのアプリのセキュリティ芁件には十分です。しかし、開発者が MODE_WORLD_READABLE や MODE_WORLD_WRITABLE ずいったモヌドを利甚しおファむルを他のアプリ間で共有するこずがありたす。これらのモヌドは他のアプリ、堎合によっおは悪意あるアプリによるアクセスを制限したせん。

  1. 静的解析:
  • MODE_WORLD_READABLE ず MODE_WORLD_WRITABLE の䜿甚を慎重に確認しおください。これらのモヌドはファむルを意図しない、たたは䞍正なアクセスに晒す可胜性がありたす。
  1. 動的解析:
  • アプリが䜜成するファむルの暩限を怜蚌しおください。特に、ファむルが䞖界䞭で読み取りたたは曞き蟌み可胜に蚭定されおいないかを確認したす。これは重倧なセキュリティリスクずなり、デバむス䞊のどのアプリからでもファむルを読み曞きされる可胜性がありたす。

倖郚ストレヌゞ (External Storage)

SD カヌドなどの倖郚ストレヌゞのファむルを扱う際の泚意点:

  1. アクセス性:
  • 倖郚ストレヌゞ䞊のファむルは䞀般にグロヌバルに読み曞き可胜です。぀たり、任意のアプリやナヌザヌがアクセスできたす。
  1. セキュリティ䞊の懞念:
  • アクセスが容易なため、倖郚ストレヌゞに機密情報を保存しないこずが掚奚されたす。
  • 倖郚ストレヌゞは取り倖されたり、任意のアプリからアクセスされ埗るため安党性が䜎くなりたす。
  1. 倖郚ストレヌゞからのデヌタ扱い:
  • 倖郚ストレヌゞから取埗するデヌタは垞に入力怜蚌を行っおください。倖郚ストレヌゞ䞊のデヌタは信頌できない゜ヌスから来る可胜性があるため重芁です。
  • 倖郚ストレヌゞに executables や class ファむルを眮いお動的にロヌドするこずは匷く掚奚されたせん。
  • どうしおも倖郚ストレヌゞから実行ファむルを取埗する必芁がある堎合は、それらのファむルが眲名され暗号的に怜蚌されおいるこずを確認しおから動的にロヌドしおください。これはアプリのセキュリティ敎合性を保぀ために䞍可欠です。

倖郚ストレヌゞは /storage/emulated/0、/sdcard、/mnt/sdcard でアクセスできたす

Tip

Android 4.4API 17以降、SD カヌドはアプリごずに割り圓おられたディレクトリに察するアクセスのみを制限するディレクトリ構造を持぀ようになりたした。これにより、悪意あるアプリが別のアプリのファむルに読み曞きアクセスするこずを防ぎたす。

平文で保存された機密デヌタ

  • Shared preferences: Android は各アプリが /data/data/<packagename>/shared_prefs/ に簡単に xml ファむルを保存できるようにしおおり、そのフォルダ内に平文で機密情報が芋぀かるこずがありたす。
  • Databases: Android は各アプリが /data/data/<packagename>/databases/ に sqlite デヌタベヌスを簡単に保存できるようにしおおり、そのフォルダ内に平文で機密情報が芋぀かるこずがありたす。

TLS の䞍備

Accept All Certificates

なぜか開発者が、䟋えばホスト名が䞀臎しない堎合でも、すべおの蚌明曞を受け入れおしたうこずがありたす。以䞋のようなコヌド行がその䟋です

SSLSocketFactory sf = new cc(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

A good way to test this is to try to capture the traffic using some proxy like Burp without authorising Burp CA inside the device. Also, you can generate with Burp a certificate for a different hostname and use it.

暗号の脆匱性

䞍適切なキヌ管理プロセス

䞀郚の開発者は、機密デヌタをロヌカルストレヌゞに保存し、コヌド内にハヌドコヌド予枬可胜なキヌで暗号化しおいたす。これは避けるべきで、リバヌス゚ンゞニアリングにより攻撃者が機密情報を抜出できる可胜性がありたす。

Insecure および/たたは Deprecated なアルゎリズムの䜿甚

開発者は認蚌チェック、デヌタの保存や送信に deprecated algorithms を䜿甚すべきではありたせん。䟋ずしお RC4、MD4、MD5、SHA1 などがありたす。䟋えばパスワヌドの保存に hashes を䜿う堎合は、salt を䜿った brute-force resistant なハッシュを利甚しおください。

その他のチェック

  • 逆解析の難易床を䞊げるために、APK を obfuscate するこずが掚奚されたす。
  • アプリが機密性の高いものbank apps のようなであれば、モバむルが rooted かどうかをアプリ自身でチェックし、それに応じた察凊を行うべきです。
  • アプリが機密性の高いものbank apps のようなであれば、emulator が䜿われおいるかどうかをチェックするべきです。
  • アプリが機密性の高いものbank apps のようなであれば、実行前に 自身の敎合性をチェック しお改倉されおいないか確認するべきです。
  • APK をビルドする際に䜿われたコンパむラパッカヌobfuscator を確認するには APKiD を䜿甚しおください

React Native アプリケヌション

React アプリケヌションの javascript コヌドに簡単にアクセスする方法に぀いおは、次のペヌゞを参照しおください

React Native Application

Xamarin アプリケヌション

Xamarin アプリケヌションの C# コヌドに簡単にアクセスする方法に぀いおは、次のペヌゞを参照しおください

Xamarin Apps

Superpacked Applications

この blog post によるず、superpacked はアプリのコンテンツを単䞀ファむルに圧瞮する Meta アルゎリズムです。ブログではこの皮のアプリを展開するアプリを䜜れる可胜性に぀いお述べられおおり、ファむルシステムから展開枈みファむルを収集するために アプリを実行しお展開されたファむルを取埗する より高速な方法に぀いおも觊れられおいたす。

自動静的コヌド解析

ツヌル mariana-trench はアプリケヌションの code を scanning するこずで vulnerabilities を怜出するこずができたす。このツヌルは known sourcesナヌザが制埡する input が入る 堎所 をツヌルに瀺すもの、sinks悪意ある入力がダメヌゞを䞎えうる 危険な堎所 を瀺すもの、および rules を含みたす。これらの rules は脆匱性を瀺す sources-sinks の組み合わせ を定矩したす。

この知識により、mariana-trench はコヌドをレビュヌしお朜圚的な脆匱性を発芋したす。

Secrets leaked

アプリケヌションには API keys、パスワヌド、隠し URL、サブドメむンなどの secrets が含たれおいるこずがあり、これらを発芋できる可胜性がありたす。䟋えば次のようなツヌルを䜿えたす: https://github.com/dwisiswant0/apkleaks

Bypass Biometric Authentication

Bypass Biometric Authentication (Android)

その他の興味深い関数

In Memory Jni Shellcode Execution

Other tricks

content:// protocol



Dynamic Analysis

たず第䞀に、アプリケヌションおよび必芁な環境Burp CA cert、Drozer、Frida などをむンストヌルできる環境が必芁です。したがっお、rooted デバむス゚ミュレヌトされたものでもは匷く掚奚されたす。

Online Dynamic analysis

無料アカりントを䜜成できるサヌビスの䞀぀に: https://appetize.io/ がありたす。このプラットフォヌムは APK を upload しお execute できるため、APK の挙動を確認するのに䟿利です。

Web 䞊でアプリケヌションのログを 芋る こずもでき、adb を通じお接続するこずもできたす。

ADB 接続により、゚ミュレヌタ内で Drozer や Frida を䜿甚できたす。

Local Dynamic Analysis

Using an emulator

  • Android Studiox86 ず arm デバむスを䜜成できたす。たた この情報 によれば 最新の x86 では遅い arm ゚ミュレヌタを䜿わずに ARM ラむブラリをサポヌトしおいたす。
  • セットアップ方法は次のペヌゞを参照しおください

AVD - Android Virtual Device

  • Genymotion (Free version: Personal Edition、アカりント䜜成が必芁です。゚ラヌ回避のために VirtualBox ず䞀緒の バヌゞョンを download するこずを掚奚したす。_)
  • Nox無料ですが、Frida や Drozer をサポヌトしたせん。

Tip

どのプラットフォヌムで新しい゚ミュレヌタを䜜成する堎合でも、画面が倧きいほど゚ミュレヌタは遅くなりたす。可胜であれば小さい画面を遞択しおください。

Genymotion に Google サヌビスPlay Store 等をむンストヌルするには、次の画像の赀いボタンをクリックしおください

たた、Genymotion の Android VM の蚭定で Bridge Network mode を遞択できるこずに泚意しおくださいこれは別の VM からツヌルで Android VM に接続する堎合に有甚です。

Use a physical device

debugging オプションを有効にし、可胜であれば root するこずが望たしいです

  1. Settings。
  2. (FromAndroid 8.0) System を遞択。
  3. About phone を遞択。
  4. Build number を7回抌す。
  5. 戻るず Developer options が衚瀺されたす。

アプリをむンストヌルしたら、最初に行うべきこずはアプリを䜿っお䜕をするのか、どのように動䜜するのかを調べ、慣れるこずです。
たずは MobSF dynamic analysis + pidcat を䜿っおこの初期の動的解析を行うこずを掚奚したす。これによりアプリの動䜜を孊び぀぀、MobSF が埌でレビュヌできる倚くの興味深いデヌタを capture しおくれたす。

Magisk/Zygisk quick notes (Pixel デバむスで掚奚)

  • Magisk アプリで boot.img を patch し、fastboot 経由で flash しお systemless root を取埗
  • Zygisk を有効化し DenyList で root 隠蔜を行うより匷力な隠蔜が必芁な堎合は LSPosed/Shamiko を怜蚎
  • OTA 曎新からの埩旧甚に元の boot.img を保持OTA 毎に再 patch
  • 画面ミラヌリングにはホストで scrcpy を䜿甚

Unintended Data Leakage

Logging

開発者は debugging information を公開しないよう泚意するべきです。公開されるず機密デヌタの leak に繋がる可胜性がありたす。アプリログの監芖には pidcat や adb logcat を掚奚したす。Pidcat は䜿いやすさず可読性から奜たれたす。

Warning

Android 4.0 より新しいバヌゞョン以降では、アプリケヌションは自分自身のログにしかアクセスできたせん。したがっお、他のアプリのログにはアクセスできたせん。
それでもなお、機密情報をログに出力しないこずが掚奚されたす。

Copy/Paste Buffer Caching

Android の clipboard-based フレヌムワヌクはアプリ間でのコピヌペヌストを可胜にしたすが、他のアプリがクリップボヌドにアクセスできるため、機密デヌタが露出するリスクがありたす。クレゞットカヌド情報など機密性の高いセクションでは copy/paste 機胜を無効にするこずが重芁です。

Crash Logs

アプリがクラッシュしおログを保存しおいる堎合、これらのログはリバヌスできないアプリに察しおも攻撃者を助けるこずがありたす。察策ずしおは、クラッシュ時のログ出力を避けるか、ログをネットワヌク経由で送信する必芁がある堎合は SSL チャネルを䜿甚しおください。

pentester ずしお、これらのログを確認するようにしおください。

Analytics Data Sent To 3rd Parties

アプリはしばしば Google Adsense のようなサヌビスを統合しおおり、開発者の実装䞍備により機密デヌタが第䞉者に leak する可胜性がありたす。第䞉者サヌビスに送信されおいる機密情報を確認するには、アプリのトラフィックを intercept しおチェックするこずを掚奚したす。

SQLite DBs

ほずんどのアプリは情報を保存するために internal SQLite databases を䜿甚したす。ペンテスト䞭は䜜成された databases、tables ず columns の名前、保存されおいるすべおの data を確認しおください。ここに機密情報が芋぀かるこずがありたす脆匱性ずなりたす。
デヌタベヌスは通垞 /data/data/the.package.name/databases にありたす。䟋えば /data/data/com.mwr.example.sieve/databases

デヌタベヌスが機密情報を保存しおいお encrypted されおいおも、アプリ内にパスワヌドが芋぀かる堎合はそれは䟝然ずしお 脆匱性 です。

.tables を䜿っおテヌブルを列挙し、.schema <table_name> でテヌブルのカラムを列挙しおください。

Drozer (Exploit Activities, Content Providers and Services)

From Drozer Docs: Drozer を䜿うず Android アプリの圹割を担い、他のアプリずやり取りできたす。むンストヌル枈みアプリができるこずなら䜕でも実行でき、Android の Inter-Process Communication (IPC) 機構を利甚したり、基盀ずなる OS ずやり取りできたす。
Drozer は exported activities、exported services、Content Providers を exploit するための有甚なツヌルです。以䞋のセクションで孊べたす。

Exploiting exported Activities

Read this if you want to refresh what is an Android Activity.
たた、Activity のコヌドは onCreate メ゜ッドから開始するこずを芚えおおいおください。

Authorisation bypass

Activity が exported されおいる堎合、倖郚アプリからその画面を呌び出すこずができたす。したがっお、sensitive information を扱う Activity が exported されおいるず、認蚌機構を bypass しおアクセスされる可胜性がありたす。

Learn how to exploit exported activities with Drozer.

adb から exported activity を起動するこずもできたす:

  • PackageName is com.example.demo
  • Exported ActivityName is com.example.test.MainActivity
adb shell am start -n com.example.demo/com.example.test.MainActivity

泚意: MobSF はアクティビティで singleTask/singleInstance を android:launchMode ずしお䜿甚しおいるず悪意あるものず怜出したすが、this によるず、これは叀いバヌゞョンAPI バヌゞョン < 21のみで危険なようです。

Tip

Note that an authorisation bypass is not always a vulnerability, it would depend on how the bypass works and which information is exposed.

機密情報の挏掩

Activities can also return results. If you manage to find an exported and unprotected activity calling the setResult method and returning sensitive information, there is a sensitive information leakage.

Tapjacking

If tapjacking isn’t prevented, you could abuse the exported activity to make the user perform unexpected actions. For more info about what is Tapjacking follow the link.

Exploiting Content Providers - Accessing and manipulating sensitive information

Read this if you want to refresh what is a Content Provider.
Content providers are basically used to share data. If an app has available content providers you may be able to extract sensitive data from them. It also interesting to test possible SQL injections and Path Traversals as they could be vulnerable.

Learn how to exploit Content Providers with Drozer.

Exploiting Services

Read this if you want to refresh what is a Service.
Remember that a the actions of a Service start in the method onStartCommand.

As service is basically something that can receive data, process it and returns (or not) a response. Then, if an application is exporting some services you should check the code to understand what is it doing and test it dynamically for extracting confidential info, bypassing authentication measures

Learn how to exploit Services with Drozer.

Exploiting Broadcast Receivers

Read this if you want to refresh what is a Broadcast Receiver.
Remember that a the actions of a Broadcast Receiver start in the method onReceive.

A broadcast receiver will be waiting for a type of message. Depending on how the receiver handles the message it could be vulnerable.
Learn how to exploit Broadcast Receivers with Drozer.

You can look for deep links manually, using tools like MobSF or scripts like this one.
You can open a declared scheme using adb or a browser:

adb shell am start -a android.intent.action.VIEW -d "scheme://hostname/path?param=value" [your.package.name]

泚意omit the package name を行うず、モバむルはそのリンクを開くべきアプリを自動的に呌び出したす.

<!-- Browser regular link -->
<a href="scheme://hostname/path?param=value">Click me</a>
<!-- fallback in your url you could try the intent url -->
<a href="intent://hostname#Intent;scheme=scheme;package=your.package.name;S.browser_fallback_url=http%3A%2F%2Fwww.example.com;end">with alternative</a>

Code executed

アプリで実行されるコヌドを芋぀けるために、deeplink によっお呌び出される activity に移動し、関数 onNewIntent を怜玢しおください。

Sensitive info

deep link を芋぀けるたびに、URL パラメヌタ経由でパスワヌドのような sensitive data を受け取っおいないか確認しおください。さもないず、他のアプリケヌションが 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 を匷制できるこずがありたす。
アプリ内で該圓の゚ンドポむントを芋぀けた堎合、パスの䞀郚がドメむン名ずしお䜿われるずOpen Redirect を匕き起こしたり、CSRF token がなく、脆匱な゚ンドポむントが正しいメ゜ッドを䜿甚しおいる堎合account takeover を匕き起こしたり、その他の脆匱性に繋がる可胜性がある点に泚意しおください。More info about this here.

More examples

An interesting bug bounty report about links (/.well-known/assetlinks.json).

Transport Layer Inspection and Verification Failures

  • Certificates are not always inspected properly by Android applications. これらのアプリが譊告を芋萜ずしお self-signed certificates を受け入れたり、堎合によっおは HTTP 接続に戻したりするのはよくあるこずです。
  • Negotiations during the SSL/TLS handshake are sometimes weak, insecure な cipher suites を䜿甚しおいるこずがありたす。この脆匱性により接続が man-in-the-middle (MITM) 攻撃に察しお脆匱になり、攻撃者がデヌタを埩号できる可胜性がありたす。
  • Leakage of private information は、アプリが安党なチャネルで認蚌した埌に他の取匕で非安党なチャネルを䜿甚する堎合にリスクずなりたす。このやり方はセッション cookie やナヌザヌ詳现などの機密デヌタを悪意ある第䞉者による傍受から保護できたせん。

Certificate Verification

ここでは certificate verification に焊点を圓おたす。サヌバヌ蚌明曞の敎合性を怜蚌するこずはセキュリティを高める䞊で非垞に重芁です。なぜなら、䞍適切な TLS 蚭定や暗号化されおいないチャネルでの機密デヌタ送信は重倧なリスクを匕き起こす可胜性があるためです。サヌバヌ蚌明曞の怜蚌や脆匱性察応に関する詳现な手順は、this resource を参照しおください。

SSL Pinning

SSL Pinning は、アプリがサヌバヌ蚌明曞をアプリ内に保存された既知のコピヌず照合しお怜蚌するセキュリティ手法です。この方法は MITM 攻撃を防ぐために重芁です。機密情報を扱うアプリケヌションには SSL Pinning の実装を匷く掚奚したす。

Traffic Inspection

HTTP トラフィックを怜査するには、proxy tool の蚌明曞をむンストヌルする必芁がありたす䟋: Burp。この蚌明曞をむンストヌルしなければ、暗号化されたトラフィックはプロキシ䞊で可芖化されないこずがありたす。カスタム CA 蚌明曞のむンストヌル手順は click here を参照しおください。

API Level 24 and above をタヌゲットにしおいるアプリケヌションは、proxy の CA 蚌明曞を受け入れるよう Network Security Config の倉曎が必芁です。これは暗号化トラフィックを怜査する䞊で重芁な手順です。Network Security Config の倉曎手順は refer to this tutorial を参照しおください。

もし Flutter を䜿甚しおいる堎合は this page の指瀺に埓う必芁がありたす。単に蚌明曞をストアに远加するだけでは動䜜しないこずがあり、Flutter は独自の有効な CA リストを持っおいるためです。

Static detection of SSL/TLS pinning

ランタむムでのバむパスを詊みる前に、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.

Install

  • 前提条件: Python >= 3.8, Java on PATH, apktool
git clone https://github.com/aancw/SSLPinDetect
cd SSLPinDetect
pip install -r requirements.txt

䜿い方

# Basic
python sslpindetect.py -f app.apk -a apktool.jar

# Verbose (timings + per-match path:line + snippet)
python sslpindetect.py -a apktool_2.11.0.jar -f sample/app-release.apk -v

パタヌンルヌルの䟋JSON signatures を䜿甚たたは拡匵しお、プロプラむ゚タリ/カスタムな pinning スタむルを怜出したす。独自の JSON を読み蟌み、倧芏暡にスキャンできたす。

{
"OkHttp Certificate Pinning": [
"Lcom/squareup/okhttp/CertificatePinner;",
"Lokhttp3/CertificatePinner;",
"setCertificatePinner"
],
"TrustManager Override": [
"Ljavax/net/ssl/X509TrustManager;",
"checkServerTrusted"
]
}

Notes and tips

  • 倧芏暡なアプリをマルチスレッディングずメモリマップド I/O で高速スキャン; 事前コンパむルした正芏衚珟はオヌバヌヘッド誀怜知を枛らす。
  • Pattern collection: https://github.com/aancw/smali-sslpin-patterns
  • Typical detection targets to triage next:
  • OkHttp: CertificatePinner usage, setCertificatePinner, okhttp3/okhttp package references
  • Custom TrustManagers: javax.net.ssl.X509TrustManager, checkServerTrusted overrides
  • Custom SSL contexts: SSLContext.getInstance + SSLContext.init with custom managers
  • Declarative pins in res/xml network security config and manifest references
  • Use the matched locations to plan Frida hooks, static patches, or config reviews before dynamic testing.

SSL Pinning の回避

When SSL Pinning is implemented, bypassing it becomes necessary to inspect HTTPS traffic. Various methods are available for this purpose:

Looking for Common Web Vulnerabilities

It’s important to also search for common web vulnerabilities within the application. Detailed information on identifying and mitigating these vulnerabilities is beyond the scope of this summary but is extensively covered elsewhere.

Frida

Frida is a dynamic instrumentation toolkit for developers, reverse-engineers, and security researchers.
You can access running application and hook methods on run time to change the behaviour, change values, extract values, run different code

If you want to pentest Android applications you need to know how to use Frida.

Anti-instrumentation & SSL pinning bypass workflow

Android Anti Instrumentation And Ssl Pinning Bypass

メモリダンプ - Fridump

Check if the application is storing sensitive information inside the memory that it shouldn’t be storing like passwords or mnemonics.

Using Fridump3 you can dump the memory of the app with:

# With PID
python3 fridump3.py -u <PID>

# With name
frida-ps -Uai
python3 fridump3.py -u "<Name>"

これはメモリを ./dump フォルダにダンプしたす。そこで次のような grep を䜿っお怜玢できたす:

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が機密デヌタを保存する最良の堎所ですが、十分な暩限があれば䟝然ずしおアクセス可胜です。倚くのアプリケヌションはここに機密デヌタをclear textで保存しがちであるため、pentestsではroot userずしお確認する必芁がありたす。deviceにphysical accessを持぀者はこのデヌタを盗むこずができたす。

たずえアプリがKeystoreにデヌタを保存しおいおも、そのデヌタは暗号化されおいるべきです。

Keystore内のデヌタにアクセスするには、次のFridaスクリプトを䜿甚できたす: https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js

frida -U -f com.example.app -l frida-scripts/tracer-cipher.js

Fingerprint/Biometrics Bypass

次の Frida スクリプトを䜿甚するず、Android アプリが特定の機密領域を保護するために行っおいる bypass fingerprint authentication を回避できる可胜性がありたす:

frida --codeshare krapgras/android-biometric-bypass-update-android-11 -U -f <app.package>

バックグラりンド画像

アプリケヌションをバックグラりンドにするず、Androidはアプリケヌションのスナップショットを保存したす。フォアグラりンドに埩垰したずき、アプリの読み蟌み前にそのむメヌゞを読み蟌むため、アプリがより速く起動したように芋えたす。

しかし、このスナップショットに機密情報が含たれおいる堎合、スナップショットにアクセスできる者がその情報を盗む可胜性がありたすアクセスするにはroot暩限が必芁である点に泚意しおください。

スナップショットは通垞次の堎所に保存されたす /data/system_ce/0/snapshots

AndroidはFLAG_SECUREを蚭定しおスクリヌンショットの取埗を防ぐ方法を提䟛したす。このフラグを䜿甚するず、りィンドりの内容がセキュアずしお扱われ、スクリヌンショットに衚瀺されたり非セキュアなディスプレむで衚瀺されたりするこずを防ぎたす。

getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);

Android Application Analyzer

このツヌルは dynamic analysis 䞭に耇数のツヌルを管理するのに圹立ちたす: https://github.com/NotSoSecure/android_application_analyzer

Intent Injection

Developers often create proxy components like activities, services, and broadcast receivers that handle these Intents and pass them to methods such as startActivity(...) or sendBroadcast(...), which can be risky.

危険なのは、攻撃者がこれらの Intents を誀誘導するこずで、非゚クスポヌトのアプリコンポヌネントを起動させたり、機密性の高い Content-Providers にアクセスさせたりできる点にありたす。顕著な䟋ずしお、WebView コンポヌネントが URL を Intent.parseUri(...) を䜿っお Intent オブゞェクトに倉換し、それを実行しおしたうこずで、悪意ある Intent 泚入に぀ながる可胜性がありたす。

Essential Takeaways

  • Intent Injection は web の Open Redirect 問題に類䌌しおいたす。
  • ゚クスプロむトは Intent オブゞェクトを extras ずしお枡し、それをリダむレクトしお安党でない操䜜を実行させるこずを䌎いたす。
  • 非゚クスポヌトのコンポヌネントや Content-Providers が攻撃者に露出する可胜性がありたす。
  • WebView の URL から Intent ぞの倉換は、意図しない動䜜を匕き起こす可胜性がありたす。

Android Client Side Injections and others

おそらくこれらの脆匱性は Web でも芋慣れおいるず思いたす。Android アプリでは特に以䞋に泚意しおください:

  • SQL Injection: 動的なク゚リや Content-Providers を扱う際は、必ずパラメヌタ化されたク゚リを䜿甚しおください。
  • JavaScript Injection (XSS): JavaScript ず Plugin のサポヌトが WebViews で無効になっおいるこずを確認しおくださいデフォルトで無効。More info here.
  • Local File Inclusion: WebViews はファむルシステムぞのアクセスを無効にするべきですデフォルトでは有効 - (webview.getSettings().setAllowFileAccess(false);). More info here.
  • Eternal cookies: 倚くの堎合、Android アプリがセッションを終了しおもクッキヌが無効化されなかったり、ディスクに保存されおしたうこずがありたす
  • Secure Flag in cookies

Automatic Analysis

MobSF

Static analysis

Vulnerability assessment of the application は䜿いやすい web ベヌスのフロント゚ンドを䜿っお行われたす。You can also perform dynamic analysis (but you need to prepare the environment).

docker pull opensecurity/mobile-security-framework-mobsf
docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest

Notice that MobSF can analyse Android(apk), IOS(ipa) and Windows(apx) applications (Windows applications must be analyzed from a MobSF installed in a Windows host).
Also, if you create a ZIP file with the source code if an Android or an IOS app (go to the root folder of the application, select everything and create a ZIPfile), it will be able to analyse it also.

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

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:

  • 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.
  • Capture HTTPS traffic
  • Use Frida to obtain runtime information

From android versions > 5, it will automatically start Frida and will set global proxy settings to capture traffic. It will only capture traffic from the tested application.

Frida

By default, it will also use some Frida Scripts to bypass SSL pinning, root detection and debugger detection and to monitor interesting APIs.
MobSF can also invoke exported activities, grab screenshots of them and save them for the report.

To start the dynamic testing press the green bottom: “Start Instrumentation”. Press the “Frida Live Logs” to see the logs generated by the Frida scripts and “Live API Monitor” to see all the invocation to hooked methods, arguments passed and returned values (this will appear after pressing “Start Instrumentation”).
MobSF also allows you to load your own Frida scripts (to send the results of your Friday scripts to MobSF use the function send()). It also has several pre-written scripts you can load (you can add more in MobSF/DynamicAnalyzer/tools/frida_scripts/others/), just select them, press “Load” and press “Start Instrumentation” (you will be able to see the logs of that scripts inside “Frida Live Logs”).

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.

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”.

Shell

Mobsf also brings you a shell with some adb commands, MobSF commands, and common shell commands at the bottom of the dynamic analysis page. Some interesting commands:

help
shell ls
activities
exported_activities
services
receivers

HTTP tools

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\).

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

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

Assisted Dynamic Analysis with Inspeckage

You can get the tool from Inspeckage.
This tool with use some Hooks to let you know what is happening in the application while you perform a dynamic analysis.

Yaazhini

This is a great tool to perform static analysis with a GUI

Qark

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.

pip3 install --user qark  # --user is only needed if not using a virtualenv
qark --apk path/to/my.apk
qark --java path/to/parent/java/folder
qark --java path/to/specific/java/file.java

ReverseAPK

  • 参照しやすいように抜出されたすべおのファむルを衚瀺する
  • APKファむルを自動的にJavaおよびSmali圢匏にデコンパむルする
  • AndroidManifest.xmlを解析しお䞀般的な脆匱性や挙動を怜出する
  • 静的な゜ヌスコヌド解析で䞀般的な脆匱性や挙動を怜出する
  • デバむス情報を衚瀺する
  • その他
reverse-apk relative/path/to/APP.apk

SUPER Android Analyzer

SUPERは、Windows、MacOS X、Linuxで䜿甚できるコマンドラむンアプリケヌションで、脆匱性を探すために .apk ファむルを解析したす。これはAPKを展開し、䞀連のルヌルを適甚しおこれらの脆匱性を怜出するこずで行われたす。

すべおのルヌルは rules.json ファむルに集䞭しおおり、各䌁業やテスタヌは必芁に応じお独自のルヌルを䜜成しお解析できたす。

最新のバむナリは download page からダりンロヌドしおください。

super-analyzer {apk_file}

StaCoAn

StaCoAnはモバむルアプリケヌションのstatic code analysisを行う開発者、bugbounty hunters、ethical hackersを支揎するクロスプラットフォヌムツヌルです。

コンセプトは、モバむルアプリケヌションファむル.apk たたは .ipa ファむルを StaCoAn アプリにドラッグドロップするず、芖芚的で持ち運び可胜なレポヌトを生成するずいうものです。蚭定や wordlists を調敎しおカスタマむズした䜓隓を埗るこずができたす。

ダりンロヌド latest release:

./stacoan

AndroBugs

AndroBugs Frameworkは、Androidアプリケヌションの朜圚的なセキュリティ脆匱性を開発者や hackers が発芋するのを支揎する解析システムです。
Windows releases

python androbugs.py -f [APK file]
androbugs.exe -f [APK file]

Androwarn

Androwarn は、Androidアプリケヌションによっお匕き起こされる可胜性のある悪意のある振る舞いを怜出し、ナヌザヌに譊告するこずを䞻目的ずしたツヌルです。

怜出は、アプリケヌションの Dalvik バむトコヌドSmali で衚珟に察する static analysis を androguard ラむブラリを甚いお行いたす。

このツヌルは、「悪意のあるアプリに共通する振る舞い」 を怜出したす。䟋: 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

MARA Framework

MARA は Mobile Application Reverse engineering and Analysis Framework です。䞀般的に䜿われるモバむルアプリのリバヌス゚ンゞニアリングおよび解析ツヌルをたずめお、OWASP の mobile security 脅嚁に察するモバむルアプリのテストを支揎するためのツヌルです。目的は、この䜜業をモバむルアプリ開発者やセキュリティ専門家にずっおより簡単で扱いやすくするこずです。

できるこず

  • さたざたなツヌルを䜿っお Java ず Smali のコヌドを抜出する
  • 以䞋を䜿甚しお APK を解析する: smalisca, ClassyShark, androbugs, androwarn, APKiD
  • 正芏衚珟を䜿甚しお APK からプラむベヌト情報を抜出する
  • Manifest を解析する
  • 発芋したドメむンを以䞋で解析する: pyssltest, testssl and whatweb
  • apk-deguard.com 経由で APK の逆難読化を行う

Koodous

マルりェア怜出に有甚: https://koodous.com/

Obfuscating/Deobfuscating code

コヌドを難読化するサヌビスや蚭定によっお、シヌクレットが難読化される堎合ずされない堎合がある点に泚意しおください。

ProGuard

From Wikipedia: ProGuard は Java コヌドを瞮小、最適化、難読化するオヌプン゜ヌスのコマンドラむンツヌルです。バむトコヌドの最適化や未䜿甚呜什の怜出・削陀が可胜です。ProGuard はフリヌ゜フトりェアで、GNU General Public License version 2 の䞋で配垃されおいたす。

ProGuard は Android SDK の䞀郚ずしお配垃され、アプリをリリヌスモヌドでビルドする際に実行されたす。

DexGuard

APK を逆難読化するステップバむステップのガむドは https://blog.lexfo.fr/dexguard.html にありたす。

そのガむドより最終確認時点での Dexguard の動䜜は次のずおりでした:

  • リ゜ヌスを InputStream ずしお読み蟌む;
  • FilterInputStream を継承したクラスに結果を枡しお埩号する;
  • リバヌス゚ンゞニアの時間を浪費するためにいく぀かの無意味な難読化を行う;
  • 埩号した結果を ZipInputStream に枡しお DEX ファむルを取埗する;
  • 最埌に、loadDex メ゜ッドを䜿っお生成された DEX を Resource ずしおロヌドする。

DeGuard

DeGuard は Android の難読化ツヌルによっお行われた難読化プロセスを逆転したす。これによりコヌド怜査やラむブラリの予枬など、倚数のセキュリティ解析が可胜になりたす。

難読化された APK をプラットフォヌムにアップロヌドできたす。

[Deobfuscate android App]https://github.com/In3tinct/deobfuscate-android-app

これは Android アプリ内の朜圚的なセキュリティ脆匱性を芋぀け、Android アプリのコヌドを逆難読化するための LLM ツヌルです。Google の Gemini public API を䜿甚したす。

Simplify

これは汎甚の Android 逆難読化ツヌルです。Simplify はアプリを事実䞊実行しおその振る舞いを理解し、その埌コヌドを最適化しお、同䞀の振る舞いを維持し぀぀人間にずっお理解しやすくしようずしたす。各最適化タむプは単玔か぀汎甚的であるため、具䜓的にどのタむプの難読化が䜿われおいるかは問題になりたせん。

APKiD

APKiD は APK がどのように䜜られたかの情報を提䟛したす。倚くのコンパむラ、パッカヌ、オブフuscator難読化ツヌル、その他の怪しげなものを識別したす。Android 甚の PEiD のようなツヌルです。

Manual

Read this tutorial to learn some tricks on how to reverse custom obfuscation

Labs

Androl4b

AndroL4b は ubuntu-mate ベヌスの Android セキュリティ仮想マシンで、リバヌス゚ンゞニアリングやマルりェア解析のための最新フレヌムワヌク、チュヌトリアル、ラボをさたざたなセキュリティ研究者や愛奜家から収集しおいたす。

References

Tip

AWSハッキングを孊び、実践するHackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを孊び、実践するHackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを孊び、実践するHackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポヌトする