RutgerWillemsIf you're not sure, call me Will
Resources

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>):
    1. login?form=keys and login?form=auth with {"operation":"read"} → RSA keys + seq.
    2. Pick a 16-digit AES key and IV. Body = sign=<rsa hex>&data=<urlencoded base64 AES-128-CBC of JSON>.
    3. Login sign string: k=<key>&i=<iv>&h=<md5(user+password)>&s=<seq+len(data_b64)>. Later requests use only h=…&s=….
    4. login?form=login with {"params":{"password":<rsa hex>},"operation":"login"} → stok + sysauth cookie.
    5. Replies are {"data": <base64 AES>}. Decrypt them with the same key/IV.
  • Working reads ({"operation":"read"}):
    • admin/network?form=wan_ipv4, internet, performance, lan_ipv4
    • admin/wireless?form=wlan (also write, merge semantics; SSIDs/passwords base64)
    • admin/device?form=device_list, admin/device?form=mode
    • admin/client?form=client_list needs "params":{"device_mac":"default"} (or a unit’s MAC)
  • Full endpoint list: fetch /webpages/config/modules.json + models.json, download the listed .js, grep form=.
  • 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
  • Open a direct-tcpip channel to 127.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 to 0x5A6B7C8D. seq starts at 1.
    • Business: 01 02 | opcode u16 | ptype u8 | err u8 | txid u16 | crc32(body) u32 | total u32 | offset u32. ptype 2 = request, 5 = response, 4 = pull next fragment.
    • Incoming TMP type 4 = keep-alive: answer 01 01 04 00.
  • First send opcode 0x0001 with an empty body (returns a session token). Then:

    • read body: {"config_version": <ms epoch>}
    • write body: the same plus "params": {...}
  • Verified reads:

    OpcodeReturns
    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 returns invalid args.)
  • Untested writes: 0x40C2 modify reservation, 0x40B1 add port forward, 0x424B UPnP toggle.

  • Behaviour:

    • Bad arguments are rejected with error_code 1 and 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.
  • 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-SEARCH for urn:schemas-upnp-org:device:InternetGatewayDevice:1 → LOCATION (MiniUPnPd).
  • Service WANIPConnection:1. SOAP GetGenericPortMappingEntry with index 0..n lists mappings until it errors.
  • AddPortMapping / DeletePortMapping exist (untested here). Mappings are leases and are lost on reboot.
  • Or simply run upnpc -l from miniupnpc.

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.