This machine is from the TJ Null list for the OSCP box. This room involved the following steps.

  • Enumerating HTTP to find the Command Injection
  • Finding a hidden password in source code
  • Bruteforcing with hydra
  • Generating a password list for a user to bruteforce

First, as always let’s start with the autorecon scan. Quick Initial Nmap scan results are as below.

Scanned at 2022-03-31 03:36:27 EDT for 38s
Not shown: 996 closed tcp ports (reset)
PORT     STATE SERVICE REASON         VERSION
21/tcp   open  ftp     syn-ack ttl 64 vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| -rw-r--r--    1 0        0              42 Aug 22  2017 FLAG.txt
|_drwxr-xr-x    2 0        0               6 Feb 12  2017 pub
22/tcp   open  ssh?    syn-ack ttl 64
| fingerprint-strings: 
|   NULL: 
|_    Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)
|_ssh-hostkey: ERROR: Script execution failed (use -d to debug)
80/tcp   open  http    syn-ack ttl 64 Apache httpd 2.4.27 ((Fedora))
|_http-title: Morty's Website
| http-methods: 
|   Supported Methods: POST OPTIONS HEAD GET TRACE
|_  Potentially risky methods: TRACE
|_http-server-header: Apache/2.4.27 (Fedora)
9090/tcp open  http    syn-ack ttl 64 Cockpit web service 161 or earlier
|_http-title: Did not follow redirect to https://10.0.0.7:9090/
| http-methods: 
|_  Supported Methods: GET HEAD
Uptime guess: 13.065 days (since Fri Mar 18 02:03:17 2022)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=262 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT     ADDRESS
1   0.35 ms 10.0.0.7

Although the quick Nmap only show 4 open ports full Nmap scan shows 7 open ports, and they are:

21/tcp    open  ftp     syn-ack ttl 64 vsftpd 3.0.3
22/tcp    open  ssh?    syn-ack ttl 64
80/tcp    open  http    syn-ack ttl 64 Apache httpd 2.4.27
9090/tcp  open  http    syn-ack ttl 64 Cockpit web service
13337/tcp open  unknown syn-ack ttl 64
22222/tcp open  ssh     syn-ack ttl 64 OpenSSH 7.5
60000/tcp open  unknown syn-ack ttl 64

Feroxbuster scan shows that there is a passwords directory. When we open that directory we can see passwords.html. Although there was no password there, when we check the source code we can see the password winter.

Enumerating further in HTTP takes us to robots.txt, where we find /cgi-bin/tracertool.cgi. It turns out to be the traceroute command query. I think we can perform command injection here.

Leveraging the command injection I was able to find the users list from /etc/passwd file. Using cat will show as ASCII cat so I used less /etc/passwd to view the file.

We can use hydra to brute-force some of the open port services as we have a username list and a password winter. I tried brute-forcing ssh and was successful. We find Summer has the password of winter. How nice!

Summer has access to the home folder of other Morty as well. Inside Morty’s home folder, we can see Safe_Password.jpg and journal.txt.zip. The zip file is password protected and the password is hidden inside the image.

Inside journal.txt we find another juicy detail and most likely password for something.

Inside RickSanchez’s home folder we find RICKS_SAFE. I think this is the folder that Morty was talking about in the journal.

Summer doesn’t have the execute permission for safe but has read permission. We can copy safe to our directory and try to execute it with the password from journal.txt

Now we need to generate the password for Rick using the requirements mentioned in the safes executable. The band name of Ricky is “The Flesh Curtains”. I used the following python script to create a passwords list.

import string
from sys import argv
openfile = open(argv[1],'a')
b = list(range(10))
a = string.ascii_uppercase

for al in a:
    for num in b:
        pass1 = al + str(num) + "The\n"
        pass2 = al + str(num) + "Flesh\n"
        pass3 = al + str(num) + "Curtains\n"
        openfile.write(pass1)
        openfile.write(pass2)
        openfile.write(pass3)

openfile.close()

Now let’s try to brute-force ssh using hydra. The password is P7Curtains.

So, user RickSanchez can run all sudo commands in the system.

We have successfully rooted the system and the whole process was so fun.