v0.1.1: external modules, publish YAML, proxy reset, binary-first README
- Host discovers/builds modules under modules/ (bbc, rte, tg4) - module-publish.yaml tracked; local module.yaml gitignored - drm --modules-dir / DRM_MODULES_DIR - drm proxy reset; Magisk reinject reliability - modules-v* Forgejo release workflow + build scripts - BBC full Explore channel map including S4C - README quickstart based on release binaries
This commit is contained in:
parent
1d36961a7c
commit
f9c28be3f1
52 changed files with 2915 additions and 636 deletions
|
|
@ -500,7 +500,7 @@ func StartTransparent(c *adb.Client, localBin, pkg, port, remoteDir string, rein
|
|||
return fmt.Errorf("CA hash: %w", err)
|
||||
}
|
||||
if reinject {
|
||||
ReinjectCA(c, caHash)
|
||||
ReinjectCAForPackage(c, caHash, pkg)
|
||||
}
|
||||
|
||||
if st, err := os.Stat(localBin); err != nil || st.IsDir() {
|
||||
|
|
@ -597,6 +597,67 @@ func StopTransparent(c *adb.Client) {
|
|||
fmt.Println("[*] transparent capture stopped")
|
||||
}
|
||||
|
||||
// ResetOptions controls drm proxy reset.
|
||||
type ResetOptions struct {
|
||||
KeepCaptures bool // leave /data/local/tmp/capture/
|
||||
}
|
||||
|
||||
// ResetDevice returns the phone to a clean MITM-free state: stop proxy/iptables,
|
||||
// delete pushed CA/binaries/scripts/overlays. Does not delete host data/proxy-ca.*.
|
||||
func ResetDevice(c *adb.Client, opt ResetOptions) error {
|
||||
fmt.Println("[*] Resetting device MITM state…")
|
||||
StopTransparent(c)
|
||||
|
||||
script := `
|
||||
BB=/data/adb/magisk/busybox
|
||||
# Best-effort undo conscrypt bind (ignore failures).
|
||||
if [ -x "$BB" ]; then
|
||||
$BB umount /apex/com.android.conscrypt/cacerts 2>/dev/null || true
|
||||
$BB umount /system/etc/security/cacerts 2>/dev/null || true
|
||||
fi
|
||||
rm -f /data/local/tmp/appproxy \
|
||||
/data/local/tmp/rteproxy \
|
||||
/data/local/tmp/rteproxy-ca.crt /data/local/tmp/rteproxy-ca.key \
|
||||
/data/local/tmp/appproxy-ca.crt /data/local/tmp/appproxy-ca.key \
|
||||
/data/local/tmp/appproxy_cap.json /data/local/tmp/appproxy_traffic.jsonl \
|
||||
/data/local/tmp/appproxy.log /data/local/tmp/rteproxy.log \
|
||||
/data/local/tmp/appproxy-start.out \
|
||||
/data/local/tmp/start_appproxy.sh /data/local/tmp/start_appproxy_tproxy.sh \
|
||||
/data/local/tmp/tproxy_iptables.sh \
|
||||
/data/local/tmp/reinject_ca.sh /data/local/tmp/reinject_ca.status \
|
||||
/data/local/tmp/reinject_target_uid \
|
||||
/data/local/tmp/rte_cap.json
|
||||
# HASH.0 CA copies we pushed (8 hex chars).
|
||||
rm -f /data/local/tmp/[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f].0 2>/dev/null || true
|
||||
rm -rf /data/local/tmp/cacerts-overlay
|
||||
echo RESET_CORE_OK
|
||||
`
|
||||
if !opt.KeepCaptures {
|
||||
script += "rm -rf /data/local/tmp/capture\necho RESET_CAPTURES_OK\n"
|
||||
} else {
|
||||
script += "echo RESET_CAPTURES_KEPT\n"
|
||||
}
|
||||
|
||||
tmp := filepath.Join(os.TempDir(), "drm_proxy_reset.sh")
|
||||
_ = os.WriteFile(tmp, []byte("#!/system/bin/sh\n"+script), 0o755)
|
||||
defer os.Remove(tmp)
|
||||
_ = c.Push(tmp, "/data/local/tmp/drm_proxy_reset.sh")
|
||||
_, _ = c.Shell("chmod", "755", "/data/local/tmp/drm_proxy_reset.sh")
|
||||
out, errOut, err := c.Run("shell", "su", "-c", "sh /data/local/tmp/drm_proxy_reset.sh")
|
||||
_, _ = c.Shell("su", "-c", "rm -f /data/local/tmp/drm_proxy_reset.sh")
|
||||
combined := out + errOut
|
||||
if strings.TrimSpace(out) != "" {
|
||||
for _, line := range strings.Split(strings.TrimSpace(out), "\n") {
|
||||
fmt.Println(" ", line)
|
||||
}
|
||||
}
|
||||
if err != nil && !strings.Contains(combined, "RESET_CORE_OK") {
|
||||
return fmt.Errorf("proxy reset: %v %s", err, strings.TrimSpace(errOut))
|
||||
}
|
||||
fmt.Println("[+] Device MITM artifacts cleared — next transparent/capture starts fresh")
|
||||
return nil
|
||||
}
|
||||
|
||||
func stopTransparentRules(c *adb.Client) error {
|
||||
out, errOut, err := c.Run("shell", "su", "-c", "sh "+RemoteTProxyScript+" stop")
|
||||
if strings.TrimSpace(out) != "" {
|
||||
|
|
@ -692,80 +753,154 @@ func DiscoverOutDir(root, stamp string) string {
|
|||
return filepath.Join(root, "outputs", "discover", stamp)
|
||||
}
|
||||
|
||||
// ReinjectCA best-effort Magisk bind of the mitm CA into conscrypt.
|
||||
const (
|
||||
remoteReinjectScript = "/data/local/tmp/reinject_ca.sh"
|
||||
remoteReinjectStatus = "/data/local/tmp/reinject_ca.status"
|
||||
remoteReinjectUID = "/data/local/tmp/reinject_target_uid"
|
||||
)
|
||||
|
||||
// ReinjectCA Magisk-binds the MITM CA into conscrypt (zygote + system).
|
||||
func ReinjectCA(c *adb.Client, caHash string) {
|
||||
ReinjectCAForPackage(c, caHash, "")
|
||||
}
|
||||
|
||||
// ReinjectCAForPackage Magisk-binds the MITM CA, optionally also into one app's
|
||||
// mount namespace (after writing its UID). A stale reinject_target_uid from an
|
||||
// older run is cleared when pkg is empty — that leftover caused 20s host timeouts.
|
||||
func ReinjectCAForPackage(c *adb.Client, caHash, pkg string) {
|
||||
if caHash == "" {
|
||||
caHash = DefaultCAHash
|
||||
}
|
||||
// Bound the per-app nsenter loop — wait on hundreds of PIDs can hang forever.
|
||||
if pkg != "" {
|
||||
uid := strings.TrimSpace(c.Out("shell", "su", "-c", "stat -c %u /data/data/"+pkg+" 2>/dev/null || dumpsys package "+pkg+" | grep userId= | head -1"))
|
||||
// dumpsys form: userId=10382
|
||||
if i := strings.Index(uid, "userId="); i >= 0 {
|
||||
uid = strings.TrimSpace(uid[i+len("userId="):])
|
||||
if j := strings.IndexAny(uid, " \t\r\n"); j >= 0 {
|
||||
uid = uid[:j]
|
||||
}
|
||||
}
|
||||
if uid != "" && uid != "0" {
|
||||
tmp := filepath.Join(os.TempDir(), "reinject_target_uid")
|
||||
_ = os.WriteFile(tmp, []byte(uid+"\n"), 0o644)
|
||||
_ = c.Push(tmp, remoteReinjectUID)
|
||||
_ = os.Remove(tmp)
|
||||
fmt.Printf("[*] Magisk reinject target uid %s (%s)\n", uid, pkg)
|
||||
}
|
||||
} else {
|
||||
// Stale UID files make the per-PID nsenter loop hang su -mm.
|
||||
_, _ = c.Shell("su", "-c", "rm -f "+remoteReinjectUID)
|
||||
}
|
||||
|
||||
script := fmt.Sprintf(`
|
||||
BB=/data/adb/magisk/busybox
|
||||
HASH=%s
|
||||
[ -f /data/local/tmp/$HASH.0 ] || { echo CA_SKIP; exit 0; }
|
||||
[ -x "$BB" ] || { echo CA_SKIP; exit 0; }
|
||||
STATUS=%s
|
||||
echo RUNNING > "$STATUS"
|
||||
[ -f /data/local/tmp/$HASH.0 ] || { echo CA_SKIP > "$STATUS"; exit 0; }
|
||||
[ -x "$BB" ] || { echo CA_SKIP_NO_BB > "$STATUS"; exit 0; }
|
||||
rm -rf /data/local/tmp/cacerts-overlay
|
||||
mkdir -p /data/local/tmp/cacerts-overlay
|
||||
cp /apex/com.android.conscrypt/cacerts/* /data/local/tmp/cacerts-overlay/ 2>/dev/null || true
|
||||
# Copy from the real apex store. If a previous broken bind is mounted, prefer
|
||||
# the Magisk mirror / stock path so we do not copy an empty/unreadable overlay.
|
||||
if [ -r /apex/com.android.conscrypt/cacerts/0054e830.0 ] || ls /apex/com.android.conscrypt/cacerts/*.0 >/dev/null 2>&1; then
|
||||
cp /apex/com.android.conscrypt/cacerts/* /data/local/tmp/cacerts-overlay/ 2>/dev/null || true
|
||||
fi
|
||||
cp /data/local/tmp/$HASH.0 /data/local/tmp/cacerts-overlay/$HASH.0
|
||||
# tmpfs defaults to 0755 root:root; apps need +x on the dir and 0644 on PEMs.
|
||||
# Wrong modes/contexts caused DirectoryCertificateSrc EACCES and broke iPlayer TLS.
|
||||
chmod 755 /data/local/tmp/cacerts-overlay
|
||||
chmod 644 /data/local/tmp/cacerts-overlay/*
|
||||
$BB mount -t tmpfs tmpfs /system/etc/security/cacerts 2>/dev/null || true
|
||||
chown root:root /data/local/tmp/cacerts-overlay /data/local/tmp/cacerts-overlay/* 2>/dev/null || true
|
||||
$BB mount -t tmpfs -o mode=755,uid=0,gid=0 tmpfs /system/etc/security/cacerts 2>/dev/null || true
|
||||
cp /data/local/tmp/cacerts-overlay/* /system/etc/security/cacerts/ 2>/dev/null || true
|
||||
chmod 644 /system/etc/security/cacerts/* 2>/dev/null || true
|
||||
chcon u:object_r:system_file:s0 /system/etc/security/cacerts/* 2>/dev/null || true
|
||||
chmod 755 /system/etc/security/cacerts
|
||||
chmod 644 /system/etc/security/cacerts/*
|
||||
chown root:root /system/etc/security/cacerts /system/etc/security/cacerts/* 2>/dev/null || true
|
||||
# Match AOSP cacerts file context (system_file is too loose on some Magisk builds).
|
||||
chcon u:object_r:system_security_cacerts_file:s0 /system/etc/security/cacerts 2>/dev/null || \
|
||||
chcon u:object_r:system_file:s0 /system/etc/security/cacerts 2>/dev/null || true
|
||||
chcon u:object_r:system_security_cacerts_file:s0 /system/etc/security/cacerts/* 2>/dev/null || \
|
||||
chcon u:object_r:system_file:s0 /system/etc/security/cacerts/* 2>/dev/null || true
|
||||
$BB mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts 2>/dev/null || true
|
||||
for Z in $(pidof zygote64 2>/dev/null); do
|
||||
nsenter --mount=/proc/$Z/ns/mnt -- $BB mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts 2>/dev/null || true
|
||||
done
|
||||
# Only rebind the target app if set; otherwise skip the full zygote-child sweep (hangs).
|
||||
PKG_UID_FILE=/data/local/tmp/reinject_target_uid
|
||||
PKG_UID_FILE=%s
|
||||
if [ -f "$PKG_UID_FILE" ]; then
|
||||
TUID=$(cat "$PKG_UID_FILE")
|
||||
# Cap the sweep — a long-lived app with many threads must not hang forever.
|
||||
N=0
|
||||
for PID in $(ps -A -o PID=,UID= 2>/dev/null | awk -v u="$TUID" '$2==u {print $1}'); do
|
||||
nsenter --mount=/proc/$PID/ns/mnt -- $BB mount --bind /system/etc/security/cacerts /apex/com.android.conscrypt/cacerts 2>/dev/null || true
|
||||
N=$((N+1))
|
||||
[ "$N" -ge 8 ] && break
|
||||
done
|
||||
fi
|
||||
ls /apex/com.android.conscrypt/cacerts/$HASH.0 2>/dev/null && echo CA_OK || echo CA_SKIP
|
||||
`, caHash)
|
||||
if ls /apex/com.android.conscrypt/cacerts/$HASH.0 >/dev/null 2>&1; then
|
||||
echo CA_OK > "$STATUS"
|
||||
else
|
||||
echo CA_SKIP > "$STATUS"
|
||||
fi
|
||||
`, caHash, remoteReinjectStatus, remoteReinjectUID)
|
||||
|
||||
fmt.Println("[*] Re-injecting system CA (Magisk)...")
|
||||
_, _ = c.Shell("su", "-c", "rm -f "+remoteReinjectStatus)
|
||||
tmp := filepath.Join(os.TempDir(), "reinject_ca.sh")
|
||||
_ = os.WriteFile(tmp, []byte("#!/system/bin/sh\n"+script), 0o755)
|
||||
defer os.Remove(tmp)
|
||||
_ = c.Push(tmp, "/data/local/tmp/reinject_ca.sh")
|
||||
_, _ = c.Shell("chmod", "755", "/data/local/tmp/reinject_ca.sh")
|
||||
// Host-side timeout: su -mm + nsenter has hung on some Magisk builds.
|
||||
type runResult struct {
|
||||
out string
|
||||
}
|
||||
ch := make(chan runResult, 1)
|
||||
_ = c.Push(tmp, remoteReinjectScript)
|
||||
_, _ = c.Shell("chmod", "755", remoteReinjectScript)
|
||||
|
||||
// Run in background on device so a hung su -mm cannot block the host forever.
|
||||
// Status is polled from reinject_ca.status.
|
||||
go func() {
|
||||
out, _, _ := c.Run("shell", "su", "-mm", "-c", "sh /data/local/tmp/reinject_ca.sh")
|
||||
ch <- runResult{out: out}
|
||||
_, _, _ = c.Run("shell", "su", "-mm", "-c", "sh "+remoteReinjectScript)
|
||||
}()
|
||||
var out string
|
||||
select {
|
||||
case r := <-ch:
|
||||
out = r.out
|
||||
case <-time.After(20 * time.Second):
|
||||
_, _ = c.Shell("su", "-c", "killall reinject_ca.sh 2>/dev/null; true")
|
||||
// Script may have finished mounting even if su -mm hung; verify on device.
|
||||
if caPresentOnDevice(c, caHash) {
|
||||
fmt.Println("[+] System CA present in conscrypt (reinject timed out, mount OK)")
|
||||
} else {
|
||||
fmt.Println("[!] CA reinject timed out after 20s — re-run: drm proxy install-ca --reinject")
|
||||
|
||||
deadline := time.Now().Add(18 * time.Second)
|
||||
var status string
|
||||
for time.Now().Before(deadline) {
|
||||
status = reinjectStatus(c)
|
||||
if status == "CA_OK" || strings.HasPrefix(status, "CA_SKIP") {
|
||||
break
|
||||
}
|
||||
return
|
||||
time.Sleep(400 * time.Millisecond)
|
||||
}
|
||||
if strings.Contains(out, "CA_OK") || caPresentOnDevice(c, caHash) {
|
||||
if status == "" || status == "RUNNING" {
|
||||
_, _ = c.Shell("su", "-c", "killall reinject_ca.sh 2>/dev/null; true")
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
status = reinjectStatus(c)
|
||||
}
|
||||
|
||||
switch {
|
||||
case status == "CA_OK" || caPresentOnDevice(c, caHash):
|
||||
fmt.Println("[+] System CA present in conscrypt")
|
||||
} else {
|
||||
fmt.Println("[!] CA inject skipped/failed — re-run: drm proxy install-ca --reinject")
|
||||
case strings.HasPrefix(status, "CA_SKIP"):
|
||||
fmt.Printf("[!] CA inject skipped (%s) — re-run: drm proxy install-ca --reinject\n", status)
|
||||
default:
|
||||
if caPresentOnDevice(c, caHash) {
|
||||
fmt.Println("[+] System CA present in conscrypt (status race, mount OK)")
|
||||
} else {
|
||||
fmt.Println("[!] CA reinject timed out — re-run: drm proxy install-ca --reinject")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func reinjectStatus(c *adb.Client) string {
|
||||
return strings.TrimSpace(c.Out("shell", "su", "-c", "cat "+remoteReinjectStatus+" 2>/dev/null"))
|
||||
}
|
||||
|
||||
func caPresentOnDevice(c *adb.Client, caHash string) bool {
|
||||
if caHash == "" {
|
||||
caHash = DefaultCAHash
|
||||
}
|
||||
out := c.Out("shell", "su", "-c", "ls /apex/com.android.conscrypt/cacerts/"+caHash+".0")
|
||||
path := "/apex/com.android.conscrypt/cacerts/" + caHash + ".0"
|
||||
out := c.Out("shell", "su", "-c", "ls "+path+" 2>/dev/null")
|
||||
if strings.Contains(out, caHash+".0") {
|
||||
return true
|
||||
}
|
||||
// Overlay copy is a weaker signal but useful when apex ls races the bind.
|
||||
out = c.Out("shell", "su", "-c", "ls /data/local/tmp/cacerts-overlay/"+caHash+".0 2>/dev/null")
|
||||
return strings.Contains(out, caHash+".0")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue