1

How could I go about finding uneven file/directory permissions within a directory structure? I've made some attempts at using the find command similar to:

find /bin ! \( -perm 777 -o -perm 776 -o -perm 775 -o -perm 774 -o -perm 773 -o -perm 772 -o -perm 771 -o -perm 770 -o -perm 760 -o -perm 750 -o -perm 740 -o -perm 730 -o -perm 720 -o -perm 710 -o -perm 700 -o -perm 600 -o -perm 500 -o -perm 400 but I run out of command line before I can complete the remaining permutations plus an -exec ls -lL {} \;

I've also been doing manual things similar to:

ls -lL /bin | grep -v ^-rwxr-xr-x | grep -v ^-rwx--x--x | grep -v ^-rwsr-xr-x | grep -v ^-r-xr-xr-x | grep -v ^-rwxr-xr-t but again, I run out of command line before I can complete the remaining permutations.

Both methods seem unusually awkward. Is there a better, faster, easier way? Note that I'm restricted in the shell I'm using (sh) and platform (Irix 6.5.22).

  • 3
    What exactly is an "uneven" permission? – thrig Oct 24 '16 at 23:15
  • IRIX find lets you test individual bits with thing like ! -perm -400 -a '(' -perm -040 -o -perm -004 ')', correct? – Mark Plotnick Oct 24 '16 at 23:49
  • And what does "run out of command line" mean? Your shell doesn't let you type any more or it gives an error when you run it, or...? – Jeff Schaller Oct 24 '16 at 23:49
  • Uneven file permissions means that lower security groups have greater permissions than an owner or group. For example, r--r--rw- or r--rw----- – Rob Oct 25 '16 at 16:30
  • Run out of command line means that no more text can be entered into the command line. The shell doesn't let me type any more text into the current command line. – Rob Oct 25 '16 at 16:31
0

are you looking for executable files?

find . -type f -perm /+x

regardless, the / mode is more than likely your friend... here is the man page:

   -perm /mode
          Any  of  the  permission  bits mode are set for the file.  Symbolic modes are accepted in this form.  You must specify `u', `g' or `o' if you use a symbolic mode.  See the
          EXAMPLES section for some illustrative examples.  If no permission bits in mode are set, this test matches any file (the idea here is to be consistent with  the  behaviour
          of -perm -000).

UPDATE: right, i though you were looking for uneven numbers (executable ones)...

this should work (still using 3rd perm param from find

sample data:

$ ls
000  001  002  003  004  005  006  007  010  020  030  040  050  060  070  100  200  300  400  500  600  700

Find command:

$ find . -type f \( -perm /u-x,g+x -o -perm /u-w,g+w -o -perm /u-r,g+r -o -perm /g-x,o+x -o -perm /g-w,o+w -o -perm /g-r,o+r -o -perm /u-x,o+x -o -perm /u-w,o+w -o -perm /u-r,o+r \) | sort
./001
./002
./003
./004
./005
./006
./007
./010
./020
./030
./040
./050
./060
./070

Basically you are saying, give me files where group has perms but owner does not, or files where world has perms but group does not, or where world has perms but owner does not.

note: find has 3x perm params;

  • perm mode
  • perm -mode
  • perm /mode

ps I'm not all too sure of the value of this...

  • I'm looking for uneven file permissions. Uneven file permissions give lower security groups greater permissions than the group or owner of a file or directory. An example would look like r--rw---- or rw-rwxrwx or r--r--rwx etc. Irix does have the find command and the find command does have the -perm argument as demonstrated in the example given in my original post. Attempting to search for, or not search for using the not operator !, every permutation of uneven file permissions requires a command line that is longer than my shell allows. Surely there's a better way? – Rob Oct 25 '16 at 16:40
  • The syntax works well on my CentOS 6.8 box but my Irix 6.5.22 box throws an error: # find . -type f \( -perm /u-x,g+x -o -perm /u-w,g+w -o -perm /u-r,g+r -o -perm /g-x,o+x -o -perm /g-w,o+w -o -perm /g-r,o+r -o -perm /u-x,o+x -o -perm /u-w,o+w -o -perm /u-r,o+r \) | sort Error Message: /u-x,g+x: bad option Usage: find path-list predicate-list I tried using bash on my Irix system as well with the same issue. I suspect I'd need a newer version of find to use your syntax. – Rob Oct 25 '16 at 19:20
  • I came up with a somewhat shorter version of my previous grep syntax: ls -lLR /dir1 /dir2 /dir3/subdir1 /dir3/subdir2 | egrep '(^[-d]-[-w][-x]r|^[-d]-[-w][-x][-r][-w][-x]r|^[-d][-r]-[-x][-r]w|^[-d][-r]-[-x][-r][-w][-x][-r]w|^[-d][-r][-w]-[-r][-w]x|^[-d][-r][-w]-[-r][-w][-x][-r][-w]x)' Although my testing so far shows that it isn't catching everything. – Rob Oct 25 '16 at 19:20
  • Purpose - First this is a compliance issue. The Defense Information Systems Agency (DISA) requires that all DoD systems comply with their system security requirements which they provide in Security Technical Implementation Guides (STIG)s. They believe that uneven file permissions pose a security threat to Unix/Linux systems. Assuming someone could manipulate the permissions of a file or directory they don't have permissions to, why change only the "Other" permissions instead of going with a 777? If a system is being monitored for changes it would pick up the change in either case. – Rob Oct 25 '16 at 19:29
  • We get lots of false positives from client's security / auditing companies... I see no threat from 070. It's the sticky bits and guids to look out for... I expect this is one of those standards that dictate linux must have AV... waste of compute... – mikejonesey Oct 25 '16 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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