Week 5. Appsanity
TL;DR
This is a Windows 10 machine running a medical web application. Manipulating HTTP requests we can get privileged access in the application and upload a malicious .aspx
shell. To execute the shell an SSRF attack is used. Regarding escalation, reversing of a .NET local service with dnSpy is needed, and also reversing of an executable with Ghidra.
KEYWORDS
Insecure file upload, SSRF, reversing, dnSpy, Ghidra, port forwarding.
REFERENCES
https://github.com/dnSpy/dnSpy
ENUMERATION
Port scan.
Enumerate the open ports.
Add to hosts
file and fuzz for hidden subdomains on port 443.
Add subdomain to hosts
file and browse with Firefox.
We notice we cannot access the HTTP 80 service externally. Take note of this because this service can maybe be accessed internally later if we find a place to launch an SSRF attack.
USER
Sign up a new account and intercept the request. You can see there is a parameter called AccType
set to "1". Manipulate it with Burpsuite and set it to "2", forward the request and log in using the recently created account. Verify we have made ourselves a doctor account.
We also notice in the cookie editor we have been granted an access token.
We can reuse this token to get access to the portal reserved for doctors. Just browse the site https://portal.meddigi.htb, fill in the email ID with the one you chose when signing up and enter the access_token
with the cookie editor.
Click on "Login" and you are inside the doctors panel.
Move to the "Upload report" tab. If you try to upload a shell, there is an extension filter ongoing which only accepts PDF files. Experimenting with the filter, we find out the backend only checks the file magic bytes, and it does not check file extensions.
Prepare an msfvenom
ASPX shell.
To upload the shell, navigate to the "Upload report" tab.
Upload any PDF at hand and intercept the request, keep the PDF magic bytes and remove the rest. Copy the msfvenom
shell and change the filename and to an .aspx
extension, forward the request and let the upload finish.
To execute the shell, navigate to the "Issue prescriptions" tab and in the prescription link try an SSRF attack. Enter the URL http://127.0.0.1:8080 to view all the medical reports that have been uploaded, in the output you can view the path of the malicious uploaded report.
To execute the .aspx
shell, use the SSRF vulnerability again pointing to the uploaded shell path we have just disclosed.
A reverse shell is received that can be used to retrieve the user flag.
SYSTEM
Enumerate the user and the system.
Remember there was a 5985 service open? Let's see who is allowed to use it.
It seems our next goal is to move laterally to user devdoc
to gain winRM remote access.
After largely enumerating the file system, we find this DLL.
This is decompiled with dnspy
, a tool for reversing .NET applications (https://github.com/dnSpy/dnSpy), and we find several calls to a registry key software\meddigi
Next step is to query the register. You can find a password in key HKEY_LOCAL_MACHINE\software\meddigi
. The password is 1g0tTh3R3m3dy!!
If you spray the password with crackmapexec
you'll find the password works for user devdoc
. Use the local users list we have previously enumerated.
Turns out that under this user's context we can browse this folder.
Where we find the file reportmanagement.exe
. Reversing the binary with Ghidra, we find out it uses DLL files located in the libraries
folder when running the upload
command.
So our next step is to place a malicious DLL in that folder. This payload can be generated with msfvenom
. We will name it externalupload.dll
. Copy the malicious DLL into the path c:\program files\reportmanagement\libraries\externalupload.dll
Investigating how to launch the process, we discover it is internally running on port 100.
To forward this port to our attacking machine we use chisel
In order to trigger the reverse shell we just need the application running on port 100 to make use of our malicious DLL. Connect to the application an run command upload externalupload
. A reverse shell is received on port 9001.
Last updated