Linux Privilege Escalation - Open Shell Sessions for CTF Creators
Open Shell Sessions
A terminal session represents an interaction with a terminal for software or an operating system. In UNIX systems, these sessions are stored as socket files and character files. If a terminal session has read, write, and execute permissions, it is possible to attach to the session. Programs such as GNU screen and tmux facilitate the management of terminal sessions and are known as terminal multiplexers.
Privilege Escalation via Screen
List the screen sessions directory recursively:
|
|
Change the group of the directory to your group recursively:
|
|
Add read, write, and execute permissions to your group recursively:
|
|
As we can see below the GNU screen program is aware of this misconfiguration so it doesn’t let we create this privilege escalation attack vector:
|
|
Change the permissions to the one that it must have:
|
|
If we try to add read, write, and execute permissions to the session file:
|
|
We can see that the file is not found:
|
|
The only way as of this year (2021) to escalate privileges with GNU Screen
is by using an old version or vulnerable version like GNU Screen 4.5.0 - Local Privilege Escalation.
Privilege Escalation via Tmux
Let’s create a scenario where the current session is misconfigured, startup by creating a shared session, this is done by creating a socket file:
|
|
Then create a new terminal window or tab and change the group of the shared socket file to a group that we belong:
|
|
If we can compromise a user in the user
group, we can attach to this session and gain root access. Since the owner of the socket file is root and the user we compromised is in the group user
:
|
|
Review our group membership with the id
command or the groups
commands, I’m going to execute both commands:
|
|
As we can see above, we’re in the user
group and the user
group has read, write, and execute permission in the shared socket session file. Because of this misconfiguration, we can attach to the tmux
session.
|
|
Confirm the root privileges with id
command to see the uid
or we can use the whoami
command to print the euid
. The important thing here is that either or both the uid
or the euid
is 0
(root):
|
|
In old versions of tmux
, we could attach to any session so if you’re in a system with an old tmux version running it is worth a try to attach to that session.