Persistence via customer_env.sh¶
Status: VERIFIED on hardware on the tested 55PUS8000/12 (root survived a
cold boot with the USB stick removed). The redacted capture is in
evidence/persistence/output.txt.
Firmware variants. On at least one later
TPN256Ebuild (TPN256E_V056.010.032.001),run.shdoes not referencecustomer_env.sh. Check before installing:grep -n customer_env.sh /mtd_apexe/board/run.shIf that prints nothing,
run.shwill never source the file. Use the/swdl/telnet/telnetdfallback instead.payloads/persist_root.shnow detects the hook and installs the matching one automatically. The report is external; see the variant note for the target and status.
Why this hook exists¶
/mtd_apexe/board/run.sh sources a customer environment file on every boot:
if [ -e "/mtd_apdat/customer_env.sh" ]; then
source /mtd_apdat/customer_env.sh
if [ "${CUSTOMER_BRAND_NAME}" != "" ]; then
export NF_MODEL_NAME="${CUSTOMER_BRAND_NAME}_${CUSTOMER_MARKET_MODEL}"
fi
fi
/mtd_apdat is a symlink to /mtd_rwarea/apdat, which is a rw ext4
partition (p31). This is a legitimate vendor hook for customer branding; it is
also a persistent root hook.
The ordering trap¶
run.sh sources customer_env.sh before it launches
iptables_conf.sh (the boot firewall). If you insert the :2323 rule directly
in customer_env.sh, the later firewall flush removes it. The persistent
payload therefore starts a background script that:
- waits for
/tmp/ntkdriver_completed(the markerquick_debug/menualso waits for), with a 60-second cap; - waits another 5 seconds so
iptables_conf.shhas finished flushing INPUT; - copies
/mtd_rwarea/apdat/busyboxto/tmp/persist/busybox(the basename must remainbusybox); - inserts the
:2323ACCEPT rule withiptables -w 5; - starts
telnetdfrom/tmp/persist/busyboxif the port is not already listening; - writes
/mtd_rwarea/apdat/root_boot.readyon success.
/tmp/persist/busybox is deliberately separate from /tmp/busybox, so a USB
autorun stick left in the TV cannot overwrite the running persistent binary.
Files¶
| Path | Purpose |
|---|---|
/mtd_rwarea/apdat/busybox |
Static armhf BusyBox, copied from the autoroot session. |
/mtd_rwarea/apdat/root_boot.sh |
Boot script. |
/mtd_rwarea/apdat/customer_env.sh |
Vendor hook; contains one appended line. |
/mtd_rwarea/apdat/root_boot.log |
Boot log. |
/mtd_rwarea/apdat/root_boot.ready |
Success marker with date/uptime. |
/mtd_rwarea/apdat/root_boot.ready.failed |
Failure marker. |
payloads/persist_root.sh installs all of it and runs restorecon on the three
files so they keep the idtv_data_t label.
Install¶
From the USB autoroot root shell:
# Serve the repo from your workstation:
# python3 -m http.server 8000 --bind 0.0.0.0
/tmp/busybox wget -O /tmp/persist_root.sh http://<WORKSTATION_IP>:8000/payloads/persist_root.sh
/bin/sh /tmp/persist_root.sh
The installer:
- refuses to run unless it is root and
/mtd_rwarea/apdatis writable; - detects whether
run.shsourcescustomer_env.sh, or whether the firmware has the/swdl/telnet/telnetdseam; - copies the running
/tmp/busyboxtoapdat/busybox; - writes
root_boot.sh; - on the
customer_env.shpath, backs up an existing file tocustomer_env.sh.bakand appends the hook only if it is not already present; - on the
/swdlpath, writes the wrapper and backs up any existing file to/swdl/telnet/telnetd.bak; - prints the resulting files and the test commands.
Verify without rebooting¶
/bin/sh /mtd_rwarea/apdat/root_boot.sh
cat /mtd_rwarea/apdat/root_boot.log
cat /mtd_rwarea/apdat/root_boot.ready
Because a telnetd is already listening from the USB session, the script should
print port 2323 already listening and still write READY. The important test
is the cold boot:
- Remove the USB stick.
- Unplug AC for 10 seconds.
- Plug in, wait ~20 seconds.
nc <TV_IP> 2323, thenid.
Restore¶
# customer_env.sh variant:
sed -i '/root_boot.sh/d' /mtd_rwarea/apdat/customer_env.sh
# /swdl/telnet/telnetd variant:
rm -f /swdl/telnet/telnetd
rm -f /mtd_rwarea/apdat/root_boot.sh /mtd_rwarea/apdat/busybox \
/mtd_rwarea/apdat/root_boot.log /mtd_rwarea/apdat/root_boot.ready \
/mtd_rwarea/apdat/root_boot.ready.failed
Cold boot afterwards. If the hook breaks and you lose the shell, the USB
autoroot stick is the recovery path. See the
/swdl variant restore notes
for the .bak case.
Why not modify the rootfs?¶
/ is a read-only SquashFS. Modifying it would require repacking the NFSB
secure filesystem and dealing with the RSA/SHA-256 layer. The apdat hook is
smaller, reversible, and does not touch the boot chain. See
ADR-0003.