We all know that if a script does not have execution permissions, we can still run it by invoking the interpreter and indicating the path to the script. What not many people know is that we can do the same with binary files. This way, we can run binaries without execution permissions, the only requirement is to have read permissions on it.
We write a small example program:
vi test.c
#include<stdio.h>
int main(void) {
printf("Hello world!\n");
return 0;
}
We compile the program:
gcc test.c
We check that it runs correctly:
./a.out
Hello world!
We make sure it has execution permissions:
ls -la a.out
-rwxr-xr-x 1 kr0m kr0m 16600 may 13 23:37 a.out
We remove its execution permissions:
chmod -x a.out
ls -la a.out
ls -la a.out
-rw-r--r-- 1 kr0m kr0m 16600 may 13 23:37 a.out
We check that we can no longer run it directly:
./a.out
bash: ./a.out: Permission denied
We check what type of file it is:
file a.out
a.out: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, not stripped
We run the binary through the interpreter:
/lib64/ld-linux-x86-64.so.2 /home/kr0m/a.out
Hello world!