1834207 Members
2521 Online
110066 Solutions
New Discussion

Re: Scripting Challenge

 
SOLVED
Go to solution
Robert Gamble
Respected Contributor

Scripting Challenge

A security audit is coming a I have a request coming from my customer to print to a file a list of EVERY file that is world readable and world writable (-zzzzzzzrwz, where z doesnt matter). Yes, I realize this will create a huge file.
I considered using a 'lsr -la > $FILE' but I'm not sure how to grep for just the 8th and 9th character. If I use 'cut' it strips away the rest of the output of the lsr command which is needed.

The output needs to have the $PATH/$FILENAME and permissions for each file that is world read/write.

Any Ideas ?
T.I.A.
12 REPLIES 12
James R. Ferguson
Acclaimed Contributor

Re: Scripting Challenge

Robert:

# ls -al|awk '{if (substr($1,8,2)=="rw") {print $0}}' > /tmp/results

...JRF...
Robert Gamble
Respected Contributor

Re: Scripting Challenge

not just 'rw' but '-w', 'r-'

thx
James R. Ferguson
Acclaimed Contributor

Re: Scripting Challenge

Robert:

# ls -al|awk '{if(substr($1,8,1)=="r")||(substr($1,9,1)=="w") {print $0}}' > /tmp/results

...JRF...



Fred Martin_1
Valued Contributor

Re: Scripting Challenge

I think the 'find' command would do:

find //wherever -perm -o+w -o -perm -o+r
-exec ls -la {} ;

A little hard to read but it says "find in directory //wherever, files with permissions of "other" as writable OR files with permissions of "other" as readable - then perform an 'ls -ls' on each file found.
fmartin@applicatorssales.com
Fred Martin_1
Valued Contributor

Re: Scripting Challenge

I think the 'find' command would do:

find //wherever -perm -o+w -o -perm -o+r
-exec ls -la {} ;

A little hard to read but it says "find in directory //wherever, files with permissions of "other" as writable OR files with permissions of "other" as readable - then perform an 'ls -ls' on each file found.
fmartin@applicatorssales.com
Fred Martin_1
Valued Contributor

Re: Scripting Challenge

Sorry about the double slashes above. That should read:

find /wherever -perm -o+w -o -perm -o+r
-exec ls -la {}\;
fmartin@applicatorssales.com
Robert Gamble
Respected Contributor

Re: Scripting Challenge

James,

I get an awk syntax error on the second command line you provided.
awk: The statement cannot be correctly parsed. The source line is 1. syntax error The source is line 1.

Fred,
I keep getting "invalid mode o+W-o" or variants of that when adding spaces between them.

Thanks for your help!
federico_3
Honored Contributor

Re: Scripting Challenge

put the condition between "(" ")" like this

ls -al|awk '{ifi((substr($1,8,1)=="r")||(substr($1,9,1)=="w")) {print $0}}' > /tmp/results

federico

James R. Ferguson
Acclaimed Contributor
Solution

Re: Scripting Challenge

Robert:

Sorry, been off-line. The syntax should be:

ls -al|awk '{if((substr($1,8,1)=="r")||(substr($1,9,1)=="w")) {print $0}}' > /tmp/results

...JRF...
Robert Gamble
Respected Contributor

Re: Scripting Challenge

James,

That works! Thank you very much!
Fred Martin_1
Valued Contributor

Re: Scripting Challenge

The spaces are important. If this is clearer, consider the underscores below as spaces and try it again:

find_/wherever_-perm_-o+w_-o_-perm_-o+r_-exec_ls_-al_{}_\;

Fred
fmartin@applicatorssales.com
unix team_4
Occasional Advisor

Re: Scripting Challenge

find / -xdev -type f -perm -006 -exec ls -ld {} ; > /tmp/rw.lst
Run it as a user instead of root, so you dont get into any directories that a user cant read anyways.
If you just need filenames, drop the -exec