Windows Target
Download operations (Attacker -> Target)
Powershell Base64 Encode & Decode
Linux payload preparation:
Windows PS:
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
.
The following table describes WebClient methods for downloading data from a resource:
Method | Description |
Returns the data from a resource as a Stream. | |
Returns the data from a resource without blocking the calling thread. | |
Downloads data from a resource and returns a Byte array. | |
Downloads data from a resource and returns a Byte array without blocking the calling thread. | |
Downloads data from a resource to a local file. | |
Downloads data from a resource to a local file without blocking the calling thread. | |
Downloads a String from a resource and returns a String. | |
Downloads a String from a resource without blocking the calling thread. |
File Download
File-less
Instead of downloading a PowerShell script to disk, we can run it directly in memory using the Invoke-Expression cmdlet or the alias IEX
.
PowerShell Invoke-WebRequest
From PowerShell 3.0 onwards, the Invoke-WebRequest cmdlet is also available, but it is noticeably slower at downloading files. You can use the aliases iwr
, curl
, and wget
instead of the Invoke-WebRequest
full name.
List of commands
From HarmJ0y:
Possible Errors
There may be cases when the Internet Explorer first-launch configuration has not been completed, which prevents the download. This can be bypassed using the parameter -UseBasicParsing
.
Another error in PowerShell downloads is related to the SSL/TLS secure channel if the certificate is not trusted. We can bypass that error with the following command:
SMB Downloads
We can use SMB to download files from our Pwnbox easily. We need to create an SMB server in our Pwnbox with smbserver.py from Impacket and then use copy
, move
, PowerShell Copy-Item
, or any other tool that allows connection to SMB.
Then from Windows:
New versions of Windows block unauthenticated guest access
To transfer files in this scenario, we can set a username and password using our Impacket SMB server and mount the SMB server on our windows target machine:
FTP Downloads
In case of non-interactive shell, create an ftp file:
Upload Operations (Target -> Attacker)
PowerShell Base64 Encode & Decode
PowerShell Web Uploads
Installing a Configured WebServer with Upload
Preparing the Linux attack box to receive the file:
Now we can use a PowerShell script PSUpload.ps1 which uses Invoke-RestMethod
to perform the upload operations. The script accepts two parameters -File
, which we use to specify the file path, and -Uri
, the server URL where we'll upload our file. Let's attempt to upload the host file from our Windows host.
PowerShell Base64 Web Upload
Another way to use PowerShell and base64 encoded files for upload operations is by using Invoke-WebRequest
or Invoke-RestMethod
together with Netcat. We use Netcat to listen in on a port we specify and send the file as a POST
request.
SMB Uploads
An alternative (when SMB traffic is blocked) is to run SMB over HTTP with WebDav
. WebDAV
(RFC 4918) is an extension of HTTP, the internet protocol that web browsers and web servers use to communicate with each other. The WebDAV
protocol enables a webserver to behave like a fileserver, supporting collaborative content authoring. WebDAV
can also use HTTPS.
Configuring WebDav Server
Connecting to the Webdav Share
DavWWWRoot
is a special keyword recognized by the Windows Shell. No such folder exists on your WebDAV server. The DavWWWRoot keyword tells the Mini-Redirector driver, which handles WebDAV requests that you are connecting to the root of the WebDAV server.
You can avoid using this keyword if you specify a folder that exists on your server when connecting to the server. For example: \192.168.49.128\sharefolder
If there are no SMB (TCP/445) restrictions, you can use impacket-smbserver the same way we set it up for download operations.
FTP Uploads
Before we start our FTP Server using the Python module pyftpdlib
, we need to specify the option --write
to allow clients to upload files to our attack host.
Or creating the command file
Last updated