Hello,

I found three remotely-triggerable crash vulnerabilities in ptunnel as
shipped
in Debian (ptunnel 0.72-5, trixie/sid) and confirmed all three by
reproduction
in an isolated container. ptunnel's original upstream is dead (0.72 is the
last
release), so the shipped code is current; the maintained successor is the
separate project ptunnel-ng (github.com/lnslbrty/ptunnel-ng) — whether it
shares
these defects is not yet verified.

All three hit a ptunnel proxy started WITHOUT a password (-x), the common
default: no authentication, triggered by crafted ICMP echo packets. ptunnel
is
single-process/threaded, so each crash drops all tunnels.

================================================================
1) Integer overflow in handle_data -> ~4 GB malloc/memcpy -> OOB read /
crash
================================================================
Where:  handle_data() ptunnel.c:1358-1366 + create_fwd_desc()
ptunnel.c:1489-1494
Type:   CWE-190 integer overflow -> CWE-125 OOB read / CWE-476.
Unauthenticated.
CVSS:   AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:H  (~8.6) [proposed]

handle_data() does `expected_len += pt_pkt->data_len;` (data_len is a 32-bit
attacker field) then checks `if (total_len < expected_len) ... fatal`. With
data_len = 0xFFFFFFFF and a minimal 56-byte packet, expected_len wraps
(56 + 0xFFFFFFFF mod 2^32 = 55, rounded to 56), so the "not fully received"
guard is bypassed and create_fwd_desc(seq, 0xFFFFFFFF, data) runs:
    malloc(sizeof(forward_desc_t) + 0xFFFFFFFF)   (~4 GB, return unchecked)
    ... memcpy(fwd_desc->data, data, 0xFFFFFFFF)   from a 1080-byte buffer
If the alloc fails, the following write NULL-derefs; with overcommit it
succeeds
and the memcpy reads ~4 GB out of bounds. Either way the proxy crashes.

Reproduction (container, loopback, no password): one ICMP echo carrying a
ptunnel header with magic 0xD5200880, state=kProxy_start|kUser_flag, valid
dst_ip/dst_port, data_len=0xFFFFFFFF, zero payload.
  gdb:  SIGSEGV in create_fwd_desc (ptunnel.c:1494), data_len=4294967295
  ASan: heap-buffer-overflow READ of size 4294967295, 0 bytes after the
        1080-byte ICMP receive buffer (allocated at pt_proxy:684)

Fix: validate data_len against total_len with unsigned/size_t math and an
explicit upper bound BEFORE create_fwd_desc; check malloc's return.

================================================================
2) NULL-pointer dereference via kProto_authenticate to a no-password proxy
================================================================
Where:  handle_packet() ptunnel.c:1056 -> validate_challenge() :1561 ->
        generate_response() :1545
Type:   CWE-476 NULL deref -> crash. Unauthenticated.
CVSS:   AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H = 7.5 [proposed]

cur->challenge is only allocated when a password is configured. On a
no-password
proxy it stays NULL, but the kProto_authenticate branch calls
validate_challenge(cur->challenge=NULL, ...) -> generate_response(NULL) ->
memcpy(buf, NULL, 32). No NULL/password guard.

Reproduction: send kProxy_start (creates the session) then a
kProto_authenticate
packet with data_len=32 and 32 bytes of payload.
  gdb: SIGSEGV in generate_response (challenge=0x0) at ptunnel.c:1545,
rsi=0x0

Fix: guard validate_challenge / the authenticate branch when no password is
set
(cur->challenge == NULL) and drop the packet.

================================================================
3) exit(0) on attacker data_len greater than received bytes (single-packet
DoS)
================================================================
Where:  handle_data() ptunnel.c:1362-1366
Type:   CWE-617 reachable exit / CWE-400 DoS. Unauthenticated.
CVSS:   AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H = 7.5 [proposed]

When the claimed data_len exceeds the bytes actually received, handle_data
logs
"...this error is fatal" and calls exit(0), terminating the whole proxy on
one
packet.

Reproduction: one ICMP echo with data_len=0xFFFF and a few bytes of payload.
  Proxy logs "Packet not completely received: 56 Should be: 65592 ... this
error
  is fatal" and the process (alive before) exits with code 0.

Fix: replace exit(0) with discard-and-return.

----------------------------------------------------------------
All three reproduced on Debian ptunnel 0.72-5 in an isolated container
(--cap-add=NET_RAW, loopback only). I have a Python PoC (poc.py) and can
share
it for coordinated disclosure / CVE assignment.

Thanks in advance,
Ing. Maximiliano Sebastián Quiroga

Reply via email to