Problem
How to locate SUID and SGID files.
Solution
Files with setuid and/or setguid permission settings mean that the file (actually a binary) will be executed with the ID of the owner or group, depending on which bit is set. For security reasons many system administrators need to monitor these files to make sure their system has not been compromised.
The following example uses find(C) to locate setuid files, owner ID set, and setgid files, group ID set on execution. The find is piped to xargs which outputs a full listing of the files to /tmp/suid.sgid (any output file can be named):
find . \( -perm -4000 -o -perm -2000 \) -print | xargs l >
/tmp/suid.sgidIdeally this is performed on a freshly installed system. That
file can then be compared to output files created thereafter.In order to find the same files in /etc/perms, use:
grep 4[0-9][0-9][0-9] /etc/perms/* > /tmp/perms.suid
grep 2[0-9][0-9][0-9] /etc/perms/* > /tmp/perms.sgidNOTE: The setuid, setgid and sticky bit settings have no effect on shell scripts.
See also
chmod(C) and find(C)