Skip to content

Malware University

Class is in Session

  • About
    • Privacy Policy
  • Contact
  • Resources

Recursive File Directory Downloading on Windows

Posted on August 20, 2025 - August 20, 2025 by admin

You may run into situations where you want to download a simple directory listing hosted via HTTP(S) from Powershell without needing any external tooling.

function Download-Dir {
    param(
        [string]$BaseUrl,
        [string]$LocalPath
    )

    # Create local folder
    if (-not (Test-Path $LocalPath)) {
        New-Item -ItemType Directory -Path $LocalPath | Out-Null
    }

    $ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/notacrawler Firefox/144.0"

    # Fetch the directory listing from the target
    $html = curl.exe -s -A $ua $BaseUrl

    # Extract and follow the links (no backsies)
    $links = ($html -split "`n") | Select-String -Pattern 'href="([^"]+)"' | ForEach-Object {
        ($_ -replace '.*href="([^"]+)".*','$1')
    } | Where-Object {$_ -notmatch "^\.\./" -and $_ -notmatch "index.html"}

    foreach ($link in $links) {
        $url = $BaseUrl + $link
        $dest = Join-Path $LocalPath (Split-Path $link -Leaf)

        if ($link.EndsWith("/")) {
            # Recurse into subdirectory
            Download-Dir -BaseUrl $url -LocalPath $dest
        } else {
            # Download file
            Write-Host "Downloading $url ..."
            curl.exe -A $ua -o $dest $url
        }
    }
}

# Start the recursive download
Download-Dir -BaseUrl "https://your-backups.com/My%20Personal%20Folder/" -LocalPath ".\SuperSecretPayloads"
Posted in Techniques, UtilitiesTagged downloader, infil, operations, Powershell, windows

Post navigation

Manual Scraping

Recent Posts

  • Recursive File Directory Downloading on Windows
  • Manual Scraping
  • Nitter Replacement
  • MFA Abuse in Splunk
  • Virtualbox Automation

Recent Comments

  • hello world on Repository Poisoning

Archives

  • August 2025
  • August 2024
  • July 2023
  • August 2022
  • March 2022
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • February 2021
  • December 2020
  • October 2020
  • September 2020
  • April 2020
  • March 2020
  • January 2020
  • July 2019
  • June 2019

Categories

  • Campaign Analysis
  • Campaign Management
  • Code Analysis
  • Current Events
  • Malware Development
  • Techniques
  • Uncategorized
  • Utilities

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Proudly powered by WordPress | Theme: micro, developed by DevriX.