Skip to content
Memory corruption Disclosed report Advanced

RCE on CS:GO client using unsanitized entity ID in EntityMsg message

The CS:GO client did not validate the entity index in a network message, allowing an attacker-controlled server to cause an out-of-bounds memory access and potentially execute arbitrary code on the victim's machine.

teapotd Follow

Originally disclosed on HackerOne

Bounty$9,000 Critical 9.6 View original
  • Triaged in 3 months
  • Fixed in 23 months
  • Paid in 4 months
  • Disclosed after 2.0 years

Summary by the program

Title: RCE on CS:GO client using unsanitized entity ID in EntityMsg message Scope: csgo.exe Weakness: Out-of-bounds Read Severity: Critical (9.6) Link: https://hackerone.com/reports/584603 Date: 2019-05-19 17:49:21 +0000 By: @chaynik

Details: Vulnerability

CSVCMsg_EntityMsg message is used by server to notify client about generic actions regarding entities. The message is described using the following Protocol Buffer:

message CSVCMsg_EntityMsg {
    optional int32 ent_index = 1;
    optional int32 class_id = 2;
    optional bytes ent_data = 3;
}

The pseudocode of function handling this message:

C++
void ProcessEntityMessage(CSVCMsg_EntityMsg *msg) {
    IClientNetworkable *entity = entitylist->GetClientNetworkable(msg->ent_index);
    if (entity) {
        ...
        entity->ReceiveMessage(...);
        ...
    }
    ...
}

Neither handler nor GetClientNetworkable check if entity index is valid - an arbitrary integer can be passed. This can lead to memory access outside of entity list and then to virtual function call on invalid object. By careful manipulation it can be used to divert control flow to attacker's payload.

Exploitation

The exploit is based on assumption that client_panorama.dll base address is known to the attacker. It can be procured using additional memory disclousure vulnerability, like #581774. Alternatively, in case of distributed attack guessing address may be viable (32-bit ASLR has low entropy).

The first stage is to find a variable with known address that can be controlled by server. For example, I chose to use map name because its copy is stored in a global variable somewhere in client_panorama.dll. Note that it's expected behavior and not a vulnerability.

Then I crafted a payload containing ROP chain and fake IClientNetworkable object. The payload is sent to server as map name. Obviously, map name is a string and cannot contain null characters, but there's easy way to bypass this limitation by overwriting it several times.

The final step is to use the vulnerability to trick client into executing virtual function on the fake object. Entity list is a statically allocated array inside client_panorama.dll, so the offset to the payload is constant. An appropriate entity index is calculated from the offset and message is sent.

The ROP chain goal is to run Calculator app. Luckily, client_panorama.dll imports IProcessUtils interface from tier0.dll which can be used to start processes. It simplifies ROP chain considerably.

Proof of Concept

The PoC script is demonstrating RCE capability on CS:GO client for Windows (version 13696, 2019-05-16 stable release).

  1. Download attached script: F492694
  2. Start CS:GO client
  3. Use a debugger to get the base address of client_panorama.dll and set CLIENT_BASE variable in downloaded script
  4. Run attached Python 3 script (possibly on another host)

Note: If you run this script on the same host as client you might need to change the default PORT (because for some reason CS:GO client uses it). 5. Connect to the malicious server and wait for calc.exe to pop up

Similarly as in #470520, Steam browser protocol can be used to launch an attack from web browser:

  1. Follow steps 1-4 as above
  2. Download attached HTML file (F492697) and set IP in iframe URL to malicious server
  3. Open downloaded HTML file and wait for calc.exe to pop up

Impact

An attacker can execute arbitrary code on the computer of anyone who attempts to connect to the server. After succesful exploitation an attacker can gain control over victim's computer and do whatever they want.

The connection to the server can be initiated manually by the victim or automatically using Steam browser protocol on malicious web site.

The likelihood of victim joining the server via in-game server browser can be greatly improved by faking high player count and further social engineering. Many players sort server list by player amount.

In case of an attack from web browser many users don't need to click Open steam and this method requires no further interaction from user - connection will be initiated without confirmation (even CS:GO client will be started if it's not running).

The original report as published on HackerOne, by teapotd. 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. 5 min read.

Context

Counter-Strike: Global Offensive (CS:GO) is a client-server game. The client (csgo.exe) connects to game servers, and the server drives much of what the client does by sending it network messages. One of those messages is CSVCMsg_EntityMsg, which the server uses to notify the client about generic actions regarding entities. The entity list on the client is a statically allocated array inside client_panorama.dll, and each entry is an IClientNetworkable object that the client can call virtual functions on.

The report describes a critical (9.6) out-of-bounds read in csgo.exe, disclosed on 2021-05-27, with a bounty of 9,000 USD. The report body is signed @chaynik.

Setup

The proof of concept targets the CS:GO client for Windows, version 13696, the 2019-05-16 stable release. The exploit assumes the attacker knows the base address of client_panorama.dll. The report says this can be procured using an additional memory disclosure vulnerability, citing #581774, or, in the case of a distributed attack, by guessing the address, since 32-bit ASLR has low entropy.

The PoC is a Python 3 script run against a malicious server the victim connects to. The researcher notes that if the script runs on the same host as the client, the default PORT may need changing because the CS:GO client uses it.

Finding it

The message is defined by the following Protocol Buffer:

Text
message CSVCMsg_EntityMsg {
    optional int32 ent_index = 1;
    optional int32 class_id = 2;
    optional bytes ent_data = 3;
}

The function that handles it looks like this:

C++
void ProcessEntityMessage(CSVCMsg_EntityMsg *msg) {
    IClientNetworkable *entity = entitylist->GetClientNetworkable(msg->ent_index);
    if (entity) {
        ...
        entity->ReceiveMessage(...);
        ...
    }
    ...
}

Neither the handler nor GetClientNetworkable checks whether the entity index is valid, so an arbitrary integer can be passed. That can lead to a memory access outside the entity list and then to a virtual function call on an invalid object. With careful manipulation, the researcher says, it can be used to divert control flow to an attacker's payload.

Exploitation

Step 1: Find a controllable variable at a known address

The first stage is to find a variable with a known address that the server can control. The researcher chose the map name, because its copy is stored in a global variable somewhere in client_panorama.dll. The report notes that this is expected behaviour and not a vulnerability.

Step 2: Build the payload

The payload contains a ROP chain and a fake IClientNetworkable object. It is sent to the server as the map name. A map name is a string and cannot contain null characters, but the researcher bypasses this limitation by overwriting it several times.

Step 3: Trigger the virtual call

The entity list is a statically allocated array inside client_panorama.dll, so the offset from the module base to the payload is constant. An appropriate entity index is calculated from that offset, and the message is sent, tricking the client into executing a virtual function on the fake object.

The goal of the ROP chain is to run the Calculator app. client_panorama.dll imports the IProcessUtils interface from tier0.dll, which can be used to start processes, and this simplifies the ROP chain considerably.

Step 4: Run the proof of concept

The PoC script demonstrates RCE on the CS:GO client for Windows (version 13696, 2019-05-16 stable release).

  1. Download the attached script: F492694
  2. Start the CS:GO client
  3. Use a debugger to get the base address of client_panorama.dll and set the CLIENT_BASE variable in the downloaded script
  4. Run the attached Python 3 script (possibly on another host). If you run it on the same host as the client you might need to change the default PORT, because for some reason the CS:GO client uses it.
  5. Connect to the malicious server and wait for calc.exe to pop up

Step 5: Deliver it through the browser

As in #470520, the Steam browser protocol can be used to launch the attack from a web browser:

  1. Follow steps 1-4 as above
  2. Download the attached HTML file (F492697) and set the IP in the iframe URL to the malicious server
  3. Open the downloaded HTML file and wait for calc.exe to pop up

Root cause

The handler passes msg->ent_index straight to entitylist->GetClientNetworkable without validating it, and GetClientNetworkable does not validate it either. An arbitrary integer therefore indexes outside the statically allocated entity array. The resulting pointer is treated as an IClientNetworkable, and ReceiveMessage is called on it, which means a virtual function call through a pointer the attacker influenced. Because the entity list sits at a fixed offset inside client_panorama.dll, an attacker who knows the module base can place a fake object at a predictable location and choose the index that lands on it.

The report does not describe any mitigation that stopped or slowed the attack.

Impact

An attacker can execute arbitrary code on the computer of anyone who attempts to connect to the server. After successful exploitation, the attacker can gain control over the victim's computer and do whatever they want.

The connection can be initiated manually by the victim, or automatically using the Steam browser protocol on a malicious website. The likelihood of a victim joining via the in-game server browser can be greatly improved by faking a high player count and further social engineering, since many players sort the server list by player amount. In the browser case, many users do not need to click Open steam, and the method requires no further interaction: the connection is initiated without confirmation, and the CS:GO client is started if it is not already running.

Fix

The report does not state what was changed.

Variants to test

Hunting notes

This kind of bug hides in the deserialisation path between a trusted server and a client that treats server-supplied indices as trustworthy: message handlers that look up objects in a static array and then call virtual methods on the result. The researcher showed impact by going all the way to code execution: a ROP chain that starts calc.exe, delivered both by a direct connection and by a browser-initiated connection, on a named stable release.

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. 15 min read.

What happened, in plain words

Counter-Strike: Global Offensive (CS:GO) is a shooting game that you play over the internet. Like most online games, it is split into two halves. One half is the client, the program running on your own computer (csgo.exe). The other half is the server, a computer somewhere else that runs the match. The server tells your client what is happening: where players are, what the map is, and so on. It does this by sending small packages of data called network messages.

This report is about one of those messages, called CSVCMsg_EntityMsg. The server uses it to tell the client about "entities". An entity is simply a thing in the game world that the program keeps track of, such as a player, a weapon lying on the ground, or a door. On the client, all entities are kept in a long list, like a numbered row of lockers. Each locker holds an object, and the client can ask that object to do things.

The bug is that the server can put any number it likes into the message as the locker number, and the client never checks whether that number points at a real locker. If the number points past the end of the row, the client reads whatever happens to be in memory there and then tries to use it as if it were a real game object. With careful preparation, an attacker can make the client jump to code the attacker wrote, which means running their own program on your computer. That is called remote code execution, or RCE.

The report rates this critical, with a score of 9.6, and the platform records a bounty of 9,000 USD. It was disclosed on 2021-05-27. The report body itself is signed @chaynik.

The pieces you need to know

Before the details make sense, a few ideas need explaining from scratch.

Client and server. Think of a restaurant. The server (the kitchen) decides what dishes exist and sends them out. The client (your table) receives them and presents them. In a game, the kitchen is the game server and your table is your copy of CS:GO. Normally you trust the kitchen. This bug is what happens when the kitchen can send you something poisonous and your table does not check it.

Protocol Buffer. A Protocol Buffer is a way of writing down the shape of a message so that two programs can send it to each other and both understand it. It is like a form with labelled boxes: box 1 is called ent_index, box 2 is called class_id, and so on. Each box has a type, such as a whole number (int32) or raw bytes (bytes). The definition below is the form for the entity message.

Entity index. The number of a locker in the row. If the row has 100 lockers, index 0 to 99 are real. Index 500 is not a locker at all; it is some other part of memory that the program was not expecting to be asked about.

Out-of-bounds read. Reading memory outside the area the program meant to read. Imagine a bookshelf with ten shelves and someone asks for shelf fifteen. There is no shelf fifteen, but the person reaches into the space where shelf fifteen would be and grabs whatever is there. That is an out-of-bounds read. The report classifies the weakness this way.

DLL and module base address. A DLL is a file full of code that a program loads and uses, a bit like a toolbox that the main program opens. client_panorama.dll is the toolbox that holds the game client's code and its entity list. When a program loads a toolbox into memory, it puts it at some starting address, called the base address. Everything inside the toolbox sits at a fixed distance (an offset) from that base. If you know the base, you know where everything inside is.

ASLR. Address Space Layout Randomisation. To make attacks harder, the operating system shuffles where programs and DLLs are placed in memory each time they start, so the base address is not the same every run. The report notes that on 32-bit programs ASLR has low entropy, meaning there are not many possible positions, so guessing is feasible.

Virtual function. A function (a piece of code) that an object can be asked to run, where the exact code depends on what kind of object it is. The program looks up the address of the right function in a small table attached to the object, then jumps there. If an attacker can control the object, they can control that table, and therefore control where the program jumps. This is the heart of the exploit.

ROP chain. Return-Oriented Programming. Instead of writing new code, the attacker strings together small existing snippets of code already present in the program, like using the individual tools in a toolbox in a clever order to build something the toolbox was never designed to make. A ROP chain is the ordered list of those snippets.

Debugger. A tool that lets a programmer pause a running program and inspect its memory. Here it is used to read the base address of client_panorama.dll.

Steam browser protocol. A special kind of link that a web page can use to tell Steam, and through it a game, to do something, such as connect to a server. It is the difference between a link that opens a web page and a link that opens a game.

The vulnerable message

The message is defined by this Protocol Buffer:

Text
message CSVCMsg_EntityMsg {
    optional int32 ent_index = 1;
    optional int32 class_id = 2;
    optional bytes ent_data = 3;
}

Line by line:

  • message CSVCMsg_EntityMsg { opens the definition of a message named CSVCMsg_EntityMsg. The CSVC prefix is just part of the name the game uses.
  • optional int32 ent_index = 1; is box number 1, called ent_index, holding a whole number. This is the locker number. optional means the sender may leave it out.
  • optional int32 class_id = 2; is box number 2, another whole number, describing the kind of entity.
  • optional bytes ent_data = 3; is box number 3, holding raw bytes, extra data for the entity.
  • } closes the definition.

The important part is that ent_index is a plain whole number with no stated limits. The form does not say "must be between 0 and the number of entities". Nothing in the message definition stops a malicious server from writing any number it likes there.

The code that handles it

The function that receives this message looks like this:

C++
void ProcessEntityMessage(CSVCMsg_EntityMsg *msg) {
    IClientNetworkable *entity = entitylist->GetClientNetworkable(msg->ent_index);
    if (entity) {
        ...
        entity->ReceiveMessage(...);
        ...
    }
    ...
}

Line by line:

  • void ProcessEntityMessage(CSVCMsg_EntityMsg *msg) { starts a function that takes a pointer to the message. A pointer is just the memory address where the message sits.
  • IClientNetworkable *entity = entitylist->GetClientNetworkable(msg->ent_index); asks the entity list for the entity whose number is msg->ent_index, and stores the result in a variable called entity. IClientNetworkable is the type of object stored in the lockers. GetClientNetworkable is the lookup helper: you give it a number, it gives you back the object.
  • if (entity) { checks that the lookup returned something rather than nothing. This is the only check present.
  • entity->ReceiveMessage(...); tells the found object to receive a message. Because ReceiveMessage is a virtual function, this is the moment the program jumps to code chosen through the object.
  • The closing braces end the block and the function.

The problem is in the second line. Neither this handler nor GetClientNetworkable checks whether the number is a valid locker number. Any whole number can be passed. That can lead to a memory access outside the entity list, and then to a virtual function call on an invalid object. With careful manipulation, the researcher says, it can be used to divert control flow to an attacker's payload.

Setting up the attack

The proof of concept targets the CS:GO client for Windows, version 13696, the 2019-05-16 stable release. The exploit assumes the attacker knows the base address of client_panorama.dll. The report says this can be obtained in two ways: using an additional memory disclosure vulnerability, citing #581774, or, in the case of a distributed attack, by guessing the address, since 32-bit ASLR has low entropy.

A memory disclosure is a separate bug that leaks a piece of memory to the attacker, which can reveal where things are loaded. It is like a burglar first getting a floor plan of the building. Guessing works because, as noted, there are not many possible positions for a 32-bit program.

The PoC is a Python 3 script run against a malicious server that the victim connects to. The researcher notes that if the script runs on the same computer as the client, the default PORT may need changing because the CS:GO client uses it. A port is a numbered door on a computer that a particular service listens at; two programs cannot use the same door at once.

Finding the bug

The researcher's reasoning is that the message carries an index, the index is used to look up an object, and the lookup is never checked. That is the whole discovery: a field typed as a plain number, a lookup helper with no bounds check, and a list of objects sitting at a fixed place in a DLL whose base can be leaked or guessed.

Exploitation, step by step

Step 1: Find a controllable variable at a known address

The first stage is to find a variable with a known address that the server can control. The researcher chose the map name, because its copy is stored in a global variable somewhere in client_panorama.dll. The report notes that this is expected behaviour and not a vulnerability.

Why this matters: the attacker needs somewhere to park their payload, and they need to know exactly where it is. The map name is perfect because the server sends it, the client stores it, and its location is fixed relative to the DLL base. A global variable is a named storage spot that exists for the whole life of the program, rather than being created and destroyed inside a function.

Step 2: Build the payload

The payload contains a ROP chain and a fake IClientNetworkable object. It is sent to the server as the map name. A map name is a string and cannot contain null characters, but the researcher bypasses this limitation by overwriting it several times.

Why the null character matters: in many programs a string ends at the first null character (a byte with value zero), so a payload containing zeros would be cut short. Overwriting the same variable several times lets the attacker write the payload in pieces, skipping over the positions where a zero would be needed, and assemble the full thing in memory.

Step 3: Trigger the virtual call

The entity list is a statically allocated array inside client_panorama.dll, so the offset from the module base to the payload is constant. An appropriate entity index is calculated from that offset, and the message is sent, tricking the client into executing a virtual function on the fake object.

A statically allocated array is a block of memory reserved when the program loads, at a fixed place, rather than created on demand. Because both the entity list and the map name copy live at fixed offsets from the same base, the attacker can compute the exact index that makes the lookup land on their fake object. The fake object's virtual function table points at the ROP chain, so the virtual call becomes the attacker's code running.

The goal of the ROP chain is to run the Calculator app. client_panorama.dll imports the IProcessUtils interface from tier0.dll, which can be used to start processes, and this simplifies the ROP chain considerably. An interface here is a named set of functions one DLL offers to another; tier0.dll already knows how to start a program, so the attacker does not have to build that part from scratch.

Step 4: Run the proof of concept

The PoC script demonstrates RCE on the CS:GO client for Windows (version 13696, 2019-05-16 stable release).

  1. Download the attached script: F492694
  2. Start the CS:GO client
  3. Use a debugger to get the base address of client_panorama.dll and set the CLIENT_BASE variable in the downloaded script
  4. Run the attached Python 3 script (possibly on another host). If you run it on the same host as the client you might need to change the default PORT, because for some reason the CS:GO client uses it.
  5. Connect to the malicious server and wait for calc.exe to pop up

Why each step: step 3 exists because the script needs to know where the DLL landed in memory to compute the index. Step 4 runs the malicious server. Step 5 is the victim action: joining the server is what causes the client to receive the crafted message. calc.exe is the Calculator program, chosen because it is harmless and obvious when it appears.

Step 5: Deliver it through the browser

As in #470520, the Steam browser protocol can be used to launch the attack from a web browser:

  1. Follow steps 1-4 as above
  2. Download the attached HTML file (F492697) and set the IP in the iframe URL to the malicious server
  3. Open the downloaded HTML file and wait for calc.exe to pop up

An iframe is a web page embedded inside another web page. Here the outer page uses the Steam browser protocol to make the game connect to the attacker's server, without the victim having to find and join the server themselves.

Root cause

The handler passes msg->ent_index straight to entitylist->GetClientNetworkable without validating it, and GetClientNetworkable does not validate it either. An arbitrary integer therefore indexes outside the statically allocated entity array. The resulting pointer is treated as an IClientNetworkable, and ReceiveMessage is called on it, which means a virtual function call through a pointer the attacker influenced. Because the entity list sits at a fixed offset inside client_panorama.dll, an attacker who knows the module base can place a fake object at a predictable location and choose the index that lands on it.

The report does not describe any mitigation that stopped or slowed the attack.

Impact

An attacker can execute arbitrary code on the computer of anyone who attempts to connect to the server. After successful exploitation, the attacker can gain control over the victim's computer and do whatever they want.

The connection can be initiated manually by the victim, or automatically using the Steam browser protocol on a malicious website. The likelihood of a victim joining via the in-game server browser can be greatly improved by faking a high player count and further social engineering, since many players sort the server list by player amount. In the browser case, many users do not need to click Open steam, and the method requires no further interaction: the connection is initiated without confirmation, and the CS:GO client is started if it is not already running.

Social engineering means manipulating people rather than machines: a server showing a high player count looks popular and trustworthy, so more people click it.

Fix

The report does not state what was changed. In plain terms: check that the locker number is a real locker before opening it.

Variants to test

Hunting notes

This kind of bug hides in the deserialisation path between a trusted server and a client that treats server-supplied indices as trustworthy: message handlers that look up objects in a static array and then call virtual methods on the result. Deserialisation is the act of turning a received package of bytes back into usable data. The researcher showed impact by going all the way to code execution: a ROP chain that starts calc.exe, delivered both by a direct connection and by a browser-initiated connection, on a named stable release.

Glossary

  • ASLR: Address Space Layout Randomisation; the operating system shuffles where programs and DLLs are placed in memory each run, to make addresses harder to predict.
  • Base address: the memory address where a loaded program or DLL starts; everything inside sits at a fixed offset from it.
  • Bounty: a reward paid by a company for a valid security report.
  • Client: the program running on the player's own computer, here csgo.exe.
  • Critical: the highest severity rating; a bug that can be exploited with serious consequences.
  • CS:GO: Counter-Strike: Global Offensive, a client-server shooting game.
  • Debugger: a tool that pauses a running program and lets you inspect its memory.
  • Deserialisation: turning a received package of bytes back into usable data.
  • DLL: a file full of code that a program loads and uses, like a toolbox.
  • Entity: a thing in the game world that the program tracks, such as a player or a weapon.
  • Entity index: the number identifying an entity in the entity list, like a locker number.
  • Entity list: the array of entity objects kept by the client.
  • Exploit: the concrete technique or code that turns a bug into an effect.
  • Global variable: a named storage spot that exists for the whole life of the program.
  • HTML: the language web pages are written in.
  • Iframe: a web page embedded inside another web page.
  • Interface: a named set of functions one DLL offers to another.
  • Memory disclosure: a bug that leaks a piece of memory to an attacker, often revealing where things are loaded.
  • Module: a loaded program or DLL.
  • Network message: a package of data one program sends to another over a network.
  • Null character: a byte with value zero; many programs treat it as the end of a string.
  • Offset: a fixed distance from a starting point, such as from a module base.
  • Pointer: a memory address stored in a variable.
  • Port: a numbered door on a computer where a particular service listens.
  • Protocol Buffer: a way of defining the shape of a message so two programs can exchange it and both understand it.
  • RCE: remote code execution; running the attacker's code on someone else's computer.
  • Recon: the information-gathering phase before an attack.
  • ROP chain: Return-Oriented Programming; a sequence of small existing code snippets strung together to make the program do something new.
  • Server: the computer that runs the match and sends messages to clients.
  • Social engineering: manipulating people rather than machines.
  • Statically allocated array: a block of memory reserved at load time at a fixed place.
  • Steam browser protocol: a special link a web page can use to make Steam, and through it a game, do something such as connect to a server.
  • String: a sequence of characters, such as a map name.
  • Virtual function: a function whose exact code is looked up through the object at the moment of the call, so controlling the object means controlling where the program jumps.
  • Vulnerability: a weakness in a program that an attacker can use to make it behave in a way its author did not intend.

More by teapotd

View all

1 more disclosed report, 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.