Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 81894 - net-ftp/gproftpd: gprostats format string vulnerability
Summary: net-ftp/gproftpd: gprostats format string vulnerability
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo Security
URL:
Whiteboard: B2 [glsa]
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-13 11:53 UTC by rob holland (RETIRED)
Modified: 2005-02-18 08:13 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rob holland (RETIRED) gentoo-dev 2005-02-13 11:53:36 UTC
The gproftpd source code is badly written. Lots of sprintf, strcat (versus snprintf and strncat), allowing stack and heap overflows.

The package should be masked. I have notified the author of problems.

I haven't patched it as it'd be a big patch and I don't use the software.

I haven't attempted to exploit any of the overflows but it should be possible.

Marked critical as it should be trivial to exploit.

Reproducible: Always
Steps to Reproduce:
Comment 1 solar (RETIRED) gentoo-dev 2005-02-13 11:58:43 UTC
Could you provide an example of where user/network input is taken and can be 
abused. I often see programs which do not use snprintf()/strncat() but do so 
in a semi safe way (kernel)
Comment 2 Andreas Kling 2005-02-13 14:42:43 UTC
Here's a nice (and not too revealing) example from callbacks.c:

sprintf(user_pass, "usermod -p '%s' %s", encrypted_pass, username);

Try changing a user's password in gproftpd while grep'ing for usermod processes.

You will catch something like this:

 8715 pts/8    D+     0:00 usermod -p $1$is54ShF3$4RUrFy9d8D8I0VCBlo5c91 test_user

This package should be blocked.
Comment 3 rob holland (RETIRED) gentoo-dev 2005-02-13 15:10:45 UTC
Try typing lots of stuff in the DNS server text entry box and hitting add server, overflow in xfer_update.
Comment 4 solar (RETIRED) gentoo-dev 2005-02-13 16:28:14 UTC
oh this is nice the package is maintained by bug-wranglers@gentoo.org
2 votes for masking now.
Comment 5 Andrea Barisani (RETIRED) gentoo-dev 2005-02-13 16:29:08 UTC
/me votes for masking it
Comment 6 rob holland (RETIRED) gentoo-dev 2005-02-13 16:40:45 UTC
I lied, the overflow isn't related to the text field at all.

bzero(&(myaddr.sin_zero), sizeof(myaddr));

in xfer_update, callbacks.c.

It overflows itself, doesn't need user help :P
Comment 7 rob holland (RETIRED) gentoo-dev 2005-02-14 01:15:50 UTC
Having looked post-coffee this morning I think I over-reacted here. The code is indeed crap, but I can't see anything exploitable, even if it does have stupid self-inflicted overflow in it.

There is an information leak as noted by Andreas.

Maybe if someone with more knowledge than me could review the code?
Comment 8 rob holland (RETIRED) gentoo-dev 2005-02-14 02:26:22 UTC
The code popens "ftpwho" in callbacks.c if something (anything) is listening on the port which is metioned in proftpd.conf. An evil ftpwho in my path:

--- "exploit" ---
rob@leet ~ $ cat bin/ftpwho 
#!/usr/bin/perl

print 'v' x 68000;
--- end ---

This causes a segfault. I assume this is exploitable, can someone who knows better than me check please?
Comment 9 rob holland (RETIRED) gentoo-dev 2005-02-14 03:52:33 UTC
its possible to overflow tempname in callbacks.c:user_exists by having a passwd line longer than 4096. Quite how you'd manage to get that I don't know... chfn limits you to a total of 80 chars for the gecos field.
Comment 10 Andreas Kling 2005-02-14 05:19:51 UTC
If the proftpd daemon is running without a MaxInstance limit (not default), spawn about ~500 simultaneous connections (no authentication required) and gproftpd will overflow in a strcat() call.
Comment 11 rob holland (RETIRED) gentoo-dev 2005-02-15 02:40:47 UTC
A new version has been released which fixes the ftpwho overflow. I'll let Magnus know about the passwd/ps listing bugs.
Comment 12 Tavis Ormandy (RETIRED) gentoo-dev 2005-02-15 08:45:39 UTC
There's an remotely exploitable format string vulnerability in the gprostats log parser, users can trigger it by putting or fetching a specally crafted filename:

the vulnerable statements:

314: snprintf(datestamp, x+1, old_buffer);

obvious fix, add "%s" as arg3. 

demo:

$ lftp taviso@localhost
Password: 
lftp taviso@localhost:~> put /dev/null -o foo%.500nbar
lftp taviso@localhost:~> exit                

which generates the xferlog line:

Tue Feb 15 16:43:07 2005 0 localhost 0 /home/taviso/foo%.500nbar b _ i r taviso ftp 1 * c

running gprostats:

$ gdb /usr/sbin/gprostats 
GNU gdb 6.0
Copyright 2003 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 "i686-pc-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) r -c /etc/proftpd/proftpd.conf -x /var/log/xferlog 
Starting program: /usr/sbin/gprostats -c /etc/proftpd/proftpd.conf -x /var/log/xferlog
Using conf: /etc/proftpd/proftpd.conf
Using xferlog: /var/log/xferlog

Program received signal SIGSEGV, Segmentation fault.
0x4008d26a in vfprintf () from /lib/libc.so.6

Changing component to vulnerability.
Comment 13 rob holland (RETIRED) gentoo-dev 2005-02-16 01:18:39 UTC
New version 8.1.9 released by Magnus which fixes the remote overflow via the log file.

There are still a few local format-string overflows when reading from the config file:

rob@leet /tmp/gproftpd-8.1.9 $ cat /tmp/conf 
ServerName foo%.1000nblehbleh

rob@leet /tmp/gproftpd-8.1.9 $ gdb ./src/gprostats
GNU gdb 6.2.1
Copyright 2004 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 "i686-pc-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) r -c /tmp/conf
Starting program: /tmp/gproftpd-8.1.9/src/gprostats -c /tmp/conf
Using conf: /tmp/conf

Program received signal SIGSEGV, Segmentation fault.
0xb7ed1622 in _IO_vfprintf (s=0xbffe89a0, format=0x80521cb "foo%.1000nblehbleh", ap=0xbffe8ad0 "") at vfprintf.c:1534
1534	vfprintf.c: No such file or directory.
	in vfprintf.c
(gdb) backtrace
#0  0xb7ed1622 in _IO_vfprintf (s=0xbffe89a0, format=0x80521cb "foo%.1000nblehbleh", ap=0xbffe8ad0 "") at vfprintf.c:1534
#1  0xb7eef02d in _IO_vsnprintf (string=0xbfff1440 "foo", maxlen=83, format=0x0, args=0xbffe8acc "") at vsnprintf.c:120
#2  0xb7ed6b62 in __snprintf (s=0x0, maxlen=0, format=0x0) at snprintf.c:35
#3  0x080494ae in main (argc=3, argv=0xbffff4e4) at gprostats.c:196
(gdb)
Comment 14 Tavis Ormandy (RETIRED) gentoo-dev 2005-02-16 05:41:58 UTC
net-ftp/gproftpd-8.1.9 has been added to portage.
Comment 15 Thierry Carrez (RETIRED) gentoo-dev 2005-02-16 05:45:25 UTC
sparc: please test and mark stable.
Comment 16 Gustavo Zacarias (RETIRED) gentoo-dev 2005-02-16 11:07:15 UTC
sparc stable.
Comment 17 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2005-02-18 08:13:51 UTC
Thx Rob and Tavis.

GLSA 200502-26