$ nmap -p- --min-rate 5000 10.129.71.62
Starting Nmap 7.93 ( https://nmap.org ) at 2023-05-07 08:03 EDT
Nmap scan report for 10.129.71.62
Host is up (0.0068s latency).
Not shown: 65532 closed tcp ports (conn-refused)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
3000/tcp open ppp
DumbDocs -> Code Analysis
Port 80 was some kind of documentation website.
This box uses JWT Tokens and an API to create new users and login. The API is hosted on port 3000. We can actually download all the source code and view the files within:
Since this is a JWT related challenge, the main goal here is to spoof some token by leaking the secret access token somehow. We can first enumerate the .git repository by finding the token secret.
Great! Now we can spoof tokens easily. Now let's look at the source code. Within the /routes/private.js, there's a vulnerable function:
The /logs endpoint takes the filename and passes it to exec without sanitisation. This means that this is vulnerable to RCE.
Token Spoof -> RCE
Now that we can spoof tokens and we found our RCE point, we can exploit this system. First, let's create a new user and then get the token:
They used apport-unpack to unpack the file and read it. We can do so with our crash file here:
When we use strings on the CoreDump file, we can find the root flag:
It seems that because we are running the count binary as root and we crash the program while reading the file, the file contents is still in memory. When the CoreDump file is created, the contents of memory is still present.
We can repeat these steps to read the id_rsa file of root.
$ ls
index.js node_modules package-lock.json routes validations.js
model package.json public src
$ ls -la
total 116
drwxr-xr-x 8 kali kali 4096 May 11 2022 .
drwxr-xr-x 3 kali kali 4096 May 11 2022 ..
-rwxrwxrwx 1 kali kali 72 May 11 2022 .env
drwxr-xr-x 8 kali kali 4096 May 11 2022 .git
-rwxrwxrwx 1 kali kali 885 May 11 2022 index.js
drwxr-xr-x 2 kali kali 4096 May 11 2022 model
drwxr-xr-x 201 kali kali 4096 May 11 2022 node_modules
-rwxrwxrwx 1 kali kali 491 May 11 2022 package.json
-rwxrwxrwx 1 kali kali 69452 May 11 2022 package-lock.json
drwxr-xr-x 4 kali kali 4096 May 11 2022 public
drwxr-xr-x 2 kali kali 4096 May 11 2022 routes
drwxr-xr-x 4 kali kali 4096 May 11 2022 src
-rwxrwxrwx 1 kali kali 651 May 11 2022 validations.js