If a file has permissions -rwx-wx-wx can it be read by other and group users, or can it only executed and written? Is there some way to read an executable file by executing it?

link|improve this question

73% accept rate
No standard way that I can tell. – Tim Jan 19 at 21:10
feedback

4 Answers

up vote 14 down vote accepted

A file with -rwx-wx-wx permissions has read/write/execute permissions for the owner, and write/execute (but not read) permissions for everyone else.

If it's a script (usually a text file with a #! on the first line), then it can't be executed by others, because executing a script really executes the interpreter, which must be able to read the script. (The interpreter must be a binary, not another script.)

If it's a binary executable, it can be executed directly, but its contents can't be read. This means, for example, that someone other than the owner can run it as a command, but can't grab a copy of the executable.

Of course execution requires reading, but it's read by the kernel, not by the user. You might be able to get some information about the contents of the executable by examining the memory of the process as it's running, but I doubt that you could reconstruct the binary executable file.

Incidentally, -rwx-wx-wx is a very odd set of permissions; it protects the file from being read by anyone other than the owner, but allows anyone to modify it. I can't think of a case where that would make sense.

link|improve this answer
Just an abstract random question : Would profiling/debugging tools work on execs with only executable permissions ? – Sairam Jan 23 at 19:46
@Sairam: Experiment says no: chmod 111 hello ; gdb ./hello says ./hello: Permission denied.; r says No executable file specified. – Keith Thompson Jan 23 at 19:53
For a non-executable, something like -rw--w--w- can be useful for something like a log file where you want people to be able to write info to the log without being able to read it. Of course, they could just empty the file, but that's a separate issue. – Dave Jan 25 at 21:33
feedback

With those permissions, only the owner of the file can execute it.

Other users can write to it, but not execute it (as execution in this case implies being able to read it) but they can write to it as a sort of black box:

user1:~$ cd /tmp
user1:/tmp$ echo "hostname" > testfile.sh
user1:/tmp$ chmod +x testfile.sh 
user1:/tmp$ ./testfile.sh  
server.example.com

user1:/tmp$ chmod 733 testfile.sh 
user1:/tmp$ ls -l testfile.sh 
-rwx-wx-wx 1 user1 user1 9 Jan 19 21:09 testfile.sh

user1:/tmp$ sudo su - user2
user2:~$ cd /tmp
user2:/tmp$ ./testfile.sh  
./testfile.sh: Permission denied
user2:/tmp$ cat testfile.sh 
cat: testfile.sh: Permission denied

user2:/tmp$ echo 'echo hello' >> testfile.sh 
user2:/tmp$ ./testfile.sh  
./testfile.sh: Permission denied

user2:/tmp$ logout

user1:/tmp$ ./testfile.sh
server.example.com
hello
link|improve this answer
4  
A shell script requires READ as well as EXECUTE access to run. However, a compiled binary does NOT. Thus a compiled binary with the permissions above could be executed by anybody! – mdpc Jan 19 at 21:24
1  
I suppose this brings up the question on what the OP is trying to accomplish, i.e., why would the compiled binary be writable? The set of permissions (733) actually took a moment for me to figure out, since it's so non-standard. – cjc Jan 19 at 21:28
feedback

The simple answer is no: only exec syscall may read a file without requiring read access (although mandating execute access). An open with O_RDONLY or O_RDWR shall fail.

link|improve this answer
feedback

Of course any file can be read by the root user.

Also, the system loader, memory management, swapper, etc....will read a file with 'x' permission, otherwise it could not be executed.

Possible holes in disclosing executable contents could be the /proc file for the process, core files, or by using a debugger.

link|improve this answer
this is only true if a chmod|chown has been performed – warren Jan 23 at 17:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.