Skip to content
VulnSVNCAdvisories
hping3 — hping3 Out-of-Bounds Write in display_ipopt() via IP Record Route Option

CVE-2026-136131

hping3 Out-of-Bounds Write in display_ipopt() via IP Record Route Option

Out-of-Bounds Write in display_ipopt() via IP Record Route Option (old_rr buffer overflow)

Technical Report

CVE-2026-136131 -- Out-of-Bounds Write in display_ipopt() via Record Route

Out-of-bounds write into old_rr in hping2 display_ipopt() (CWE-787)


Summary

display_ipopt() in display_ipopt.c (hping2 codebase) copies attacker-controlled data into a fixed-size 40-byte global buffer (old_rr[MAX_IPOPTLEN]) using a length value taken directly from an unvalidated byte in the received IP packet. The copy length is bounded only by 0xFF, not by MAX_IPOPTLEN or by the actual remaining IP header length. This allows an out-of-bounds write of up to ~211 bytes past the buffer, with both length and content fully controlled by whoever sent the packet.

Vulnerability Details

Field Value
CVE CVE-2026-136131
CWE CWE-787 (Out-of-bounds Write), related to CWE-20 (Improper Input Validation)
Component display_ipopt.c, function display_ipopt()
Trigger path wait_packet() → display_ipopt() in waitpacket.c
CVSS Version 4.0
CVSS Score 6.0 (MEDIUM)
CVSS Vector CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:P/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N

Affected Code

display_ipopt.c:

static int old_rrlen;
static char old_rr[MAX_IPOPTLEN];   // MAX_IPOPTLEN == 40 (hping2.h)
...
case IPOPT_RR:
    j = *++cp;              /* option length byte — raw, attacker-controlled (0–255) */
    i = *++cp;              /* option pointer byte — raw, attacker-controlled (0–255) */
    hlen -= 2;
    if (i > j)
        i = j;
    i -= IPOPT_MINOFF;      /* IPOPT_MINOFF == 4 */
    if (i <= 0)
        continue;
    ...
    old_rrlen = i;
    memcpy(old_rr, cp, i);  /* i can be up to 251; old_rr is only 40 bytes */

Neither j nor i is ever checked against MAX_IPOPTLEN (40) or against the actual bytes remaining in the IP header (hlen). The only clamp applied (if (i > j) i = j;) bounds i against j, which is itself an attacker-controlled byte, so it provides no real safety margin.

Root Cause, Step by Step

  1. wait_packet() in waitpacket.c receives a raw packet via read_packet() / pcap_recv().
  2. It checks that the packet's destination matches the local interface and (for non-ICMP, non---rand-dest cases) that the source matches the configured remote target, then calls recv_tcp() / recv_udp() / recv_icmp().
  3. These functions validate only the port (for TCP/UDP) or ICMP id/type (for ICMP). No TCP sequence/ack validation is performed, so a match is trivially achievable by an attacker who can spoof packets appearing to originate from the configured target.
  4. If the packet is deemed a "match" and hping was invoked with -G / --rroute, wait_packet() calls:
    display_ipopt(ip_packet);
    
  5. display_ipopt() walks the IP options starting right after the fixed 20-byte IP header. When it encounters option type IPOPT_RR (value 7), it reads the next two raw bytes from the packet as j (length) and i (pointer), with no bounds validation.
  6. i is clamped only against j (both attacker-controlled), then reduced by IPOPT_MINOFF (4). Maximum achievable value: 255 − 4 = 251.
  7. memcpy(old_rr, cp, i) writes up to 251 bytes into a 40-byte global buffer, i.e. up to ~211 bytes of out-of-bounds write, with content taken directly from attacker-supplied packet bytes.

Because old_rr is declared static (not a stack local), it resides in the .bss segment. The overflow corrupts whatever global/static data the linker placed immediately after it. This is not a stack/return-address overwrite, but a BSS/global-data corruption primitive.

Preconditions to Trigger

Condition Required? Notes
hping run with -G / --rroute Yes Not default behavior
Received packet classified as "match" Yes Requires correct destination IP (= operator's host), and for non-ICMP traffic correct source IP (= configured target) and matching port
Attacker position On-path, OR the probed target itself, OR an off-path blind spoofer No TCP sequence/ack or cryptographic validation is performed by recv_tcp()/recv_udp()/recv_icmp(), so blind spoofing of the configured target's source IP plus a guessed/observed source port is sufficient for UDP/ICMP modes and largely sufficient for TCP mode as implemented here
Malicious IP header Yes Must contain an IPOPT_RR option with length/pointer bytes set to trigger i > 40 after the IPOPT_MINOFF subtraction

Impact

  • Confirmed: Deterministic, attacker-controlled out-of-bounds write of up to ~211 bytes into process global memory (.bss), fully reachable over the network while hping is running with -G.
  • Confirmed: Reliable crash / denial of service against the hping process.
  • Unconfirmed (binary-dependent): Whether this can be escalated to control-flow hijack or arbitrary code execution depends on what data the linker places adjacent to old_rr in the final binary (compiler, compiler version, link order, and build flags all affect this). This has not been proven in this report and should not be assumed without separate binary-specific analysis (e.g., nm / objdump -t on the actual shipped binary).

CVSS 4.0 Assessment

Score: 6.0 — MEDIUM Vector: CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:P/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N

Metric Value Rationale
AV (Attack Vector) Network (N) The attack can be delivered over the network
AC (Attack Complexity) High (H) The packet must be accepted as a "match", which requires correct source/destination IP and port information
AT (Attack Requirements) Present (P) hping must be running with -G / --rroute during an active probe
PR (Privileges Required) None (N) The attacker needs no privileges
UI (User Interaction) Passive (P) The operator must run hping with the relevant option
VC (Confidentiality) None (N) No confidentiality impact demonstrated
VI (Integrity) Low (L) Limited corruption of global (BSS) data
VA (Availability) High (H) Process crash / denial of service
SC / SI / SA None (N) No impact on subsequent systems

Suggested Fix

Clamp the copy length against both the fixed buffer size and the actual remaining header length before the memcpy:

case IPOPT_RR:
    j = *++cp;
    i = *++cp;
    hlen -= 2;
    if (i > j)
        i = j;
    i -= IPOPT_MINOFF;
    if (i <= 0)
        continue;
    if (i > MAX_IPOPTLEN)          /* added bound */
        i = MAX_IPOPTLEN;
    if (i > hlen)                  /* added bound: don't read past actual header */
        i = hlen;
    ...
    memcpy(old_rr, cp, i);

The IPOPT_LSRR branch in the same function has the same class of issue (unbounded forward traversal of cp based on attacker-controlled j) and should be reviewed and bounded the same way, even though it does not write into a fixed buffer.

Reproduction Notes

This can be reproduced locally without network spoofing by linking a small harness that calls display_ipopt() directly with a hand-crafted buffer containing a malformed IPOPT_RR option (length/pointer bytes set to force i > 40), compiled with -fsanitize=address. ASan will report a global-buffer-overflow on the memcpy line.

Environment

  • Source analyzed: hping-master (hping2 codebase, files dated 1999–2004, $Id$ tags from antirez)
  • Verification method: Confirmed via static source review; dynamic confirmation (ASan harness run) is pending, blocked in the review environment by missing libpcap-dev, not by anything specific to the bug.

Disclosure

Reported upstream prior to public CVE assignment, per standard coordinated disclosure practice.


References

Researcher: Umut SEVİNÇ (VulnSVNC)