还未安装magisk和隐藏root的小伙伴可以参考系列第二篇: android 抓包系列二(安装magisk模块隐藏root)android 抓包系列二(安装magisk模块隐藏root)

首先,抓包软件的证书我们要把它们变成系统证书,android7.0+无法信任用户证书,有什么办法将用户证书放入系统内部呢?我的系统是android12,直接push是无法push的,不过还是有办法。

先获取到抓包软件证书,
Fiddler: wifi-->修改代理,连接你的代理,打开手机浏览器访问 ip:端口号,在页面中选择下载证书。
Charles : 同理,访问chls.pro/ssl 下载证书
Mitmproxy: http://mitm.it 下载证书
其他软件大同小异,下载的证书会在手机的/sdcard/Download文件夹内,将证书导出

在电脑上获取到证书的哈希值
openssl x509 -inform PEM -subject_hash_old -in 证书文件
file
然后将证书重命名为 e5c3944b.0 具体多少看你的值,下面脚本中也替换下你自己的文件名
将该证书导入手机/data/local/tmp/目录
然后新建一个inject-system-cert.sh脚本,脚本内容如下:

# inject-system-cert.sh
set -e # Fail on error
# Create a separate temp directory, to hold the current certificates
# Without this, when we add the mount we can't read the current certs anymore.
mkdir -m 700 /data/local/tmp/ca-copy
# Copy out the existing certificates
cp /system/etc/security/cacerts/* /data/local/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 mount, so we keep trusting them
mv /data/local/tmp/ca-copy/* /system/etc/security/cacerts/
# Copy our new cert in, so we trust that too
cp /data/local/tmp/e5c3944b.0 /system/etc/security/cacerts/
# Update the perms & selinux context labels, so everything is as readable as before
chown root:root /system/etc/security/cacerts/*
chmod 644 /system/etc/security/cacerts/*
chcon u:object_r:system_file:s0 /system/etc/security/cacerts/*
# Delete the temp cert directory & this script itself
rm -r /data/local/tmp/ca-copy
# rm ${injectionScriptPath}
echo "System cert successfully injected"

将inject-system-cert.sh 文件导入手机/data/adb/post-fs-data.d目录,该目录是开机启动的
执行chmod +rx ./inject-system-cert.sh 修改为可读可执行,开机的时候就会将你的证书安装进系统。

重启后,你的抓包软件证书就成为系统证书了,如果不需要成为系统证书,只要将inject-system-cert.sh的权限改为不可执行就可以了,不需要删除脚本。chmod -x ./inject-system-cert.sh

因为安装了shamiko,所以不要安装网上的那个可以自动安装证书的模块,会不可用,采用这种脚本的方式是最好的。

下一篇 android 抓包系列四(过证书锁定SSL Pinning)

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注