Linux
Below are the methods to escalate privileges in linux systems:
Environment Enumeration
# Current user
whoami
# Current user id
id
# Server name
hostname
# Kernal info
cat /etc/os-release
uname -a
# PATH variable
echo $PATH
# env variables
env
# CPU info
lscpu
# Available shells
cat /etc/shells
# Mounted drives and unmounted drives
cat /etc/fstab
df -h
at /etc/fstab | grep -v "#" | column -t # unmounted
# block devices on the system (hard disks, USB drives, optical drives, etc.)
lsblk
# Printers info
lpstat
# Network info
ifconfig
route
netstat -rn
arp -a
ip a
cat /etc/hostsGTFObinsis a platform that includes a list of binaries that can potentially be exploited to escalate our privileges on the target system.
We can use
straceto track and analyze system calls and signal processing.
Credential Hunting
Also check password cracking section
Wildcard and PATH Abuse
Wildcard and path abuse techniques exploit misconfigurations in file handling, especially in automated scripts.
Wildcard Abuse: Leverages
*or?in shell commands (e.g.,rm *) to inject malicious files like--execor-rffor command execution.Path Abuse: Manipulates the
PATHenvironment variable to execute malicious binaries instead of legitimate system commands.Both techniques can escalate privileges or achieve code execution if proper sanitization is missing.
Escaping Restricted Shells
A restricted shell is a type of shell that limits the user's ability to execute commands.
Examples:
rbash,rksh,rzshFollowing are methods to escape these shells:
If shell uses
envvariable to specify the directory in which commands are executed, it may be possible to escape from the shell by modifying the value of the environment variable to specify a different directory.Define and call shell functions that execute commands not restricted by the shell.
Special Permissions
The
Set User ID upon Execution (setuid)permission can allow a user to execute a program or script with the permissions of another user, typically with elevated privileges.The setuid bit appears as an
s.The
Set-Group-ID (setgid)permission is another special permission that allows us to run binaries as if we were part of the group that created them.
Find payloads here: GTFObins
Sudo Rights Abuse
Sudo privileges can be granted to an account, permitting the account to run certain commands in the context of the root (or another account) without having to change users or grant excessive privileges.
Any rights entries with the
NOPASSWDoption can be seen without entering a password.
Find payloads here: GTFObins
Privileged Groups
LXD
LXDis Ubuntu's container manager. Upon installation, all users are added to the LXD group.Membership of this group can be used to escalate privileges by creating an LXD container, making it privileged, and then accessing the host file system at
/mnt/root.
Docker
Placing a user in the docker group is essentially equivalent to root level access to the file system without requiring a password.
Members of the docker group can spawn new docker containers.
Once the container is started we are able to browse the mounted directory and retrieve or add SSH keys for the root user or read
/etc/shadowfile.
Disk
Users within the disk group have full access to any devices contained within
/dev, such as/dev/sda1, which is typically the main device used by the operating system.An attacker with these privileges can use
debugfsto access the entire file system with root level privileges.
ADM
Members of the adm group are able to read all logs stored in
/var/log.This does not directly grant root access, but could be leveraged to gather sensitive data stored in log files or enumerate user actions and running cron jobs.
Capabilities
Linux capabilities are a security feature in the Linux operating system that allows specific privileges to be granted to processes, allowing them to perform specific actions that would otherwise be restricted.
This allows for more fine-grained control over which processes have access to certain privileges, making it more secure than the traditional Unix model of granting privileges to users and groups.
Cronjobs
Logrotate
To exploit logrotate, we need some requirements that we have to fulfill.
We need write permissions on the log files
Logrotate must run as a privileged user or root
Vulnerable versions: 3.8.6, 3.11.0, 3.15.0, 3.18.0
Passive Traffic Capture
Using PCredz to capture credentials over the wire
Using net-creds
Weak NFS Permissions
We can create a
SETUIDbinary that executes/bin/shusing our local root user.We can then mount the /tmp directory locally, copy the
root-ownedbinary over to the NFS server, and set theSUIDbit.
Vulnerable to this attack
*(rw,no_root_squash)
Hijacking Tmux Sessions
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.
Below attacks when you have a setuid binary or sudo right to run a binary.
Shared Libraries
We can utilize the LD_PRELOAD environment variable to escalate privileges. For this, we need a user with sudo privileges.
If we can restart a service or run a binary with root privileges we can exploit it.
Compile it and get root.
Shared Object Hijacking
Check for any non-standard library.
It is possible to load shared libraries from custom locations.
One such setting is the
RUNPATHconfiguration. Libraries in this folder are given preference over other folders.
The configuration allows the loading of libraries from the /abc folder. If it is writable by us, this misconfiguration can be exploited by placing a malicious library in /abc, which will take precedence over other folders because entries in this file are checked first.
Run the binary, generate an error and check which function it is calling from the custom library.
Compile the library
Python Library Hijcking
Wrong Write Permissions
If we have a script with setuid and have
readprivileges on it.We can check if we have
writepermissions on any module used in it.
If we can write, add reverse shell code into it.
Library Path
In Python, each version has a specified order in which libraries (modules) are searched and imported from.
The order in which Python imports modules from are based on a priority system.
To be able to exploit this, two prerequisites are necessary. -The module that is imported by the script is located under one of the lower priority paths listed via the
PYTHONPATHvariable.We must have write permissions to one of the paths having a higher priority on the list.
Create a file with the same name as the library file with reverse shell code.
PYTHONPATH Environment Variable
PYTHONPATHis an environment variable that indicates what directory (or directories) Python can search for modules to import.This is important as if a user is allowed to manipulate and set this variable while running the python binary, they can effectively redirect Python's search functionality to a user-defined location when it comes time to import modules.
We can see if we have the permissions to set environment variables for the python binary by checking our sudo permissions:
Create a file with the same name as the library file with reverse shell code in /tmp.
Other things to check
Kernal Exploits
Sudo version exploit (eg: sudo -u#-1 id)
Dirty Pipe
Dirt Cow
Polkit (pkexec, pkaction, pkcheck)
Netfilter
Last updated