Catching Files over HTTP(S)
Last updated
Last updated
Web transfer is the most common way most people transfer files because HTTP
/HTTPS
are the most common protocols allowed through firewalls. Another immense benefit is that, in many cases, the file will be encrypted in transit. There is nothing worse than being on a penetration test, and a client's network IDS picks up on a sensitive file being transferred over plaintext and having them ask why we sent a password to our cloud server without using encryption.
We have already discussed using the Python3 to set up a web server with upload capabilities, but we can also use Apache or Nginx. This section will cover creating a secure web server for file upload operations.
A good alternative for transferring files to Apache
is because the configuration is less complicated, and the module system does not lead to security issues as Apache
can.
When allowing HTTP
uploads, it is critical to be 100% positive that users cannot upload web shells and execute them. Apache
makes it easy to shoot ourselves in the foot with this, as the PHP
module loves to execute anything ending in PHP
. Configuring Nginx
to use PHP is nowhere near as simple.
Create the Nginx configuration file by creating the file /etc/nginx/sites-available/upload.conf
with the contents:
If we get any error messages, check /var/log/nginx/error.log
. If using Pwnbox, we will see port 80 is already in use.
We see there is already a module listening on port 80. To get around this, we can remove the default Nginx configuration, which binds on port 80.
Now we can test uploading by using cURL
to send a PUT
request. In the below example, we will upload the /etc/passwd
file to the server and call it users.txt
Once we have this working, a good test is to ensure the directory listing is not enabled by navigating to http://localhost/SecretUploadDirectory
. By default, with Apache
, if we hit a directory without an index file (index.html), it will list all the files. This is bad for our use case of exfilling files because most files are sensitive by nature, and we want to do our best to hide them. Thanks to Nginx
being minimal, features like that are not enabled by default.