Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute binary directly from curl

Is there a bash command to execute a binary-"stream"? There is a nice way to load and run shell scripts directly from the internet.

as example:

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

Is it possible to run binaries without saving the file, chmod etc. ?

something like:

curl http://example.com/compiled_file | exec_binary
like image 347
NaN Avatar asked Feb 16 '13 11:02

NaN


People also ask

Why do I get binary output using curl?

De-compressing curl output Binary output may be the result of HTTP compression which is often used to save bandwidth and speed-up transmission.

How do I download a binary file using curl?

Grab file with curl run: $ curl https://your-domain/file.pdf. Get file using ftp or sftp protocol: $ curl ftp://ftp-your-domain-name/file.tar.gz. You can set the output file name while downloading file with the curl, execute: $ curl -o file.


1 Answers

The Unix kernels I know expect binary executable files to be stored on disk. This is required so they can perform seek operations to arbitrary offsets, and also map the file contents into memory. Therefore, directly executing a binary stream from the standard input is not possible.

The best you can do is to write a script that will indirectly accomplish what you want, by saving the data into a temporary file.

#!/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.$$
like image 147
Diomidis Spinellis Avatar answered Oct 10 '22 02:10

Diomidis Spinellis