Unchecked weapon id in WeaponList message parser on client leads to RCE
The client-side WeaponList message parser copies a weapon into a fixed array using an unchecked, signed weapon id, so an out-of-range id writes outside the array. A malicious server can send a crafted message that overwrites an engine function table entry and leads to remote code execution on the connecting client.
Originally disclosed on HackerOne
- Triaged in 14 days
- Fixed in 33 days
- Paid in 33 days
- Disclosed after 6 months
Let's look at WeaponList message parser code in the HLSDK:
int CHudAmmo::MsgFunc_WeaponList(const char *pszName, int iSize, void *pbuf )
{
BEGIN_READ( pbuf, iSize );
WEAPON Weapon;
strcpy( Weapon.szName, READ_STRING() );
Weapon.iAmmoType = (int)READ_CHAR();
Weapon.iMax1 = READ_BYTE();
if (Weapon.iMax1 == 255)
Weapon.iMax1 = -1;
Weapon.iAmmo2Type = READ_CHAR();
Weapon.iMax2 = READ_BYTE();
if (Weapon.iMax2 == 255)
Weapon.iMax2 = -1;
Weapon.iSlot = READ_CHAR();
Weapon.iSlotPos = READ_CHAR();
Weapon.iId = READ_CHAR();
Weapon.iFlags = READ_BYTE();
Weapon.iClip = 0;
gWR.AddWeapon( &Weapon );
return 1;
}
And WeaponResource::AddWeapon:
void AddWeapon( WEAPON *wp )
{
rgWeapons[ wp->iId ] = *wp;
LoadWeaponSprites( &rgWeapons[ wp->iId ] );
}
There are no boundary check, and the range of iId is [-128, 128), so I can modify many things in the data section.
In client.dll, there's an object called gEngfuncs, it is a function table that has various functions of the engine. After some calculations on latest CS 1.6 client.dll, I concluded that this function table could be overwritten using the above bug.
I have attached a PoC that will pop calc.exe on latest CS 1.6 client when connected to malicious server. The AMXX plugin will catch InitHUD message, and send crafted WeaponList message to overwrite the address of function used in HUD_DirectorMessage to execute client cmds to a ROP gadget that will trigger the chain sent in the next SendCmd call. To overwrite that address, I used a crafted weapon sprite list (weapon_pwn.txt) (see WEAPON struct, file cl_dll/ammo.h in the HLSDK).
Impact
Since it's RCE, attacker can do almost anything that don't require higher privilege (ex. compromise account, inject malware, ...)
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
The weapon id read from the network message is used directly as an array index in AddWeapon without any bounds check, allowing writes outside the weapon array.
Impact
A malicious server could achieve remote code execution on the connecting client, doing anything that does not require higher privilege, such as compromising the account or injecting malware.
What the attacker needed
Victim connects to a malicious server; server runs a crafted plugin
How it was found
- Connect the client to a malicious server running the provided plugin.
- The plugin catches the InitHUD message and sends a crafted WeaponList message.
- The crafted weapon sprite list overwrites the address of the function used in HUD_DirectorMessage.
- The overwritten address points to a ROP gadget that triggers the chain sent in the next SendCmd call.
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 client trusts messages sent by the server. Here the client used a number from that message as an index into a fixed-size list without checking it was in range, so a bad number let the server write into memory it should not touch. By choosing what to overwrite, the attacker could make the player's computer run their code.
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.