HTB{Brainfuck}
by yunaranyancat
Box introduction
Requirements
Basic Linux command
Basic Python
WordPress Framework
Basic Cryptography
Enumeration
First, by running nmap scan, we will find the version of the services on the common ports that are open.
So, there are 5 open ports which are;
Ports:Service
` 22:ftp `
` 25:ssh `
` 110:smb`
` 143:smb`
` 443:ssl/http`
It seems that the web port of the target is open, and we will focus on web based attacks first if possible.
Enumerating HTTPS/SSL
When we browse to the web page at https://10.10.10.17
, we have been prompted by a certificate error.
In the error information, we found another domain names which are www.brainfuck.htb
and sup3rs3cr3t.brainfuck.htb
.
So, we can add these domain names to our \etc\hosts
file, simply add
10.10.10.17 www.brainfuck.htb sup3rs3cr3t.brainfuck.htb
.
Then, accept the certificate. After that, we can browse through these sites.
Enumerating WordPress (www.brainfuck.htb)
We are then prompted to a WordPress webpage. A quick glance already give us possible credentials.
orestis@brainfuck.htb
We first will use wpscan
on the site to find any known vulnerabilities. Type,
` wpscan –url https://brainfuck.htb/ –disable-tls-checks ` .
After, we found out there are lots of vulnerabilities in the site. So, where should we start? Okay, here’s one trick that can be used(not guaranteed 100%). We will choose the vulnerabilities that only have been documented by exploitdb
. Using this way, we also can read exploits from searchsploit
and just maybe, we might get the exploit working.
So, we found there is a WP Support Plus vulnerabilities that has exploitdb
documentation. So, we can type searchsploit WP Support Plus
and read the exploits/reports.
Okay, we got three exploits. But, we will discard the first one as it’s version is older than what we currently dealing with.
Exploitation
Let’s read the first exploits. ( cat /usr/share/exploitdb/exploits/php/webapps/41006.txt
)
It seems that we can exploit the usage of wp_set_auth_cookie()
and login as anyone. We also got the Proof Of Concept. Let’s try this one. But first, we need to get users information. So, we will run wpscan --url https://brainfuck.htb/ --disable-tls-checks --enumerate u
.
Using the information above, we can guess that orestis
might be an admin
.
We then copy the POC then put it in an empty html file. Edit the url and add other information and we will have something like this.
So, we are currently trying to get admin
access on the WordPress page. Load up our simple python server by executing
` python -m SimpleHTTPServer `
Go to localhost:8000/[yourfilename].html
we will be prompted with this page.
Click login and wait until the page finishes loading. Go back to our WP page and click the refresh button.
Boom! We are logged in as admin
. At first glance, we can try to create a reverse php shell that will connect back to our netcat listener. We can go to theme-editor.php
and we can add our shellcode there. But the problem here is we don’t have a writable permission to edit the php files. So we will use other way to get in.
Now, the first post that we saw in the WP front page earlier will give us a hint about SMTP. So, we can go to Settings -> Easy WP SMTP Settings
.
We found that there is a password for orestis
. We can simply reveal the hidden pass by inspecting the page.
Now, we have an SMTP credential
orestis@brainfuck.htb:kHGuERB29DNiNE
Based on our nmap scan earlier, we know that SMTP port is open. So, we can use evolution
in Kali to log in the SMTP service as orestis
.
In evolution
, go to File->New->Mail Account
. And follow these steps in the images below to completely set up the mail.
Then we will find out that there are two messages in the inbox. The second one will show us another orestis
credential.
orestis:kIEnnfEKJ#9UmdO
And as we know there is a “secret forum” at sup3rs3cr3t.brainfuck.htb
, we will use that credential to log in and try to find something there.
Enumerating Secret Forum (sup3rs3cr3t.brainfuck.htb)
Once we logged in, we found three forum threads, Key, SSH Access , Development
. Going through all three of them, we only know that the forum Key
is encrypted by some sort of encryption.
Decrypting ciphertext
By analysing the ciphertext, we got some useful information.
Ciphertext :
Pieagnm - Jkoijeg nbw zwx mle grwsnn
Wejmvse - Fbtkqal zqb rso rnl cwihsf
Qbqquzs - Pnhekxs dpi fca fhf zdmgzt
Clear text :
Orestis - Hacking for fun and profit
So, starting from the first letter O
we can see there is three possible letters for the clear text. This encryption is same as enigma
machine.
Cracking the Enigma
The enigma can be attacked using known plain text. In this case, we will use one time pad cracking because we know the ciphertext and the plaintext. There is a site that can be used to unpad it.
So we got a key for the ciphertext which is, fuckmybrain
.
Using the key, we can get the clear text of other cipher text using keyed Vigenere or also known as Quagmire III.
Upon playing with the key, clear text and ciphertext, we found out that the real key is fuckmybrain
and we will get a clear text for all of the ciphertext. We will get a link that leads to ssh key for Orestis
.
Enumerating SSH
As we can see, the ssh key for orestis is encrypted.
So we need to crack it using john
. We will use sshng2john
from this site first to convert it into john
format, then we can crack it using john
using the following commands.
and run john
,
boom! We got the passphrase for the ssh key.
passphrase:3poulakia!
We can then log in to orestis ssh using ssh -i id_rsa orestis@10.10.10.17
.
But first, change the permission for id_rsa
file or you’ll get an error.
chmod 600 id_rsa
.
Then you can log in and use the cracked passphrase that we got earlier.
Post exploitation
We found out that there are interesting files in orestis
home directory.
debug.txt
: random numbers (what does the numbers for each line represent)
encryption.sage
: encryption script (p? q? e? p*q? (p-1)*
(q-1))
output.txt
: the output result (root.txt)
This type of encryption is called RSA encryption. You can find more information on wiki , particularly at the Key generation
part.
So, it is possible to attack the RSA encryption when we know the p
, q
, e
and the ciphertext
. Doing a quick search on Google will lead us to this forum where there is a decryption code given.
So, we will use it, and try if it’s working. Well, if it’s not working, guess we will have to crack it manually. :3
We will have something like this in our decryption script which we will call decrypt.py
.
So we will get this output :
We got a plain text but it is in integers. So we need to convert it into readable ascii. By passing it to hex and convert the hex to string, we will create a simple python script to automate it.
And when we run the script, we will get a plain text which is the hash for root.
Knowledge gained
Exploiting WP using vulnerable plugins
Cracking the Enigma using known plaintext attack
Decrypt RSA given p q e and ciphertext
And, thank you for today. Hope you learned a lot from this writeup. Until next time. :D