Skip to content

Commit 53d877e

Browse files
committed
HTB Yummy update
1 parent aaf4298 commit 53d877e

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

_posts/2025-02-21-htb-yummy.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ toc: true
99
header:
1010
teaser: "/assets/images/headers/Yummy.png"
1111
---
12-
"Yummy" is a hard Linux machine that starts off by finding a Local File Inclusion (LFI) vulnerability in order to find several cron job scripts. These scripts lead to a database backup script of the website's source code that leaks a secret JWT key to forge a token for the admin account on the site. The backend is vulnerable to SQL injection that gives us initial access to the machine. Further enumeration reveals the password for another user that can run a command as another user to move laterally to a developer account. This account can run `rsync` as root, which allows us to copy the root user's SSH key.
12+
Yummy is a hard box that starts with a Restaurant web app using Caddy web service, on port 80, where an attacker finds an arbitrary file read HTTP Location header, which is not handled and sanitized properly by the default Caddy configuration. This allows an attacker to find several `cronjob` scripts that allow downloading the web app source code. Reading the source code, the web app uses JWT RSA keypairs to forge an admin token and escalate privileges on the web app. The admin panel has an SQL injection, allowing arbitrary file write over a file running periodically (`cronjob`). Improper directory permissions allow the attacker to move laterally to `www-data` and eventually a `dev` user. The `dev` user can execute `rsync` binary as root, which helps escalate privileges to root.
1313

1414
# Reconnaissance
15-
Our initial port scan only shows two standard ports open, 22 and 80.
15+
Our initial port scan only shows two ports open: SSH on port 22 and a web server on port 80. By looking at the `http-server-header`, we identify that the server is running Caddy as a reverse proxy.
1616

1717
```
1818
# Nmap 7.94SVN scan initiated Sun Oct 6 14:04:12 2024 as: nmap -p- -sCV -v -oN yummy.nmap 10.129.74.97
@@ -32,15 +32,17 @@ PORT STATE SERVICE VERSION
3232
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
3333
```
3434

35-
Navigating to the website redirects us to `yummy.htb` and also displays that the version in use is **Caddy**. We add this domain to the `/etc/hosts` file and continue to explore the webpages. After creating an account and logging in, we can make a reservation.
35+
Navigating to the website redirects us to `yummy.htb`. We add this domain to the `/etc/hosts` file and continue to explore the webpages. The website is hosting a restaurant application to manage appointments and reservations. After creating an account and logging in, we can make a new reservation.
3636

3737
![](../assets/images/writeups/yummy/booking.png)
3838

3939
From our dashboard, it is possible to save our reservation to a calendar file (ics) via the `save iCalendar` option.
4040

4141
![](../assets/images/writeups/yummy/save-icalendar.png)
4242

43-
The request makes a call to the `/export/Yummy_reservation_YYYYMMDD_hhmmss` endpoint where the date is the current timestamp of the export. This endpoint is vulnerable to LFI and we can alter the request to read arbitrary files as the `www-data` user.
43+
The request makes a call to the `/export/Yummy_reservation_YYYYMMDD_hhmmss` endpoint where the date is the current timestamp of the export. This endpoint is vulnerable to LFI and we can alter the request to read arbitrary files as the `www-data` user. Another thing to notice is that the cookie uses a JWT token which can be decoded with tools like [CyberChef](https://gchq.github.io/CyberChef/) or [jwt.io](https://jwt.io/). Decoding the token, there's a role `customer` and fields `e` and `n` are specified, which are essential encryption exponent and modulus respectively.
44+
45+
Manipulating the GET request to `/export/../../etc/passwd` gives us Arbitrary File Read.
4446

4547
![](../assets/images/writeups/yummy/LFI.png)
4648

@@ -75,11 +77,12 @@ cd /var/www
7577
/usr/bin/zip -r backupapp.zip /opt/app
7678
```
7779

78-
This zip file is a backup of the original source code located in `/opt/app`. After downloading the zip and extracting it, we have the application's source code.
80+
We can download the backed-up file from `/var/www/backupapp.zip`. This zip file is a backup of the original source code located in `/opt/app`. Once unzipped, we can view the content of `app.py`.
7981

8082
![](../assets/images/writeups/yummy/backup.png)
8183

82-
We can proceed to do some code analysis and see if we can spot additional vulnerabilities or credentials. The login method in `app.py` looks interesting.
84+
We can proceed to do some code analysis and see if we can spot additional vulnerabilities or credentials. The login method in `app.py` looks interesting. The pair of RSA keys are generated in the `config/signature.py`. The validation is done in the
85+
`middleware/verification.py`.
8386

8487
```python
8588
if user:
@@ -154,7 +157,7 @@ Let's perform a search query on the admin dashboard and intercept the request wi
154157

155158
By using SQLMap we can check our user privileges:
156159

157-
```bash
160+
```console
158161
$ sqlmap -r request --privileges
159162

160163
[15:27:11] [INFO] retrieved: 'FILE'
@@ -214,7 +217,7 @@ write_file "" "/data/scripts/dbstatus.json"
214217

215218
We start a netcat listener on port 9001, run the above script and after a minute we should have received a connection back to our machine.
216219

217-
```bash
220+
```console
218221
$ nc -nvlp 9001
219222
mysql@yummy:/var/spool/cron$
220223
```
@@ -247,8 +250,8 @@ www-data@yummy:~/app-qatesting/.hg/store/data$ strings app.py.i
247250

248251
We can now SSH as `qa`.
249252

250-
```bash
251-
ssh qa@yummy.htb
253+
```console
254+
$ ssh qa@yummy.htb
252255
qa@yummy:~$ cat user.txt
253256
```
254257

@@ -306,7 +309,7 @@ The key element is the `--chmod` flag of the rsync binary. This additional param
306309

307310
```console
308311
$ chmod 600 id_rsa
309-
$ shh -i id_rsa root@yummy.htb
312+
$ ssh -i id_rsa root@yummy.htb
310313
root@yummy:~# id
311314
uid=0(root) gid=0(root) groups=0(root)
312315
root@yummy:~# cat root.txt

0 commit comments

Comments
 (0)