Malformed save files (.sav) allow to write files with arbitrary extensions and content in GoldSrc-based games.
A save-file loader in GoldSrc-based games checked for the allowed .HL? extension by substring anywhere in the path rather than at the end, so a crafted .sav could unpack a file with an arbitrary extension such as .dll. A malicious server could deliver the save, run console commands to place the DLL where the client library is loaded, and get its code into the client's memory.
- Triaged in 4 days
- Fixed in 3 months
- Paid in 2 months
- Disclosed after 15 months
The structure of the save file implies unpacking of temporary files with extensions .HL1, .HL2 and .HL3. In the code of command 'load', there is a check for invalid substrings, such as .., so unpacking the files into the top directories will not work. Also, it seems, there is a code for checking the file extension by substring *.HL?. So, the problem is that it seems that checking for the presence of this substring is valid throughout the file path, and not just at its end. Therefore, such a check can be bypassed by inserting a substring in the middle of the file path and setting its extension.
In the attached archive there is a demonstration file fakeresource.sav, which in turn unpacks the file test.HL1.dll with the ASCII string 'Hello World!' inside.
How to reproduce it:
- Put the file
fakeresource.savin the path%gamedir%/SAVE/; - Launch the game client and type in the console
load fakeresource;
The file test.HL1.dll will appear in the folder SAVE next to the file fakeresource.sav.
Also, files can be unpacked into internal child directories, with the help of this it can be loaded into memory, the game client simply starts to connect to the mailicious server:
- The server downloads the file
SAVE/fakeresource.savto the game client; - After downloading the file, the server, using the messages
SVC_StuffTextorSVC_Director, execute the following string in the client console_setgamedir %gamedir%_downloads;_restart. Let's take a closer look at this string:
_setgamedir %gamedir%_downloads- sets the directory in which the .sav file is downloaded, for its subsequent load;_restart- applying the above changes.
- Since the client was on the server, when the engine is restarted, it starts to reconnect to it. This time the server executes the following string in the client console
logsdir SAVE/test.HL1/cl_dlls;log on;_setgamedir %gamedir%_downloads/SAVE/test.HL1;load fakeresource;_restart. Consider more:
logsdir SAVE/test.HL1/cl_dlls;log on- creates directories into which the .dll file will be unpacked, because files cannot be unpacked in non-existent directories;_setgamedir %gamedir%_downloads/SAVE/test.HL1- sets the directory against which the engine will try to load the client library 'cl_dlls/client.dll' into memory when restarted;load fakeresource- unpacks the file along the pathSAVE/test.HL1/cl_dlls/client.dll;_restart- restarts the engine to apply changes and load the new library into memory.
As a proof, there is a video in the attached archive showing the connection to the test server, which downloads such a .dll file to the client with a call to MsgBox.
Impact
A malicious server can download the .sav file to the game client, execute commands on the client console to unpack a binary file, such as .dll, and load its malicious code into the client’s memory.
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 extension validation used a substring search over the entire file path instead of checking that the path ends with the permitted extension.
Impact
A malicious server could deliver a crafted save and cause a binary of its choosing to be loaded into the client's memory, as demonstrated with a DLL that showed a message box.
What the attacker needed
Victim connects to a malicious server; server can send console commands
How it was found
- Place the crafted save file in the game's SAVE directory.
- Launch the client and run the load command for that save from the console.
- The unpacked file with the crafted name appears in the SAVE folder.
- A server can send the save to the client and use console messages to switch the game directory and restart.
- The server then creates the target directories, sets the game directory, loads the save and restarts so the new library is loaded.
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.
Games store saved games in files, and this engine unpacks small helper files from inside them. The check that those helper files must have a certain extension was done by searching the whole path for the text instead of looking at the end, so a name like test.HL1.dll slipped through. That let a rigged save drop a program file that the game later loaded and ran.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.