In short, howto run a bash compressed script?, but can this be done with a binary, instead of a shell script?
Suppose I have a binary which is compressed into a .gz. I can unzip to a pipe and examine the contents thus:
$ 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 $
Instead of piping this output to a command, is there any way I can actually execute the contents of the pipe itself, without writing it to a file?
I considered using a named pipe, but this doesn't seem to work:
$ 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 $
Is there a way to execute the contents of a pipe without creating an actual file?
I believe the answer is no.
You can execute a file manually by passing it to the Linux loader, which will be named something like /lib/ld-linux.so
.* It needs an actual file, though. It can't execute a pipe or stdin; it needs to be able to mmap()
the file.
$ /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
* On my Red Hat machine it's /lib/ld-linux.so.2
(32-bit) or /lib64/ld-linux-x86-64.so.2
(64-bit). On my Ubuntu machine it's /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With