Post

Instant Write Up

Pic

Reconnaissance

As always, we are going to start with a port scan to see which ports are opened and what services are running. To do that we are going to use nmap:

1
nmap -p- --open -sS --min-rate 5000 -n -v -Pn -oN IScan 10.10.11.37

Pic

Now we want to know the version of the services running, to see if we can take advantage of it.

1
nmap -sCV -p 22,80 10.10.11.37 -oN SScan

Pic

As we can see in the picture, the web is trying to redirect us to instant.htb, so we have to add it to the /etc/hosts file.

Once done, we can access to the web and we can see that the web addresses of an android application to manage money. We can download it to test in our machine.

Pic

An apk is nothing more than a compressed file, so we can list its content and move between its files. To do this we can use apktool.

1
2
7z l instant.apk
apktool d instant.apk

If we search recursively for “instant” or “intant.htb” we will find two subdomains.

1
grep -ri "instant.htb" .

Pic

Once we discover all the available subdomains, in this case mywalletv1 and swagger-ui, we can add them to the /etc/hosts file to see what its all about.

In the other hand, if we search for filenames containing the “admin” word we will find two files, and in one of them, a JWT.

1
find . -type f -iname '*admin*'

Pic

The swagger-ui site looks like the documentation of an api being used by the web application. After trying the different options it gives to us I found one that looks usefull, logs. Maybe we can read files from the machine using this utility.

Pic

If we try to read the example file, it will display a error message saying: Unauthorized, but if we add to the request the JWT that we found in the apk it will work.

Pic

Explotation

If we try to read other internal files, it won’t work, but if we try it doing a Directory Path Traversal and we try to read files like /etc/passwd it will work.

Pic

We also have access to the id_rsa of the shirohige user, so we can connect to the machine.

Pic

Privilege Escalation

Once connected, after enumerating for a while we find a weird file in /opt/backup/Solar-Putty/ called sessions-backup.dat, which looks encrypted.

Pic

After a small search we find a tool that decrypts it.

Pic

This tool will try to crack the password and show us the content but our file has not set a password so it will display its content.

Pic

Once we get the root’s password in plain text we can run this:

1
2
su root
password:

Pic

Reconocimiento

Como siempre, empezaremos lanzando un escaner de puertos para ver cuáles están abiertos y qué servicios están corriendo en ellos. Para ello usaremos nmap:

1
nmap -p- --open -sS --min-rate 5000 -n -v -Pn -oN IScan 10.10.11.37
  •    -p-   Indica todo el rango de puertos (1-65535)
  •    –open  Únicamente muestra los puertos abiertos
  •    -sS  Hace un escaneo “SYN”, más sigiloso
  •    –min-rate 5000  Envía paquetes no más lentos de los indicados
  •    -n  No aplica resolución DNS
  •    -v  Muestra lo que encuentra en tiempo real (verbose)
  •     -Pn  Da por hecho que los hosts están activos
  •     -oN IScan  Guarda el output en el formato mostrado, en ese archivo

Pic

Ahora nos interesa saber qué versiones tienen estos servicios, por si podemos aprovecharnos de alguno.

1
nmap -sCV -p 22,80 10.10.11.37 -oN SScan
  •    -sCV  Comprueba la versión y prueba unos scripts de reconocimiento
  •    -p  Indica los puertos a escanear

Pic

Como vemos en la imagen, la web nos intenta redirigir a instant.htb, por lo que lo añadiremos al archivo /etc/hosts.

Una vez en la web vemos que se trata de una aplicación para Android para temas fiscales. Si nos descargamos la aplicación podemos tratar de enumerarla.

Pic

Una apk no es más que un archivo comprimido, por lo que podemos listar su contenido y “descomprimirlo” en busca de información. Para esto último usaremos apktool.

1
2
7z l instant.apk
apktool d instant.apk

Si buscamos de forma recursiva por la cadena “insant” o “instant.htb” podemos encontrar subdominios como se muestra en la siguiente imagen.

1
grep -ri "instant.htb" .

Pic

Una vez identificados todos los subdominios, en este caso mywalletv1 y swagger-ui, podemos añadirlos al /etc/hosts y ver de qué se trata.

Por otra parte, si buscamos en la apk por el nombre de algún archivo que contenga la palabra “admin” encontraremos dos archivos y, en uno de ellos, un JWT.

1
find . -type f -iname '*admin*'

Pic

El sitio swagger-ui parece documentar el uso de la API de la aplicación web. Tras probar distintas opciones hay una que me llama la atención, Logs. Parece ser que se pueden leer archivos internos de la máquina asi que vamos a probar esta función.

Pic

Si tratamos de leer los archivos de ejemplo, nos saldrá el mensaje de “Unauthorized” pero si añadimos el JWT que encontramos en la apk funcionará sin problemas.

Pic

Explotación

Podemos intentar leer otros archivos pero no funciona, si hacemos un Directory Path Traversal y probamos rutas como el /etc/passwd vemos que podemos llegar a leer archivos internos de la máquina.

Pic

Tenemos acceso a la id_rsa del usuario shirohige por lo que podemos conectarnos a la máquina con sus credenciales.

Pic

Escalada de Privilegios

Una vez conectados, si enumeramos la máquina encontraremos en el directorio /opt/backup/Solar-Putty un archivo llamado sessions-backup.dat el cual parece estar encriptado.

Pic

Con una rápida búsqueda en google encontramos una herramienta capaz de desencriptar su contenido.

Pic

Esta herramienta tratará de crackear la contraseña del archivo aunque en nuestra caso, no tenga contraseña.

Pic

Y una vez obtengamos la contraseña de root en texto plano, nos conectamos

Pic

This post is licensed under CC BY 4.0 by the author.