Cesanta Mongoose Websocket Protocol Fragmented Packet Code Execution Vulnerability
The websocket frame reassembly code in Cesanta Mongoose 6.8 resizes the receive buffer with realloc but keeps using pointers into the old buffer. A remote attacker can send a crafted fragmented websocket packet to trigger a use-after-free, leading to denial of service and potentially remote code execution.
Originally disclosed on Cisco Talos
An exploitable memory corruption vulnerability exists in the Websocket protocol implementation of Cesanta Mongoose 6.8. A specially crafted websocket packet can cause a buffer to be allocated while leaving stale pointers which leads to a use-after-free vulnerability which can be exploited to achieve remote code…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code calls realloc on the receive buffer but does not update or invalidate the pointers (p, buf, e, sizep, wsm.data) that were derived from the old buffer before the resize.
Impact
A remote unauthenticated attacker could cause a denial of service and potentially achieve remote code execution; the text notes realloc does not always move the buffer, so the trigger is probabilistic and can be made more reliable with many simultaneous connections.
What the attacker needed
Network access to the websocket service; no authentication required
The fix
The pointers should be recomputed from the receive buffer after the resize, or the resize should be avoided, so no stale pointer is used.
How it was found
- Open a TCP connection to the websocket service and send an HTTP upgrade request to switch to websocket.
- Send a websocket frame whose flags mark it as the first fragment of a fragmented message, with a length that forces the receive buffer to be resized.
- The resize moves the buffer and the parser then reads, writes and copies through the stale pointers, producing the use-after-free.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program needs more memory it can ask the system to move its data to a new, larger area and free the old one. This library did that but kept using addresses that pointed at the freed old area, so it read and wrote memory that no longer belonged to it. An attacker who sends a specially shaped websocket message can steer that mistake into a crash or worse.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.