加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 从管道执行二进制内容

发布时间:2020-12-13 19:19:07 所属栏目:Linux 来源:网络整理
导读:简而言之,howto run a bash compressed script?,但这可以用二进制代替shell脚本吗? 假设我有一个压缩成.gz的二进制文件.我可以解压缩到管道并检查内容: $gzip -d --stdout hello.gz | file -/dev/stdin: ELF 64-bit LSB executable,AMD x86-64,version 1 (
简而言之,howto run a bash compressed script?,但这可以用二进制代替shell脚本吗?

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

$gzip -d --stdout hello.gz | file -
/dev/stdin: ELF 64-bit LSB executable,AMD x86-64,version 1 (SYSV),dynamically linked (uses shared libs),not stripped
$

而不是将此输出传递给命令,是否有任何方法可以实际执行管道本身的内容,而无需将其写入文件?

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

$mkfifo execpipe
$chmod 777 execpipe
$gzip -d --stdout hello.gz > execpipe &
[3] 30034
$./execpipe 
bash: ./execpipe: Permission denied
$[3]+  Broken pipe             gzip -d --stdout hello.gz >execpipe

$

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

解决方法

我相信答案是否定的.

您可以通过将文件传递给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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读