Burp 인증서 설치

Tip

AWS Hacking을 배우고 연습하세요:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking을 배우고 연습하세요: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking을 배우고 연습하세요: HackTricks Training Azure Red Team Expert (AzRTE) 평가 트랙 (ARTA/GRTA/AzRTA)과 Linux Hacking Expert (LHE)를 보려면 전체 HackTricks Training 카탈로그를 둘러보세요.

HackTricks 지원하기

ADB를 통한 시스템 전체 프록시

모든 앱이 인터셉터(Burp/mitmproxy)를 통해 트래픽을 라우팅하도록 전역 HTTP 프록시를 구성합니다:

# Set proxy (device/emulator must reach your host IP)
adb shell settings put global http_proxy 192.168.1.2:8080

# Clear proxy
adb shell settings put global http_proxy :0

팁: Burp에서 리스너를 0.0.0.0에 바인드하면 LAN의 장치들이 연결할 수 있습니다 (Proxy -> Options -> Proxy Listeners).

가상 머신에서

먼저 Burp에서 Der 인증서를 다운로드해야 합니다. 이는 Proxy –> Options –> _Import / Export CA certificate_에서 할 수 있습니다.

Der 형식으로 인증서를 내보낸 뒤 이를 Android가 이해할 수 있는 형태로 변환합시다. AVD의 Android 머신에 Burp 인증서를 구성하려면 이 머신을 -writable-system 옵션으로 실행해야 합니다.
예를 들어 다음과 같이 실행할 수 있습니다:

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

그런 다음, burps 인증서를 구성하려면:

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

Once the machine finish rebooting the Burp 인증서가 적용됩니다!

Magisk 사용

만약 당신이 Magisk로 기기를 루팅했다면(에뮬레이터일 수 있음), 그리고 파일시스템이 read-only라서 이전 단계대로 Burp cert를 설치할 수 없고 writable로 remount할 수 없다면, 다른 방법이 있습니다.

이 비디오에 설명된 대로 다음을 수행해야 합니다:

  1. CA 인증서 설치: DER Burp 인증서를 .crt확장자 변경하여 모바일의 Downloads 폴더에 드래그&드롭한 뒤 Install a certificate -> CA certificate로 이동
  • Trusted credentials -> USER로 이동하여 인증서가 올바르게 저장되었는지 확인
  1. 시스템 신뢰로 만들기: Magisk 모듈 MagiskTrustUserCerts (.zip 파일)를 다운로드하고, 폰으로 드래그&드롭한 뒤, 폰의 Magisk 앱에서 Modules 섹션으로 가서 **Install from storage**를 클릭하여 .zip 모듈을 선택하고 설치가 완료되면 폰을 reboot합니다:
  • 재부팅 후 Trusted credentials -> SYSTEM으로 가서 Postswigger cert가 있는지 확인

대안: AlwaysTrustUserCerts (Android 7-16 Beta)

Android 14+를 사용 중이거나 Conscrypt Mainline 업데이트를 받아 이제 /apex/com.android.conscrypt/cacerts를 사용하는 오래된 기기라면, Magisk 모듈 AlwaysTrustUserCerts는 시스템 신뢰를 위해 필요한 bind-mount 작업을 자동화합니다. 이 모듈은 user CA를 system trust로 미러링하고 Zygote/app 네임스페이스에 마운트 인젝션을 하여 앱이 수동 nsenter 작업 없이 인증서를 보도록 합니다.

  1. 먼저 Burp CA를 user cert로 설치합니다.
  2. 모듈을 설치하고 재부팅합니다.
  3. 모듈이 옵션을 제공하면 /system/etc/security/cacerts/apex/com.android.conscrypt/cacerts에 마운트할 때 중첩 마운트(다른 모듈에서 온)를 보이게 하기 위해 --rbind를 선호하십시오.

Magisk 모듈 만드는 법 배우기

체크: https://medium.com/@justmobilesec/magisk-for-mobile-pentesting-rooting-android-devices-and-building-custom-modules-part-ii-22badc498437

Android 14 이후

최신 Android 14 릴리스에서 system-trusted Certificate Authority(CA) 인증서 처리 방식에 중요한 변화가 있었습니다.

참고: Conscrypt Mainline 업데이트를 받은 일부 Android 12/13 기기들은 이미 /apex/com.android.conscrypt/cacerts를 사용합니다. 기기에 해당 디렉터리가 있다면 아래에 설명된 동일한 APEX 인젝션 기술을 사용해야 합니다.

이전에는 이러한 인증서들이 **/system/etc/security/cacerts/**에 위치하여 root 권한이 있는 사용자가 접근·수정할 수 있어 시스템 전반에 즉시 적용할 수 있었습니다. 하지만 Android 14에서는 저장 위치가 **/apex/com.android.conscrypt/cacerts**로 이동했으며, 이는 /apex 경로 내의 디렉터리로 본질적으로 변경 불가능(immutable)합니다.

APEX cacerts 경로를 writable로 remount하려는 시도는 실패로 돌아가며, 시스템은 이러한 작업을 허용하지 않습니다. 디렉터리를 unmount하거나 임시 파일 시스템(tmpfs)로 오버레이하려는 시도도 불변성을 우회하지 못합니다; 애플리케이션은 파일 시스템 레벨의 변경과 무관하게 원본 인증서 데이터를 계속 접근합니다. 이는 /apex 마운트가 PRIVATE 전파로 구성되어 있어 /apex 내의 변경이 다른 프로세스에 영향을 주지 않도록 보장하기 때문입니다.

Android 초기화 과정에서 init 프로세스는 운영체제를 시작할 때 Zygote 프로세스도 시작합니다. 이 프로세스는 새로운 마운트 네임스페이스를 포함한 애플리케이션 프로세스를 시작할 책임이 있으며, 여기에는 private /apex 마운트가 포함되어 있어 이 디렉터리에 대한 변경이 다른 프로세스들과 분리됩니다.

그럼에도 불구하고 /apex 디렉터리 내의 system-trusted CA 인증서를 수정해야 하는 경우를 위한 우회 방법이 존재합니다. 이는 PRIVATE 전파를 제거하기 위해 수동으로 **/apex**를 remount하는 것을 포함합니다. 절차는 **/apex/com.android.conscrypt**의 내용을 다른 위치로 복사하고, 읽기 전용 제약을 제거하기 위해 /apex/com.android.conscrypt 디렉터리를 언마운트한 다음, 원래 위치로 내용을 복원하는 과정을 포함합니다. 이 방법은 시스템 충돌을 피하기 위해 신속하게 수행되어야 합니다. 변경 사항을 시스템 전역에 적용하려면 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"

Bind-mounting through NSEnter

  1. 쓰기 가능한 디렉터리 설정: 처음에는 기존 non-APEX 시스템 인증서 디렉터리 위에 tmpfs를 마운트하여 쓰기 가능한 디렉터리를 생성합니다. 이는 다음 명령으로 수행됩니다:
mount -t tmpfs tmpfs /system/etc/security/cacerts
  1. Preparing CA Certificates: 쓰기 가능한 디렉터리를 설정한 후, 사용할 CA 인증서를 이 디렉터리로 복사해야 합니다. 이는 /apex/com.android.conscrypt/cacerts/에서 기본 인증서를 복사하는 것을 포함할 수 있습니다. 이러한 인증서들의 권한과 SELinux 레이블을 적절히 조정하는 것이 중요합니다.
  2. Bind Mounting for Zygote: nsenter를 사용하여 Zygote의 마운트 네임스페이스로 들어갑니다. Zygote는 Android 애플리케이션을 시작하는 프로세스이므로, 이 단계는 이후 시작되는 모든 애플리케이션이 새로 구성된 CA 인증서를 사용하도록 보장하는 데 필요합니다. 사용되는 명령은 다음과 같습니다:

Tip: /system/etc/security/cacerts에 중첩된 마운트가 있는 경우(일반적으로 Magisk 모듈과 함께 발생), --bind 대신 --rbind를 사용하여 해당 마운트들이 앱 네임스페이스로 전파되도록 하세요.

nsenter --mount=/proc/$ZYGOTE_PID/ns/mnt -- /bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts
# If /system/etc/security/cacerts includes nested mounts, prefer --rbind
nsenter --mount=/proc/$ZYGOTE_PID/ns/mnt -- /bin/mount --rbind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts

이렇게 하면 새로 시작되는 모든 앱이 업데이트된 CA certificates 설정을 따르도록 보장됩니다.

  1. 실행 중인 앱에 변경 사항 적용: 이미 실행 중인 애플리케이션에 변경사항을 적용하려면, nsenter를 다시 사용하여 각 앱의 namespace에 개별적으로 들어가 동일한 bind mount를 수행합니다. 필요한 명령은 다음과 같습니다:
nsenter --mount=/proc/$APP_PID/ns/mnt -- /bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts
  1. 대체 방법 - Soft Reboot: 대안적인 방법은 init 프로세스 (PID 1)에서 bind mount를 수행한 후 stop && start 명령으로 운영체제를 소프트 리부트하는 것입니다. 이 방법은 변경 사항이 모든 namespaces에 전파되어 각 실행 중인 앱을 개별적으로 다룰 필요가 없습니다. 다만 재부팅의 번거로움 때문에 일반적으로 덜 선호됩니다.

참고 자료

Tip

AWS Hacking을 배우고 연습하세요:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking을 배우고 연습하세요: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking을 배우고 연습하세요: HackTricks Training Azure Red Team Expert (AzRTE) 평가 트랙 (ARTA/GRTA/AzRTA)과 Linux Hacking Expert (LHE)를 보려면 전체 HackTricks Training 카탈로그를 둘러보세요.

HackTricks 지원하기