Skip to content
Memory corruption Disclosed report Advanced

Signedness issue in ClassInfo message handler leads to RCE on CS:GO client

A signedness bug in the CS:GO client's handling of the ClassInfo network message allows a malicious server to write out of bounds in memory. An attacker can exploit this to bypass ASLR and execute arbitrary code, such as launching the calculator, on a victim's computer.

teapotd Follow

Originally disclosed on HackerOne

Bounty$7,500 Critical 9.6 View original
  • Triaged in 14 hours
  • Fixed in 12 months
  • Paid in 11 months
  • Disclosed after 12 months

Summary by the program

Title: Signedness issue in ClassInfo message handler leads to RCE on CS:GO client Scope: csgo.exe Weakness: Array Index Underflow Severity: Critical (9.6) Link: https://hackerone.com/reports/876719 Date: 2020-05-17 20:31:35 +0000 By: @chaynik

Details: Vulnerability

CSVCMsg_ClassInfo message is used by Source Engine to pass information about entity classes. It is described by the following Protobuf:

message CSVCMsg_ClassInfo {
    message class_t {
        optional int32 class_id = 1;
        optional string data_table_name = 2;
        optional string class_name = 3;
    }

    optional bool create_on_client = 1;
    repeated .CSVCMsg_ClassInfo.class_t classes = 2;
}

The bug is present in CSVCMsg_ClassInfo message handler on client. The pseudocode of function that handles this message:

C++
bool ProcessClassInfo(CSVCMsg_ClassInfo *msg) {
    ...
    int nClasses = msg->classes_size;
    ClassInfo *pClasses = new ClassInfo[nClasses];
    ...
    for (int i = 0; i < nClasses; i++) {
        class_t *src = msg->classes[i];
        if (src->class_id >= nClasses) { // class_id can be negative!
            ...
            return false;
        }
        ClassInfo *dst = &pClasses[src->class_id];
        ...
    }
    ...
}

An array of appropriate size is allocated to hold the received information. The array is indexed by class_id, which is improperly sanitized: it can be an arbitrary negative integer. This allows an out of bounds write, which can be exploited to perform remote code execution.

Any Source Engine (and Source 2) game that uses Protobuf network messages should be affected by this vulnerability, including CS:GO and Dota 2. Only CS:GO has been tested.

Exploit details

The Proof-of-Concept exploit consists of two main phases:

  1. ASLR bypass - the bug is used to get base address of client_panorama.dll
  2. Remote code execution - the bug is used to divert control flow to ROP chain

In order to craft a ROP chain, attacker needs to know the absolute address of some application module. The ASLR attempts to prevent it by randomizing memory layout.

Bypassing the ASLR

Source Engine has mechanism that allows server to set and query "cvars" - variables that control various game-related settings. The exploit leverages cvars to steal a pointer to predictable memory location in game process:

  1. Spray the heap with entities
    • we want to make heap allocations more predictable
    • if we allocate 500+ entities there is high chance that last of them are side-by-side
  2. Delete last 20 entities
    • deallocated data, including pointers to vtables, remains on heap
  3. Set some cvar to a string of appropriate length
    • we want it to be allocated in place of old entities
    • we want the vtable pointer of some old entity to be right after the end of the string
  4. Use the vulnerability to overwrite null terminator of cvar string
    • we want the class-infos to get allocated next to cvar
    • if we succeed, the cvar string will be extended to contain the vtable pointer
  5. Query the cvar string
    • the leaked vtable pointer allows us to calculate client_panorama.dll base address

There is one issue with this idea: the client breaks connection after the vulnerability is used, due to some late sanity check. There's an easy way around it though. Server can queue a retry command to be executed on client, so the client automatically reconnects.

Executing code

After succesful pointer leakage, a ROP chain that runs calc.exe is crafted using gadgets from client_panorama.dll. The RCE is performed as follows:

  1. Deliver the ROP chain in CCSUsrMsg_ShowMenu user message
    • client stores it in global buffer in client_panorama.dll
    • we can easily calculate address to it
  2. Spray the heap with entities
    • we want to make heap allocations more predictable
  3. Use the vulnerability to overwrite vtable pointer of some entity
    • we want the class-infos to get allocated after last entity
  4. The client breaks connection and deallocates entities
    • the fake vtable will divert control flow to our ROP chain
    • the ROP chain will launch Calculator app

Reproduction

The PoC script simulates a malicious CS:GO server. It demonstrates RCE capability on CS:GO client for Windows (version 13752, 2020-05-14 stable release).

  1. Download the attached Python 3 script: F831986
  2. Run the script (possibly on another host)
  3. Start CS:GO client
  4. Connect to the malicious server
  5. 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. Download the attached Python 3 script: F831986
  2. Run the script (possibly on another host)
  3. Download attached HTML file - F831987
  4. Set address in iframe URL to the malicious server
  5. Open downloaded HTML file and confirm Open steam
  6. 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 successful exploitation an attacker can gain control over victim's computer.

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

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

Context

Source Engine games receive information about entity classes from the server through the CSVCMsg_ClassInfo network message. The message is described by the following Protobuf definition:

Text
message CSVCMsg_ClassInfo {
    message class_t {
        optional int32 class_id = 1;
        optional string data_table_name = 2;
        optional string class_name = 3;
    }

    optional bool create_on_client = 1;
    repeated .CSVCMsg_ClassInfo.class_t classes = 2;
}

Each entry carries a class_id, a data_table_name and a class_name. The client handler for this message builds a local array of class information and fills it from the entries the server sent. Because the server controls the contents of the message, everything the handler does with class_id is attacker-controlled input.

The report targets csgo.exe, the CS:GO client. The researcher notes that any Source Engine (and Source 2) game that uses Protobuf network messages should be affected, including CS:GO and Dota 2, but only CS:GO was tested.

Setup

The proof of concept simulates a malicious CS:GO server. The researcher provides a Python 3 script (attachment F831986) and an HTML file (attachment F831987). The demonstrated target is the CS:GO client for Windows, version 13752, 2020-05-14 stable release. The script can run on another host, so the attacker does not need to be on the same machine as the victim.

No account, role or special tooling is described beyond running the script and connecting a stock client to it.

Finding it

The bug sits in the client-side handler for CSVCMsg_ClassInfo. The pseudocode of the function, as given in the report, is:

C++
bool ProcessClassInfo(CSVCMsg_ClassInfo *msg) {
    ...
    int nClasses = msg->classes_size;
    ClassInfo *pClasses = new ClassInfo[nClasses];
    ...
    for (int i = 0; i < nClasses; i++) {
        class_t *src = msg->classes[i];
        if (src->class_id >= nClasses) { // class_id can be negative!
            ...
            return false;
        }
        ClassInfo *dst = &pClasses[src->class_id];
        ...
    }
    ...
}

The array pClasses is allocated with exactly nClasses elements, matching the number of entries in the message. Each entry is then written to pClasses[src->class_id]. The only validation on class_id is an upper bound check, src->class_id >= nClasses. There is no lower bound check, and class_id is a signed int32. A negative value therefore passes validation and indexes before the start of the array, producing an out of bounds write. The researcher's comment in the pseudocode marks the exact spot: class_id can be negative!.

Exploitation

The exploit has two phases: an ASLR bypass that leaks the base address of client_panorama.dll, and a second stage that diverts control flow into a ROP chain. A ROP chain needs the absolute address of some application module, and ASLR randomises the memory layout to prevent that.

Step 1: Bypass ASLR with a cvar string

Source Engine lets the server set and query cvars, the variables that control game settings. The exploit uses this to place a pointer to a predictable memory location into a string the client will hand back:

  1. Spray the heap with entities, to make heap allocations more predictable. If 500+ entities are allocated there is a high chance that the last of them are side-by-side.
  2. Delete the last 20 entities. The deallocated data, including pointers to vtables, remains on the heap.
  3. Set some cvar to a string of appropriate length, so that it is allocated in place of the old entities, with the vtable pointer of some old entity right after the end of the string.
  4. Use the vulnerability to overwrite the null terminator of the cvar string. The class-infos should be allocated next to the cvar; if that succeeds, the cvar string is extended to contain the vtable pointer.
  5. Query the cvar string. The leaked vtable pointer allows calculation of the client_panorama.dll base address.

There is one obstacle: the client breaks the connection after the vulnerability is used, because of some late sanity check. The workaround is that the server can queue a retry command to be executed on the client, so the client automatically reconnects.

Step 2: Execute code through a fake vtable

With the module base known, a ROP chain that runs calc.exe is built from gadgets in client_panorama.dll. The RCE proceeds as follows:

  1. Deliver the ROP chain in a CCSUsrMsg_ShowMenu user message. The client stores it in a global buffer in client_panorama.dll, whose address can easily be calculated.
  2. Spray the heap with entities again, for the same predictability reason.
  3. Use the vulnerability to overwrite the vtable pointer of some entity. The class-infos should be allocated after the last entity.
  4. The client breaks the connection and deallocates the entities. The fake vtable diverts control flow to the ROP chain, which launches the Calculator app.

Reproduction

Direct connection:

  1. Download the attached Python 3 script: F831986
  2. Run the script (possibly on another host)
  3. Start the CS:GO client
  4. Connect to the malicious server
  5. Wait for calc.exe to pop up

Attack from a web browser, using the Steam browser protocol, as in report #470520:

  1. Run the script (possibly on another host)
  2. Download the attached HTML file: F831987
  3. Set the address in the iframe URL to the malicious server
  4. Open the downloaded HTML file and confirm Open steam
  5. Wait for calc.exe to pop up

Root cause

The handler validates class_id only against the upper bound of the array. Because class_id is a signed 32-bit integer, any negative value passes the check and is used directly as an array index, writing before the start of the heap allocation. The missing lower bound check is the whole defect; the report classifies it as an array index underflow.

The loop processes the entries in the message, and the index comes from the attacker-controlled class_id. That is what turns a bounds error into a primitive usable for corrupting adjacent heap objects such as cvar strings and entity vtables. The client breaks the connection after the vulnerability is used, due to some late sanity check, and the server can queue a retry command so the client reconnects.

Impact

An attacker can execute arbitrary code on the computer of anyone who attempts to connect to the server, and after successful exploitation can gain control over the victim's computer. The connection can be initiated manually by the victim or automatically by visiting a malicious website through the Steam browser protocol.

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 game client is started if it is not already running.

Fix

The report does not describe a fix or a vendor response. The change the code needs is a lower bound check on class_id alongside the existing upper bound check, rejecting any value below zero before it is used as an index into pClasses.

Variants to test

  • Other Source Engine and Source 2 games that use Protobuf network messages, such as Dota 2. A positive result is the same out of bounds write from a negative class_id in a CSVCMsg_ClassInfo-style handler.
  • Other message handlers that index a heap array with a signed field taken from the network. A positive result is a field that passes an upper bound check but is accepted when negative, with the write landing in adjacent heap data.
  • Server-controlled cvars combined with a heap corruption primitive. A positive result is a cvar string whose contents change after the corruption, leaking a pointer such as a vtable address.
  • Server-queued client commands such as retry used to survive a connection drop caused by a sanity check. A positive result is an automatic reconnect after the corrupted message is processed.
  • User messages that store attacker data in a global buffer at a calculable address, such as CCSUsrMsg_ShowMenu. A positive result is a known, stable address holding attacker-controlled bytes.

Hunting notes

This class of bug hides in client-side handlers for network messages where a length or count from the message sizes an allocation and a separate signed field from the same message is used as an index. The signal is a validation check that only tests one side of a range, especially >= size on a signed type. Heap spraying with entities and observing allocation adjacency, as done here, is the practical way to turn the write into a leak and then into control flow. The researcher demonstrated impact with a working exploit that launches calc.exe on the stable client, both from a direct connection and from a browser via the Steam protocol.

Disclosure

The report was submitted on 2020-05-17 and disclosed on 2021-05-27. The program lists it as critical, CVSS 9.6, weakness array index underflow, with a bounty of 7500.00 USD.

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

What happened, in plain words

A security researcher found a way to make the CS:GO game client run any program the attacker wants, just by having the player connect to a server the attacker controls. The attacker does not need the player to install anything, click a file or type a password. Connecting to the wrong server is enough.

The report was submitted to Valve through HackerOne on 2020-05-17 and disclosed on 2021-05-27. The program rated it critical, with a CVSS score of 9.6, classified the weakness as an array index underflow, and paid a bounty of 7500.00 USD. The affected file is csgo.exe, the game client itself.

To understand the bug you need one idea: when you play online, your computer and the game server constantly exchange messages. The server tells your client what exists in the game world, where things are, and what to draw. Here the server was run by the attacker, and one of those messages contained a number the client used without checking it properly. That number was used as a position in a list, and a negative position pointed outside the list, into memory the attacker should never be able to touch. From there the attacker could read secret addresses and eventually make the game run their own code.

Some background first

What CS:GO and the Source Engine are

CS:GO (Counter-Strike: Global Offensive) is a multiplayer first-person shooter. It runs on the Source Engine, a piece of software made by Valve that handles graphics, networking, physics and the game world. Other games use the same engine, including Dota 2, which runs on a newer version called Source 2.

When you join a multiplayer game, your computer runs the client and the machine hosting the match runs the server. The server is the authority: it decides what happens, and it sends updates to every connected client. The client draws the result on your screen.

What a network message is

A network message is a small package of data sent from one computer to another. Think of it as a form with labelled fields, like a parcel with a customs declaration. Both sides must agree on the form's layout in advance, otherwise the receiver cannot tell which bytes mean what.

What Protobuf is

Protobuf (Protocol Buffers) is a way of describing those forms in a text file. You write down the fields and their types, and a tool generates code that can read and write the binary form. The description in this report looks like this:

Text
message CSVCMsg_ClassInfo {
    message class_t {
        optional int32 class_id = 1;
        optional string data_table_name = 2;
        optional string class_name = 3;
    }

    optional bool create_on_client = 1;
    repeated .CSVCMsg_ClassInfo.class_t classes = 2;
}

Line by line:

  • message CSVCMsg_ClassInfo { starts the definition of a message named CSVCMsg_ClassInfo.
  • message class_t { defines a smaller, nested form that describes one game class (a type of object in the world, such as a player, a weapon or a door).
  • optional int32 class_id = 1; is a whole number called class_id. int32 means it is stored in 32 bits and, crucially, it is signed: it can be positive or negative. optional means it may be absent. The = 1 is the field number used on the wire, not a default value.
  • optional string data_table_name = 2; is a text field holding the name of the data table (a table describing the properties of the class).
  • optional string class_name = 3; is a text field holding the class's name.
  • optional bool create_on_client = 1; is a true/false flag telling the client whether to create the classes locally.
  • repeated .CSVCMsg_ClassInfo.class_t classes = 2; is a list (the word repeated means zero or more) of the nested class_t entries. This is the list the server fills in.

So the message is essentially a list of class descriptions, each with an ID number, a table name and a class name. The server sends it, and the client reads it.

What a client handler is

A handler is the piece of code that runs when a particular message arrives. Think of a post room: each type of letter has a clerk assigned to it. The clerk for CSVCMsg_ClassInfo takes the list out of the envelope and stores it in the client's own memory so the game can use it.

Because the server writes the contents of the message, everything inside it is attacker-controlled input when the server is malicious. The handler must treat it with suspicion, the same way a bank clerk should not accept a withdrawal slip whose amount was written by the customer without checking the account.

What memory, arrays and indexes are

Your computer's memory is a long row of numbered boxes, each holding a small amount of data. A program reserves a block of boxes when it needs space. An array is such a block, treated as a row of identical slots. To reach slot number 3 you use an index: the position in the row. Index 0 is the first slot, index 1 the second, and so on.

If a program is told to write to slot 5 of a four-slot array, it writes past the end of the block, into whatever happens to be next to it. That is called an out of bounds write. If the index is negative, the write lands before the start of the block. That is the underflow named in the weakness classification.

What ASLR is

ASLR (Address Space Layout Randomization) is a defence built into modern operating systems. Every time a program starts, the operating system loads its code and data at a different random address. An attacker who wants to jump to a specific function needs to know where that function is; ASLR makes the address different on every run, so a hard-coded address will not work.

Think of a library where the shelves are rearranged every morning. A note saying "third shelf from the left" is useless unless you first find out how the shelves are arranged today.

What a ROP chain is

ROP (Return-Oriented Programming) is a technique for making a program do something it was not written to do, without injecting new code. The attacker finds small snippets of existing code, called gadgets, each ending in an instruction that returns to the next address on a list. By chaining the addresses of these snippets together, the attacker builds a sequence of actions out of the program's own parts. It is like writing a new recipe using only sentences already printed in a cookbook, referenced by page number.

To build such a chain, the attacker needs to know the absolute address of the module containing the gadgets. That is exactly what ASLR is designed to prevent, which is why the exploit has two phases: first leak an address, then use it.

What a DLL, a vtable and a heap are

A DLL (Dynamic Link Library) is a file containing code that a program loads at runtime. client_panorama.dll is the part of CS:GO that implements the game client. Its base address is where it happens to be loaded in memory on this run.

The heap is the area of memory a program uses for objects it creates while running, as opposed to fixed structures decided at compile time. When the game creates a game entity, the memory for it comes from the heap.

A vtable (virtual method table) is a hidden list of function addresses attached to an object. When the program calls a function on an object, it looks up the address in the object's vtable and jumps there. If an attacker can overwrite a vtable pointer, the next function call on that object jumps wherever the attacker wants. It is like swapping the phone number on a business card: the next person who dials it reaches the attacker instead.

What a cvar is

A cvar (console variable) is a named setting in the game, such as a graphics option or a gameplay toggle. Source Engine lets the server set and query cvars on the client. That is a legitimate feature, but it gives a malicious server a way to place text into the client's memory and read it back.

Setting up the test

The researcher wrote a proof of concept: a Python 3 script that pretends to be a CS:GO server. Python is a programming language often used for quick tools; the script speaks the game's network protocol and sends the malicious messages. The script is attachment F831986. There is also an HTML file, attachment F831987, used for the browser-based variant.

The target was the CS:GO client for Windows, version 13752, the stable release of 2020-05-14. The script can run on a different machine from the victim, so the attacker only needs the victim to connect to their server; they do not need access to the victim's computer beforehand.

No account, role or special tool is needed beyond running the script and connecting a normal, unmodified game client to it.

Finding the bug

The problem is in the client-side handler for CSVCMsg_ClassInfo. The report gives pseudocode for the function. Pseudocode is simplified code written to show the logic, not the exact original source:

C++
bool ProcessClassInfo(CSVCMsg_ClassInfo *msg) {
    ...
    int nClasses = msg->classes_size;
    ClassInfo *pClasses = new ClassInfo[nClasses];
    ...
    for (int i = 0; i < nClasses; i++) {
        class_t *src = msg->classes[i];
        if (src->class_id >= nClasses) { // class_id can be negative!
            ...
            return false;
        }
        ClassInfo *dst = &pClasses[src->class_id];
        ...
    }
    ...
}

Line by line:

  • bool ProcessClassInfo(CSVCMsg_ClassInfo *msg) { declares a function that takes the received message and returns true or false (success or failure).
  • int nClasses = msg->classes_size; reads how many class entries the message contains. This number comes from the server.
  • ClassInfo *pClasses = new ClassInfo[nClasses]; reserves a block of memory big enough for exactly that many entries. new is the C++ way of asking the system for memory. pClasses points at the first slot.
  • for (int i = 0; i < nClasses; i++) { starts a loop that visits each entry in the message, one at a time.
  • class_t *src = msg->classes[i]; picks the current entry from the message.
  • if (src->class_id >= nClasses) { checks whether the entry's ID is too large for the array. If it is, the code rejects the message and returns false.
  • // class_id can be negative! is the researcher's comment marking the flaw: the check only tests the upper side.
  • ClassInfo *dst = &pClasses[src->class_id]; computes the address of the slot at position class_id and prepares to write there.

Why this is a bug: class_id is a signed 32-bit number, so it can be negative. The check src->class_id >= nClasses only rejects values that are too big. A negative value passes, and pClasses[src->class_id] then points before the start of the allocated block. The loop writes the class data there. The attacker controls the position through the negative number, so the write lands before the start of the array.

The researcher notes that any Source Engine or Source 2 game using Protobuf network messages should be affected, including CS:GO and Dota 2, but only CS:GO was tested.

Exploiting it

The exploit has two phases. First, defeat ASLR by leaking the base address of client_panorama.dll. Second, use that knowledge to redirect execution into a ROP chain that starts the Windows Calculator (calc.exe). The calculator is the demonstration; the report states an attacker can execute arbitrary code.

Phase 1: leaking an address

The idea is to place a known pointer into a text string the client will send back, then read the string. The steps:

  1. Spray the heap with entities. The attacker makes the game create a large number of entities. The report says that if 500+ entities are allocated there is a high chance that the last of them are side-by-side in memory. This is called heap spraying: filling memory with many copies of something so that its layout becomes predictable. Think of filling a shelf with identical boxes so you know exactly where the next box will land.
  2. Delete the last 20 entities. The game frees that memory, but the report notes that the deallocated data, including pointers to vtables, remains on the heap. Freeing memory does not wipe it; the old contents stay until something overwrites them.
  3. Set a cvar to a string of appropriate length. The new string is allocated in the space left by the deleted entities. The goal is for the vtable pointer of an old entity to sit right after the end of the string.
  4. Use the vulnerability to overwrite the null terminator of the cvar string. In C and C++, a string ends with a special zero byte called the null terminator. If that byte is overwritten, the string no longer ends where it should, and reading it continues into the neighbouring memory, which contains the vtable pointer. The class-infos need to be allocated next to the cvar for this to work.
  5. Query the cvar string. The client sends the string back, now longer than intended and containing the leaked pointer. From that pointer the attacker calculates the base address of client_panorama.dll.

There is one obstacle: the client drops the connection after the vulnerability is used, because of a late sanity check. The workaround is that the server can queue a retry command for the client to execute, so the client reconnects automatically.

Phase 2: running code

With the module base known, the attacker builds a ROP chain out of gadgets in client_panorama.dll that launches calc.exe. The steps:

  1. Deliver the ROP chain in a CCSUsrMsg_ShowMenu user message. A user message is another kind of server-to-client message. The client stores its contents in a global buffer inside client_panorama.dll, and because the module base is now known, the address of that buffer can easily be calculated.
  2. Spray the heap with entities again, for the same reason as before: to make the layout predictable.
  3. Use the vulnerability to overwrite the vtable pointer of some entity. This time the class-infos should be allocated after the last entity, so the out of bounds write lands on the entity's vtable pointer.
  4. The client breaks the connection and deallocates the entities. When the game cleans up, it calls functions through the vtable. The fake vtable now points at the ROP chain, so control flow goes there, and the chain launches the Calculator app.

Reproducing it

Direct connection:

  1. Download the attached Python 3 script: F831986
  2. Run the script (possibly on another host)
  3. Start the CS:GO client
  4. Connect to the malicious server
  5. Wait for calc.exe to pop up

Attack from a web browser, using the Steam browser protocol, as in report #470520:

  1. Run the script (possibly on another host)
  2. Download the attached HTML file: F831987
  3. Set the address in the iframe URL to the malicious server
  4. Open the downloaded HTML file and confirm Open steam
  5. Wait for calc.exe to pop up

The Steam browser protocol is a way for web pages to ask Steam to do things, such as open a game or join a server. An iframe is a web page embedded inside another web page. In this variant the attacker hosts a page that points an iframe at the malicious server address, so opening the page triggers the connection.

Root cause

The handler checks class_id only against the upper bound of the array. Because class_id is a signed 32-bit integer, any negative value passes the check and is used directly as an array index, writing before the start of the heap allocation. The missing lower bound check is the whole defect; the report classifies it as an array index underflow.

The loop processes the entries in the message, and the index comes from the attacker-controlled class_id. That is what turns a bounds error into a tool for corrupting adjacent heap objects such as cvar strings and entity vtables. The client breaks the connection after the vulnerability is used, due to some late sanity check, and the server can queue a retry command so the client reconnects.

Impact

An attacker can execute arbitrary code on the computer of anyone who attempts to connect to the server, and after successful exploitation can gain control over the victim's computer. The connection can be initiated manually by the victim or automatically by visiting a malicious website through the Steam browser protocol.

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 game client is started if it is not already running.

Fix

The report does not describe a fix or a vendor response. The change the code needs is a lower bound check on class_id alongside the existing upper bound check, rejecting any value below zero before it is used as an index into pClasses.

Variants to test

  • Other Source Engine and Source 2 games that use Protobuf network messages, such as Dota 2. A positive result is the same out of bounds write from a negative class_id in a CSVCMsg_ClassInfo-style handler.
  • Other message handlers that index a heap array with a signed field taken from the network. A positive result is a field that passes an upper bound check but is accepted when negative, with the write landing in adjacent heap data.
  • Server-controlled cvars combined with a heap corruption primitive. A positive result is a cvar string whose contents change after the corruption, leaking a pointer such as a vtable address.
  • Server-queued client commands such as retry used to survive a connection drop caused by a sanity check. A positive result is an automatic reconnect after the corrupted message is processed.
  • User messages that store attacker data in a global buffer at a calculable address, such as CCSUsrMsg_ShowMenu. A positive result is a known, stable address holding attacker-controlled bytes.

Hunting notes

This class of bug hides in client-side handlers for network messages where a length or count from the message sizes an allocation and a separate signed field from the same message is used as an index. The signal is a validation check that only tests one side of a range, especially >= size on a signed type. Heap spraying with entities and observing allocation adjacency, as done here, is the practical way to turn the write into a leak and then into control flow. The researcher demonstrated impact by producing a working exploit that launches calc.exe on the current stable client, both from a direct connection and from a browser via the Steam protocol, which is what made the case for critical severity.

Glossary

  • ASLR (Address Space Layout Randomization): an operating system defence that loads a program's code and data at a random address each time it runs, so an attacker cannot rely on fixed addresses.
  • Array: a block of memory divided into identical slots, reached by position number.
  • Array index underflow: using a negative position to reach memory before the start of an array.
  • Attacker-controlled input: data that comes from the attacker and is processed by the victim's software.
  • Bounty: a payment made by a company to a researcher who reports a security problem.
  • Buffer: a block of memory used to hold data, often text.
  • Client: the program on the player's computer that connects to a game server.
  • Client handler: the code that runs when a particular network message arrives.
  • CSVCMsg_ClassInfo: the Source Engine network message that carries descriptions of game entity classes from server to client.
  • CCSUsrMsg_ShowMenu: a Source Engine user message; the client stores its contents in a global buffer.
  • CVSS: a standard scoring system for the severity of a security flaw; 9.6 is in the critical range.
  • Cvar (console variable): a named game setting that the server can set and query on the client.
  • DLL (Dynamic Link Library): a file of code that a program loads at runtime; client_panorama.dll is the CS:GO client module.
  • Entity: an object in the game world, such as a player, weapon or door.
  • Gadget: a short sequence of existing instructions ending in a return, used as a building block in a ROP chain.
  • Global buffer: a fixed block of memory inside a module, at an address that can be calculated from the module base.
  • Heap: the area of memory a program uses for objects created while it runs.
  • Heap spraying: filling memory with many copies of something so its layout becomes predictable.
  • HTML file: a text file describing a web page.
  • Iframe: a web page embedded inside another web page.
  • int32: a 32-bit whole number that can be positive or negative.
  • Module base address: the memory address where a DLL or executable is loaded.
  • Null terminator: the zero byte that marks the end of a text string in C and C++.
  • Out of bounds write: writing to memory outside the block a program reserved.
  • Pointer: a value that holds a memory address.
  • Proof of concept (PoC): a working demonstration that a flaw can be exploited.
  • Protobuf (Protocol Buffers): a format for describing structured messages and encoding them in binary.
  • Pseudocode: simplified code written to show logic rather than exact source.
  • Python 3: a programming language often used for quick tools and scripts.
  • Remote code execution (RCE): making a program on someone else's computer run code of your choosing.
  • retry: a client command that makes the game reconnect to the server.
  • ROP (Return-Oriented Programming): building a sequence of actions from small snippets of existing code, chained by their addresses.
  • ROP chain: the ordered list of gadget addresses that makes up a ROP attack.
  • Sanity check: a validation step that rejects obviously wrong data.
  • Server: the computer hosting the match, which sends updates to clients.
  • Signed integer: a whole number that can be negative as well as positive.
  • Social engineering: manipulating people into doing something, such as joining a server.
  • Source Engine / Source 2: Valve's game engine, used by CS:GO and Dota 2 respectively.
  • Steam browser protocol: a way for web pages to ask Steam to perform actions such as joining a server.
  • User message: a category of server-to-client message in Source Engine.
  • Vtable (virtual method table): a hidden list of function addresses attached to an object; overwriting its pointer redirects function calls.
  • Vtable pointer: the value in an object that points at its vtable.

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.