> For the complete documentation index, see [llms.txt](https://angellm.gitbook.io/hacknotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://angellm.gitbook.io/hacknotes/thm/2022/tomghost.md).

# TomGhost

## tomghost CTF - Writeup

Are you able to complete the challenge?

**Date**: 24/03/2022

**Difficulty**: Medium

**CTF**: <https://tryhackme.com/room/tomghost>

## Compromise this machine and obtain user.txt

First of all, let’s do a quick scan of the open ports of the target:

<figure><img src="/files/FU6ghXAIk78T5mzp7GXb" alt=""><figcaption></figcaption></figure>

Nmap discovers 4 open ports: 22, 53, 8009 and 8080 let’s do a proper scan to those ports:

<figure><img src="/files/9zClTAFxap4TcCLLPVaW" alt=""><figcaption></figcaption></figure>

Let’s see if there is anything in the port 8080 we can view using the web browser:

<figure><img src="/files/XFbszRXdzziaOdCGF7Pl" alt=""><figcaption></figcaption></figure>

So, it seems like the owner of the target system has been installed tomcat recently. The version installed is the 9.0.30. Let’s see if we find any vulnerability that allow us to exploit the target.

<figure><img src="/files/Fbh2wgffZo95bWvUT0O2" alt=""><figcaption></figcaption></figure>

As we can see in the fixes of newer versions of Tomcat, there were some important vulnerabilities with the version 9.0.3. Let’s check exploit database to see if there is any exploit we can use.

Looking for the CVE-2020-1938 a exploit appears:

<figure><img src="/files/cqoPh3moUbmhT90xgv2z" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/NxI72qE4W7xiUJYcAXBv" alt=""><figcaption></figcaption></figure>

Let’s use it with msfconsole:

<figure><img src="/files/ILPfRnBNWRmQsx5JCXSB" alt=""><figcaption></figcaption></figure>

Let’s configure it:

<figure><img src="/files/aHuh95iJtOqE6ONbRuKH" alt=""><figcaption></figcaption></figure>

The RHOSTS parameter is the IP adress of the target, but I’m not sure about the File name, so I’ll keep it as it is and try once:

<figure><img src="/files/JlFyFE6rCKWAXp1Oi0zu" alt=""><figcaption></figcaption></figure>

How lucky! We obtained what it looks like a username and a password hash! Let’s try to crack it using John The Ripper! But first, we should discover in which format has the password been hashed:

<figure><img src="/files/lcKhcCXziqqLMOqsH7tW" alt=""><figcaption></figcaption></figure>

Strange, I supposed it to be a password hashed, not a password in plain text... In the first scan we have seen that there is a ssh service open, let’s try to log in with this credentials:

<figure><img src="/files/yVRAFzcfC9yUHFs35Jsm" alt=""><figcaption></figcaption></figure>

Woah, it worked... Let’s look around for the user.txt file

<figure><img src="/files/FvEofHZqLxDnJGyeUror" alt=""><figcaption></figcaption></figure>

It catched my eye the .asc and .pgp files

<figure><img src="/files/OdYyXNoW3aLpz4IcDQzQ" alt=""><figcaption></figcaption></figure>

Let’s see if we can use the tryhackme.asc key to de-encrypt the credential.pgp file:

<figure><img src="/files/kRIGXifs2pXVIX9p9YZm" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/2lFkWRL0Ed4c0nytxtiu" alt=""><figcaption></figcaption></figure>

The key has a password, let’s transfer the key file to our machine and try to crac;k the password using John The Ripper:

<figure><img src="/files/2r54rBvQcvV7nU5dYYTh" alt=""><figcaption></figcaption></figure>

Before trying to crack it with John The Ripper we have to convert the file using `gpg2john`

<figure><img src="/files/aZNifWUm3FCo0n5q51cX" alt=""><figcaption></figcaption></figure>

And then, let’s try to crack it!

<figure><img src="/files/bpPhxNknoRrmPMr4ahkz" alt=""><figcaption></figcaption></figure>

We got the password in no time. Let’s go back and try to find the user.txt file first:

<figure><img src="/files/E70NUfLv6pt4NOlM1Zrv" alt=""><figcaption></figcaption></figure>

Let’s see if we can read it with the current user:

<figure><img src="/files/YA3QbBErBjGFPVzr2CYs" alt=""><figcaption></figcaption></figure>

Yes, we can and that’s how we get the first flag of this CTF.

## Escalate privileges and obtain root.txt

It’s unlikely, but let’s see if we can find the root.txt file with the current user:

<figure><img src="/files/LDv2NjIXBUNtkwlsxEmm" alt=""><figcaption></figcaption></figure>

Nope, let’s de-encrypt the credential.gpg file:

<figure><img src="/files/YLsqFa6JYl3AXhOSElfM" alt=""><figcaption></figcaption></figure>

we got what it looks like a username and password again? Let’s try to switch to that user:

<figure><img src="/files/YplTeQJqnkwzncN6UB3A" alt=""><figcaption></figcaption></figure>

We can’t, I double checked. It would be the ssh password? Let’s try:

<figure><img src="/files/nBkw0RNv5Cv4HG5IqSxW" alt=""><figcaption></figcaption></figure>

It is. Let’s see if this user has permissions to read the /root folder:

<figure><img src="/files/IqoU1oxSjY7DEEGYl7xL" alt=""><figcaption></figcaption></figure>

Nope... So we have to do more privesc. Let’s see if this user can run sudo commands:

<figure><img src="/files/ltfKJLPrwyjBS6DRgETK" alt=""><figcaption></figcaption></figure>

Niiice, so we can run zip as root! This is exploitable for sure, let’s check it out at GTFOBins:

<figure><img src="/files/LJj9LdyR8CKX3ZBeshUY" alt=""><figcaption></figcaption></figure>

Let’s try it!

<figure><img src="/files/nG3tDOpUO7cnGtZRYnrS" alt=""><figcaption></figcaption></figure>

It worked! Let’s find the root flag!

<figure><img src="/files/MqQMkxAvtBVWaoBgW2lv" alt=""><figcaption></figcaption></figure>

And that’s it! I’ve been lucky finding the sudo permission at first try!
