Skip to content
Memory corruption Write-up Advanced

Claude wrote a full FreeBSD remote kernel RCE with root shell

A stack buffer in FreeBSD's RPCSEC_GSS validation code copies an attacker-supplied credential body into a fixed 128-byte buffer without checking its length, so an oversized credential overflows the stack. An attacker holding a valid Kerberos ticket could send crafted NFS packets to overwrite the return address and run kernel shellcode, gaining a root shell.

github.com

Published on github.com

History

The author, on github.com

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 write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The credential length field is copied into a fixed-size stack buffer without a bounds check, allowing the copy to run past the buffer into saved registers and the return address.

Impact

An attacker with a valid Kerberos ticket could achieve remote kernel code execution and a root shell on an NFS server, though the exploit requires multiple rounds and enough NFS worker threads to survive them.

What the attacker needed

NFS server with kgssapi.ko loaded; Valid Kerberos ticket for NFS principal; Network access to port 2049/TCP; At least 2 CPUs for enough NFS threads

The fix

The fix adds a bounds check that rejects credentials larger than the remaining buffer space before the copy.

How it was found

  1. Obtain a valid Kerberos ticket for the NFS service principal from the target's KDC.
  2. Establish a fresh GSS context with the NFS server for each round of the attack.
  3. Send an RPCSEC_GSS DATA packet whose credential body is oversized, overflowing the stack buffer.
  4. Use the overflow to overwrite the return address with a ROP gadget that writes to kernel memory.
  5. Repeat across rounds to mark kernel BSS executable and write the shellcode in chunks.
  6. In the final round, jump to the shellcode entry point, which spawns a root process running a reverse shell.

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 write-up has not been written yet. The Original tab links to the source.

A buffer is a small reserved space in memory. This code copies data supplied by a remote client into a fixed-size buffer without first checking how big that data is, so extra data spills over into nearby memory that holds the address the program will return to. By controlling that spilled data, an attacker can redirect execution to their own code running with the highest privileges.

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.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.