hacktricks/mobile-pentesting/android-app-pentesting/install-burp-certificate.md

14 KiB
Raw Blame History

Burp証明書のインストール

☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥

仮想マシン上で

まず、BurpからDer証明書をダウンロードする必要があります。これは、Proxy --> Options --> Import / Export CA certificate で行うことができます。

証明書をDer形式でエクスポートし、それをAndroidが理解できる形式に変換しましょう。なお、AVDのAndroidマシンでburp証明書を設定するには、このマシンを-writable-systemオプションで実行する必要があります。 例えば、次のように実行できます:

{% code overflow="wrap" %}

C:\Users\<UserName>\AppData\Local\Android\Sdk\tools\emulator.exe -avd "AVD9" -http-proxy 192.168.1.12:8080 -writable-system

{% endcode %}

次に、Burpの証明書を設定するために、以下の手順を実行します:

{% code overflow="wrap" %}

openssl x509 -inform DER -in burp_cacert.der -out burp_cacert.pem
CERTHASHNAME="`openssl x509 -inform PEM -subject_hash_old -in burp_cacert.pem | head -1`.0"
mv burp_cacert.pem $CERTHASHNAME #Correct name
adb root && sleep 2 && adb remount #Allow to write on /syste
adb push $CERTHASHNAME /sdcard/ #Upload certificate
adb shell mv /sdcard/$CERTHASHNAME /system/etc/security/cacerts/ #Move to correct location
adb shell chmod 644 /system/etc/security/cacerts/$CERTHASHNAME #Assign privileges
adb reboot #Now, reboot the machine

{% endcode %}

マシンが再起動を完了すると、Burp証明書はそれによって使用されます

Magiscを使用する

もし、あなたがMagiscでデバイスをルート化していておそらくエミュレータ、そしてファイルシステムが読み取り専用であり、書き込み可能にリマウントすることができないため、前の手順に従うことができない場合、別の方法があります。

このビデオで説明されているように、次の手順を実行する必要があります。

  1. CA証明書をインストールするDER形式のBurp証明書を.crtに拡張子を変更して、モバイルにドラッグ&ドロップするだけで、ダウンロードフォルダに保存されます。次に、「証明書をインストール」->「CA証明書」に移動します。
  • 証明書が正しく保存されたことを確認するために、「信頼された証明書」->「ユーザー」に移動します。
  1. システム信頼済みにするMagiscモジュールMagiskTrustUserCerts.zipファイルをダウンロードし、それを電話にドラッグドロップします。次に、電話のMagicsアプリに移動し、Modulesセクションに移動し、ストレージからインストールをクリックし、.zipモジュールを選択してインストールしたら、電話を再起動します。
  • 再起動後、「信頼された証明書」->「システム」に移動し、Postswigger証明書が存在することを確認します。

Android 14以降

変更点:

  • これまで、システム信頼済みのCA証明書は**/system/etc/security/cacerts/に存在していました。標準のAOSPエミュレータでは、これらは最小限のセットアップでルートアクセスで直接変更することができ、すぐにすべての場所に効果が現れました**。
  • Android 14では、システム信頼済みのCA証明書は一般的に**/apex/com.android.conscrypt/cacertsに存在し、/apex全体が変更不可能**です。
  • このAPEX cacertsパスは書き込み可能にリマウントできません - リマウントは単に失敗します。実際、ルートシェルからパス全体をアンマウントしても、アプリは証明書を問題なく読み取ることができます。
  • トップにtmpfsディレクトリをマウントする代替手法も機能しません - これにより、ls /apex/com.android.conscrypt/cacertsは何も返さない(または任意の内容を返す)かもしれませんが、アプリは同じ元のデータを見ることができます。
  • /apexマウントは明示的にマウントされています PRIVATEプロパゲーションで、したがって/apexパス内のマウントへの変更はプロセス間で共有されません。

これはOSを起動するinitプロセスによって行われ、それが親からコピーされた新しいマウント名前空間を持つZygoteプロセス独自の/apexマウントを含む)を起動し、デバイス上でアプリが起動されるたびに各アプリプロセスを開始します(それぞれが同じプライベート/apexマウントをコピーします)。

マウントポイントの再帰的なリマウント

  • /apexを手動でリマウントし、PRIVATEプロパゲーションを削除して書き込み可能にすることができます皮肉なことに、プライベートプロパゲーションを完全に削除すると、どこにでもプロパゲートされるようです
  • /apex/com.android.conscryptの内容を別の場所にコピーします
  • 次に、/apex/com.android.conscryptを完全にアンマウントします - これにより、このモジュールを不変に提供する読み取り専用マウントが削除されます
  • 次に、コンテンツをコピーして、それが直接/apexマウントに存在するようにします(これを素早く行う必要があります。おそらく、それ以外の場合はクラッシュが発生する可能性があります)
  • これは即座に効果がありますが、すべてを一貫した状態に戻すためにsystem_serverを終了することをお勧めします
# Create a separate temp directory, to hold the current certificates
# Otherwise, when we add the mount we can't read the current certs anymore.
mkdir -p -m 700 /data/local/tmp/tmp-ca-copy

# Copy out the existing certificates
cp /apex/com.android.conscrypt/cacerts/* /data/local/tmp/tmp-ca-copy/

# Create the in-memory mount on top of the system certs folder
mount -t tmpfs tmpfs /system/etc/security/cacerts

# Copy the existing certs back into the tmpfs, so we keep trusting them
mv /data/local/tmp/tmp-ca-copy/* /system/etc/security/cacerts/

# Copy our new cert in, so we trust that too
mv $CERTIFICATE_PATH /system/etc/security/cacerts/

# Update the perms & selinux context labels
chown root:root /system/etc/security/cacerts/*
chmod 644 /system/etc/security/cacerts/*
chcon u:object_r:system_file:s0 /system/etc/security/cacerts/*

# Deal with the APEX overrides, which need injecting into each namespace:

# First we get the Zygote process(es), which launch each app
ZYGOTE_PID=$(pidof zygote || true)
ZYGOTE64_PID=$(pidof zygote64 || true)
# N.b. some devices appear to have both!

# Apps inherit the Zygote's mounts at startup, so we inject here to ensure
# all newly started apps will see these certs straight away:
for Z_PID in "$ZYGOTE_PID" "$ZYGOTE64_PID"; do
if [ -n "$Z_PID" ]; then
nsenter --mount=/proc/$Z_PID/ns/mnt -- \
/bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts
fi
done

# Then we inject the mount into all already running apps, so they
# too see these CA certs immediately:

# Get the PID of every process whose parent is one of the Zygotes:
APP_PIDS=$(
echo "$ZYGOTE_PID $ZYGOTE64_PID" | \
xargs -n1 ps -o 'PID' -P | \
grep -v PID
)

# Inject into the mount namespace of each of those apps:
for PID in $APP_PIDS; do
nsenter --mount=/proc/$PID/ns/mnt -- \
/bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts &
done
wait # Launched in parallel - wait for completion here

echo "System certificate injected"

NSEnterを介したバインドマウント

  • まず、書き込み可能なディレクトリをどこかに設定する必要があります。既存のアプローチとの互換性を維持するために、私はまだ存在する非-APEXシステム証明書ディレクトリ上にtmpfsマウントを行っています:
mount -t tmpfs tmpfs /system/etc/security/cacerts
  • 次に、興味のあるCA証明書をこのディレクトリに配置します例えば、既存の/apex/com.android.conscrypt/cacerts/ CA証明書ディレクトリからデフォルトのすべてをコピーすることができますそして、適切な権限とSELinuxラベルを設定します。
  • 次に、nsenterを使用してZygoteのマウント名前空間に入り、このディレクトリをAPEXディレクトリの上にバインドマウントします
nsenter --mount=/proc/$ZYGOTE_PID/ns/mnt -- \
/bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts

Zygoteプロセスは各アプリを生成し、そのマウント名前空間をコピーして実行します。したがって、これにより、新たに起動されるすべてのアプリ今後開始されるすべてのものがこれを使用することが保証されます。

  • 次に、nsenterを使用してすでに実行中の各アプリの名前空間に入り、同じ操作を行います:
nsenter --mount=/proc/$APP_PID/ns/mnt -- \
/bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts

または、使い勝手が悪くても構わない場合は、init自体PID 1でバインドマウントを行い、stop && startを実行してOSをソフトリブートし、すべての名前空間を再作成し、変更をすべてに伝播させることができるはずですただし、個人的にはリブートが使い勝手が悪いので、この方法は無視しています

☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥