Summary
This assessment identified a vulnerability chain that allowed an unauthenticated attacker to obtain root access to a Linux host through a publicly accessible file upload endpoint.
The issue originated from unsafe handling of multipart filenames during file uploads. By controlling the filename parameter supplied in the upload request, it was possible to write attacker-controlled content outside the intended upload directory.
Combined with a deployment configuration where the application ran under a privileged Linux user account with SSH access and passwordless sudo privileges, the vulnerability resulted in full host compromise.
The affected organisation, hostnames, and implementation details have been redacted to prevent reproduction against the remediated environment.
Discovery
During reconnaissance, a publicly accessible Python-based web application exposed a file upload feature that accepted unauthenticated submissions.
The application allowed users to upload files through a multipart form and subsequently processed the uploaded content. Initial testing focused on validating whether uploaded files were being written to disk using user-controlled filename values.
The upload functionality accepted arbitrary filenames and did not appear to perform path validation or sanitisation.
Confirming Arbitrary File Write
Testing showed that the server trusted the filename field supplied within the multipart request and used this value when determining the destination path for uploaded content.
By supplying path traversal sequences within the filename, it was possible to influence where files were written on the underlying filesystem.
Application responses indicated that uploaded files were successfully written and subsequently processed by the backend application. Error conditions occurred during post-upload parsing rather than during file creation, confirming that the file write operation itself had succeeded.
Additional validation demonstrated that files could be written outside the intended upload directory, resulting in an arbitrary file write primitive.
Escalation to System Access
Once arbitrary file write had been established, the next objective was determining whether a writable location existed that could be leveraged to obtain execution or system-level access.
The application was running under a standard Linux user account rather than a dedicated low-privilege service account. The user owned a home directory with an accessible SSH configuration.
By writing an SSH public key into the user’s authorized keys configuration, it was possible to authenticate as that user over SSH.
This converted the file write vulnerability into interactive access on the target host.
Privilege Escalation
Following successful SSH access, local permissions were reviewed.
The application user was a member of the sudo group and had been granted passwordless sudo privileges. As a result, elevation to root required no additional exploitation.
The complete attack chain was therefore:
Plain Text
Unauthenticated file upload
↓
Path traversal in multipart filename
↓
Arbitrary file write
↓
Modification of SSH authorized_keys
↓
SSH access as application user
↓
Passwordless sudo
↓
Root access
The overall impact was full compromise of the underlying host from a single unauthenticated entry point.
Root Cause
The primary vulnerability was unsafe handling of user-supplied filenames during file uploads.
The application used the multipart filename value directly when constructing filesystem paths and did not adequately validate or restrict the resulting location.
As a result, attacker-controlled input influenced both:
- The contents written to disk.
- The destination path where those contents were written.
The vulnerability was compounded by architectural decisions within the deployment environment:
- The application ran under a real user account rather than a dedicated service account.
- The user account had a writable SSH configuration.
- The user possessed passwordless sudo privileges.
Any one of these issues alone would have increased risk. Combined with the arbitrary file write vulnerability, they resulted in complete host compromise.
Remediation
The following remediations were recommended:
- Sanitize uploaded filenames using framework-provided validation functions such as
secure_filename(). - Validate resolved filesystem paths and ensure uploads cannot escape the intended directory structure.
- Run web applications using dedicated, low-privilege service accounts.
- Prevent service accounts from maintaining interactive SSH access where unnecessary.
- Remove passwordless sudo privileges from application service accounts.
- Review similar upload functionality throughout the application for equivalent path traversal vulnerabilities.
Conclusion
This issue demonstrates how relatively common weaknesses can combine into a critical security vulnerability.
The initial bug was an arbitrary file write caused by unsafe handling of multipart filenames. On its own, this represented a serious security issue. However, the surrounding deployment configuration transformed that primitive into complete system compromise.
An unauthenticated attacker could leverage a single upload request to gain access as the application user and then elevate directly to root through existing sudo privileges, resulting in full control of the underlying host.