TP-Link Deco local control
Tested on: X60 v3, firmware 1.6.12.
There are three local interfaces. TP-Link documents only UPnP. ROUTER is the main Deco’s LAN IP (default 192.168.68.1).
1. Web API (HTTPS :443): Wi-Fi, WAN, mesh units, clients
- HTTP redirects to HTTPS with a self-signed cert (
CN=tplinkdeco.net), so disable certificate verification. - The login user is
admin. The password is the Deco web/TP-Link ID password. - Flow (all
POST https://ROUTER/cgi-bin/luci/;stok=<stok>/<path>):login?form=keysandlogin?form=authwith{"operation":"read"}→ RSA keys +seq.- Pick a 16-digit AES key and IV. Body =
sign=<rsa hex>&data=<urlencoded base64 AES-128-CBC of JSON>. - Login sign string:
k=<key>&i=<iv>&h=<md5(user+password)>&s=<seq+len(data_b64)>. Later requests use onlyh=…&s=…. login?form=loginwith{"params":{"password":<rsa hex>},"operation":"login"}→stok+sysauthcookie.- Replies are
{"data": <base64 AES>}. Decrypt them with the same key/IV.
- Working reads (
{"operation":"read"}):admin/network?form=wan_ipv4,internet,performance,lan_ipv4admin/wireless?form=wlan(alsowrite, merge semantics; SSIDs/passwords base64)admin/device?form=device_list,admin/device?form=modeadmin/client?form=client_listneeds"params":{"device_mac":"default"}(or a unit’s MAC)
- Full endpoint list: fetch
/webpages/config/modules.json+models.json, download the listed.js, grepform=. - Dead ends:
- A 404/500 with a bare base64 blob is an AES-encrypted LuCI error page, not a hidden format.
- No endpoints exist for DHCP reservations or port forwarding.
- The UI “Backup” file decrypts to an empty
<config></config>.
2. App protocol (TMP over SSH :20001): reservations, port forwards, UPnP, DHCP
This is what the Deco mobile app speaks. It was reverse-engineered by mthsg/pydeco-tmp (MIT; opcode table in src/pydeco/opcodes.py).
-
SSH (dropbear) on
ROUTER:20001, password auth:- username =
hex(sha1(lowercased TP-Link ID email)) - password = TP-Link ID password
- username =
-
Open a
direct-tcpipchannel to127.0.0.1:20002. There’s no handshake. -
Frame = TMP header (16 B, big-endian) + business header (20 B) + JSON:
- TMP:
01 01 05 00 | len u16 | 00 00 | seq u32 | crc32 u32. The CRC covers the whole packet with the CRC field preset to0x5A6B7C8D.seqstarts at 1. - Business:
01 02 | opcode u16 | ptype u8 | err u8 | txid u16 | crc32(body) u32 | total u32 | offset u32.ptype2 = request, 5 = response, 4 = pull next fragment. - Incoming TMP type 4 = keep-alive: answer
01 01 04 00.
- TMP:
-
First send opcode
0x0001with an empty body (returns a session token). Then:- read body:
{"config_version": <ms epoch>} - write body: the same plus
"params": {...}
- read body:
-
Verified reads:
Opcode Returns 0x40C0DHCP reservations 0x40B0port forwarding rules 0x424AUPnP on/off 0x4213DHCP pool, gateway, DNS 0x423DDHCP leases 0x40D0DDNS 0x4004WAN/LAN status -
Verified writes (MACs as
AA-BB-CC-DD-EE-FF):- Add reservation:
0x40C1,{"reservation_list":[{"ip":"…","mac":"…"}]} - Remove reservation:
0x40C3,{"reservation_list":["AA-BB-…"]}: a list of MAC strings. ({"mac":…}as documented upstream returnsinvalid args.)
- Add reservation:
-
Untested writes:
0x40C2modify reservation,0x40B1add port forward,0x424BUPnP toggle. -
Behaviour:
- Bad arguments are rejected with
error_code 1and change nothing. - After a successful write the port closes for ~5 s (from ~9 s to ~14 s after the write). Wait ~20 s between writes.
- Repeated failed logins lock the port. Make one attempt per run and never loop.
- Bad arguments are rejected with
-
Hygiene:
- Pin the SSH host key fingerprint and abort on mismatch before sending the password.
- Always read → write → read back.
- Python needs only
paramiko.
3. UPnP IGD (:1900): live port mappings, no login
- SSDP
M-SEARCHforurn:schemas-upnp-org:device:InternetGatewayDevice:1→LOCATION(MiniUPnPd). - Service
WANIPConnection:1. SOAPGetGenericPortMappingEntrywith index 0..n lists mappings until it errors. AddPortMapping/DeletePortMappingexist (untested here). Mappings are leases and are lost on reboot.- Or simply run
upnpc -lfromminiupnpc.
Caveats
- All of this is unofficial and may break with a firmware update.
- Any device on the LAN that knows the TP-Link ID credentials has full router control through :20001. Keep them in a file with mode 600, not in scripts or shell history.