【问题标题】:execute binary directly from curl直接从 curl 执行二进制文件
【发布时间】:2013-02-01 07:42:06
【问题描述】:

是否有执行二进制“流”的 bash 命令?有一种直接从 Internet 加载和运行 shell 脚本的好方法。

例如:

curl http://j.mp/spf13-vim3 -L -o - | sh

是否可以在不保存文件、chmod 等的情况下运行二进制文件?

类似:

curl http://example.com/compiled_file | exec_binary

【问题讨论】:

  • 你试过curl http://j.mp/spf13-vim3 -L -o - | xargs sh吗?对于二进制文件,您可以编写一个脚本,保存一个临时文件,通过 chmod 添加执行权限并运行它。然而,所有这些行为都会带来巨大的安全风险。
  • 是的,这是一个安全风险,但我知道该文件,这不是问题所在。一个 shell 脚本是可能的,但我正在寻找一个没有 shell 脚本的更好的解决方案。

标签: bash curl binary executable


【解决方案1】:

我知道的 Unix 内核期望二进制可执行文件存储在磁盘上。这是必需的,因此他们可以对任意偏移执行查找操作,并将文件内容映射到内存中。因此,直接从标准输入执行二进制流是不可能的。

您可以做的最好的事情是编写一个脚本,通过将数据保存到一个临时文件中来间接完成您想要的事情。

#!/bin/sh

# Arrange for the temporary file to be deleted when the script terminates
trap 'rm -f "/tmp/exec.$$"' 0
trap 'exit $?' 1 2 3 15

# Create temporary file from the standard input
cat >/tmp/exec.$$

# Make the temporary file executable
chmod +x /tmp/exec.$$

# Execute the temporary file
/tmp/exec.$$

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 2017-11-29
    • 2016-02-07
    • 2013-12-02
    • 2013-08-04
    相关资源
    最近更新 更多