1755841 Members
6627 Online
108838 Solutions
New Discussion юеВ

find all setuid files

 
SOLVED
Go to solution
dictum9
Super Advisor

find all setuid files

I am running the following but it's only getting files that have these permissions. How do I find files with setuid with any permissions, ie. 4755?

---S------
------S---


find / -perm -2000 -o -perm -4000 -exec ls -l {} \;
14 REPLIES 14
Patrick Wallek
Honored Contributor

Re: find all setuid files

Your command looks good to me.

I ran the same thing and it returned all appropriate files.

Are you running the command as root?
Rodney Hills
Honored Contributor

Re: find all setuid files

What do you get if you leave the "-" off the perm value, example-

find / -perm 2000 -o -perm 4000 exec ls -ld {} \;

Rod Hills
There be dragons...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: find all setuid files

Depending upon the version of find you may need to escape your or condition by enclosing it in parentheses. I would also restrict the search to regular files.

find / -type f \( -perm -2000 -o -perm -4000 \) -exec ls -l {} \;


You definitely want the -4000 as opposed to 4000 because 4000 would match only those files with mode 4000 as opposed to 4xxx (where x in this case means means "don't care" rather than execute.)
If it ain't broke, I can fix that.
dictum9
Super Advisor

Re: find all setuid files

The problem is, the command I am running does NOT match 4xxxx, it only matches 4000.

I need all permutations of 4xxx, e.q. 4700, 4500, and so on.
Patrick Wallek
Honored Contributor

Re: find all setuid files

I just ran the following on HP-UX versions 10.20, 11.0, 11.11 and 11.23 and got all files with SUID or SGID bits turned on:

# find / -perm -2000 -o -perm -4000 -exec ll -d {} \;

Are you absolutely SURE you put the '-' in front of the 2000 and 4000 in your original find? If you don't have the '-' it will look for exact permissions.
James R. Ferguson
Acclaimed Contributor

Re: find all setuid files

Hi
James R. Ferguson
Acclaimed Contributor

Re: find all setuid files

Hi:

# find . -type f -perm -u+s

...will find files in the current working directory with the setuid bit on whether or not the owner's execute bit is on ("s") or off ("S").

# find . -type f -perm -g+s

...finds those files whose setgid bit is on regarless of group execution rights.

...and:

# find . -type f -perm -ug+s

...finds files where both bits are on.

Regards!

...JRF...
dictum9
Super Advisor

Re: find all setuid files


Here are 2 files I am trying to match. The first command matches none of them, the second just one. How can I fix it to match both of them?

# ll ?
-rwsr-xr-x 1 root sys 5 Mar 29 11:03 a
-rw---Srw- 1 root sys 4 Mar 29 11:41 b

# find . -type f -perm -ug+s
#
# find /data -perm -2000 -o -perm -4000 -exec ls -l {} \;
-rwsr-xr-x 1 root sys 5 Mar 29 11:03 /data/a
#
James R. Ferguson
Acclaimed Contributor

Re: find all setuid files

Hi (again):

If you re-read my first post, then for:

-rwsr-xr-x 1 root sys 5 Mar 29 11:03 a
-rw---Srw- 1 root sys 4 Mar 29 11:41 b

For file "a" to match use:

# find . -type f -perm -u+s

For file "b" to match, use:

# find . -type f -perm -g+s

Regards!

...JRF...