This box was downloaded from VulnHub and is also on the TJnull list of practice boxes for OSCP preparation. The box involved the following steps:
- Enumeration of port 80
- Webdirectory bruteforcing
- SQL Injection exploitation in vulnerable OpenEMR
- Exploiting the PATH variable on SUID binary for Privilege Escalation
I always start my exploitation from the autorecon scan. Initial Nmap scan results are as below:
Nmap scan report for 10.0.0.25
Host is up, received arp-response (0.00026s latency).
Scanned at 2022-04-19 05:45:34 EDT for 10s
Not shown: 998 closed tcp ports (reset)
PORT STATE SERVICE REASON VERSION
21/tcp open ftp syn-ack ttl 64 ProFTPD 1.3.3d
80/tcp open http syn-ack ttl 64 Apache httpd 2.2.17 ((PCLinuxOS 2011/PREFORK-1pclos2011))
| http-robots.txt: 8 disallowed entries
| /manual/ /manual-2.2/ /addon-modules/ /doc/ /images/
|_/all_our_e-mail_addresses /admin/ /
|_http-title: Coming Soon 2
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-favicon: Unknown favicon MD5: 7D4140C76BF7648531683BFA4F7F8C22
|_http-server-header: Apache/2.2.17 (PCLinuxOS 2011/PREFORK-1pclos2011)
MAC Address: 08:00:27:35:9F:E3 (Oracle VirtualBox virtual NIC)
OS fingerprint not ideal because: Didn't receive UDP response. Please try again with -sSU
Aggressive OS guesses: Linux 2.6.38 (99%), Linux 2.6.32 - 3.5 (98%), Linux 2.6.38 - 3.0 (96%), Linux 2.6.37 (95%), Linux 2.6.9 - 2.6.30 (95%), Linux 2.6.32 - 3.10 (94%), Linux 2.6.18 - 2.6.32 (94%), OpenWrt (Linux 2.4.32) (93%), Linux 2.6.22 (Fedora Core 6) (93%), Linux 2.6.27 - 2.6.28 (92%)
Uptime guess: 0.001 days (since Tue Apr 19 05:44:22 2022)
Network Distance: 1 hop
TCP Sequence Prediction: Difficulty=203 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OS: Unix
TRACEROUTE
HOP RTT ADDRESS
1 0.26 ms 10.0.0.25
From the initial scan, I can see that there are two ports open. One is port 80 and other port 21.
As always I started with port 80. Checked robots.txt, source-code of the webpage and almost everything. Nikto scan mentioned the shellshock vulnerability but no luck. No other initial vector to proceed.
I tried to find web directories but had no luck. I always start with a medium list and in this machine web directories that are spotted from the medium list did not provide me with any juicy details. Next, I moved to the big list. I found an interesting directory. It’s always good to go for the bigger list if you are stuck.
Visiting the /openemr gives me a login page with OpenEMR version.
A quick searchsploit scan shows that this version is vulnerable to SQL injection.
I used the 49742.py script for the Blind SQL injection. This python script does not take any arguments so, you have to edit the url in the script.
So, I got the following credentials from the python SQL Injection script.
admin:3863efef9ee2bfbc51ecdca359c6302bed1389e8
medical:ab24aed5a7c4ad45615cd7e0da816eea39e4895d
I used crackstation and was able to crack the password for admin.
I tried using the credential for FTP login and it didn’t work. I tried cracking the password for medical user and succeeded.
medical:medical
I was able to log in to FTP using the user medical credential. But I could not find any more information there.
Going back to the openEMR and looking around the system. I came to an interesting setting, where I can edit the file.
I changed the PHP content with the pentest monkey PHP payload. And when I visited that PHP page from the browser, I got the reverse shell.
I tried changing the user to medical using the above credential and was successful.
After running the linpeas script I couldn’t find anything interesting. Looking further into directories, I found passwd and shadow file inside /var/backups . Cracking the shadow file using john the ripper, I got the password for the user almirant.
Now further running the linpeas script, I can see that there are a few setuid binaries that are usually not on the list.
This being the health-themed box, I went straight ahead and ran the healthcheck binary.
After looking at the contents of the binary using strings command. I can see the binary runs ifconfig and fdisk command. But the absolute PATH for the command is not mentioned. So we can exploit the PATH environment variable and gain privilege escalation.
[almirant@localhost shm]$ cd /tmp
[almirant@localhost tmp]$ export PATH=/tmp:$PATH
[almirant@localhost tmp]$ echo "/bin/bash" > ifconfig
[almirant@localhost tmp]$ chmod +x ifconfig
Now running the binary should give us root access.
I tried harder. lol!