Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.
HASH EXTENSION ATTACKLFILINUXLINUX-PRIVESCOSCPSENSITIVE FILE DISCLOSUREWEB

DropFile

Challenge Lab (Easy) - by rezydev

The following post by 0xb0b is licensed under CC BY 4.0


Scenario

Objective

You have been hired to perform an internal pentest against a sensitive Linux server in the client's network. Your task is to identify all vulnerabilities and (if possible) elevate your privileges to root.

Initial Access

The client has provided you with VPN access to their environment, but no other information.

Summary

Summary

In DropFile, we begin with a port scan against a Linux host at 10.1.37.56, revealing SSH on port 22 and HTTP on port 80 redirecting to http://dropfile.hs/. A vhost scan with ffuf uncovers dev.dropfile.hs, which hosts a Gitea instance containing the application's source code. The main site is a file-sharing platform; after registering, we can upload files and receive download links containing a filename and an HMAC-like signature.

Reviewing the source reveals that signatures are generated via SHA-256(secret + filename) which is vulnerable to hash length extension attacks. The /download endpoint also decodes the filename with latin-1 and, if it contains a /, strips everything before the first slash and opens the remainder as an arbitrary file path. Using a valid share link and the length-extension-tool Python package, we brute-force the secret's key length, forge a new valid signature with path traversal appended, and achieve LFI. We read /etc/passwd to identify the user ravi, then /proc/self/cmdline to locate the app at /opt/dropfile.local/. From there we read /home/ravi/.ssh/id_rsa, save the key, and SSH in as ravi to obtain the user flag.

For privilege escalation, sudo -l shows that ravi can run /usr/local/bin/python2.7 /opt/backup.py as root. The backup script uses Python2s input(), which evaluates arbitrary expressions. When prompted for confirmation, we supply __import__('pty').spawn('/bin/bash'), spawning a root shell and recovering the root flag at /root/root.txt.

Recon

We use rustscan -b 500 -a 10.1.37.56 --top -- -sC -sV -Pn to enumerate all TCP ports on the target machine, piping the discovered results into Nmap which runs default NSE scripts -sC, service and version detection -sV, and treats the host as online without ICMP echo -Pn.

A batch size of 500 trades speed for stability, the default 1500 balances both, while much larger sizes increase throughput but risk missed responses and instability.

The target 10.1.37.56 is a Linux host running nginx 1.24.0 on port 80, which redirects to http://dropfile.hs/. SSH is available on port 22 running OpenSSH 9.6p1 (Ubuntu

We add the following entry to our /etc/hosts file.

dropfile.hs

We move on to the web page and visit the pages manually. The page offers a service to share files securely, but access is required. We'll put that to the test. It doesn't seem like we can proceed any further without authenticating. Before we register, we'll enumerate additional directories and vhosts using feroxbuster and ffuf.

Next, we scan for further directories using Feroxbuster but nothing special pops up.

We perform a VHOST scan using FFuF and are able to identify the vhost dev.

We edit our /etc/hosts file entry as follows.

We'll take a look at the VHOST dev in a moment and stay on the main page. We'll sign up and will be logged in automatically.

On this page, we can upload various file formats, such as TXT, PDF, or PNG files.

First, we'll test the normal behavior and create a sample file.

After we've uploaded them using drag-and-drop, we'll see an entry, and we can now download or delete the file.

We intercept the download request and see that the file is associated with an object referenced as file_1. At first glance, it appears that no other files have been uploaded yet, or that this reference is tied to our account. However, we see that a download link has been provided for us in the reponse. It contains the actual filename and a signature.

We modify our request in the Burp Suite Repeater module to download the file and enter the URL we received. We are able to download the file.

If we try to include other files locally with the same signature, we get a 403 error. It's possible that either the permission to retrieve the file or the invalid signature is blocking the request to the file giving us a 403.

If we try to download our file directly using curl without specifying a session, we are able to retrieve the file. No authentication is required. That seems to be the application's feature that allows to share files without a session. The signature essentially grants the requester permission to do so. Now the question for us is: How is this signature generated? Is it based on the file name, the content, and which algorithm is used?

At first glance, this appears to be an SHA-256 hash, as confirmed by hashid.

dev.dropfile.hs

We'll continue with the web enumeration before turning our attention to the signature again. We may uncover additional information about it at the dev vhost.

We visit http://dev.dropfile.hs/ and see a Gitea instance in front of us

We click on explore and find a publicly available repository of the dropfile.hs application. From there we can inspect the logic of the application and see how signature is crafted and may uncover other vulnerabilities that we have not yet spotted or derived from what we have seen so far.

We spot how the signature is created. In this case it is tried to create a cryptographic signature by simply concatenating a secret key and the data, then hashing it with SHA-256. This is a massive flaw, since this is open to Length Extension Attacks.

SHA-256 and other Merkle–Damgård hash functions are vulnerable to length extension attacks. Because anyone can see valid pairs (filename, signature) from /share, an attacker doesn't even need to know the secret. We can take an existing valid signature, mathematically extend the padding of the filename, append malicious data, and calculate a new, completely valid signature without knowing the secret.

There are already several tools and libraries available that we can make use of.

But what does this actually allow us to do? If we look at the /download directory, then we can choose any path on the system. If the filename contains a /, the code drops everything before the first slash and opens the rest as a path. That allows absolute paths and ../ traversal. The latin-1 decoding of raw bytes also lets the hash padding bytes through. Together with a hash extension attack we and a share link we can read any file the process can read, including app_data.json and .env. That in turn lets us forge session cookies and log in as anyone for example.

Shell as ravi

We reuse the share link from our sample file.

Next, we craft a simple hash extension script using the length-extension-tool package with the help of Claude. Since we do not know the key, we need to brute-force the key size for the proper padding. We want to perform the identified LFI and already include that in the script that then loops through possible key lengths to forge a valid signature and read /etc/passwd.

We run the script and are able to craft a valid signature with the key size of 16 and are able to read the /etc/passwd file.

To read the /etc/passwd file fully, we use the resulting URL and send a request using curl. We identify ravi as a user.

From here, we'll now also read /proc/self/cmdline to determine where the application is running, so we can read the .env and app_data.json files. The app_data.json file may contain additional content that has been shared.

We could also now read the secret to create genuine, valid signatures directly. We can see that the app is running in /opt/dropfile.local/.

But app_data.json doesn't contain any other shares, just ours.

Now that we have identified the user ravi and did not find anything else, we are checking whether we can read the contents of the users home directory. Specifically, the contents of the .ssh directory, in order to obtain a private key and perhaps authenticate ourselves as ravi via SSH. We include the authorized_keys keys file and see an ssh-rsa entry present. Maybe the key is named after id_rsa.

We request the key and are successful.

To read the key fully, we use the resulting URL and send a request using curl. We copy the contents to a file called id_rsa on our machine.

Next, we change the permission accordingly and get a session as ravi using the key via SSH. We find the users flag in the home directory - which we could have already obtained through guessing via the LFI.

Shell as root

As ravi we are allowed to run /usr/local/bin/python2.7 /opt/backup as root via sudo.

We'll take a closer look at the script to see if we can exploit it to gain code execution as root.

Unfortunately, we can't edit the script; otherwise, it would be very easy for us to just write our code directly into it. But we can read the script. Maybe there's a flaw in the code.

The script creates a compressed .tar.gz backup of the /opt/dropfile.local directory after asking for confirmation.

The flaw is that it uses input() in Python 2, which evaluates the input as Python code instead of reading it as a string.

We run the script as root using sudo.

Instead of confirming the backup we insert our code.

We want to spawn a interactive shell using Python's pty module. The following one will fail, but a single-expression payload like __import__('os').system('/bin/bash') should succed.

We enter the following payload and get a root session. From there we can access the flag at /root/root.txt.

Last updated