# GoldSrc: Buffer Overflow in DELTA_ParseDelta function leads to RCE

Malicious game server sends crafted svc_deltadescription and svc_event packets to overflow a stack buffer in DELTA_ParseDelta, achieving RCE on the Counter-Strike client.

- Payout: $3,000
- Severity: critical
- Program: Valve
- Found by: pixelindigo
- Disclosed: 2021-05-04
- Write-up quality: 9/10
- Original: https://hackerone.com/reports/484745
- Library page: https://bugbountylibrary.com/r/h1%3A484745
- Tags: area:devices domain:desktop domain:network impact:rce kind:bounty platform:hackerone sev:critical tech:windows technique:chained technique:source-review vuln:memory-corruption vuln:rce

**Target:** GoldSrc engine (hl.exe) network delta parsing, svc_deltadescription/svc_event packets
**Root cause:** DELTA_ParseDelta trusts field_offset and field_size from svc_deltadescription without validating that field_offset + field_size stays within the allocated structure bounds, allowing writes past the stack-allocated event_t in ParseEvent.
**Steps:**
1. Send `svc_deltadescription` defining event_t fields with attacker-controlled type/offset, e.g. a String field at offset `0xac` (return address in ParseEvent) and Integer fields at `0xac + <offset in payload>`.
2. Send `svc_event` packet so ParseEvent allocates event_t on the stack and DELTA_ParseDelta fills it per the malicious layout.
3. Use the String field to write the ROP payload; use extra Integer fields to write bytes containing `\0` (e.g. `0x0b` for syscall) since string copy stops at null.
4. Build ROP: `strncpy` to assemble `/usr/bin/xcalc` and `DISPLAY=:0` in .bss, `Sys_LoadModule("hw.so")` to get its base, then set execve args and jump to `int 0x80` gadget in hw.so.
5. Host the two packets via `python3 poc.py`, launch CS 1.6, connect to 127.0.0.1; xcalc pops.
**How found:** Code review of delta parsing: noticed DELTA_ParseDelta uses field_offset/field_size from the wire without bounds checks; traced which callers allocate fixed structures on the stack and found ParseEvent allocates event_t, making the return address reachable via a crafted field offset.
**Exploitation:** Attacker controls a game server the victim connects to. Two packets: svc_deltadescription sets a field offset to the saved return address of ParseEvent's stack frame; svc_event triggers the overflow. NX blocks shellcode, but hl.exe is at a fixed address enabling ROP without a leak; hw.so is ASLR'd so the chain calls Sys_LoadModule to resolve its base at runtime, then invokes execve via int 0x80 to spawn xcalc.
**Escalation:** Chained info-free ROP with runtime module base resolution (Sys_LoadModule) to defeat ASLR on hw.so, turning a stack overflow into arbitrary command execution.
**Insight:** When a protocol lets the peer describe struct layout (type/offset/size), check whether the consumer validates offset+size against the actual allocation; then find a caller that places the struct on the stack so a field offset can target the saved return address.

## Proof of concept (copied exactly from the original report)

**Crafted svc_deltadescription memory layout for event_t overflow**

```
payload:
  - type=String
  - offset=0xac  # offset of return address in ParseEvent function
int1:
  - type=Integer
  - offset=0xac + <int1 offset in payload>
...
intn:
  - type=Integer
  - offset=0xac + <intn offset in payload>
The first field is used for the payload. Other extra integer fields are used to put data in the payload that has 2 or more zeros (for example 0x0b for syscall) since `DELTA_ParseDelta` copies string until it meets the null character `\0`.
```

