Adding compromised.htb to /etc/hosts file. Also starting off a all port scan in the background.
Using gobuster to scan for directories and files
gobuster dir -w /opt/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -u http://compromised.htb/ -o go-dirscan.out -x php,html,tx
Using timestamps to get recently modified files
Now that we have backup files for the CMS running, we can potentially search for config files. There is this one trick that I learned from ippsec (Using timestamps to get the recently modified files)
find . -printf "%T+ %p\n" -type f | sort -u
2020-09-03+17:19:16.0000000000 ./includes/library
2020-09-03+17:19:16.0000000000 ./includes/library/lib_user.inc.php
2020-09-03+17:20:34.0000000000 ./admin/login.php
2020-09-03+17:20:56.0000000000 ./admin
// These were the recently modified files
But the only problem is that we can't run system executing commands on php. This can be because of PHP disabled functions. To check it ,we can execute phpinfo() command.
There are two ways to get a shell on the box. The first way is to use weevely (Weevely is a stealth PHP web shell that simulate telnet-like connection. It is an essential tool for web application post exploitation, and can be used as stealth backdoor or as a web shell to manage legit web accounts, even free hosted ones.) and the another way is to use disable_functions bypass - PHP 7.0-7.4 script.
Get the exploit from here and upload it. We can even modify the script a bit to accept a GET/POST request and execute it, rather than manually entering the values.
We can't get a reverse shell because of the firewall rules. To check the iptables rules, we can browse to /etc/iptables and list for rules.
# Generated by iptables-save v1.6.1 on Mon May 11 02:27:29 2020
*filter
:INPUT DROP [6:1032]
:FORWARD DROP [0:0]
:OUTPUT DROP [5:394]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -m tcp -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -m tcp -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 22 -m tcp -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 80 -m tcp -j ACCEPT
COMMIT
# Completed on Mon May 11 02:27:29 2020
Instead we can use forward shell.
Using forward shell to shell access
We can even upgrade the shell (Uses pty from python) by typing upgrade command.
The pty module defines operations for handling the pseudo-terminal concept: starting another process and being able to write to and read from its controlling terminal programmatically. ... Connect the child's controlling terminal to a pseudo-terminal. Return value is (pid, fd) .
Let's see if mysql has UDF(User-defined functions) present. We have creds to connect.
Looks like we run commands as mysql user.
One thing that we can do is create a .ssh directory and then copy the contents of our public key into it. This is how we can get shell as mysql using SSH Protocol.
So after reading the local_x variables, if it's equal then it will run /bin/sh command. Let's decode that variable values using Cyberchef.
Decoded Value : 2wkeOU4sjv84ok/
So upon execution of SUID Binary (binary should accept input from the user), if we enter the value that we just decoded, we will get a root shell. Let's try that on su (substitute user)binary.