I noticed this weird issue in a Ubuntu 18.04 (Bionic Beaver) box and a couple of other Debian-based systems -- I will take statically linked
netcat binary (a unix networking tool) for the sake of demonstration, however the result is the same for any other ELF executable.
Executing it gives the following message (from any normal directory such as
/tmp$ ./nc -bash: ./nc: Permission denied
The permissions with
chmod are correct for execute permissions:
/tmp$ ls -lah nc -rwxr-xr-x 1 user user 2.8M May 19 19:38 nc
I have tried lots of combinations, but none worked, until a friend of mine suggested that I put the binary in
/var/lib/php/session (where PHPSESSIDs reside) and it works:
/var/lib/php/session$ ./nc Ncat: You must specify a host to connect to. QUITTING.
However, I have not been able to find an explanation for this yet, and
php is not present in every system, so what do I do in that case?