Searching for SETUID and SETGID using PERL file find with lstat


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching for SETUID and SETGID using PERL file find with lstat
# 1  
Old 03-31-2006
Searching for SETUID and SETGID using PERL file find with lstat

About System and Perl: Sun Solaris 5.9 sparc, Perl 5.6.1

I've decided to use the perl file::find module to look for all the SETUID and SETGID files on my unix boxes. I wrote something like this: (I've shorted it a little to make it simple)

#!/opt/perl/bin/perl

use File::Find;
find \&wanted, "/";
sub wanted {

(($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = lstat("$_"));


if ($mode eq "34280") {
print "Mode = $mode\n";
system "ls -dl $_\n";
}



As you can see I am making an lstat call on each file. I'm reading the mode variable on each file to determine if it's a SETUID/SETGID or both.

However, each mode seems to differ. A file that is -rwsrwsrwx might have a mode of 36351 but a file with -rwsrwsrw- might have a file mode of 37987. Maybe this isn't the best way to do this. Can someone show me a better way to do this or explain how I get a list of mode numbers in Solaris. I don't want to use the unix find because it's to damn slow. Perl file find is fast and I prefer to us it.

Thanks,
x
# 2  
Old 03-31-2006
The answer is in this page:

http://perldoc.perl.org/functions/stat.html

Some hints:
- use Fcntl ':mode';
- use the S_I* named constants;
- Bitmasking with the '&' operator.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What keeps me from abusing setuid(0) and programs with setuid bit set?

Just learning about the privilege escalation method provided by setuid. Correct me if I am wrong but what it does is change the uid of the current process to whatever uid I set. Right ? So what stops me from writing my own C program and calling setuid(0) within it and gaining root privileges ? ... (2 Replies)
Discussion started by: sreyan32
2 Replies

2. Shell Programming and Scripting

Setuid and setgid and similar settings

so im writing a script for a android system. these types of systems are not the typical unix systems. what i need to do is basic. i have a script which I put in a directory and then zipped up the directory in a zip file. that way, when the script is unzipped, the person unzipping will see... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. Solaris

Special File Permissions Setgid and setuid ..HELP

I have a user AAA who's who is part of a group call clserv and techsupp, His userfiles have the following permissions:- drwxrwx--- 16 AAA clserv 1858 Aug 22 12:48 UserFiles he has a link in his UserFiles/ lrwxrwxrwx 1 root root 36 Mar 9 2013 TECHSUPP_GLOBAL... (5 Replies)
Discussion started by: kilobyter
5 Replies

4. UNIX for Dummies Questions & Answers

How can I re-enable the setuid or setgid bits ???

While I was looking for tips for hardening the security of my MAC OSX I found the following posting: "<How to disable Setuid and Setgid Binaries > Setuid programs run with the privileges of the file's owner (which is often root), no matter which user executes them. Bugs in these programs... (6 Replies)
Discussion started by: Vera
6 Replies

5. Shell Programming and Scripting

Searching a string in a file using perl

Hi I would like to read a file using perl and search for a string (last entry). Then read that into an array and do further grep File content for ex: comp=a,value=30,runtime=12,type=lic comp=d,value=15,runtime=2,type=lic comp=a,value=90,runtime=43,type=lic... (1 Reply)
Discussion started by: vivek_damodaran
1 Replies

6. UNIX Desktop Questions & Answers

find setuid files

I would like to list files with setuid and setgid set up. I used the find command, but I got a lot of permission denied error. I tried to redirect the error to the hole it does not work. I used the command string below find . -type f \( -perm -4000 -o -perm -2000 \) -exec ls {} \; 2>/dev/null... (3 Replies)
Discussion started by: Pouchie1
3 Replies

7. Solaris

about setuid setgid permissions

hi.. why we go for setuid, setgid permissions? as a system admin ,when we use this ,except default solaris setuid,setgid files and dirs.. hopes that anyone can help me regarding this.. (1 Reply)
Discussion started by: saravananpalani
1 Replies

8. Shell Programming and Scripting

Perl: searching for a string in a file...

Hi All, I need to search for a string in a file that I've opened and base a decision on the result. The logic is this: "if the word 'Shared' appears on the first line then do this on the whole file else do this on the whole file " The code I currently have isn't working:... (4 Replies)
Discussion started by: pondlife
4 Replies

9. UNIX for Dummies Questions & Answers

Using setuid and setgid

Hi, I have been looking at setuid and setgid. I understand that setuid determines who owns the file and setgid determines which group of people can access the file... yeah?! But i need to know how to actually use setuid and setgid. I'm guessing chmod will feature somewhere.. Any help... (1 Reply)
Discussion started by: crispy
1 Replies

10. Shell Programming and Scripting

perl: why the return valure of stat and lstat are the same?

i tried to use stat to get the attributes of a file and a soft link. but the result i got from stat and lstat are the same. say: ln -s f1 soft1 (soft is a soft link , point to f1) if i use > ls -il shows the inode and modify time of soft1 and f1 are different. but the modify... (1 Reply)
Discussion started by: gusla
1 Replies
Login or Register to Ask a Question