DEV Community

Cover image for UPnP Security Risks: What Any Device on Your LAN Can Open
ParallaxGrain
ParallaxGrain

Posted on

UPnP Security Risks: What Any Device on Your LAN Can Open

The UPnP security risks come from one design choice. UPnP IGD, the Internet Gateway Device profile, lets any device on the LAN ask the router to forward a port from the internet to it, and the base protocol has no login for that request. A game server or a media server uses this on purpose. A compromised camera or a hijacked laptop can send the same request. UPnP assumes a trusted LAN, and a network full of IoT gadgets is not one.

UPnP moves the decision about opening a port from the admin to every device on the LAN.

What UPnP IGD lets a device do

A client, which UPnP calls a control point, works in three steps. It multicasts an SSDP (Simple Service Discovery Protocol) M-SEARCH to 239.255.255.250 on UDP port 1900, and the router answers with the address of its description file. The client fetches that XML file over HTTP, which lists the router's services and their control URLs. It then sends SOAP requests, XML over HTTP, to those URLs.

The service that manages the router's WAN link, WANIPConnection, holds the actions that matter. AddPortMapping takes an external port, a protocol, an internal client address, an internal port, a description and a lease time. GetGenericPortMappingEntry reads the mapping table by index, so a client can list every rule.

The internal client address is a parameter of that call, so a router that does not check it lets one device forward a port to another. IGD:2, the 2010 revision, recommends that unauthenticated clients may map only their own address and only ports from 1024 up, but vendors may choose another policy, and its authentication service, Device Protection, was not widely adopted. miniupnpd, a common open source IGD daemon, limits a client to its own address by default.

UPnP security risks: four ways it has gone wrong

  • A compromised device opens ports for itself. Malware inside the network uses UPnP to make an infected machine reachable from outside the firewall. A web page can do the same: many routers used predictable control URLs, so a page loaded in a LAN browser could reach them through DNS rebinding, a trick that makes the page's hostname resolve to a LAN address, and silently open ports.
  • The UPnP stack has bugs. A 2012 scan of the whole IPv4 space found over 81 million addresses answering UPnP discovery from the internet, about 17 million with the SOAP service open as well. Eight stack overflows in the libupnp SSDP parser, CVE-2012-5958 to CVE-2012-5965, gave remote code execution from a single spoofable UDP packet. The code is still being patched: Microsoft fixed a use-after-free in the Windows UPnP Device Host in April 2026 (CVE-2026-27925).
  • The router listens on the WAN side. A gateway must refuse UPnP traffic that arrives on its WAN interface, and some did not. SSDP on UDP 1900 became a DDoS reflector, amplifying a search request 30.8 times. In 2018 the UPnProxy campaigns injected NAT entries into such routers from outside: some exposed the SMB ports 139 and 445 of machines behind the router, others pointed at internet hosts so that the router relayed attacker traffic as a proxy. In 2020 CallStranger (CVE-2020-12695) showed that the SUBSCRIBE callback in the specification could point to any destination, which allows traffic floods and data exfiltration. The specification was fixed on April 17, 2020, and devices need updated firmware.
  • Old mappings keep working. A mapping stays until its lease ends or the client deletes it. In IGD:1 a lease of 0 creates a static mapping. IGD:2 limits leases to 604800 seconds, one week, and reads 0 as that maximum.

NAT-PMP vs UPnP: same trust model, narrower request

NAT-PMP (RFC 6886) and its standards-track successor PCP (RFC 6887) do the same job over UDP port 5351. A client sends a small binary packet to the default gateway, so there is no multicast search, no XML and no HTTP server on the router, and less parsing code to get wrong.

The security difference is whose address a mapping can point at. In NAT-PMP the router must use the packet's source address as the internal address, and the protocol is not meant to let one device create mappings for another. PCP defines a third-party option for that, its baseline threat model assumes servers do not support it, and miniupnpd leaves it off by default. A compromised camera can open a port to itself, and only by spoofing its source address could it open one to the NAS.

There is still no login. NAT-PMP is unsuitable for LANs with many hosts where some may be untrustworthy, and a 2014 scan found about 1.2 million devices answering NAT-PMP on UDP 5351 from the internet, the same WAN-side exposure as UPnP. On IPv6 there is no NAT to edit. UPnP's IPv6 firewall service and PCP open pinholes, narrow inbound exceptions in the router's firewall, and access lists written for IPv4 clients may not cover them: pfSense's UPnP and PCP lists, for example, apply to IPv4 clients only.

Should I disable UPnP? What to use instead

Turn it off when nothing on the network needs inbound connections. When something does, choose the narrowest mechanism that serves it.

Option Who can open a port How long it stays Fits
UPnP on Any LAN device, no login in the protocol Until the lease expires or the client removes it A home network with many apps that ask for ports
UPnP off Nobody Not applicable Labs, servers, offices, any network without inbound needs
Manual port forward The admin, once Until the admin deletes it One reachable server on a host with a fixed address
NAT-PMP or PCP Any LAN device, normally only for itself Leased, NAT-PMP recommends two hours Clients that support it, when UPnP is too broad
VPN or tunnel Nobody on the LAN A VPN server at home needs one forwarded port, a mesh VPN or an outbound tunnel usually none Remote access to your own services

A permanent forward is not automatically safer: it stays reachable until someone deletes it, and a hand-written rule can be wider than the app needs. Reserve the target host's address in DHCP, forward one port and one protocol to it and test from outside. Game consoles are the usual reason to keep UPnP on, and the full UPnP guide covers how Xbox, PlayStation and Switch handle it.

Defaults differ by vendor and firmware, so look instead of assuming; RouterOS, for one, ships with its UPnP service off. If UPnP has to stay on, restrict it. In miniupnpd keep secure mode, allow only named hosts and ports above 1023, and end the rule list with a deny. In pfSense turn on Default Deny and write allow entries. Put the devices that need UPnP on a separate segment and keep the router firmware current, since fixes reach routers only as updates.

How to check if UPnP is enabled and what it opened

  1. Open the router's UPnP page, usually under advanced or NAT settings, and read the service state and the mapping table. Each entry lists a protocol, an external port, an internal address and a description. Match every internal address against the DHCP lease list and delete mappings you cannot explain.
  2. List the mappings as a LAN client sees them. The miniupnpc client discovers the gateway and prints its mappings, which is also the view a hostile device gets, and Nmap's upnp-info script queries UDP port 1900.
  3. Check from outside which TCP ports answer. The Port Scan on packet.guru takes a domain or an IPv4 address plus up to 10 comma-separated TCP ports, reports each as OPEN, closed or filtered and adds a guess at the service from the port number. It does not fill in your address, it blocks private addresses, it allows one scan per 15 seconds and it cannot test UDP, so start with the TCP ports from step 1. Scan only addresses you own.
  4. From a machine outside your network that you control, probe UDP 1900 on the router's WAN address, with the same Nmap script for example. It should get no answer. If it does, disable UPnP on the WAN interface and update the firmware.
  5. Change the setting, restart the apps that relied on UPnP and repeat steps 1 and 3.

Top comments (0)