[Source Engine] Material path truncation leads to Remote Code Execution
The console command that opens the material file under the crosshair passes a 256-byte path buffer to the Windows shell, but Windows limits paths to 260 characters, so a crafted path can be truncated to point at a different file. An attacker could get a downloaded script file executed instead of a material file, running arbitrary commands on the victim's machine.
Originally disclosed on HackerOne
- Triaged in 3 days
- Fixed in 2.0 years
- Paid in 5 months
- Disclosed after 2.0 years
Summary by the program
Title: [Source Engine] Material path truncation leads to Remote Code Execution Scope: *.exe Weakness: Improper Input Validation Severity: High (7.1) Link: https://hackerone.com/reports/544096 Date: 2019-04-20 12:18:09 +0000 By: @nyancat0131
Details:
Summary
The handler of mat_crosshair_edit command supplies a buffer of size 256 for material path.
That function will call vgui2::system()->ShellExecute("open", path); to open the .vmt file in associated editor if available.
But in windows, MAX_PATH is 260.
So path truncation can be abused to trick the command to execute file of another extension.
I choose .js extension since it is associated with Windows Script Host by default, and it is not blocked by Source Engine download filter.
Affects
CS:Source, CS:GO, and maybe all Valve's Source Engine games.
Environment for reproduction
- Windows 10 x64 10.0.17763.437
- CS:Source installed at default location:
C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Source\
NOTE: CS:Source must be installed at that path for this PoC to work.
Steps to reproduce
- Download F472693, extract it to
C:\Program Files (x86)\Steam\steamapps\common\Counter-Strike Source\cstrike\download\ - Start CS:Source
- Type in the console
map aim_pathand wait for the map to load - Type in the console
sv_cheats 1 - Type in the console
mat_crosshair_editandcalc.exewill be executed
Impact
Since the engine has filter for ClientCommand function on the server, attacking without user interaction is almost impossible. The only way to pass the filter is to brute force cmd marker random number, which is 1 in 2^19.
Once the victim has triggered the bug, attacker can run arbitrary commands on victim's computer.
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 material path is held in a 256-byte buffer and passed to ShellExecute without accounting for Windows' 260-character MAX_PATH limit, so a long path is truncated to a different file.
Impact
Once the victim triggers the bug, an attacker can run arbitrary commands on the victim's computer, though the server-side filter on client commands makes attack without user interaction almost impossible.
What the attacker needed
Windows victim; Game installed at the default path; Victim triggers the command; Cheats enabled
How it was found
- Download the provided archive and extract it into the game's download folder.
- Start the game.
- Load the specified map from the console and wait for it to finish loading.
- Enable cheats in the console.
- Run the material crosshair edit command, which executes the calculator program.
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 game command lets you open the file you are looking at in an editor. The program stores the file path in a fixed-size box, and Windows has a maximum path length, so a very long path gets cut short and can end up pointing at a different file. If that other file is a script, Windows runs it, which lets an attacker run their own commands.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.