コマンドプロンプトに以下貼り付け
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('http://hoge.com/sample.ps1'))"
- http://hoge.com/sample.ps1 がダウンロードされpowershellで実行される。
解説: powershellにて動作
- sample.ps1にて http://hoge.com/sample.exe を
%TEMP%\ps\sample.exe
に保存。 -
%TEMP%\ps\sample.exe
が実行される
sample.ps1
$url = "http://hoge.com/sample.exe"
if ($env:TEMP -eq $null) {
$env:TEMP = Join-Path $env:SystemDrive 'temp'
}
$fixTempDir = Join-Path $env:TEMP "ps"
if (![System.IO.Directory]::Exists($fixTempDir)) {[System.IO.Directory]::CreateDirectory($fixTempDir)}
$file = Join-Path $fixTempDir "sample.exe"
function Download-File {
param (
[string]$url,
[string]$file
)
# Downloading $url to $file
$downloader = new-object System.Net.WebClient
$downloader.Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials;
$downloader.DownloadFile($url, $file)
}
# download the package
Download-File $url $file
# start sample.exe
Start-Process "$file"