Jack-of-All-Trades

Jack-of-All-Trades

Room link: https://tryhackme.com/room/jackofalltrades

Scanning

Like I always do, I started with an aggressive NMAP scan using -A.

ajread@aj-ubuntu:~/TryHackMe$ nmap -A [Remote IP]
Starting Nmap 7.80 ( https://nmap.org ) at 2022-02-21 09:38 EST
Nmap scan report for [Remote IP]
Host is up (0.092s latency).
Not shown: 998 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  http    Apache httpd 2.4.10 ((Debian))
|_http-server-header: Apache/2.4.10 (Debian)
|_http-title: Jack-of-all-trades!
|_ssh-hostkey: ERROR: Script execution failed (use -d to debug)
80/tcp open  ssh     OpenSSH 6.7p1 Debian 5 (protocol 2.0)
| ssh-hostkey: 
|   1024 13:b7:f0:a1:14:e2:d3:25:40:ff:4b:94:60:c5:00:3d (DSA)
|   2048 91:0c:d6:43:d9:40:c3:88:b1:be:35:0b:bc:b9:90:88 (RSA)
|   256 a3:fb:09:fb:50:80:71:8f:93:1f:8d:43:97:1e:dc:ab (ECDSA)
|_  256 65:21:e7:4e:7c:5a:e7:bc:c6:ff:68:ca:f1:cb:75:e3 (ED25519)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 43.81 seconds

Enumeration

It appeared the only services running were SSH and HTTP, but they had switched ports! When I tried to navigate to the http service hosted on port 22, Firefox gave me an error: This address is restricted. Doing some outside research, it appeared that Firefox did not allow network connections on restricted ports like 22. Within Firefox's settings there was a network.security.ports.banned.override preference which can be changed to allow connections on restricted ports like 22. According to Mozilla's documentation,"Ports are used when any program accesses the Internet so that the system can keep separate applications' data separate. Some port numbers are reserved for functions such as e-mail or FTP. To prevent potential security risks if a protocol was allowed access a port reserved for a seperate protocol, Gecko applications contain a list of banned ports. This preference allows you to unban a port banned by default and therefore prevent the "Access to the port number given has been disabled for security reasons." or "This address uses a network port which is normally used for purposes other than Web browsing. Firefox has canceled the request for your protection." messages. " I used this site to change the preference: https://www.specialagentsqueaky.com/blog-post/r5iwj96j/2012-02-20-how-to-remove-firefoxs-this-address-is-restricted/.

Now with the ability to connect to the site, there was a base64 string within the html that hinted at some credentials to be used at /recovery.php.

Converting the string base64, it provided a password that can be used somewhere. There was no clear username though.

I also ran gobuster to see if there was anything else of interest on the http service. It didnt appear so.

Initial Access

I accessed the /recovery.php directory and found a basic login screen. I tried the user:password credentials that were found in the homepage. But, I was not able to authenticate. When I curl'd the /recovery.php page, it provided an interesting encoded string.

Dropping the string into cyberchef (https://gchq.github.io/CyberChef/), it automatically detected the string was base32. However, I needed to do some manual testing to find it was both base32 encoded and ROT13 encoded. The decoded string pointed to credentials that were stored on the homepage with a hint.

Based on the hint, the credentials must be stored within one of the jpg images located on the site using steganography. I downloaded all 3 images and ran steghide on each. The header appeared to be the image with the credentials stored, called cms.creds, within. For steghide (http://steghide.sourceforge.net/documentation/manpage.php), I used the password found on the homepage as the passphrase.

With the credentials, I went back to the recovery page to login. Out of curiosity, I also tried to ssh with the user credentials and was unsuccessful.

After I logged in, I was prompted with a page that only says: GET me a 'cmd' and I'll run it for you Future-Jack.. Could this site be vulnerable to directory traversal and code injection? Could it be?? It looked like I had to use some cmd= within the url to navigate around the machine. I first ran http://[REDACTED]:22/nnxhweOV/index.php?cmd=id to test directory traversal/code injection and it worked!

I needed to move over to user jack in order to get the first flag. I looked around on the site to see if there are any credentials hidden anywhere for jack. There appeared to be none. When I moved over to the /home directory of the machine using http://[REDACTED]:22/nnxhweOV/index.php?cmd=cd /home;ls I found something interesting: a file named jacks_password_list. Maybe these are possible passwords for user jack?

I copied the list of passwords over to a txt file named passlist.txt and ran hydra from my local machine to try to brute force jack's ssh password.

I got creds!

There was a user.jpg file within the home directory of jack. I wanted to look at the jpg on my local machine so I copied it over using SCP (https://linuxize.com/post/how-to-use-scp-command-to-securely-transfer-files/), which is a nice tool if you have credentials and can use SSH.

The jpg was a recipe for Penguin Soup with one of the ingredients being the user flag!

Privilege Escalation

I checked to see if jack could run any commands as sudo.

It appeared not. The next step was to get for easy SUID bits.

Great! It looked like strings was able to be run as root (/usr/bin/strings).

And found the root flag!

Last updated