Forge was Easy-Medium Linux machine. Initial foothold part could be little tricky if you are not familiar with SSRF. Through subdomain bruteforcing, I discovered admin.forge.htb and through SSRF, I can access it to read it. On admin.forge.htb, it noticed me of how to connect to FTP through SSRF and using that I was able to read id_rsa key from it. Using id_rsa, I spawned SSH connection as the user. Privilege Escalation was very simple, remote-management.py was open to any user to be ran as root. By inputting value to the script, the script spawns PDB as sudo, and through that I can get root shell.
Information Gathering
Rustscan
Rustscan finds SSH and HTTP open:
Nmap
Nmap finds nothing interesting:
Enumeration
HTTP - TCP 80
Going to the IP address throguh web browser, it leads me to forge.htb which I add to /etc/hosts:
Subdomain bruteforcing discovered one valid entry: admin.forge.htb:
After adding it to /etc/hosts, I can access it. However, it seems that only localhost is allowed for access:
admin.forge.htb/
forge.htb is some sort of gallery website:
Through /upload, I can choose to upload local file or to upload form URL:
After submiting random image from local directory, it shows the path where the image is saved:
Image successfully uploads as such:
Unfortunately, this web app won’t read any php scripts.
No matter what PHP script I upload, it won’t render it properly.
SSRF
Moving on to Upload from url, I will try uploading file from my local Python HTTP server:
I see that the connection is made to my local listener from the web app:
Normally, I would upload PHP webshell to it and open it through /uploads and spawn a reverse shell through it but in this case, I know this webapp is not reading PHP.
Remembering admin.forge.htb is only accessible by localhost, I will try to access it through upload from url:
Unfortunately, there seems to be protection running here:
Bypass SSRF Protection
I will try to bypass the blacklist through capitalization as such and it works:
Using curl, I can read admin.forge.htb in html:
Below is the full output for admin.forge.htb:
Based on above’s code, I will now try reading /announcements:
Using the same way, I can read /announcements in HTML:
Below is the full output:
/announcements reveals potentials credentials(user:heightofsecurity123!) as well as the way to access ftp through /upload paremeter:
After copying id_rsa in to a file name mykey to my local kali machine, now I have SSH access as user:
Privesc: user to root
Sudo Privilege Abuse
I will first check if there’s anything I can run as the root with sudo -l:
/opt/remote-manage.py can be run as root using sudo.
Script can be seen in plain-text and password secretadminpassword is shown:
Below is the whole python code:
The script appears to be a simple server-side application that listens for incoming connections, prompts the client for a password, and then provides various options based on user input.
Running the script will prompt you with what port is being used for listening:
I will use nc to connect to it and sign-in using the found password from earlier:
Choosing whatver option I want by typing in number will return me with the output after the command runs:
Now, I will run the script as the root using sudo:
I will connect the listening port and sign-in. I will try throwing in random value this time:
On the terminal where I ran the script, it shows an error and PDB(Python Debugger) shell is spawned.
After importing os, I can run commands as the root as such: