This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new!

find dangerous permissions

Posted by: Anonymous Coward on July 13, 2006 04:11 AM
find is also useful for finding dangerous permissions. unzip, in particular, seems to randomly ignore umask and create world-writable files and directories. It's also helpful to search for suid/sgid programs in odd places.

Most portably, you can do:
<tt>find / \! -type l \( -perm -04000 -o -perm -02000 -o -perm -01000 -o -perm -00002 -o -perm -00020 \) -ls</tt>
Eeek! What a mess! If you have GNU find, you can make it shorter:
<tt>find / \! -type l -perm +07022 -ls</tt>
... or use symbolic permissions:
<tt>find / \! -type l -perm +ugo+s,go+w -ls</tt>
These search for all files in the root directory and below, ignoring symbolic links, and matching set user id, set group id, sticky, world writable, or group writable permissions.

We exclude symbolic links because they are usually mode 0777 and would be false positives. The permissions of the link don't matter, only the target of the link. "-perm -N" means to match permissions including ALL bits of N. "-perm +N" means to match ANY bits of N. Some versions of find (e.g. BSD) don't have the -perm + option.


Return to CLI Magic: Searching with find