Repository navigation
telnet_opener: add dvrHelper 9530 telnet gate (no-reboot route for XM DVRs/NVRs) - #16
Conversation
PR Summary by QodoAdd no-reboot XM dvrHelper telnet gate
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
|
Addressed all five review findings in c3d7cd7:
KAT digest unchanged ( |
… DVRs) XM DVR/NVR firmware ships dvrHelper with a hidden listener on TCP 9530 that spawns "telnetd xmforever" (root on port 23) after an XM3DES challenge-response. New xmtelnet.py implements the vendor's in-house DES variant (textbook tables, LSB-first bit cells, no final half-swap) plus the wire protocol; telnet_opener.py now probes for the gate first and prefers it when present: no reboot, no DVRIP credentials, and it works on NVR firmware where the SkipCheck InstallDesc path is absent. One wrong OEM password disables the listener until reboot (never blind-retried; --xm-passwd for customized units); a reachable WAN makes the gate answer Refuse:Internet, which is retryable. Root password xc3511 added for the xmforever telnetd (checked against /etc/xmtelnetdpw DES-crypt field). Verified end-to-end on a QEMU twin of the stock NBD6804T-F (HI3520DV200) firmware: verify:OK -> Open:OK -> root shell on :23.
Review findings fixed: 1. `-t` bypassed the 9530 gate described in the README example. The make_telnet flow now probes the gate first as well (same root shell, no InstallDesc upload, no reboot); InstallDesc port 4321 remains the fallback for gate-less cameras. README example corrected. 2. A custom --ports list without 23 discarded a working gate: dvrHelper always spawns telnetd on the vendor default port 23, so 23 is probed explicitly after Open:OK regardless of --ports, then the user list. 3. Socket errors (refused connect, resets, mid-handshake drops) aborted the whole opener; they are now caught and returned as False so the caller falls back to InstallDesc instead of crashing. 4. The hand-rolled reply reader could truncate frames split across TCP segments. Replies are now read to their protocol-fixed lengths (16B randNum, 9B/12B verify, 7B/15B verdict) with a reassembling recv loop and never past the frame, which would have blocked into the server's 15 s select timeout. 5. Short OEM passwords crashed the key setup: dvrHelper zero-pads the combined key material to 16 bytes (sub_2BB28 memset/memcpy), so the client now does the same; self_test covers 1-3 byte passwords. Validated against a fragmenting mock server (all replies split across segments, incl. verify:OK as 5+4) plus the negative paths: verify:ERROR, garbage, Refuse:Internet, refused connection. KAT unchanged. Ruff clean.
c3d7cd7 to
0f05972
Compare
Add 9530 dvrHelper telnet gate to telnet_opener (verified on HI3520DV200)
What
XM DVR/NVR firmware ships a second telnet-enable mechanism besides the
InstallDesc exploit:
dvrHelperlistens on TCP 9530 and spawnstelnetd xmforever(root shell on port 23) for any caller that passes itschallenge-response. This PR adds that route to
telnet_opener.pyas thepreferred, no-reboot path whenever the device has the listener, with
the new self-contained
xmtelnet.pymodule carrying the crypto/protocol.Why prefer it:
telnetctrlneeds a device reboot; the9530 gate spawns telnetd immediately.
which is a firmware constant (
2wj9fsa2) unless the vendor put one in/mnt/custom/TelnetOEMPasswd. Overridable with--xm-passwd.unavailable (tested on an NBD6804T-F / HI3520DV200 DVR).
The crypto (xmtelnet.py)
The gate uses XM's in-house DES variant, not textbook 3DES — a naive
"standard DES" implementation fails the verification:
verified byte-for-byte against dvrHelper's rodata in the XM busybox.
(byte >> i) & 1),S-box output nibbles are also stored LSB-first, and there is no final
half-swap before FP.
the vendor's own degradation to single DES with K1 is reproduced).
The implementation was derived from the dvrHelper applet disassembly
(sub_2BB28/sub_2BC60/sub_2BD98/sub_2BE88) and proved bit-exact against a
live QEMU twin of the stock NBD6804T-F firmware: it reproduces the
server's own E-expansion scratch cells from a guest RAM dump, and the
embedded known-answer test (
self_test()) carries ground truth capturedon the wire.
Protocol notes baked into the code
Every server frame is a single segment with an exact length and no
terminator (
verify:OKis 9 bytes — reading "up to newline" or past theframe length deadlocks into the server's 15 s select timeout and kills
the session).
Two firmware properties the tooling must respect:
device reboots (the accept thread exits, no respawn). The tool
never blind-retries and prints an explicit warning on
verify:ERROR.8.8.8.8 / 180.76.76.76), the gate answers
Refuse:Internetand thelistener survives — that state is retryable once the addresses are
blocked.
Changes
xmtelnet.py(new): stdlib-only XM3DES + 9530 handshake, runnablestandalone (
python3 xmtelnet.py <ip>), KAT-protected self-test.telnet_opener.py:enable_telnet_via_9530()probes for the gate andruns the handshake; wired into the default flow,
-b/--backupflow,and
--xm-passwdoption;xc3511added to the root credentials (thetelnetd xmforeverlogin checks the DES-crypt field of/etc/xmtelnetdpw—absxcfbgXtb3o == crypt("xc3511", "ab")on thetested unit). Also includes the previously-staged fix:
telnetdindaemon mode so the port probe can't kill the listener.
README.md/CLAUDE.md: document the route and its caveats.Testing
python3 xmtelnet.py— KAT only, offline.flash dump:
verify:OK→Open:OK→ root ash on port 23, both viaxmtelnet.pystandalone and viapython3 telnet_opener.py <ip>withno flags (dvrHelper route chosen automatically, no reboot).
ruff check --select E9,F63,F7,F82 --exclude examples --target-version py310 .— clean (matches CI).