【问题标题】:Execute the content of binary from a pipe从管道执行二进制的内容
【发布时间】:2013-11-23 23:30:21
【问题描述】:

简而言之,howto run a bash compressed script?,但这可以用二进制文件而不是 shell 脚本来完成吗?


假设我有一个压缩成 .gz 的二进制文件。我可以解压缩到管道并检查内容:

$ gzip -d --stdout hello.gz |文件 - /dev/stdin:ELF 64 位 LSB 可执行文件,AMD x86-64,版本 1 (SYSV),动态链接(使用共享库),未剥离 $

有没有什么方法可以实际执行管道本身的内容,而不是将其写入文件?

我考虑过使用命名管道,但这似乎不起作用:

$ mkfifo 执行管道 $ chmod 777 执行管道 $ gzip -d --stdout hello.gz > execpipe & [3] 30034 $ ./execpipe bash: ./execpipe: 权限被拒绝 $ [3]+ 损坏的管道 gzip -d --stdout hello.gz >execpipe $

有没有办法在不创建实际文件的情况下执行管道的内容?

【问题讨论】:

  • Permission denied 如果你尝试 sudo 会怎样?
  • @Samoth - sudo 失败并显示“sudo: ./execpipe: command not found”。在su 下运行也会失败并显示“bash: ./execpipe: Permission denied”
  • 你能做的最好的是将其转储到 ramfs 或 tmpfs 中的文件中并执行。

标签: linux shell pipe executable


【解决方案1】:

我相信答案是否定的。

您可以通过将文件传递给Linux loader 来手动执行文件,该文件将被命名为/lib/ld-linux.so* 但它需要一个实际文件。它不能执行管道或标准输入;它需要能够mmap() 文件。

$ /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /bin/true
$ /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 - < /bin/true
-: error while loading shared libraries: -: cannot open shared object file: No such file or directory
$ /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 <(cat /bin/true)
/dev/fd/63: error while loading shared libraries: /dev/fd/63: invalid ELF header

* 在我的 Red Hat 机器上,它是 /lib/ld-linux.so.2(32 位)或 /lib64/ld-linux-x86-64.so.2(64 位)。在我的 Ubuntu 机器上,它是 /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2

【讨论】:

    猜你喜欢
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    相关资源
    最近更新 更多