Install Burp Certificate

支持 HackTricks

在虚拟机上

首先,您需要从 Burp 下载 Der 证书。您可以在 代理 --> 选项 --> 导入 / 导出 CA 证书 中完成此操作。

以 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

然后,配置 burp 的证书

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

一旦机器完成重启,burp证书将被使用!

使用Magisc

如果你用Magisc获取了设备的root权限(可能是模拟器),并且你无法按照之前的步骤安装Burp证书,因为文件系统是只读的,你无法重新挂载为可写,还有另一种方法。

这个视频中解释,你需要:

  1. 安装CA证书:只需拖放DER Burp证书,更改扩展名.crt,存储在手机的下载文件夹中,然后转到安装证书 -> CA证书

  • 检查证书是否正确存储,转到受信任的凭据 -> 用户

  1. 使其系统信任:下载Magisc模块MagiskTrustUserCerts(一个.zip文件),拖放到手机中,转到手机中的Magics应用的**模块部分,点击从存储安装,选择.zip模块,安装完成后重启**手机:

  • 重启后,转到受信任的凭据 -> 系统,检查Postswigger证书是否存在

Android 14之后

在最新的Android 14版本中,系统信任的证书颁发机构(CA)证书的处理方式发生了显著变化。以前,这些证书存放在**/system/etc/security/cacerts/中,用户可以通过root权限访问和修改,从而立即在系统中应用。然而,在Android 14中,存储位置已移至/apex/com.android.conscrypt/cacerts,这是/apex**路径中的一个目录,天生是不可变的。

尝试将APEX cacerts路径重新挂载为可写时会失败,因为系统不允许此类操作。即使尝试卸载或用临时文件系统(tmpfs)覆盖该目录也无法规避不可变性;应用程序继续访问原始证书数据,无论文件系统级别的更改如何。这种韧性是由于**/apex挂载配置为PRIVATE传播,确保/apex**目录中的任何修改不会影响其他进程。

Android的初始化涉及init进程,该进程在启动操作系统时还会启动Zygote进程。该进程负责以新的挂载命名空间启动应用程序进程,其中包括一个私有的**/apex**挂载,从而将对该目录的更改与其他进程隔离。

然而,对于需要修改**/apex目录中系统信任的CA证书的人来说,存在一种解决方法。这涉及手动重新挂载/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"

Bind-mounting through NSEnter

  1. 设置可写目录: 最初,通过在现有的非APEX系统证书目录上挂载一个 tmpfs 来建立一个可写目录。可以使用以下命令实现:

mount -t tmpfs tmpfs /system/etc/security/cacerts
  1. 准备 CA 证书:在设置可写目录后,应该将打算使用的 CA 证书复制到该目录中。这可能涉及从 /apex/com.android.conscrypt/cacerts/ 复制默认证书。必须相应地调整这些证书的权限和 SELinux 标签。

  2. 为 Zygote 绑定挂载:利用 nsenter,进入 Zygote 的挂载命名空间。Zygote 是负责启动 Android 应用程序的进程,这一步骤是确保所有随后启动的应用程序使用新配置的 CA 证书。使用的命令是:

nsenter --mount=/proc/$ZYGOTE_PID/ns/mnt -- /bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts

这确保了每个新启动的应用程序将遵循更新的 CA 证书设置。

  1. 将更改应用于正在运行的应用程序:要将更改应用于已经运行的应用程序,再次使用 nsenter 逐个进入每个应用程序的命名空间并执行类似的绑定挂载。必要的命令是:

nsenter --mount=/proc/$APP_PID/ns/mnt -- /bin/mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts
  1. 替代方法 - 软件重启:一种替代方法涉及在 init 进程(PID 1)上执行绑定挂载,然后使用 stop && start 命令对操作系统进行软件重启。此方法将更改传播到所有命名空间,避免逐个处理每个正在运行的应用程序。然而,由于重启的不便,这种方法通常不太受欢迎。

参考文献

Support HackTricks

Last updated