How Hackers Use UDP to Bypass Stateful Firewalls

This article explores how malicious actors exploit the User Datagram Protocol (UDP) to circumvent stateful firewall protections. Because UDP is inherently connectionless, stateful firewalls must rely on simulated state tables and temporary pinholes to manage inbound and outbound traffic. Attackers leverage these architectural concessions through techniques such as UDP hole punching, source port spoofing, packet fragmentation, and protocol tunneling to pierce perimeter defenses and maintain unauthorized network access.

The Challenge of UDP for Stateful Firewalls

Stateful firewalls track the state of active network connections to determine whether incoming traffic is legitimate. For Transmission Control Protocol (TCP), this is straightforward because TCP uses a formal three-way handshake (SYN, SYN-ACK, ACK) and explicit teardown flags (FIN, RST).

UDP, by contrast, is completely connectionless. It has no handshakes, sequence numbers, or termination signals. To handle UDP, a stateful firewall must implement “pseudo-state” tracking:

  1. An internal client sends an outbound UDP packet to an external server.
  2. The firewall records the internal IP/port and external IP/port in its state table.
  3. The firewall opens a temporary inbound rule (a “pinhole”) allowing incoming packets from that specific external IP/port back to the internal client.
  4. An inactivity timer (often 30 to 120 seconds) counts down; if no further packets are observed, the pinhole closes.

Attackers exploit the mechanics of these pseudo-states to bypass firewall filtering.

1. Unsolicited Inbound Injection via UDP Hole Punching

UDP hole punching is standard for peer-to-peer (P2P) networking, but attackers weaponize it for persistence and command-and-control (C2).

When a compromised host or rogue payload inside a network sends a single outbound UDP datagram to an attacker-controlled endpoint, the firewall creates a state entry. Even if the firewall blocks unsolicited inbound traffic, the inbound rule created by the outbound packet allows the attacker’s external server to immediately send commands back through the newly created pinhole. By sending periodic “keep-alive” datagrams, the attacker keeps the firewall state entry perpetually open.

2. Exploiting Trusted Well-Known Source Ports

Many basic stateful configurations automatically trust incoming UDP traffic if the source port belongs to a standard service, such as UDP port 53 (DNS) or UDP port 123 (NTP), under the assumption that it is a response to an internal query.

Attackers can configure external scanning or exploitation tools to originate from source port 53. If the stateful firewall is poorly configured to prioritize static port rules over strict state verification, the inbound traffic passes through directly to the target system behind the firewall.

3. UDP IP and Port Spoofing

Because UDP lacks sequence validation and handshake verification, it is vulnerable to source address spoofing. If an attacker determines that an internal host frequently communicates over UDP with a specific external IP (such as an external DNS resolver or time server), the attacker can forge UDP packets using that external server’s IP address.

If the firewall has an open state entry for communication between the internal host and that specific external IP, it will accept the spoofed inbound packet as a legitimate response and forward it to the internal host.

4. UDP Fragmentation Attacks

When UDP packets exceed the Maximum Transmission Unit (MTU), they are split into IP fragments. Only the initial fragment contains the UDP header with the source and destination port numbers. Subsequent fragments contain only the IP header with an offset identifier.

Some stateful firewalls do not properly reassemble fragments before inspecting them, or they lack the memory capacity to buffer out-of-order fragments. Attackers take advantage of this by:

5. Protocol Tunneling and Encapsulation

Stateful firewalls often permit outbound UDP traffic on common ports to prevent disruption of essential services like DNS queries (port 53) or WebRTC/QUIC traffic (ports 443/80).

Attackers encapsulate non-UDP protocols (such as SSH, RDP, or raw shell payloads) inside standard UDP packets. Because the firewall only evaluates the outer UDP transport layer and verifies that an outbound connection was initiated, it allows the bidirectional data stream without inspecting the malicious payload embedded within the payload field.

6. State Table Exhaustion

Stateful firewalls maintain connection states in memory. Attackers can flood a network with massive volumes of randomized UDP packets to non-existent external hosts. Each outbound packet forces the firewall to allocate memory for a new state entry.

Once the state table is fully saturated: - The firewall may drop all new legitimate traffic (Denial of Service). - Certain firewalls fail open, disabling stateful tracking and allowing unfiltered packet traversal across the perimeter.

Defense and Mitigation

Mitigating UDP-based stateful firewall bypasses requires measures beyond simple port-level tracking: