Skip to content
Memory corruption Disclosed report Advanced

Malformed BSP in GoldSrc Engine may cause shellcode injection

A buffer overflow in the GoldSrc engine's UTIL_StringToIntArray function allows an attacker to overwrite the return address and execute shellcode when a malformed BSP map is loaded. The attacker can deliver the map via a malicious server or by uploading it to a website, leading to remote code execution on the client.

kohtep2010 Follow

Originally disclosed on HackerOne

  • Triaged in under an hour
  • Fixed in 3 months
  • Paid in 2 months
  • Disclosed after 16 months

Summary by the program

Introduction

Hello. There's a vulnerability in GoldSrc Engine that allows to run arbitrary assembly code using incorrect BSP format processing.

Description

The vulnerability is found in the UTIL_StringToIntArray function. This function belongs to the game mod library (mp.dll/cs.so) and has the following call chain:

SV_LoadEntities -> ED_LoadFromFile -> ED_ParseEdict -> gEntityInterface.pfnKeyValue -> CGameText::KeyValue -> UTIL_StringToIntArray

The call of this function occurs at server start during processing of the entities of map being loaded. The vulnerability itself is a classic buffer overflow with the possibility of rewriting the return address to the address where the shellcode is located.

Vulnerability was tested on Windows 10 and it works successfully.

How to reproduce

In order to reproduce the vulnerability, an attacker needs to perform an entity list correction within the BSP itself. As a demonstration, I took a 35hp_2 map, which uses the game_text entity, into which we can write the shellcode that runs OS calculator via WinExec function. You can see shellcode implementation on the image below.

When client connects to the HLDS, attacker will send malformed map to it. After client completes download, server will send console command map 35hp_2_shell to client, which will start a local server, causing the load of malformed map and the shellcode execution, since this command is not on the stufftext filter list.

To quickly check the work of the shellcode, it is enough just to put the malformed map in the maps folder of any mod (I used Counter-Strike 1.6, Steam) and execute the console command 'map 35hp_2_shell' manually.

I attached malformed map to report.

Possible solutions

The argument pString needs to be checked for length. So, if it is larger than the buffer where the string is copied, then the function must be terminated. You can also simply replace the function strcpy with strncpy.

Impact

An attacker can execute code remotely on a client machine using HLDS, or he can upload a malformed map to web-resources, that can lead to infection of users of the resource.

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the UTIL_StringToIntArray function copies a string into a fixed-size buffer without checking its length, leading to a stack-based buffer overflow.

Impact

An attacker could execute arbitrary code remotely on a client machine via a malicious server or by uploading a malformed map to a website, potentially infecting users.

What the attacker needed

Victim connects to malicious server; or victim loads malformed map

The fix

The function should check the length of the input string and terminate if it exceeds the buffer size, or use a bounded copy function like strncpy instead of strcpy.

How it was found

  1. Modify the entity list inside a BSP map file to include a game_text entity containing shellcode.
  2. Place the malformed map in the maps folder of a game mod.
  3. Connect to a server that sends the malformed map and then issues a console command to load it, or manually run the map command.
  4. The game loads the map, triggering the buffer overflow and executing the shellcode.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A buffer overflow happens when a program copies more data into a fixed-size memory space than it can hold, spilling over into nearby memory. Here, a game function that reads map data does not check the length of a string, so a crafted map can overwrite the return address and make the game run attacker-supplied code. This means opening a malicious map file could let someone else run programs on your computer.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by kohtep2010

View all

3 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.