Skip to content
RCE Disclosed report Advanced

[GoldSrc] RCE via 'spk' Console Command

A console command that loads voice sound files copies a path into a fixed-size stack buffer without checking its length, so an overlong path overflows the buffer. An attacker who can get a victim to run a crafted config file can execute arbitrary code on the victim's machine.

gamer7112 Follow

Originally disclosed on HackerOne

Bounty$350 High View original
  • Triaged in 1 hour
  • Fixed in 7 months
  • Paid in 2 days
  • Disclosed after 7 months

Summary by the program

Details: #Description RCE can be achieved on clients via the 'spk' console command due to missing length checks before copying into a stack based buffer.

#POC

  1. Place the attached cfg file in the root directory of the game:
  2. Launch the game and bring up the console with ~
  3. Type in exec rce.cfg and press enter
  4. View calc pop

#Vulnerable Code The problem arises because VOX_LoadSound calls VOX_GetDirectory which copies into the stack buffer szpath without any length validation which leads to a buffer overflow.

C++

char *VOX_GetDirectory(char *szpath, char *psz)
{
	char c;
	int cb = 0;
	char *pszscan = psz + strlen(psz) - 1;

	// scan backwards until first '/' or start of string
	c = *pszscan;
	while (pszscan > psz && c != '/')
	{
		c = *(--pszscan);
		cb++;
	}

	if (c != '/')
	{
		// didn't find '/', return default directory
		strcpy(szpath, "vox/");
		return psz;
	}

	cb = strlen(psz) - cb;
	memcpy(szpath, psz, cb); // missing length validation
	szpath[cb] = 0;
	return pszscan + 1;
}

aud_sfxcache_t *VOX_LoadSound(aud_channel_t *pchan, char *pszin)
{
	char buffer[512];
	int i, j, k, cword;
	char	pathbuffer[64];
	char	szpath[32];
	aud_sfxcache_t *sc;
	voxword_t rgvoxword[CVOXWORDMAX];
	char *psz;

	if (!pszin)
		return NULL;

	memset(rgvoxword, 0, sizeof (voxword_t) * CVOXWORDMAX);
	memset(buffer, 0, sizeof(buffer));

	// lookup actual string in (*gAudEngine.rgpszrawsentence), 
	// set pointer to string data

	psz = VOX_LookupString(pszin, NULL);

	if (!psz)
	{
		gEngfuncs.Con_DPrintf ("VOX_LoadSound: no sentence named %s\n",pszin);
		return NULL;
	}

	// get directory from string, advance psz
	psz = VOX_GetDirectory(szpath, psz);

	if (strlen(psz) > sizeof(buffer) - 1)
	{
		gEngfuncs.Con_DPrintf ("VOX_LoadSound: sentence is too long %s\n",psz);
		return NULL;
	}

	// copy into buffer
	strncpy(buffer, psz, sizeof(buffer) - 1);
	buffer[sizeof(buffer) - 1] = 0;
	psz = buffer;

	// parse sentence (also inserts null terminators between words)
	
	VOX_ParseString(psz);

	// for each word in the sentence, construct the filename,
	// lookup the sfx and save each pointer in a temp array	

	i = 0;
	cword = 0;
	while (rgpparseword[i])
	{
		// Get any pitch, volume, start, end params into voxword

		if (VOX_ParseWordParams(rgpparseword[i], &rgvoxword[cword], i == 0))
		{
			// this is a valid word (as opposed to a parameter block)
			_snprintf(pathbuffer, sizeof(pathbuffer), "%s%s.wav", szpath, rgpparseword[i]);
			pathbuffer[sizeof(pathbuffer) - 1] = 0;

			if (strlen(pathbuffer) >= sizeof(pathbuffer))
				continue;

			// find name, if already in cache, mark voxword
			// so we don't discard when word is done playing
			rgvoxword[cword].sfx = S_FindName(pathbuffer, &(rgvoxword[cword].fKeepCached));
			cword++;
		}
		i++;
	}

	k = VOX_IFindEmptySentence();
	if (k < 0)
		return NULL;

	j = 0;
	while (rgvoxword[j].sfx != NULL)
		rgrgvoxword[k][j] = rgvoxword[j++];

	pchan->isentence = k;
	pchan->iword = 0;
	pchan->sfx = rgvoxword[0].sfx;

	sc = S_LoadSound(pchan->sfx, pchan);
	if (!sc)
	{
		S_FreeChannel(pchan);
		return NULL;
	}

	return sc;
}

Impact

RCE allows for an attacker to execute any arbitrary code on a chosen victim.

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

Likely the directory-extraction routine copies the path into a 32-byte stack buffer using memcpy without validating that the copied length fits.

Impact

An attacker could execute arbitrary code on a chosen victim's machine, but only if the victim runs the crafted config file.

What the attacker needed

Victim runs a crafted config file; attacker delivers the file to the victim

How it was found

  1. Place the crafted config file in the game's root directory
  2. Launch the game and open the console
  3. Run the config file with the exec command
  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 buffer is a small reserved area of memory. When a program copies more data into it than it can hold, the extra data spills over into nearby memory, which an attacker can shape to run their own code. Here a sound-loading routine copied a file path into a small fixed-size buffer without checking how long the path was.

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.