
NFS Underground 2 — Network Remote Code Execution (two heap overflow RCE vectors, CVSS 9.8)
Two remote code execution vulnerabilities discovered in Need for Speed: Underground 2 (SPEED2.EXE). This repository contains a working proof-of-concept for one of them — a single TCP packet that achieves arbitrary code execution through the game's own code. No injection, no external tools, no user interaction beyond connecting to a server.
| # | Vector | Description | Status |
|---|---|---|---|
| 1 | TCP certificate handler (state 0xb) | Unbounded memcpy → pool free-list corruption → DWORD shoot | Working PoC |
| 2 | UDP game session | Heap overflow via oversized packet | Identified |
| Binary | SPEED2.EXE (32-bit x86 PE) |
| SHA-256 | 8f6a9ae2c4cfa01181d2fd755d99c6f4b7103f60273908ea1de1e719dfe2a297 |
| Image base | 0x00400000 (fixed) |
| ASLR | None — every address is known at compile time |
| DEP | None — /NXCOMPAT not set, heap is executable |
| SafeSEH | None — no structured exception handler validation |
| Stack cookies | Present but irrelevant — this exploit targets the heap |
| Online servers | Shut down by EA in 2007 |
The complete absence of ASLR means every function, every global variable, and every IAT entry sits at a fixed, predictable address. No DEP means heap memory is executable — shellcode placed there runs directly without needing a ROP chain. These are the conditions that make a single-packet RCE possible.
When the player clicks "Online", the game connects to pcnfs05.ea.com on TCP port 20971 and begins a TLS-like authentication handshake. The game sends a 30-byte hello, and the server is expected to reply with an X.509 certificate. The game allocates a Key Exchange (KE) buffer of 0x88C0 bytes (35,008 bytes) on its custom heap to hold the handshake state.
The certificate handler (state 0xb in the TLS state machine) processes the server's reply. After parsing the ASN.1 certificate, it copies additional data from the packet into the KE buffer starting at offset 0x81D4:
KE buffer: 0x88C0 bytes allocated
Copy starts: KE + 0x81D4
Remaining: 0x88C0 - 0x81D4 = 0x6EC bytes (1,772 bytes)
Attacker sends: up to ~1,921 bytes of copy data
There is no bounds check. The copy length comes directly from the attacker's packet. This means the attacker can write approximately 1,900 bytes past the end of the KE buffer, directly into whatever heap structure sits next to it.
The game uses a custom pool allocator — not the Windows heap. This allocator maintains its own metadata structures that sit directly adjacent to allocated blocks. Immediately after the KE buffer's allocation, there is a free-list node — a 16-byte structure that's part of the allocator's bookkeeping:
Free-list node layout (16 bytes):
Offset 0x00: next (4 bytes) — pointer to next free node
Offset 0x04: prev (4 bytes) — pointer to previous free node
Offset 0x08: size (4 bytes) — size of this free block
Offset 0x0C: magic (4 bytes) — always 0x44443333 for valid free nodes
The free list is a circular doubly-linked list, sorted by address. Each node points forward and backward to its neighbors. The overflow lets us replace all four fields with attacker-controlled values.
When a block is freed, the allocator runs through these steps in this exact order:
1. SET SIZE + MAGIC
Write the block's size and magic (0x44443333) into the freed block's
node header.
2. SORTED INSERT
Walk the free list forward from the sentinel. Find the first node
whose address is greater than the freed block. Insert the freed
block BEFORE that node.
This means:
freed->next = found_node
freed->prev = found_node->prev
found_node->prev->next = freed ← WRITE to corrupted prev
found_node->prev = freed
3. FORWARD COALESCE
Check if freed_block + freed_size == next_node.
If adjacent, merge them: unlink next_node from the list.
Unlink does:
next_node->next->prev = next_node->prev
next_node->prev->next = next_node->next ← WRITE via corrupted pointers
4. BACKWARD COALESCE
Check if prev_node + prev_size == freed_block.
If adjacent (by 32-bit arithmetic), merge them: unlink freed_block.
Unlink does:
freed->next->prev = freed->prev ← THE DWORD SHOOT
freed->prev->next = freed->next
5. DEBUG FILL
If the pool descriptor's debug flag is set (it is), fill the
entire freed data area with 0xEEEEEEEE.
Fill range: [block_start, free_node_addr + 16)
Each unlink operation writes 4 bytes to an address derived from the node's pointers. By controlling those pointers through the overflow, we turn the allocator's own maintenance code into an arbitrary write primitive. This is the DWORD shoot — a controlled 4-byte write to any writable address.
At address 0x007FBE54 in the .data section (writable, fixed address, no ASLR), there is a function pointer that the pool allocator calls on every allocation:
PTR_FUN = 0x007FBE54 — the pointer itself (in writable .data)
*PTR_FUN = 0x005832E0 — original value (pool alloc wrapper FUN_005832E0)
Every time the game allocates memory, it does CALL [0x007FBE54], which jumps to whatever address is stored there. If we overwrite that stored address with the location of our shellcode, the next allocation executes our code.
The exploit uses the backward coalesce for the final DWORD shoot, not the forward coalesce. Here's why:
The free function's steps happen in order. During sorted insert (step 2), the allocator writes to corrupted_node->prev, which clobbers the first 4 bytes at our fake prev node's address. If we put shellcode starting at byte 0, insert destroys it.
During forward coalesce (step 3), the unlink writes the KE block address to PTR_FUN. This is a temporary value — it's not our shellcode address.
During backward coalesce (step 4), the unlink overwrites PTR_FUN again — this time with our fake prev node's address, which IS our shellcode. This is the final write that sticks.
After the coalesce, the allocator fills the freed region with 0xEEEEEEEE for debugging. The fill range covers:
[KE_block_start, free_node_addr + 16)
If we put shellcode inside this range, the fill destroys it. The solution: place the fake prev node (containing our shellcode) 32 bytes past the free node, which is 16 bytes outside the fill boundary:
Fill range: [KE_block ... free_node + 16) ← 0xEE overwrites everything here
Shellcode at: free_node + 32 ← 16 bytes PAST the fill, safe
The sorted insert step writes the KE block address to *(fakePrevAddr), clobbering bytes 0-3 of our fake prev node. We can't prevent this, so we design bytes 0-11 as a bridge that works regardless of what gets written to bytes 0-3:
Byte layout of the fake prev node:
[0-3] CLOBBER ZONE
After insert: written with KE_block address (e.g. 0x0C4B1058)
After backward coalesce: overwritten with 0x007FBE50
Final bytes: 50 BE 7F 00
Decodes as: PUSH EAX (50)
MOV ESI, imm32 (BE xx xx xx xx — consumes bytes 1-5)
[4-5] 90 90 (NOP NOP)
These are consumed as part of MOV ESI's 4-byte immediate operand.
ESI gets junk, which is harmless.
[6-7] EB 04 (JMP SHORT +4)
Jumps over bytes 8-11 (the size field that gets modified during merge).