Burp 인증서 설치

Reading time: 8 minutes

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 지원하기

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

모든 앱의 트래픽이 인터셉터(Burp/mitmproxy)를 통해 전달되도록 전역 HTTP 프록시를 구성합니다:

bash
# 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 옵션과 함께 실행해야 합니다.\
예를 들어 다음과 같이 실행할 수 있습니다:

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

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

bash
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 certificate will be in use by it!

Magisc 사용하기

If you rooted your device with Magisc (maybe an emulator), and you can't follow the previous steps to install the Burp cert because the filesystem is read-only and you cannot remount it writable, there is another way.

Explained in this video you need to:

  1. Install a CA certificate: Just 드래그&드롭 the DER Burp certificate changing the extension to .crt in the mobile so it's stored in the Downloads folder and go to Install a certificate -> CA certificate
  • 인증서가 제대로 저장되었는지 확인하려면 Trusted credentials -> USER로 이동하세요
  1. Make it System trusted: Download the Magisc module MagiskTrustUserCerts (a .zip file), 드래그&드롭 it in the phone, go to the Magics app in the phone to the Modules section, click on Install from storage, select the .zip module and once installed reboot the phone:
  • Reboot 후 Trusted credentials -> SYSTEM으로 가서 Postswigger cert가 있는지 확인하세요

Magisc 모듈 만드는 법 배우기

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

Android 14 이후

최신 Android 14 릴리스에서는 시스템 신뢰 Certificate Authority(CA) 인증서 처리 방식에 큰 변화가 있었습니다. 이전에는 이러한 인증서가 **/system/etc/security/cacerts/**에 위치해 있어 root 권한이 있는 사용자가 수정할 수 있었고, 시스템 전체에 즉시 적용될 수 있었습니다. 그러나 Android 14에서는 저장 위치가 **/apex/com.android.conscrypt/cacerts**로 이동되었으며, 이는 /apex 경로 내의 디렉터리로 본질적으로 불변(immutable)입니다.

APEX cacerts path를 쓰기 가능하게 remount하려는 시도는 실패로 돌아갑니다. 시스템이 이러한 작업을 허용하지 않습니다. tmpfs로 디렉터리를 언마운트하거나 오버레이하려는 시도도 불변성을 우회하지 못합니다; 애플리케이션들은 파일 시스템 수준의 변경과 관계없이 원래의 인증서 데이터를 계속 참조합니다. 이는 /apex 마운트가 PRIVATE propagation으로 구성되어 있어 /apex 디렉터리 내의 변경이 다른 프로세스에 영향을 미치지 않기 때문입니다.

Android 초기화 과정은 init 프로세스가 운영체제를 시작하면서 Zygote 프로세스를 함께 시작하는 것을 포함합니다. 이 프로세스는 새로운 마운트 네임스페이스와 함께 애플리케이션 프로세스를 실행하며, 여기에는 private /apex 마운트가 포함되어 이 디렉터리에 대한 변경을 다른 프로세스와 격리합니다.

그럼에도 불구하고 /apex 디렉터리 내의 시스템 신뢰 CA 인증서를 수정해야 하는 경우를 위한 우회 방법은 존재합니다. 이 방법은 PRIVATE propagation을 제거하기 위해 수동으로 **/apex**를 재마운트(remount)하여 쓰기 가능하게 만드는 것을 포함합니다. 과정은 **/apex/com.android.conscrypt**의 내용을 다른 위치로 복사하고, 읽기 전용 제약을 제거하기 위해 /apex/com.android.conscrypt 디렉터리를 언마운트한 다음, 내용을 원래 위치인 /apex 내로 복원하는 것입니다. 이 방법은 시스템 크래시를 피하기 위해 신속하게 수행되어야 합니다. 변경 사항을 시스템 전체에 적용하려면 system_server를 재시작하는 것이 권장되며, 이는 모든 애플리케이션을 효과적으로 재시작하고 시스템을 일관된 상태로 만듭니다.

bash
# 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를 마운트하여 쓰기 가능한 디렉터리를 생성합니다. 다음 명령으로 수행합니다:
bash
mount -t tmpfs tmpfs /system/etc/security/cacerts
  1. CA 인증서 준비: 쓰기 가능한 디렉터리를 설정한 후, 사용하려는 CA 인증서를 이 디렉터리로 복사해야 합니다. 이 과정은 /apex/com.android.conscrypt/cacerts/에 있는 기본 인증서를 복사하는 작업을 포함할 수 있습니다. 이러한 인증서들의 권한 및 SELinux 라벨을 적절히 조정하는 것이 필수적입니다.
  2. Zygote를 위한 바인드 마운트: nsenter를 사용하여 Zygote의 마운트 네임스페이스로 진입합니다. Android 애플리케이션을 시작하는 프로세스인 Zygote는 이후 시작되는 모든 애플리케이션이 새로 구성한 CA 인증서를 사용하도록 보장하기 위해 이 단계가 필요합니다. 사용되는 명령은:
bash
nsenter --mount=/proc/$ZYGOTE_PID/ns/mnt -- /bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts

이렇게 하면 시작되는 모든 새로운 앱이 업데이트된 CA 인증서 설정을 따르게 됩니다.

  1. 실행 중인 앱에 변경 사항 적용하기: 이미 실행 중인 애플리케이션에 변경 사항을 적용하려면 nsenter를 다시 사용해 각 앱의 네임스페이스에 개별적으로 들어가 유사한 bind mount를 수행합니다. 필요한 명령은:
bash
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 명령으로 운영체제를 soft reboot하는 방식이 있습니다. 이 방법은 변경사항이 모든 네임스페이스에 전파되어 실행 중인 각 앱을 개별적으로 처리할 필요를 없앱니다. 다만 재부팅의 번거로움 때문에 일반적으로 선호되지 않습니다.

참고자료

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 지원하기