⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crash course in x windows security.txt

📁 黑客培训教程
💻 TXT
字号:
Crash Course in X Windows Security1. 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 option7. Trojan X programs [xlock and xdm] 8. X Security tools - xauth MIT-MAGIC-COOKIE 9. Concluding remarks1. Motivation / introductionX windows pose a security risk. Through a network, anyone can connectto an open X display, read the keyboard, dump the screen and windowsand start applications on the unprotected display. Even if this is aknown fact throughout the computer security world, few attempts oninforming the user community of the security risks involved have beenmade.  This article deals with some of the aspects of X windowssecurity. It is in no sense a complete guide to the subject, butrather an introduction to a not-so-known field of computersecurity. Knowledge of the basics of the X windows system isnecessary, I haven't bothered including an introductory section toexplain the fundamentals. I wrote some code during the research forthis article, but none of it is included herein.  If the lingual flowof English seem mayhap strange and erroneous from byte to byte, thisis due to the fact that I'm Scandinavian.  Bare with it. :)2. How open X displays are foundAn open X display is in formal terms an X server that has its accesscontrol disabled. Disabling access control is normally done with thexhost command.$ xhost +allows connections from any host. A single host can be allowedconnection with the command$ xhost + ZZZ.ZZZ.ZZZ.ZZZwhere Z is the IP address or host-name. Access control can be enabledby issuing an$ xhost - command. In this case no host but the local-host can connect to thedisplay.  Period. It is as simple as that - if the display runs in'xhost -' state, you are safe from programs that scans and attaches tounprotected X displays.  You can check the access control of yourdisplay by simply typing xhost from a shell. Sadly enough, most sitesrun their X displays with access control disabled as default. They aretherefore easy prey for the various scanner programs circulating onthe net.Anyone with a bit of knowledge about Xlib and sockets programming canwrite an X scanner in a couple of hours. The task is normallyaccomplished by probing the port that is reserved for X windows,number 6000. If anything is alive at that port, the scanner callsXOpenDisplay("IP-ADDRESS:0.0") that will return a pointer to thedisplay structure, if and only if the target display has its accesscontrol disabled. If access control is enabled, XOpenDisplay returns 0and reports that the display could not be opened.E.g:Xlib: connection to "display:0.0" refused by serverXlib: Client is not authorized to connect to ServerThe probing of port 6000 is necessary because of the fact that callingXOpenDisplay() on a host that runs no X server will simply hang thecalling process. So much for unix programming conventions. :)I wrote a program called xscan that could scan an entire subnet orscan the entries in /etc/hosts for open X displays. My remark aboutmost sites running X displays with access control disabled, originatesfrom running xscan towards several sites on the internet.3. The localhost problemRunning your display with access control enabled by using 'xhost -'will guard you from XOpenDisplay attempts through port number6000. But there is one way an eavesdropper can bypass thisprotection. If he can log into your host, he can connect to thedisplay of the localhost. The trick is fairly simple. By issuing thesefew lines, dumping the screen of the host 'target' is accomplished:$ rlogin target$ xwd -root -display localhost:0.0 > ~/snarfed.xwd$ exit$ xwud -in ~/snarfed.xwdAnd voila, we have a screendump of the root window of the X servertarget. Of course, an intruder must have an account on your system and be ableto log into the host where the specific X server runs. On sites with alot of X terminals, this means that no X display is safe from thosewith access. If you can run a process on a host, you can connect to(any of) its X displays.Every Xlib routine has the Display structure as it's firstargument. By successfully opening a display, you can manipulate itwith every Xlib call available. For an intruder, the most 'important'ways of manipulating is grabbing windows and keystrokes.4. Snooping techniques - dumping windowsThe most natural way of snarfing a window from an X server is by usingthe X11R5 utility xwd or X Window System dumping utility. To get agrip of the program, here's a small excerpt from the man page 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.Shortly, xwd is a tool for dumping X windows into a format readable byanother program, xwud. To keep the trend, here's an excerpt from theman page of xwud: 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 bothself-explanatory and easy to use. Both the entire root window, aspecified window (by name) can be dumped, or a specified screen.  As a'security measure' xwd will beep the terminal it is dumping from, oncewhen xwd is started, and once when it is finished (regardless of thexset b off command). But with the source code available, it is amatter of small modification to compile a version of xwd that doesn'tbeep or otherwise identifies itself - on the process list e.g.  If wewanted to dump the root window or any other window from a host, wecould simply pick a window from the process list, which often givesaway the name of the window through the -name flag.  As beforementioned, to dump the entire screen from a host:$ xwd -root localhost:0.0 > filethe output can be directed to a file, and read with$ xwud -in fileor just piped straight to the xwud command.Xterm windows are a different thing. You can not specify the name ofan xterm and then dump it. They are somehow blocked towards theX_Getimage primitive used by xwd, so the following$ xwd -name xtermwill result in an error. However, the entire root window (with Xtermsand all) can still be dumped and watched by xwud. Some protection.5. Snooping techniques - reading keyboardIf you can connect to a display, you can also log and store everykeystroke that passes through the X server. A program circulating thenet, called xkey, does this trick. A kind of higher-level version ofthe infamous ttysnoop.c. I wrote my own, who could read the keystrokesof a specific window ID (not just every keystroke, as my version ofxkey).  The window ID's of a specific root-window, can be acquiredwith a call to XQueryTree(), that will return the XWindowAttributes ofevery window present. The window manager must be able to control everywindow-ID and what keys are pressed down at what time.  By use of thewindow-manager functions of Xlib, KeyPress events can be captured, andKeySyms can be turned into characters by continuous calls toXLookupString. You can even send KeySym's to a Window. An intruder may therefore notonly snoop on your activity, he can also send keyboard events toprocesses, like they were typed on the keyboard.  Reading/writingkeyboard events to an xterm window opens new horizons in processmanipulation from remote. Luckily, xterm has good protectiontechniques for prohibiting access to the keyboard events.6. Xterm - Secure keyboard optionA lot of passwords is typed in an xterm window. It is thereforecrucial that the user has full control over which processes can readand write to an xterm.  The permission for the X server to send eventsto an Xterm window, is set at compile time. The default is false,meaning that all SendEvent requests from the X server to an xtermwindow is discarded. You can overwrite the compile-time setting with astandard resource definition in the .Xdefaults file:xterm*allowSendEvents	Trueor by selecting Allow Sendevents on the Xterm Main Optionsmenu. (Accessed by pressing CTRL and the left mouse button But this is_not_ recommended. Neither by me, nor the man page. ;) Read access isa different thing. Xterms mechanism for hindering other X clients to read the keyboardduring entering of sensitive data, passwords etc. is by using theXGrabKeyboard() call. Only one process can grab the keyboard at anyone time. To activate the Secure Keyboard option, choose the MainOptions menu in your Xterm window (CTRL+Left mouse button) and selectSecure Keyboard.  If the colors of your xterm window inverts, thekeyboard is now Grabbed, and no other X client can read the KeySyms.The versions of Xterm X11R5 without patch26 also contain a rathernasty and very well known security hole that enables any user tobecome root through clever use of symbolic links to the passwordfile. The Xterm process need to be setuid for this hole to beexploitable.  Refer to the Cert Advisory:CA-93:17.xterm.logging.vulnerability.7. Trojan X clients - xlock and X based loginsCan you think of a more suitable program for installing apassword-grabbing trojan horse than xlock? I myself cannot. With a fewlines added to the getPassword routine in xlock.c, the password ofevery user using the trojan version of xlock can be stashed away in afile for later use by an intruder. The changes are so minimal, only acouple of bytes will tell the real version from the trojan version.If a user has a writable homedir and a ./ in her PATH environmentvariable, she is vulnerable to this kind of attack. Getting thepassword is achieved by placing a trojan version of Xlock in the usershomedir and waiting for an invocation.  The functionality of theoriginal Xlock is contained in the trojan version.  The trojan versioncan even tidy up and destroy itself after one succesfull attempt, andthe user will not know that his password has been captured.Xlock, like every password-prompting program, should be regarded withsuspicion if it shows up in places it should not be, like in your ownhomedir.Spoofed X based logins however are a bit more tricky for the intruderto accomplish.  He must simulate the login screen of the login programran by XDM. The only way to ensure that you get the proper XDM loginprogram (if you want to be really paranoid) is to restart theX-terminal, whatever key combination that will be for the terminal inquestion. 8. X Security tools - xauth MIT-MAGIC-COOKIE To avoid unathorized connections to your X display, the command xauthfor encrypted X connections is widely used. When you login, xdmcreates a file .Xauthority in your homedir. This file is binary, andreadable only through the xauth command. If you issue the command$ xauth listyou will get an output of:your.display.ip:0  MIT-MAGIC-COOKIE-1  73773549724b76682f726d42544a684a  display name     authorization type               keyThe .Xauthority file sometimes contains information from oldersessions, but this is not important, as a new key is created at everylogin session. To access a display with xauth active - you must havethe current access key.If you want to open your display for connections from a particularuser, you must inform him of your key.He must then issue the command $ xauth add your.display.ip:0  MIT-MAGIC-COOKIE-1 73773549724b7668etc.Now, only that user (including yourself) can connect to your display.Xauthority is simple and powerful, and eliminates many of the securityproblems with X.9. Concluding remarksThanks must go to Anthony Tyssen for sending me his accumulated infoon X security issues from varius usenet discussions. I hope someonehas found useful information in this text. It is released to thenet.community with the idea that it will help the user to understandthe security problems concerned with using X windows. Questions orremarks can be sent to the following address:______________________________________________________________________runeb / cF --- runeb@stud.cs.uit.no  ---   http://www.cs.uit.no/~runeb 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -