Malformed .BMP file in Counter-Strike 1.6 may cause shellcode injection
A malformed BMP overview file processed by the GoldSource engine's LoadBMP8 function overflows the stack, letting a malicious server run arbitrary code on a connecting client. The author built a tool that produces such a file and demonstrated shellcode launching the calculator process.
Originally disclosed on HackerOne
- Triaged in 12 hours
- Fixed in 4 days
- Paid in 4 days
- Disclosed after 18 months
With the vulnerability of the GoldSource Engine, the server is able to perform remote code execution on the client, overwriting the stack when reading the BMP file. The problem is in the LoadBMP8 function, which is executed when the player connects to the server, by loading the "overviews%MAPNAME%.bmp" file. If we send a badly formed file to this function, then we will be able to rewrite the stack of the function by setting the own code in the stack and passing program control to it.
I've wrote a program that compiles file like that. The shellcode, which runs on the stack, starts the "calc.exe" process with the WinExec function.
For the client to execute this file, the server must send this file to the client. The server can do this if map that is not present on the client is launched. The server must load a map with random name, for example, "definitely_missing_client_map.bsp". In this case, the name of the BMP file must also be "definitely_missing_client_map.bmp" and it must be in "overviews" folder. You also must create the "overviews\definitely_missing_client_map.txt" file, which is overview description. The nonstandard name of the map prompts the client to download the missing files (bsp, bmp and txt). Upon completion, when the client is able to see the map, the BMP file will be loaded and the binary code from BMP file will be executed on the stack.
I've attached the source code of "compiler" to the message. You can find more detailed instructions in the code comments. You need to compile this project in "Release" configuration and then start this project. After that, malformed "de_dust2.bmp" file will be produced.
Impact
An attacker can execute remote code on the client's machine.
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 a stack buffer overflow in the LoadBMP8 function, which copies data from the BMP file into a fixed-size stack buffer without validating its length.
Impact
An attacker can execute remote code on the client's machine.
What the attacker needed
Victim connects to attacker's server; client downloads missing map files; malicious BMP in overviews folder
How it was found
- Host a map with a random name that the client does not have, so the client is prompted to download missing files.
- Place a malformed BMP with the same map name in the overviews folder, plus a matching overview description text file.
- Have the victim connect to the server and let the client download the missing map files.
- Once the client can see the map, the BMP is loaded and the injected code runs on the stack.
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.
When a player joins a Counter-Strike server, the game downloads small picture files that show a map overview. The code that reads these pictures does not check their size properly, so a crafted picture can spill past the space reserved for it and overwrite the program's own instructions. Because the attacker controls the server, they can make the game run their own code on the player's 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.