Can I execute a Linux binary without the execute permission bit being set?

Is there a way to run an executable binary file under Linux which does not have the execute bit set? chmod +x is not an option.

E.g. it's permissions may be r--r--r-- only.

Executing scripts is possible without setting the execute bit and putting in a shebang by passing the source to the interpreter, e.g. bash script.sh or python script.py.

So is there something like execute abinaryfile that will load the object code into memory and run it?


Solution 1:

You can use /lib/ld*.so as an ELF interpreter, like so:

$ cp /bin/ls /tmp/ls
$ chmod a-x /tmp/ls
$ /lib/ld-linux.so.2 /tmp/ls

The actual name differs from architecture to architecture. Some names include /lib/ld-linux.so.2, /lib/ld-linux-x86-64.so.2 and /lib/ld-2.7.so. You can probably find it singularly as /lib/ld*.

Solution 2:

No. At least, not in the same way. You are still executing a binary when you do the python thing. Python is +x. You would need to compile something that can load a file and execute it.

TiCL should make his/her response an answer because it is the best way to go.