File Transfers (Continue Here)
In penetration testing, you will usually need to transfer files to your targets. For example, you might exploit a target and need to upload a script to check for vulnerabilities in the system.
Since there are usually restrictions in place, you need to know different techniques. If one technique doesn't work, you can try another or even combine or chain different techniques to bypass the controls of the targets.
Windows File Transfer Methods
Downloading
PowerShell Base64 Encode & Decode
In this technique, you encode the file into base64 and then decode it on the target system. This technique doesn't require an internet connection and can be done through a terminal connection. Aditionally, you can optionally use hashing to check for the integrity of the file.
The drawbacks of this technique are that the Windows command line has a character limit (8,191), so if the file's base64 is larger than the limit, this technique will not work. Also, sometimes a web shell may error if large strings are sent.
The process:
PowerShell Web Downloads
In any version of PowerShell, the
System.Net.WebClient
class can be used to download a file over HTTP, HTTPS or FTP.Commands:
Common Error with PowerShell:
If Edge first-launch configuration wasn't completed then the download process will be prevented. This can be bypassed by using the flag
-UseBasicParsing
Another error related to SSL/TLS happens when the certificate isn't trusted. This can by bypassed by using running this command.
SMB Downloads
The Server Message Block protocol (SMB protocol) that runs on port TCP/445 is a protocol that allows users to transfer files to and from remote servers.
The Process:
FTP Downloads
Another way to transfer files is using FTP (File Transfer Protocol), which use port TCP/21 and TCP/20.
Uploading
To upload we can use the same techniques just reversed.
PowerShell Base64 Encode & Decode
Powershell Web Uploads
PowerShell doesn't have a built-in function for upload operations, but we can use
Invoke-WebRequest
orInvoke-RestMethod
to build our upload function.
Last updated