Hijacking Tmux Sessions
Terminal multiplexers such asΒ tmuxΒ can be used to allow multiple terminal sessions to be accessed within a single console session.
For many reasons, a user may leave aΒ tmuxΒ process running as a privileged user, such as root set up with weak permissions, and can be hijacked. This may be done with the following commands to create a new shared session and modify the ownership.
π οΈ Step-by-Step Breakdown of the Attack
The first two steps are not the attack, but the conditions that posibilitates the attack.
1οΈβ£ tmux is Started as Root with a Shared Socket
- This command creates a new tmux session named
debugsess. - The
-S /sharedsoption sets up a custom Unix domain socket at/sharedsinstead of the default/tmp/tmux-<uid>/. - Since the user running the command is root, the session runs with root privileges.
2οΈβ£ Changing Ownership of the tmux Socket File
- This changes the ownership of the tmux socket (
/shareds) to:- User:
root - Group:
devs
- User:
- The group
devsnow has access to attach to the session.
3οΈβ£ Attacker Checks for Running tmux Sessions
- This command lists all running processes that contain "tmux."
- The attacker sees:
- Key takeaways:
- The
tmuxsession is running as root. - The socket file is located at
/shareds.
- The
4οΈβ£ Checking Permissions on the tmux Socket
- Output:
- Breakdown of permissions (
srw-rw----):sβ Socket file.rw- rw- ---β Owner (root) and group (devs) can read/write to it.---β Other users cannot access it.
π΄ Dangerous Misconfiguration!
- Any user in the
devsgroup can attach to this session. - Since the session is running as root, attaching grants full root access.
5οΈβ£ Attacker Confirms Group Membership
- Output:
- The attacker (
htb) is part of thedevsgroup, meaning they have access to the/sharedssocket.
6οΈβ£ Attacker Hijacks the Root tmux Session
- The attacker attaches to the existing root session.
Once inside, they run:
- Output:
β The attacker now has a full root shell! π
Summary
- Flaw: Root starts a shared tmux session with weak permissions (
root:devs). - Attack: Attacker, part of
devs, attaches to the session and gets a root shell. - Fix: Restrict access to the tmux socket file (
chmod 600 /shareds) and avoid assigning sensitive groups.