X11 - Port 6000

Basic info

X11 (also known as X Window System or simply X) is a network-transparent window system that was designed in the 1980s at MIT. The key architectural principle is that X11 separates the display server from the applications:

  • X Server: Manages the display, keyboard, and mouse (runs on the machine with the physical screen)

  • X Client: The application that wants to display something (can run anywhere on the network)

This client-server architecture means that applications can run on one machine while displaying their GUI on another - a powerful feature that also introduces security risks.

How X11 Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         Network         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  X Client   β”‚ ───────────────────────>β”‚  X Server   β”‚
β”‚ (App/Shell) β”‚ X11 Protocol (Port 6000)β”‚  (Display)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ <β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     Remote                                   Local

The X server listens on port 6000 + display number:

  • Display :0 β†’ Port 6000

  • Display :1 β†’ Port 6001

  • Display :2 β†’ Port 6002

X11 Authentication Mechanisms

X11 supports several authentication methods:

  1. No Authentication (xhost +) - Anyone can connect (extremely insecure)

  2. MIT-MAGIC-COOKIE-1 - 128-bit cookie stored in ~/.Xauthority

  3. XDM-AUTHORIZATION-1 - More secure, uses DES

  4. SUN-DES-1 - Secure RPC using DES

  5. MIT-KERBEROS-5 - Kerberos-based authentication

Most systems use MIT-MAGIC-COOKIE-1, which stores authentication cookies in the .Xauthority file.

The .Xauthority File

This file contains authentication cookies for X11 connections:

The cookie is a 128-bit random value that both client and server must know.

Default Port Information

Default Port: 6000 (plus display number offset)

Reconnaissance & Enumeration

Port Scanning

Basic Nmap Scan

X11 Access Testing Script

Metasploit Scanner

Manual Connection Testing

Using xdpyinfo

Using xwininfo

Shodan Queries

Find exposed X11 servers on the internet:

Local Enumeration

Finding X11 Sessions

Check Active X Sessions

Identify Display Numbers

Finding .Xauthority Files

Extracting and Using Cookies

SSH X11 Forwarding Detection

Exploitation Techniques

1. Verify Anonymous Connection

Before exploitation, verify you can connect:

2. Screenshot Capture

Using xwd (X Window Dump)

Automated Screenshot Capture

Using import (ImageMagick)

3. Keylogger (Keystroke Capture)

Using xspy

Alternative: Using xinput

Using xev for Event Monitoring

Custom Python Keylogger

4. Remote Desktop Viewing

Using xrdp.py

Using xwatchwin for Live Monitoring

Manual Live Viewing with VNC

5. Command Execution

Using Metasploit

Manual Command Execution via xterm

Using xdotool for Command Simulation

Opening GUI Applications Remotely

6. Getting a Reverse Shell

Method 1: Via xrdp.py

Method 2: Via xterm

Method 3: Via Keyboard Simulation (MSF)

Method 4: X11 Forwarding Hijack

If user has SSH with X11 forwarding:

7. Clipboard Access

8. Screen Recording

Post-Exploitation

Privilege Escalation

Check for SUID Binaries in X Session

Check X11 Configuration Files

Check for Sensitive Data in X Sessions

Persistence

Add Startup Application

Modify .xinitrc or .xsession

X11 Port Forward Persistence

Lateral Movement

Enumerate Other X11 Sessions

Find .Xauthority Files of Other Users

SSH X11 Forwarding Pivot

Advanced Techniques

X11 + Docker Escape

If X11 socket is mounted in container:

X11 in Kubernetes

Wayland Security Bypass

Modern systems use Wayland instead of X11, but many still have X11 compatibility:

CVE Analysis: X11 Vulnerabilities

CVE-2020-14360 - X.Org Server Input Validation

CVE-2022-46340 - X Server DeepCopy Issues

Tools Reference

Essential X11 Pentesting Tools

  1. xdpyinfo - Display information utility

  2. xwininfo - Window information utility

  3. xwd - X Window dump (screenshots)

  4. xspy - Keystroke logger

  5. xwatchwin - Live desktop viewer

  6. xrdp.py - Remote desktop access

  7. xdotool - X11 automation

  8. xclip - Clipboard access

  9. xinput - Input device testing

  10. xev - Event monitor

Installation

Custom Scripts

Multi-Function X11 Exploit Script

Defense & Hardening

Disable X11 Network Listening

Method 1: Configure X Server Startup

Method 2: Firewall Rules

Method 3: X Server Configuration

Proper X11 Authentication

SSH X11 Forwarding Security

Monitor X11 Access Attempts

Using auditd

Using tcpdump

Log Analysis

Migrate to Wayland

Wayland is more secure than X11:

Security Best Practices

Detection & Incident Response

Detecting X11 Attacks

Network-Based Detection

Host-Based Detection

Signs of Compromise

  • Unknown xterm or GUI applications appearing

  • Unusual network connections to port 6000

  • Unexpected .Xauthority file modifications

  • Keyboard input lag or duplication

  • Screenshot files in /tmp

  • Unauthorized SSH X11 forwarding sessions

Incident Response Steps

Real-World Attack Scenarios

Scenario 1: Red Team Assessment

Goal: Access internal workstation via exposed X11

Scenario 2: Privilege Escalation

Goal: Escalate from low-privileged user to root via X11

Scenario 3: Persistence via X11

Goal: Maintain access after initial compromise

Scenario 4: Lateral Movement

Goal: Use X11 to move from one compromised host to another

Troubleshooting Common Issues

"No protocol specified" Error

"Connection refused" Error

Permission Issues

Display Not Found

Cheat Sheet

Quick Reference

Common Ports

  • 6000/tcp - X11 Display :0

  • 6001/tcp - X11 Display :1

  • 6002/tcp - X11 Display :2

  • 6010/tcp - SSH X11 Forwarding (typically)

Important Files

  • ~/.Xauthority - X11 authentication cookies

  • ~/.xinitrc - X session initialization script

  • ~/.xsession - Alternative session script

  • /tmp/.X11-unix/ - X11 socket directory

  • /etc/X11/Xwrapper.config - X wrapper configuration

  • /var/log/Xorg.0.log - X server log

Conclusion

X11, while providing powerful remote display capabilities, presents significant security risks when misconfigured. As a penetration tester, X11 access can provide:

  • Screenshot capture for sensitive information gathering

  • Keystroke logging for credential harvesting

  • Command execution for initial access

  • Reverse shells for persistent access

  • Lateral movement opportunities in enterprise networks

Key Takeaways:

  1. Always scan for exposed X11 services (port 6000+)

  2. Test for anonymous access before attempting auth bypass

  3. Screenshot capture is often the quickest win

  4. Keylogging can reveal passwords and sensitive data

  5. X11 can provide direct shell access on the target's display

  6. Proper defense requires disabling network listening (-nolisten tcp)

  7. Migrate to Wayland for better security

  8. Monitor for unauthorized X11 connections

  9. Restrict .Xauthority file permissions

  10. Use SSH X11 forwarding instead of direct access when possible

Remember that X11 exploitation should only be performed during authorized security assessments. Unauthorized access to systems is illegal and unethical.

Additional Resources

circle-check

Last updated