Skip to content
RCE Disclosed report Advanced

[GoldSrc] RCE via malformed BSP file

A malformed BSP map file causes a stack buffer overflow because a WAD filename is copied into a fixed-size buffer without length validation. An attacker could run arbitrary code on a victim who loads the crafted map.

gamer7112 Follow

Originally disclosed on HackerOne

Bounty$450 High 8.1 View original
  • Triaged in 15 days
  • Fixed in 8 months
  • Paid in 17 days
  • Disclosed after 8 months

Summary by the program

#Description RCE can be achieved via a malformed BSP file due to the lack of length validation when copying data from the BSP file into a stack based buffer.

#POC

  1. Place the attached BSP in the maps directory of the chosen GoldSrc game (czero/maps, cstrike/maps, tfc/maps, etc..)
  2. Launch the game and bring up the console with ~
  3. Type in map de_RCE and press enter
  4. View calc pop

#Vulnerable Code Within the following function, COM_FileBase copies data from pszWadFile into wadName without any length validation which leads to a buffer overflow.

C++
qboolean TEX_InitFromWad(char *path)
{
	char *pszWadFile;
	FileHandle_t texfile;
	char szTmpPath[1024];
	char wadName[260];
	char wadPath[260];
	wadinfo_t header;

	Q_strncpy(szTmpPath, path, 1022);
	szTmpPath[1022] = 0;
	if (!Q_strchr(szTmpPath, ';'))
		Q_strcat(szTmpPath, ";");
	for (pszWadFile = strtok(szTmpPath, ";"); pszWadFile; pszWadFile = strtok(NULL, ";"))
	{
		ForwardSlashes(pszWadFile);
		COM_FileBase(pszWadFile, wadName);//Vulnerable Function
		Q_snprintf(wadPath, 0x100u, "%s", wadName);
		COM_DefaultExtension(wadPath, ".wad");

		if (Q_strstr(wadName, "pldecal") || Q_strstr(wadName, "tempdecal"))
			continue;

		texfile = FS_Open(wadPath, "rb");
		texfiles[nTexFiles++] = texfile;
		if (!texfile)
			Sys_Error("%s: couldn't open %s\n", __func__, wadPath);

		Con_DPrintf("Using WAD File: %s\n", wadPath);
		SafeRead(texfile, &header, 12);
		if (Q_strncmp(header.identification, "WAD2", 4) && Q_strncmp(header.identification, "WAD3", 4))
			Sys_Error("%s: %s isn't a wadfile", __func__, wadPath);

		header.numlumps = LittleLong(header.numlumps);
		header.infotableofs = LittleLong(header.infotableofs);
		FS_Seek(texfile, header.infotableofs, FILESYSTEM_SEEK_HEAD);
		lumpinfo = (texlumpinfo_t *)Mem_Realloc(lumpinfo, sizeof(texlumpinfo_t) * (header.numlumps + nTexLumps));

		for (int i = 0; i < header.numlumps; i++, nTexLumps++)
		{
			SafeRead(texfile, &lumpinfo[nTexLumps], sizeof(lumpinfo_t));
			CleanupName(lumpinfo[nTexLumps].lump.name, lumpinfo[nTexLumps].lump.name);
			lumpinfo[nTexLumps].lump.filepos = LittleLong(lumpinfo[nTexLumps].lump.filepos);
			lumpinfo[nTexLumps].lump.disksize = LittleLong(lumpinfo[nTexLumps].lump.disksize);
			lumpinfo[nTexLumps].iTexFile = nTexFiles - 1;
		}

	}
	qsort(lumpinfo, nTexLumps, sizeof(texlumpinfo_t), lump_sorter);
	return 1;
}

Impact

RCE can be used to execute any arbitrary code that an attacker could want to execute on any victim of choice.

The original report as published on HackerOne, by gamer7112. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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 function COM_FileBase copies the WAD filename into a fixed 260-byte stack buffer without checking the source length, allowing a stack buffer overflow.

Impact

An attacker could execute arbitrary code on any victim who loads the crafted map.

What the attacker needed

Victim loads a crafted map file; attacker supplies the BSP file

How it was found

  1. Place the crafted BSP file in the maps directory of a GoldSrc game.
  2. Launch the game and open the console.
  3. Load the crafted map by name.
  4. The calculator opens, showing code execution.

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 map file can point to texture files by name. The game copies that name into a small fixed-size space without checking how long it is, so a very long name spills over into nearby memory. An attacker can use that spill to run their own code on the player's computer.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by gamer7112

View all

9 more disclosed reports, best first.

More from Valve

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.