[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.
- 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
- Place the attached cfg file in the root directory of the game:
- Launch the game and bring up the console with
~ - Type in
exec rce.cfgand press enter - 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.
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.
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
- Place the crafted config file in the game's root directory
- Launch the game and open the console
- Run the config file with the exec command
- 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.