GreenHorn

HackTheBox Machine Writeup

Hello everyone Hope you are doing great. I am here with another writeup for “greenhorn machine” Which was quite challenging involved lot of research and had to discover new topics and tools you will read and experience them in this writeup if you followed it through so enjoy the walkthrough and you can follow along to solve the machine as well.

GreenHorn Machine

Step 1: Let's add it to hosts

Everytime when we solve HTB, need to add the machine to our hosts by using any text editor, i have used gedit you can use any editor of your choice

gedit etc/hosts
Step 1 Image

Step 2: Nmap result for greenhorn.htb

We will start Network mapping here using “NMAP” command and flags. we can see open Ports, services and its version which will be helpful for vulnerability detection.

Nmap -sV  10.10.11.25
Step 2 Image

Step 3: visiting port 80

I started my scanning and enumeration by Visiting “Port 80”. On this port website welcomes user “junior” where on the bottom there’s mention of “admin” and “pluck” which draws my attention

Step 3 Image

Step 4: Exploring the WEB

On clicking “admin” it routes to login.php page. On that page there is a password field and an Admin page where pluck with version 4.7.18 is mentioned

Step 4 Image

I quickly checked for the vulnerable versions for it and I got that Pluck 4.7.18 is vulnerable and exploitable For Remote Code Execution.

Step 4.1 Image

Step 5: Enumerating PORT 3000

Simultaneously Checked On the Port “3000”. On this PORT GreenHorns page was hosted with some git functionality

Step 5 Image

On further Exploration on the same PORT I got a repository which was named as GreenAdmin/GreenHorn

Step 5.1 Image

Step 6: Exploring Git

Thought to give it a try to see any juicy content from GreenAdmin.

Step 6 Image

Step 7: pass.php

And finally in GreenHorn/data/settings got “pass.php” file

http://greenhorn.htb:3000/GreenAdmin/GreenHorn/src/branch/main
Step 7 Image

The pass.php file was protected and to crack it I used some tools

Step 7.1 Image

Step 8: Lets decrypt pass.php file

I have used “Hash-identifier” to identify the type of hashes, and I got it has SHA-512.

Step 8 Image

Now we can use “Hashcat” to get the plaintext readable password with the help of SHA-512

Step 8.1 Image

Step 9: Login using decrypted password

Got the password and used to to login in Admin.

Step 9 Image

Step 10: exploring the admin page

I scanned the entire website to check it’s functionality and there is a feature of “install a module” which can be used as target to upload created “RCE”

Step 10 Image

Step 11: Install "Modules"

In “Install modules” feature we can upload files, I tried uploading php file directly but it did not allowed me to do so but It does allowed Zip file

Step 11 Image

Step 12: reverse shell creation for pluck version 4.7.18

Remember back then the Pluck version 4.7.18 is vulnerable for RCE and I have created a “reverse shell” script for php. As Php file cannot be uploaded in module feature it can be converted it to zip file and I have named it as “Payload.zip”.

Step 12 Image

Step 13: delivering the payload as "payload.zip"

Now I have uploaded the same zip enclosed with reverse shell file by browsing and selecting “payload.zip” file.

Step 13 Image

Step 14: trying exploits on multiple File Upload functions

I tried uploading file in all the input fields which are possible and tried to access it but got in one field.

Step 14 Image

Step 15: successfully delivering payload

On successfully uploading file in install modules section, I got this screen which says “The module has been installed successfully”. Here you may not get reverse shell but you need to access the reverse shell file which we have uploaded as ZIP to open the file we have created we need to know the path where it is uploaded which I got with some research on Modules.

Step 15 Image

Step 16: starting listener on 4321 port

I have started a Listner on 4321 Port which I have used in reverse shell. When I analysed the path I got the below URL which access the reverse.php file which is uploaded as zip in “install module” section.

Step 16 Image

Step 17: accessing ZIP file

I Used this URL to access the zip file:

http://greenhorn.htb/data/modules/reverseshelll/reverse.php

Here what exactly happened is when I have uploaded the reverseshell.php it has My IP and PORT. When I opened the file using above URL it got executed and I got the Reverse shell on the listener Port 4321:

Step 17 Image

Step 18: gaining access to www-data

On successfully getting reverse shell I got access to the machine but my User was www-data

Step 18 Image

Step 19: "user.txt"

There was “user.txt” file in www-data but user did not had permission to access “user.txt”.

Step 19 Image

Step 20: sudoing in www-data

Remember the user which we got as “Junior” might have the access to look for user.txt So here I did sudo in “www-data” and using same password I have got “user.txt” file

Step 20 Image

Step 21: Getting hands on "OpenVAS.pdf"

Additionally on the same location there was “OpenVAS.pdf” file which might be a hint

Step 21 Image

Step 22: Downloading the file to local machine

To view the pdf had to download the file by Locally hosting on the user

Step 22 Image

I have Downloaded the file using basic commands

Step 22.1 Image

Step 23: lets open that PDF

The PDF is opened and in the file you can see Enter password field is pixelized. Looked for some more clues and enumerated for some more time but maybe we might get some clue on de-pixelising the fields where Enter Password is written in “OpenVAS.pdf”.

Step 23 Image

Step 24: depixalizing tool

I searched for depixalizing it on git and depixelated it using a tool got on github named “Depix”

https://github.com/spipm/Depix
Step 24 Image

Step 25: Extracting images out of pdf

The tool “depix” require an image for depixalising the pixelated text, so need to convert pdf to image. For that I have used online pdf converter called “PDF24 tools”.

Step 25 Image

After some time you will get “Extract images” option which enables you to download pixelated text into plaintext in png format.

Step 26 Image

Step 26: depixalizing image

I Tried depix commands as per the instruction written in the tool to de-pixelate the image and got the plaintext password which was not so clear but readable.

Step 27 Image

Root password provided by depix in png format, our next step will be using the password

Step 27.1 Image

Step 27: getting root access

On getting root password tried ssh login using cracked password to the root user, on successful login i have got the “root.txt” for the GreenHorn machine.

Step 28 Image

Hope you liked my write-up, You can Follow for upcoming write-ups as well. Till then Keep learning, keep reading and keep Updating knowledge.