πInject Write-Up
The write-up covers boot-to-root method with very less explanation
Boot To Root
Enumeration
Lets use Rustscan for initial enumeration
As we can see there is not much we have in terms of open ports, lets see whatβs on the other side of the website that is hosted on the machine.
From here we have only 2 options, one being Signup and other being Upload method.
While enumerating Signup, we have hit a dead end π
Sub-Directory Enumeration
We are going to use feroxbuster for this job, I am using custom bash functions, so dont worry about the commands that I use in the screenshots.
Here is the command that you can actually use to do the sub-directory enumeration, make sure to replace the wordlist.txt with the one that you want to use
Lets check the upload section
Try uploading any file, and you will get an error stating that only image files can be uploaded, however if you just change the extension of the file that can allow you to upload any file you want.
You donβt have to manipulate the magic number to bypass the verification system, just upload any file you want, and make sure to provide a .jpg extension.
However if you want to further enumerate the endpoint we can use any sample image file and try understand the path where it is being uploaded.
Lets try that.
After uploading the file you will get a link, to view your file, click that and you will be taken to a new page.
And now notice the URL parameters that is being used.
Local File Inclusion
Lets try enumerating for LFI
We can use ffuf for this
As we can see we have multiple hits
we can use any one of them, lets try using curl and see what happens
We can read the the contents of the /etc/passwd files now.
Lets check for the files in the Web root directory which is by default /var/www
Hmmm, Looks like we have a Spring Boot Project, here.
The pom.xml file is a dependency list for the project, lets enumerate that
We have multiple dependencies here, lets enumerate the first one
The spring cloud function web 3.2.2 looks very interesting.
A quick google search for the exploit shall lead us to spring4shell exploit. Which has a CVE-2022-22963
spring cloud function web 3.2.2 exploit - Google Search
Exploit PoC
https://github.com/me2nuk/CVE-2022-22963
Using the knowledge from the PoC from github link we can craft out own bash function to make a more interactive exploit:
You can just copy and paste this function in your .bashrc or .zshrc or any aliases file that you are using and initialise it, or you can just start a new terminal session.
Once done we can start our exploitation phase.
Exploitation
To get a shell we need to upload our reverse shell via the upload method we discovered earlier, however we donβt know where it is being uploaded, So to get that information we can simply use curl and make a request to get a file that does not exists.
We have an Information Disclosure here, the error points out where the files are being uploaded
lets craft our own reverse shell
And upload this to the server via the upload method
Now start a reverse shell handler in your terminal
And then Execute it via the RCE Exploit, before you do that you might want to check if you are getting a ping request via the target or not
If all goes well, we can start to execute our reverse shell.
I have 2 separate windows open one to execute RCE and one to get the reverse shell.
Privilege Escalation
First things first, try to get a better shell, for example as you are βfrankβ the current user, you can create an authroized_keys file in the /home/frank/.ssh/ folder, if the .ssh folder does not exist create it. And upload your own public key that you can use to authenticate via the SSH.
Once thatβs done, we can check the .m2 folder and check for the maven settings file which contains credentials
Escalate up to the other user βphilβ, using the credentials mentioned in the settings.xml file
So how do we escalate from here, lets use pspy, which you can upload via your own web server
Via pspy we can see that there is a cron job running, which is executing ansible playbook files.
If we can inject our own playbook file we can get a root reverse shell.
We can use this template : https://gist.githubusercontent.com/Reelix/32ccf1baaa3066654a460265fca53960/raw/7c61e2ec5c2261d525f4726e5d0511824ac0e15e/reverse-shell.yml
And edit the file and upload it to the /opt/automation/tasks/evil.yml
As you can see I got root access after waiting for some time.
Thank you for reading my post, have a great rest of your day, and good hunting π
Last updated