X11 Session Hijacking
An open X11 display allows full interaction with the remote desktop session: capturing screenshots, recording keystrokes, and injecting mouse/keyboard input. This turns display access into command execution as the logged-in user without needing credentials. Confirm access first through X11 open display enumeration.
Screenshot Capture
xwd dumps the root window (entire screen) to an XWD image file. Convert it to PNG for viewing.
Explain command
| -root | Capture the entire root window instead of prompting for a window selection. |
| -display $TARGET_IP:0 | Connect to display :0 on the target host. |
Requires ImageMagick. Install with apt install imagemagick if not present. Review the screenshot for open terminals, browser sessions, credentials on screen, or application context.
Live Screen Watching
xwatchwin streams a live view of the remote display, updated in real time. Useful for monitoring user activity and waiting for credential entry.
Explain command
| -w root | Watch the root window (full screen). |
Opens a local window showing the remote desktop. The stream is read-only. Ctrl+C to stop.
Keylogging
xspy registers for keyboard events on the remote X server and logs every keystroke the user types, including passwords and sudo prompts.
sudo su - P@ssw0rd123 cat /etc/shadow
Captures keystrokes in real time. Runs until killed with Ctrl+C. Passwords typed into sudo prompts, SSH connections, and web forms all appear in plaintext.
xspy may not be installed by default on Kali. Install it with apt install xspy or compile from source. Alternative: use xinput to list devices and monitor keyboard events.
Command Injection via xdotool
xdotool synthesizes keyboard and mouse events on the remote display. Combined with a terminal window, this turns display access into command execution as the logged-in user.
Ctrl+Alt+T opens a terminal on most Linux desktop environments (GNOME, XFCE, KDE). Wait a moment for the terminal to open before typing.
Type the command, then send Enter. The reverse shell connects back to your listener. Ensure nc -lvnp is running first.
If the desktop environment does not respond to Ctrl+Alt+T, use xdotool to type a command that opens a terminal explicitly:
Spawns an xterm window on the remote display that immediately runs the reverse shell. The victim will see the xterm window appear briefly.
Window Enumeration
List all open windows on the remote display to identify what applications the user has running.
Terminal - user@target:~ Firefox Files
Window titles reveal running applications, open file paths, and browser tabs. Look for password managers, admin panels, or sensitive documents.
References
-
Hacking Articles: Penetration Testing on X11LINK: Hacking Articles: Penetration Testing on X11, www.hackingarticles.in/penetration-testing-on-x11-server (opens in new tab)
Screenshot capture, keylogging, and command injection walkthrough.
-
Keyboard and mouse event synthesis for X11 displays.
-
Infosec: Exploiting X11 Unauthenticated AccessLINK: Infosec: Exploiting X11 Unauthenticated Access, resources.infosecinstitute.com/topic/exploiting-x11-unauthenticated-access (opens in new tab)
X11 exploitation techniques with xwd, xspy, and xdotool.