Issue
I have a simple Perl script as below:
#!/usr/bin/perl
print "###################################\n";
But when I try to execute it from the command line, I always see:
[root@testbox001 tmp]# ./def
-bash: ./def: Permission denied
The script is executable:
-rwxr-xr-x 1 root root 88 Dec 22 01:42 def
Also the bash and shebang:
[root@testbox001 tmp]# ls -l /usr/bin/bash
-rwxr-xr-x. 1 root root 1150560 Jun 20 2022 /usr/bin/bash
[root@testbox001 tmp]# ls -l /usr/bin/perl
-rwxr-xr-x. 2 root root 12752 Jan 17 2023 /usr/bin/perl
[root@testbox001 tmp]#
What are the causes?
I can only run it explicitly:
[root@testbox001 tmp]# /usr/bin/perl def
#########################################################
[root@testbox001 tmp]#
Solution
The program is found on the /tmp
volume, which is mounted noexec
.
$ mount | grep 'on /tmp ' /dev/sda3 on /tmp type ext4 (rw,nosuid,nodev,noexec,noatime,nodiratime,data=ordered)
This prevents programs on that volume from being executed.
$ /bin/echo foo
foo
$ cp /bin/echo /tmp/
$ /tmp/echo foo
-bash: /tmp/echo: Permission denied
The goal is to help neuter attacks.
Answered By - ikegami Answer Checked By - Pedro (WPSolving Volunteer)