In my last post, I showed you how to turn the Android Emulator into a forensic lab that trusts OWASP ZAP as a System Root CA. I also told you, very confidently, to stick with API 33 because newer versions “sandbox network traffic more aggressively”.
Well, that was the lazy answer. API 33 is getting old, more and more apps simply refuse to install on it, and the real reason the old method breaks on Android 14 has nothing to do with network sandboxing. It’s about where Android reads its certificates from.
So I went back down the rabbit hole, and this is the updated recipe for Android 14+ (API 34 and above).
What changed? Link to heading
Up until Android 13, the system CA store lived in /system/etc/security/cacerts/. If you could make /system writable (hence all that -writable-system, disable-verity and remount dance from last time), you could drop your certificate in there and call it a day.
Starting with Android 14, system CA certificates are shipped inside the Conscrypt APEX module and loaded from /apex/com.android.conscrypt/cacerts. Google did this so they can update root certificates through the Play Store without a full OS update, which is great for regular users and terrible for us.
This means:
- Pushing files into
/system/etc/security/cacerts/does nothing. Android isn’t looking there anymore. - APEX modules are mounted read-only and signed, so we can’t just remount them as writable.
- The good news: since we’re not touching
/systemanymore, we can forget about-writable-system,disable-verity,avbctlandadb remount. Yay!
So how do we get in? We don’t write into the APEX, we cover it up. We build our own certificate folder in RAM and bind-mount it right on top of the Conscrypt one, so anyone looking at /apex/com.android.conscrypt/cacerts sees our folder instead. This trick was popularized by the folks at HTTP Toolkit, and their write-up is absolutely worth a read.
Prerequisites Link to heading
Pretty much the same list as last time:
- OWASP ZAP (installed and running)
- Android SDK Platform-Tools (
adb) (configured in your system PATH) - OpenSSL on your host
- An Android Emulator (AVD) with API 34 or higher, using a “Google APIs” image. Once again, avoid “Google Play” images: they’re production builds and won’t give you root, which we absolutely need.
Step 1: Crafting the certificate (same as before) Link to heading
Nothing new here. Android still wants the certificate in PEM format and named after its (old-style) subject hash.
- Export from ZAP: Go to
Tools > Options > Network > Server Certificatesand save your root CA aszap_root_ca.cer.
.cer extension, ZAP usually exports the certificate in PEM format. Open it in a text editor: if it starts with -----BEGIN CERTIFICATE-----, you’re good and there’s no need to convert anything.- Hash and rename:
# Get the subject hash
HASH=$(openssl x509 -inform PEM -subject_hash_old -in zap_root_ca.cer -noout)
# Copy/Rename to the format Android expects (<hash>.0)
cp zap_root_ca.cer $HASH.0
Write down that hash, you’ll need it later. I’ll be using 9a5ba575 as an example from now on.
Step 2: Sneaking into the APEX Link to heading
Here’s where the fun begins. The script below runs on the device, as root, and does the following:
- Copies all the certificates Android currently trusts (straight from the APEX) plus our ZAP certificate into a temporary folder.
- Mounts a
tmpfs(a RAM disk) over/system/etc/security/cacerts, which gives us a writable folder in a “system-looking” location, and fills it with those certificates, with the right owner, permissions and SELinux context. - Bind-mounts that folder over
/apex/com.android.conscrypt/cacerts.
But there’s a catch. On Android, apps don’t all share the same mount namespace, so a mount done from our adb shell is only visible to… our adb shell. Every app is forked from a process called Zygote (zygote and zygote64), so whatever is mounted in Zygote’s namespace gets inherited by every app launched from then on, and the apps that are already running need the mount done in their own namespaces.
So the script walks through every mount namespace on the device and uses nsenter to jump into each one and do the bind mount. Since lots of processes share the same namespace, it keeps track of the ones it has already visited, so it mounts only once per namespace instead of stacking dozens of identical bind mounts.
It also has a couple of safety nets: it refuses to run without root, it skips everything if the certificate is already injected (this will come in handy later), and on pre-APEX Android it simply stops after filling /system/etc/security/cacerts.
Save this as inject_ca.sh:
#!/system/bin/sh
# inject_ca.sh - System CA Injection for Android 14+ (API 34+)
# Based on the HTTP Toolkit APEX mount namespace technique.
# Usage: inject_ca.sh <cert_hash> (expects /data/local/tmp/<cert_hash>.0)
CERT_HASH="${1%.0}"
TMP_DIR="/data/local/tmp"
CERT_FILE="$CERT_HASH.0"
TARGET_CERT="$TMP_DIR/$CERT_FILE"
if [ "$(id -u)" != "0" ]; then
echo "Error: must run as root (run 'adb root' first)."
exit 1
fi
if [ -z "$CERT_HASH" ] || [ ! -f "$TARGET_CERT" ]; then
echo "Error: $TARGET_CERT not found!"
exit 1
fi
SYSTEM_CERTS="/system/etc/security/cacerts"
CONSCRYPT_CERTS="/apex/com.android.conscrypt/cacerts"
OVERRIDE_DIR="$TMP_DIR/cacerts_override"
# Skip if already injected (e.g. state restored from a snapshot)
if grep -q " $SYSTEM_CERTS tmpfs " /proc/mounts && [ -f "$SYSTEM_CERTS/$CERT_FILE" ]; then
echo "Certificate $CERT_FILE already injected, skipping."
exit 0
fi
# On Android 14+ the Conscrypt APEX holds the authoritative CA store
if [ -d "$CONSCRYPT_CERTS" ]; then
SOURCE_CERTS="$CONSCRYPT_CERTS"
else
SOURCE_CERTS="$SYSTEM_CERTS"
fi
# Prepare temporary copy of existing + ZAP certs
rm -rf "$OVERRIDE_DIR"
mkdir -p -m 700 "$OVERRIDE_DIR"
cp "$SOURCE_CERTS"/* "$OVERRIDE_DIR/" || exit 1
cp "$TARGET_CERT" "$OVERRIDE_DIR/" || exit 1
# Mount tmpfs over system certs folder and fill it
mount -t tmpfs tmpfs "$SYSTEM_CERTS" || exit 1
mv "$OVERRIDE_DIR"/* "$SYSTEM_CERTS/"
rm -rf "$OVERRIDE_DIR"
# Set permissions and SELinux context
chown root:root "$SYSTEM_CERTS"/*
chmod 644 "$SYSTEM_CERTS"/*
chcon u:object_r:system_file:s0 "$SYSTEM_CERTS"/*
if [ ! -d "$CONSCRYPT_CERTS" ]; then
echo "Successfully injected certificate $CERT_FILE into $SYSTEM_CERTS (pre-APEX Android)."
exit 0
fi
# Bind-mount into the Conscrypt APEX dir of every mount namespace (incl. this
# one and zygote's, so newly started apps inherit it). Many processes share a
# namespace, so mount once per namespace to avoid stacking bind mounts.
SEEN_NS=""
NS_COUNT=0
for NS in /proc/[0-9]*/ns/mnt; do
NS_ID=$(readlink "$NS" 2>/dev/null) || continue
case " $SEEN_NS " in
*" $NS_ID "*) continue ;;
esac
SEEN_NS="$SEEN_NS $NS_ID"
if nsenter --mount="$NS" -- mount --bind "$SYSTEM_CERTS" "$CONSCRYPT_CERTS" 2>/dev/null; then
NS_COUNT=$((NS_COUNT + 1))
fi
done
echo "Successfully injected certificate $CERT_FILE into $NS_COUNT Conscrypt APEX mount namespaces."
tmpfs and the bind mounts are gone the moment the emulator reboots. The script has to run after every boot. Don’t worry, we’ll automate that in a bit (or freeze it).Step 3: Routing the traffic Link to heading
Same as last time, we set a global HTTP proxy at the Android settings database level:
adb shell settings put global http_proxy 10.0.2.2:9090
Note: 10.0.2.2 is the special Android Emulator alias for your host machine’s 127.0.0.1.
8080 by default, but so does half of the internet: Tomcat, Jenkins, every other dev server and Docker container you forgot was running… I got tired of fighting over it, so I moved ZAP to 9090. You can change it in Tools > Options > Network > Local Servers/Proxies. Pick whatever you want, just make sure it matches everywhere below.A few things I learned the hard way since the last post:
- One proxy layer only. Last time I also passed
-http-proxyto the emulator. Don’t combine the two. Pick the global setting and stick with it. - If you do prefer
-http-proxy, remember it’s the emulator process making the connection, so the address ishttp://127.0.0.1:9090and not10.0.2.2. Also, Chrome may decide to talk QUIC over UDP, which happily walks around the proxy. - This is the same proxy you would set through the Wi-Fi settings, so apps that deliberately bypass system proxies (OkHttp with
Proxy.NO_PROXY, Flutter apps, raw TCP sockets, …) won’t show up in ZAP. For those you’ll need heavier artillery, like a VPN-based capture or Frida. - I also dropped the
-dns-server 8.8.8.8flag. If you’re on a corporate network, public DNS is very often blocked, and then nothing resolves and you spend an afternoon blaming ZAP. Ask me how I know.
Step 4: Automate with a launch script Link to heading
Doing all of this by hand on every boot gets old very fast. Put the certificate (<hash>.0) and inject_ca.sh together in a folder, and add this to your ~/.bashrc (or ~/.zshrc):
ZAP_CERT_HASH="9a5ba575" # Replace with your actual certificate hash
ZAP_CERT_DIR="$HOME/zap_certs" # Folder containing <hash>.0 and inject_ca.sh
launchemulator() {
if [ -z "$1" ]; then
echo "Error: Please specify an AVD name."
echo "Usage: launchemulator <AVD_NAME>"
echo "Available AVDs:"
emulator -list-avds
return 1
fi
# Pick a free console/adb port pair so adb can target this emulator explicitly
local PORT
for PORT in $(seq 5554 2 5584); do
[ -z "$(ss -Hltn "sport = :$PORT or sport = :$((PORT + 1))")" ] && break
done
local SERIAL="emulator-$PORT"
local ADB=(adb -s "$SERIAL")
local EMU_LOG="${TMPDIR:-/tmp}/emulator-$1.log"
echo "Starting forensic Android AVD: $1 ($SERIAL, log: $EMU_LOG)"
emulator -avd "$1" \
-port "$PORT" \
-no-snapshot \
-netdelay none \
-netspeed full >"$EMU_LOG" 2>&1 &
local EMU_PID=$!
echo "Waiting for Android boot to complete..."
until [ "$("${ADB[@]}" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" = "1" ]; do
if ! kill -0 "$EMU_PID" 2>/dev/null; then
echo "Error: emulator exited during boot. See $EMU_LOG"
return 1
fi
sleep 2
done
echo "Restarting adb daemon with root privileges..."
"${ADB[@]}" root >/dev/null 2>&1
local i IS_ROOT=""
for i in $(seq 1 15); do
if [ "$("${ADB[@]}" shell id -u 2>/dev/null | tr -d '\r')" = "0" ]; then
IS_ROOT=1
break
fi
sleep 1
done
if [ -z "$IS_ROOT" ]; then
echo "Error: could not get a root adb shell (Google Play images don't allow it, use a Google APIs image)."
return 1
fi
echo "Pushing certificate and CA injection script..."
"${ADB[@]}" push "$ZAP_CERT_DIR/$ZAP_CERT_HASH.0" /data/local/tmp/ || return 1
"${ADB[@]}" push "$ZAP_CERT_DIR/inject_ca.sh" /data/local/tmp/ || return 1
"${ADB[@]}" shell chmod +x /data/local/tmp/inject_ca.sh
echo "Executing CA injection script..."
if ! "${ADB[@]}" shell /data/local/tmp/inject_ca.sh "$ZAP_CERT_HASH"; then
echo "Error: CA injection failed."
return 1
fi
echo "Setting global HTTP proxy to 10.0.2.2:9090..."
"${ADB[@]}" shell settings put global http_proxy 10.0.2.2:9090
echo "Environment ready on $SERIAL! OWASP ZAP Proxy active on 10.0.2.2:9090."
}
killemulator() {
if [ -z "$1" ]; then
echo "Error: Please specify the AVD name to kill."
echo "Usage: killemulator <AVD_NAME>"
return 1
fi
local AVD_NAME="$1"
local PID=$(pgrep -f "qemu-system.*$AVD_NAME")
if [ -z "$PID" ]; then
echo "No running emulator found with the name: $AVD_NAME"
return 1
fi
echo "Killing emulator: $AVD_NAME (PID: $PID)"
kill -9 $PID
}
A few things worth pointing out:
- Port selection: each emulator grabs a pair of ports (console and
adb), starting at5554. The function looks for the first free pair and tells the emulator to use it with-port, so it knows the exact serial (emulator-<PORT>) beforehand. Everyadbcall then goes throughadb -s $SERIAL, which means you can run several emulators side by side withoutadbcomplaining about “more than one device” or, worse, injecting the certificate into the wrong one. -no-snapshot: every launch is a cold boot, and nothing gets saved when you close it.- No more
/dev/null: the emulator output goes to a log file, and if the emulator dies during boot, the function stops and tells you where to look, instead of waiting forever. - Root check:
adb rootcan fail silently, so the function checks that the shell is actually running as UID 0. If it isn’t, you’re almost certainly on a Google Play image.
adb simply never connects after a cold boot unless I also pass -wipe-data, which resets /data to factory state on every launch. If you’re stuck at “Waiting for Android boot to complete…” forever, give it a try. Just don’t use it if you don’t need it, and definitely not together with the snapshot from Step 6.Reload your shell and launch it:
source ~/.bashrc
launchemulator Pixel_API_34
-no-snapshot, the emulator now always cold boots and never saves anything on exit, so you can close it however you like. killemulator is still there for when it decides to hang.Step 5: The “Trust But Verify” checklist Link to heading
Before starting your analysis, run through these checks:
System tab: Go to
Settings > Security & privacy > More security settings > Encryption & credentials > Trusted credentialsand open the System tab. You must see “OWASP Root CA” here. If it only shows up under User, the injection failed.Global proxy: Run
adb shell settings get global http_proxy. It must return10.0.2.2:9090.Browser: Open Chrome in the emulator and browse to any HTTPS site. The requests should immediately show up in ZAP’s History tab.
Native app (the one that actually matters): Open a third-party app (one that is not a browser and targets API 24+) and check that its HTTPS requests are decrypted in ZAP without any TLS errors.
Step 6: Freeze it (optional) Link to heading
If cold booting and injecting on every launch bothers you, you can bring back the snapshot idea from last time, but in a much more controlled way. Once everything is set up and verified, save a named snapshot of the running emulator (use the serial launchemulator printed):
adb -s emulator-5554 emu avd snapshot save zap_ready
Because snapshots capture the emulator’s RAM, the tmpfs and all the bind mounts are saved along with it. From then on, just swap the boot flags in launchemulator:
emulator -avd "$1" \
-port "$PORT" \
-snapshot zap_ready \
-no-snapshot-save \
-netdelay none \
-netspeed full >"$EMU_LOG" 2>&1 &
You don’t need to touch anything else: when inject_ca.sh runs on the restored state, it notices the certificate is already injected and skips the whole thing. And the -no-snapshot-save flag is what keeps zap_ready clean: whatever you install or break during an analysis is thrown away when you close the emulator. That’s your cleanroom, just like in Safety Glasses First.
When things still don’t work Link to heading
Certificate pinning Link to heading
Getting the CA into the system store gets you past Android’s default trust rules, but apps that implement certificate pinning (OkHttp’s CertificatePinner, TrustKit, or custom native C/C++ implementations) will still refuse to talk to ZAP. To get around pinning:
- Use Frida with one of the many SSL unpinning scripts out there.
- Use objection:
objection -g <package_name> explore, thenandroid sslpinning disable.
“My emulator has no internet!” Link to heading
If you close ZAP but leave the global proxy set, the emulator loses all connectivity, because everything is still being sent to a proxy that no longer exists. Reset it with:
adb shell settings put global http_proxy :0
Conclusion Link to heading
Android 14 moved the goalposts, but honestly, the new setup ended up cleaner than the old one. No more writable system partitions, no more disabling verity, no more praying that a Quickboot snapshot didn’t get overwritten. Just a RAM disk, a couple of bind mounts, and a launch script that rebuilds the whole thing from scratch every time.
It’s also a nice reminder of why this field never gets boring: the moment you think you’ve “perfected” a setup, someone at Google changes where a folder lives.
Happy hunting!