This website uses cookies

To provide the highest level of service we use cookies on this site.
Your continued use of the site means that you agree to their use in accordance with our terms and conditions.

Pentest Chronicles

Arbitrary Code Execution Through Uploading a Malicious JSP File – Vulnerability Analysis

Mikołaj Pudlicki

December 13, 2024

Introduction During security tests, a critical vulnerability was discovered in the tested application. This issue allows an attacker to execute any code on the server by uploading a malicious JSP file. The problem arises from a lack of proper validation of uploaded files, which can be exploited by attackers.
Exploiting improper file validation An attacker can upload a malicious JSP file to the server due to weak file validation. This ZIP file contains a web page structure that is converted into a JSP file. The attacker places harmful code in the file, such as in index.html. After the ZIP file is uploaded and extracted, the attacker can access the path to the JSP file and execute any system commands on the server using the permissions of the application user (e.g., Tomcat).
Proof of concept The attack requires logging into an administrator account, which lowers the risk level to high. Below are examples of information obtained by executing system commands on the server:

1. “pwd”: /home/tomcat-[REDACTED]
2. “id”: uid=1003(tomcat-[REDACTED]) gid=1003(tomcat-[REDACTED]) groups=1003(tomcat-[REDACTED])

Importantly, the tests showed that no antivirus software was running on the server to detect the malicious code in the uploaded files.
How the attack works 1. Creating a malicious file - the attacker crafts an index.html with harmful JSP code that allows executing system commands. 2.Preparing the ZIP file - the attacker places the index.html file in a specific folder structure and compresses it into a ZIP file: 3. Uploading the file to the server - after logging into the administrator account, the attacker:

a) Navigates to: Administration → Web Templates → New Template.
b) Fills out the form and select the prepared malicious ZIP file as the template.
c) Submits the template and opening its preview.

4. Executing system commands - once the file is uploaded and previewed, the attacker tests the vulnerability by running commands such as uname -a, gaining detailed system information.
Recommendations To defend the application from such attacks, it is crucial to implement several protective measures.

Firstly, the use of an allowlist for uploaded files is highly recommended. By restricting the types of files that can be uploaded, such as permitting only specific extensions and verifying MIME types, the risk of undetected malicious files can be minimized. Additionally, checking file headers and limiting file size can add further layers of security.

Secondly, every file uploaded to the server should undergo rigorous validation and scanning. This ensures that harmful code embedded within files can be detected and neutralized. It is essential to apply these checks to all areas of the application that facilitate file uploads, leaving no potential entry points unprotected.

Finally, adding extra layers of protection can significantly enhance security. Installing antivirus software on the server provides a frontline defense against malicious files. Moreover, restricting user permissions related to file handling and keeping a close watch on administrative activities through detailed monitoring can prevent unauthorized actions and quickly identify suspicious behavior.


#Cybersecurity #WebApplicationSecurity #PenetrationTesting #SecureDevelopment




Next Pentest Chronicles

When Usernames Become Passwords: A Real-World Case Study of Weak Password Practices

Michał WNękowicz

9 June 2023

In today's world, ensuring the security of our accounts is more crucial than ever. Just as keys protect the doors to our homes, passwords serve as the first line of defense for our data and assets. It's easy to assume that technical individuals, such as developers and IT professionals, always use strong, unique passwords to keep ...

SOCMINT – or rather OSINT of social media

Tomasz Turba

October 15 2022

SOCMINT is the process of gathering and analyzing the information collected from various social networks, channels and communication groups in order to track down an object, gather as much partial data as possible, and potentially to understand its operation. All this in order to analyze the collected information and to achieve that goal by making …

PyScript – or rather Python in your browser + what can be done with it?

michał bentkowski

10 september 2022

PyScript – or rather Python in your browser + what can be done with it? A few days ago, the Anaconda project announced the PyScript framework, which allows Python code to be executed directly in the browser. Additionally, it also covers its integration with HTML and JS code. An execution of the Python code in …

Any questions?

Happy to get a call or email
and help!