Skip to content

upnpnat

7h30th3r0n3 edited this page Dec 7, 2025 · 2 revisions

🌐 UPnP NAT

A full-featured module for automatic UPnP NAT mapping on local networks.
Detects LAN hosts, discovers Internet Gateway Devices, and exposes internal services to the WAN.


🚀 Workflow

Wi-Fi Connected
        │
        ▼
[1] ARP Discovery → Detect all LAN devices
        │
        ▼
[2] Host Identification → IP + NetBIOS / “Evil” label for self
        │
        ▼
[3] Target Selection → single host or ALL HOSTS + ALL PORTS
        │
        ▼
[4] Port Selection → choose internal port (or proxy → 80)
        │
        ▼
[5] IGD Discovery → detect router supporting UPnP
        │
        ▼
[6] NAT Mapping → external port ► internal service
        │
        ▼
[7] WAN Exposure → show public IP + mapped port

📦 Modes

1) Targeted NAT (Manual)

  • Scans LAN for active hosts and displays a selectable list.
  • Each host shows its IP and optional NetBIOS name.
  • Select a host:
    • Self (Evil-Cardputer) → use port 80 directly or via local proxy (e.g., 8080→80).
    • Remote host → scans for open services (HTTP, SSH, RTSP, etc.).
  • Prompts for an external WAN port to expose the selected service.
  • Displays public WAN IP and final mapped endpoint on success.

2) Full Auto NAT

  • Enumerates all active LAN devices.
  • Tests a predefined list of common ports (HTTP, HTTPS, RTSP, SSH, RDP, P2P...).
  • Automatically maps every reachable service to consecutive external ports (starting at 50001).
  • Shows mapping results in real time on-screen (OK / FAIL).
  • Ends with WAN IP and total mapped ports summary.

📡 Internal Proxy

  • Creates a local TCP relay from any port (e.g., 81 or 8080) to the internal web service on port 80.
  • Useful when exposing the Cardputer’s own web interface through custom external ports.
  • Traffic is mirrored both ways in real time.
Client ──► Cardputer:8080 → (proxy) → Cardputer:80

📁 Display Flow

[ARP] Found: 192.168.1.10
[ARP] Found: 192.168.1.23
[UPnP] Router detected
[MAP] 192.168.1.23:80 → 203.0.113.7:50080 [OK]

⌨️ Keyboard Shortcuts

Context Keys Action
Global Backspace Abort / return
Menus ; / . Up / Down
Menus Enter Select
Auto NAT Backspace Stop mapping

📑 Example Output

------------------------------------------------------------
LAN Host: 192.168.1.50 - Evil
Internal Port: 80
External Port: 50080
Mapping: SUCCESS
WAN IP: 203.0.113.7
→ Exposed service: http://203.0.113.7:50080/
------------------------------------------------------------

⚖️ Disclaimer

Use strictly for authorized network audits and red team assessments.
This module relies on UPnP-enabled routers, hardened or filtered gateways will block mapping attempts or demand that not provided by original host.
Use responsibly automated exposure can significantly increase network attack surface.


❓ FAQ

Why does NAT mapping fail on some routers?

Several Internet Gateway Devices implement restrictive UPnP security rules. Common causes include:

  • Strict UPnP filtering: some routers only allow port mappings if the SOAP request originates from the same internal host being mapped.
  • IP consistency checks: the IGD compares the source IP of the request with the InternalClient parameter. If they differ, the action is rejected.
  • Partial UPnP disablement: many routers allow SSDP discovery but block WANIPConnection actions.
  • Third-party host refusal: on most consumer routers, only the device initiating the request may map its own internal ports, preventing NAT exposure of other LAN devices.
In these scenarios, the module can only create mappings for the Cardputer itself. To expose a Cardputer service cleanly, you may need to use the internal proxy (e.g., 8080→80) to provide a sanitized and accepted internal port for the IGD.

Why can the Cardputer map its own ports but not other LAN devices?

Most routers enforce a rule requiring the internal IP of the mapped service to match the IP of the device issuing the UPnP request. When the Cardputer attempts to expose a remote host (e.g., 192.168.1.23), the IGD typically rejects the call with an error such as:

[UPnP] Action Failed - ConflictInMappingEntry
However, when exposing a service hosted by the Cardputer itself, all parameters are consistent, and the mapping succeeds.

When should the internal proxy be used?

The internal proxy is recommended when:

  • the Cardputer’s web interface runs on a non-standard port;
  • the router refuses port 80 or considers it reserved/conflicting;
  • you must relay an arbitrary local port (e.g., 81 or 8080) to 80 to satisfy IGD restrictions.
This approach bypasses local port limitations and allows the UPnP module to present a clean, compliant internal service to the router.

How does the UPnP NAT module work internally?

The module follows the standardized UPnP IGD workflow:

  1. SSDP discovery → detect routers exposing WANIPConnection services.
  2. IGD parsing → download and parse the device description XML to extract SOAP control URLs.
  3. AddPortMapping() → send a SOAP action containing:
    InternalClient = 192.168.X.X
    InternalPort   = Internal service port
    ExternalPort   = Chosen WAN port
    Protocol       = TCP
    Enabled        = 1
        
  4. IGD validation → router checks for conflicts, IP consistency, and allowed ranges.
  5. GetExternalIPAddress() → retrieve WAN IP to produce the final accessible endpoint.
Once accepted, the mapping becomes immediately available from the public WAN interface.

Clone this wiki locally