X Windows
X Windows
no
1. Motivation / introduction
2. How open X displays are found
3. The local-host problem
4. Snooping techniques - dumping windows
5. Snooping techniques - reading keyboard
6. Xterm - secure keyboard option
7. Trojan X programs [xlock and xdm]
8. X Security tools - xauth MIT-MAGIC-COOKIE
9. Concluding remarks
1. Motivation / introduction
$ xhost +
allows connections from any host. A single host can be allowed connection
with the command
$ xhost + ZZZ.ZZZ.ZZZ.ZZZ
$ xhost -
command. In this case no host but the local-host can connect to the
display. Period. It is as simple as that - if the display runs in 'xhost
-' state, you are safe from programs that scans and attaches to
unprotected X displays. You can check the access control of your display
by simply typing xhost from a shell. Sadly enough, most sites run their X
displays with access control disabled as default. They are therefore easy
prey for the various scanner programs circulating on the net.
Anyone with a bit of knowledge about Xlib and sockets programming can
write an X scanner in a couple of hours. The task is normally
accomplished by probing the port that is reserved for X windows, number
6000. If anything is alive at that port, the scanner calls
XOpenDisplay("IP-ADDRESS:0.0") that will return a pointer to the display
structure, if and only if the target display has its access control
disabled. If access control is enabled, XOpenDisplay returns 0 and
reports that the display could not be opened.
E.g:
The probing of port 6000 is necessary because of the fact that calling
XOpenDisplay() on a host that runs no X server will simply hang the
calling process. So much for unix programming conventions. :)
I wrote a program called xscan that could scan an entire subnet or scan
the entries in /etc/hosts for open X displays. My remark about most sites
running X displays with access control disabled, originates from running
xscan towards several sites on the internet.
Running your display with access control enabled by using 'xhost -' will
guard you from XOpenDisplay attempts through port number 6000. But there
is one way an eavesdropper can bypass this protection. If he can log into
your host, he can connect to the display of the localhost. The trick is
fairly simple. By issuing these few lines, dumping the screen of the host
'target' is accomplished:
$ rlogin target
$ xwd -root -display localhost:0.0 > ~/snarfed.xwd
$ exit
$ xwud -in ~/snarfed.xwd
Every Xlib routine has the Display structure as it's first argument. By
successfully opening a display, you can manipulate it with every Xlib
call available. For an intruder, the most 'important' ways of
manipulating is grabbing windows and keystrokes.
DESCRIPTION
Xwd is an X Window System window dumping utility. Xwd allows Xusers
to store window images in a specially formatted dump file. This file
can then be read by various other X utilities for redisplay, printing,
editing, formatting, archiving, image processing, etc. The target
window is selected by clicking the pointer in the desired window. The
keyboard bell is rung once at the beginning of the dump and twice when
the dump is completed.
DESCRIPTION
Xwud is an X Window System image undumping utility. Xwud allows X
users to display in a window an image saved in a specially formatted
dump file, such as produced by xwd(1).
I will not go in detail of how to use these programs, as they are both
self-explanatory and easy to use. Both the entire root window, a
specified window (by name) can be dumped, or a specified screen. As a
'security measure' xwd will beep the terminal it is dumping from, once
when xwd is started, and once when it is finished (regardless of the xset
b off command). But with the source code available, it is a matter of
small modification to compile a version of xwd that doesn't beep or
otherwise identifies itself - on the process list e.g. If we wanted to
dump the root window or any other window from a host, we could simply
pick a window from the process list, which often gives away the name of
the window through the -name flag. As before mentioned, to dump the
entire screen from a host:
Xterm windows are a different thing. You can not specify the name of an
xterm and then dump it. They are somehow blocked towards the X_Getimage
primitive used by xwd, so the following
will result in an error. However, the entire root window (with Xterms and
all) can still be dumped and watched by xwud. Some protection.
If you can connect to a display, you can also log and store every
keystroke that passes through the X server. A program circulating the
net, called xkey, does this trick. A kind of higher-level version of the
infamous ttysnoop.c. I wrote my own, who could read the keystrokes of a
specific window ID (not just every keystroke, as my version of xkey).
The window ID's of a specific root-window, can be acquired with a call to
XQueryTree(), that will return the XWindowAttributes of every window
present. The window manager must be able to control every window-ID and
what keys are pressed down at what time. By use of the window-manager
functions of Xlib, KeyPress events can be captured, and KeySyms can be
turned into characters by continuous calls to XLookupString.
You can even send KeySym's to a Window. An intruder may therefore not
only snoop on your activity, he can also send keyboard events to
processes, like they were typed on the keyboard. Reading/writing
keyboard events to an xterm window opens new horizons in process
manipulation from remote. Luckily, xterm has good protection techniques
for prohibiting access to the keyboard events.
xterm*allowSendEvents True
The versions of Xterm X11R5 without patch26 also contain a rather nasty
and very well known security hole that enables any user to become root
through clever use of symbolic links to the password file. The Xterm
process need to be setuid for this hole to be exploitable. Refer to the
Cert Advisory: CA-93:17.xterm.logging.vulnerability.
Spoofed X based logins however are a bit more tricky for the intruder to
accomplish. He must simulate the login screen of the login program ran
by XDM. The only way to ensure that you get the proper XDM login program
(if you want to be really paranoid) is to restart the X-terminal,
whatever key combination that will be for the terminal in question.
$ xauth list
If you want to open your display for connections from a particular user,
you must inform him of your key. He must then issue the command
Now, only that user (including yourself) can connect to your display.
Xauthority is simple and powerful, and eliminates many of the security
problems with X.