Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ self-contained `ipctool` hardware backup to an NFS share (`-b`). Note:
the `InstallDesc` shell-injection path is **blocked on XM firmware built
after 2020-05-07**, which affects what this tool can do on newer cameras.

A second, DVR/NVR-only enable route lives in `xmtelnet.py`: the hidden
dvrHelper listener on TCP 9530 spawns `telnetd xmforever` after an
XM3DES challenge-response (XM's in-house LSB-first DES variant — the
tables are textbook, the bit-cell convention is not; see the module
docstring and the KAT in `self_test()`). `telnet_opener.py` probes 9530
first and prefers it when present (no reboot, no DVRIP credentials).
Two firmware properties to respect: a single wrong OEM password
permanently disables the listener until reboot (never blind-retry),
and a reachable WAN (pings to 114.114.114.114/8.8.8.8/180.76.76.76
succeeding) makes the gate answer `Refuse:Internet`.

## Conventions when extending

- Protocol/wire changes belong in `dvrip.py`; mirror into
Expand Down
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,45 @@ python3 telnet_opener.py 10.0.0.10 -b --nfs 10.0.0.1:/srv/ipctool
# Manual: just enable telnet (camera reboots once).
python3 telnet_opener.py 10.0.0.10

# Manual: open a non-persistent shell on port 4321 (no reboot).
# Manual: open a shell with no reboot -- port 4321 via InstallDesc on
# cameras; on DVRs/NVRs the 9530 gate (below) opens port 23 instead.
python3 telnet_opener.py 10.0.0.10 -t
```

Default telnet credentials on Xiongmai stock firmware are `root` / `xmhdipc`.
Firmware built from 2021 on (e.g. `HI3516EV300_85H50AI` `000529B2` build
2021-03-03, and a 2024 `GK7201V200` build) uses `root` / `Hp#!8CocD_g` instead;
the tool tries both.
the tool tries both. NVRs opened through the 9530 gate (below) ask for
`root` / `xc3511` — that, too, is tried automatically.

### The dvrHelper gate (port 9530): telnet with no reboot and no DVRIP login

XM DVR/NVR firmware also ships `dvrHelper` — a hidden listener on TCP port
9530 that starts `telnetd xmforever` (root on port 23) for any caller that
answers its XM3DES challenge-response with the right OEM password
(default `2wj9fsa2`, or the first 8 bytes of `/mnt/custom/TelnetOEMPasswd`
on customized units). `telnet_opener.py` probes for this listener first
and prefers it when present: no reboot, no credentials, and it works on
NVR firmware where the SkipCheck exploit is unavailable:

```sh
# Any mode -- no flags, -t, or -b/--backup -- tries the gate first and
# only falls back to the reboot route on gate-less devices.
python3 telnet_opener.py 10.0.0.10
```

Details live in `xmtelnet.py` (`python3 xmtelnet.py <ip>` also runs the
handshake standalone). Two caveats from the firmware:

* **One wrong OEM password kills the 9530 listener until the device
reboots** — it exits, no respawn. Wrong answers are never retried
automatically; pass `--xm-passwd` if your unit is customized.
* While the device can ping `114.114.114.114` / `8.8.8.8` / `180.76.76.76`,
the gate answers `Refuse:Internet` and keeps the listener alive (a
blocked WAN makes it proceed). That state is retryable.

Verified on an `NBD6804T-F` (HI3520DV200 DVR) both on hardware and on a
QEMU digital twin of its stock firmware.

`-b/--backup` is self-contained and exits 0 / non-0 for use in scripts and
agentic automation. It checks for telnet on port 23 — if closed, it runs
Expand Down
85 changes: 82 additions & 3 deletions telnet_opener.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import requests
import zipfile

import xmtelnet

TELNET_PORT = 4321
ARCHIVE_URL = "https://github.com/widgetii/xmupdates/raw/main/archive"

Expand All @@ -19,13 +21,23 @@
# (`telnetctrl 1`); 50119 was observed on GK7205V300 + 000699H7.
DEFAULT_TELNET_PORTS = (23, 4321, 50119)

# Hidden dvrHelper gate (XM DVR/NVR firmware): a listener on this port
# spawns `telnetd xmforever` (= port 23, root) for callers that pass its
# XM3DES challenge-response. See xmtelnet.py.
XM_TELNETD_PORT = 9530

# Root passwords of the stock telnet, tried in order. The password changed
# between firmware builds: xmhdipc is the classic one; builds from 2021 on
# (seen on HI3516EV300_85H50AI 000529B2 build 2021-03-03 and on a 2024
# GK7201V200 build) use Hp#!8CocD_g.
TELNET_CREDENTIALS = (
("root", "xmhdipc"),
("root", "Hp#!8CocD_g"),
# For the `telnetd xmforever` session opened through the 9530
# dvrHelper gate: busybox login checks the DES-crypt field of
# /etc/xmtelnetdpw, absxcfbgXtb3o == crypt("xc3511", "ab").
# Observed on an NBD6804T-F NVR (HI3520DV200).
("root", "xc3511"),
)

# InstallDesc that bypasses Hardware/Vendor/Flash validation ("SkipCheck"
Expand Down Expand Up @@ -117,6 +129,39 @@ def check_port(host_ip, port):
return result_of_check == 0


def enable_telnet_via_9530(host_ip, passwd=xmtelnet.XM9530_PASSWD,
ports=DEFAULT_TELNET_PORTS, wait_timeout=120):
"""No-reboot enable path for XM DVRs/NVRs: probe for the dvrHelper
gate on port 9530 (its presence is the device-property check -- it
only exists on XM firmware with the dvrHelper telnet backdoor), and
if present run the XM3DES handshake from xmtelnet.py. Unlike the
InstallDesc route this needs neither DVRIP credentials nor a
reboot, and it works on NVR firmware where the SkipCheck exploit
is unavailable. Returns the telnet port, or None."""
if not check_port(host_ip, XM_TELNETD_PORT):
return None
if not xmtelnet.open_telnet_9530(host_ip, passwd=passwd):
# EITHER refused (recoverable, printed by xmtelnet) OR the one
# bad-digest rule fired (9530 dead until reboot, also printed).
# Do not retry from here, whatever the reason.
return None
# dvrHelper spawns `telnetd xmforever` on the vendor default telnet
# port (23) -- probe it explicitly even when --ports customizes the
# list (a list without 23 must not discard a working gate), then
# the user's ports (some OEM variants move telnetd).
candidates = [23] + [p for p in ports if p not in (23, XM_TELNETD_PORT)]
telnet_port = next(
(p for p in candidates if check_port(host_ip, p)),
None)
if telnet_port:
print(f"Telnet open on {host_ip}:{telnet_port} "
"(no reboot needed -- dvrHelper route)")
return telnet_port
print("9530 said Open:OK but no telnet port answered; "
"check for a port-forward/NAT issue.")
return None


def extract_gen(swver):
return swver.split(".")[3]

Expand All @@ -130,9 +175,12 @@ def cmd_armebenv(swver):


def cmd_telnetd(port):
# No -F: foreground telnetd serves exactly one session and exits
# when it closes — the port probe itself would kill the listener.
# Daemon mode detaches and survives the upgrade context.
return {
"Command": "Shell",
"Script": f"busybox telnetd -F -p {port} -l /bin/sh",
"Script": f"busybox telnetd -p {port} -l /bin/sh",
}


Expand Down Expand Up @@ -228,8 +276,13 @@ def telnet_login(host_ip, port, credentials=TELNET_CREDENTIALS):

def do_backup_via_telnet(host_ip, nfs_share, mount_point="/utils",
user="admin", password="",
telnet_ports=DEFAULT_TELNET_PORTS):
telnet_ports=DEFAULT_TELNET_PORTS,
xm_passwd=xmtelnet.XM9530_PASSWD):
telnet_port = next((p for p in telnet_ports if check_port(host_ip, p)), None)
if telnet_port is None:
# First: the no-reboot dvrHelper route (XM DVRs/NVRs, port 9530).
telnet_port = enable_telnet_via_9530(host_ip, passwd=xm_passwd,
ports=telnet_ports)
if telnet_port is None:
print(f"Telnet closed on {host_ip}, enabling via SkipCheck InstallDesc...")
telnet_port = enable_telnet_via_dvrip(host_ip, user, password, telnet_ports)
Expand Down Expand Up @@ -309,6 +362,7 @@ def open_telnet(host_ip, port, **kwargs):
user = kwargs.get("username", "admin")
password = kwargs.get("password", "")
ports = kwargs.get("ports") or DEFAULT_TELNET_PORTS
xm_passwd = kwargs.get("xm_passwd", xmtelnet.XM9530_PASSWD)

if make_backup:
if not nfs_share:
Expand All @@ -317,12 +371,29 @@ def open_telnet(host_ip, port, **kwargs):
return False
return do_backup_via_telnet(host_ip, nfs_share,
user=user, password=password,
telnet_ports=ports)
telnet_ports=ports,
xm_passwd=xm_passwd)

if not make_telnet:
# Prefer the no-reboot dvrHelper route when the device has the
# 9530 backdoor (XM DVRs/NVRs); fall back to InstallDesc +
# reboot otherwise (or when the gate refuses us).
opened = enable_telnet_via_9530(host_ip, passwd=xm_passwd, ports=ports)
if opened:
print(f"Now use 'telnet {host_ip} {opened}' to login")
return True
return enable_telnet_via_dvrip(host_ip, user=user, password=password,
ports=ports) is not None

# make_telnet (-t): still prefer the no-reboot dvrHelper gate when
# the device has it -- same root shell, but no InstallDesc upload
# and no DVRIP credentials; InstallDesc port 4321 remains the
# fallback for gate-less cameras.
opened = enable_telnet_via_9530(host_ip, passwd=xm_passwd, ports=ports)
if opened:
print(f"Now use 'telnet {host_ip} {opened}' to login")
return True

cam = DVRIPCam(host_ip, user=user, password=password)
if not cam.login():
print(f"Cannot connect {host_ip}")
Expand Down Expand Up @@ -399,6 +470,14 @@ def main():
"(post-reboot port is firmware-determined). "
f"Default {','.join(str(p) for p in DEFAULT_TELNET_PORTS)}.",
)
parser.add_argument(
"--xm-passwd",
default=xmtelnet.XM9530_PASSWD.decode(),
help="OEM password for the dvrHelper 9530 gate (first 8 bytes of "
"/mnt/custom/TelnetOEMPasswd on the device; default is XM's "
"built-in '2wj9fsa2'). CAUTION: one wrong answer disables the "
"9530 listener until the device reboots.",
)
args = parser.parse_args()
kwargs = vars(args)
kwargs["ports"] = tuple(int(p) for p in args.ports.split(","))
Expand Down
Loading
Loading