SNI-20: Telnetd tgetent vulnerability

Secure Networks Inc. (sni@SILENCE.SECNET.COM)
Tue, 21 Oct 1997 18:24:02 -0600

-----BEGIN PGP SIGNED MESSAGE-----

###### ## ## ######
## ### ## ##
###### ## # ## ##
## ## ### ##
###### . ## ## . ######.

Secure Networks Inc.

Security Advisory
October 21, 1997

in.telnetd tgetent buffer overflow

This advisory addresses a vulnerability in the tgetent(3) library
routine which allows an attacker to obtain root privileges by connecting
to a vulnerable system's telnet daemon.

Problem Description
~~~~~~~~~~~~~~~~~~~

A vulnerability in the tgetent(3) library routine can result in a
buffer overflow in the telnet daemon on some BSD derived systems. By
uploading an alternate terminal capability database, an attacker
can exploit this vulnerability to gain unauthorized super-user access
to a vulnerable system, or to gain super-user access on a system
which they already have access to.

This problem can be exploited by mailing a file into the system, or
uploading a file via FTP. Once this file has been transferred to the
remote system, the attacker must only be able to connect to the telnet
daemon, to obtain super-user access.

Technical Details
~~~~~~~~~~~~~~~~~

The tgetent(3) library call requires the passing in of a buffer in
which the terminal entry is stored.

/*
* Get an entry for terminal name in buffer bp from the termcap file.
*/
int
tgetent(bp, name)
char *bp, *name;
{

The tgetent(3) library call does no checking on the size of data which
is placed into the *bp buffer. Many programs pass in a buffer of size
1024 bytes. By creating a termcap terminal specification larger than
1024 bytes, we can overflow a buffer in the calling function. If this
buffer is stored on the stack in the calling function, we can cause
arbitrary machine code to be executed.

The BSD telnet daemon calls the tgetent(3) function as follows:

char buf[1024];

if (terminaltype == NULL)
return(1);

if (tgetent(buf, s) == 0)
return(0);
return(1);

By specifying a terminal capability entry which is larger than 1024
bytes, an overflow occurs in the telnet daemon, allowing arbitrary
machine instructions to be executed.

Impact
~~~~~~

Remote individuals can obtain super-user access to any vulnerable system.
This vulnerability can allow remote users to obtain super-user access on
vulnerable systems, and can allow local users to obtain super-user access.

Vulnerable Systems
~~~~~~~~~~~~~~~~~~

BSD/OS (BSDI)

Version 2.1 of BSD/OS is vulnerable
Version 3.0 of BSD/OS is NOT vulnerable

BSDI has issued a security fix which is currently in the testing
phases and will be availible at the following location:

ftp://ftp.bsdi.com/bsdi/patches/patches-2.1/U210-043

Solaris 2.x

Solaris 2.x is NOT vulnerable to this problem

AIX

AIX is NOT vulnerable to this problem

HP-UX

HP-UX is NOT vulnerable to this problem

Linux

The current versions of Linux which were tested include Slackware
and Redhat, which appear to be NOT vulnerable.

IRIX

IRIX appears to be NOT vulnerable.

NetBSD

Current versions of NetBSD are not vulnerable.

FreeBSD

Versions of FreeBSD newer than 2.1.5 are NOT vulnerable to this
problem. FreeBSD-current, FreeBSD 2.1.7 and FreeBSD 2.2.2 are NOT
vulnerable.

OpenBSD

Versions of OpenBSD newer than 2.0 are NOT vulnerable to this problem.

Additional Information
~~~~~~~~~~~~~~~~~~~~~~

This problem was discovered by Theo de Raadt <deraadt@openbsd.org>

You can contact Secure Networks Inc. at <sni@secnet.com> using
the following PGP key:

Type Bits/KeyID Date User ID
pub 1024/9E55000D 1997/01/13 Secure Networks Inc. <sni@secnet.com>
Secure Networks <security@secnet.com>

- -----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.3ia

mQCNAzLaFzIAAAEEAKsVzPR7Y6oFN5VPE/Rp6Sm82oE0y6Mkuof8QzERV6taihn5
uySb31UeNJ4l6Ud9alOPT/0YdeOO9on6eD1iU8qumFxzO3TLm8nTAdZehQSAQfoa
rWmpwj7KpXN/3n+VyBWvhpBdKxe08SQN4ZjvV5HXy4YIrE5bTbgIhFKeVQANAAUR
tCVTZWN1cmUgTmV0d29ya3MgSW5jLiA8c25pQHNlY25ldC5jb20+iQCVAwUQM1yd
EB/bLKAOe7p9AQFptAQAiYpaZCpSmGgr05E698Z3t5r5BPAKUEtgvF53AvZUQLxz
ZsYsVU5l5De0qKWJOQ/9LiDyWu1lvKhlTphbLy2RatWD4kO3oQL9v3TpSXm2WQhU
uIzyZvj7S5ENodNnKn+gCDIvbou6OMot+7dRbWWgN2oabbru4CSlOxbG++yaTz+J
AJUDBRAzTefbtOXez5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P PUBLIC KEY BLOCK-----

Copyright Notice
~~~~~~~~~~~~~~~~
The contents of this advisory are Copyright (C) 1997 Secure Networks Inc,
and may be distributed freely provided that no fee is charged for
distribution, and that proper credit is given.

You can find Secure Networks papers at ftp://ftp.secnet.com/pub/papers
and advisories at ftp://ftp.secnet.com/advisories

You can browse our web site at http://www.secnet.com

You can subscribe to our security advisory mailing list by sending mail to
majordomo@secnet.com with the line "subscribe sni-advisories"

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv

iQCVAwUBNE1O6bgIhFKeVQANAQG6UQP/ZmaI1E6yhEJKX8tdkwCMZt8GPATb7Ktx
dUW+aapmPiy1f4rOr1TpYg+ntBhQ7Rpifk/umJJ0mHNBwk0zUvnVXWS8OFZxDER/
6wshV0i3ZuVx+FGEqkV1dCDSgsygTieuf5hUGiVpWdpR4vtJ5oZhmzDJH2xOexNp
3bxn5PGOa8w=
=+I+e
-----END PGP SIGNATURE-----