0

Two part question:

  • What is a world-writeable directory and file?
  • I'm looking for a script that would display the directories on all partitions of a server, that are not owned by root or a system account. In our environment, all world-writable directories should be owned by root or another system account.
rob
  • 1
  • 3
  • Welcome to Ask Ubuntu!, please elaborate on your question, it'll help people to answer your question better. – Projjol Dec 16 '13 at 15:11
  • Welcome to Ask Ubuntu! It is preferred if you can post separate questions instead of combining your questions into one. That way, it helps the people answering your question and also others hunting for atleast one of your questions. Thanks! – guntbert Dec 16 '13 at 20:04

2 Answers2

0
  1. world-writable files are files that anyone can write to. Regardless of who they are. This is considered a security issue where some random person on the other side of the world that has access to your system can abuse. Imagine some software that uses /tmp (=world-writeable by design) is also listening to incomming data in /tmp.

    There is one extra thing though: sticky bit. The most common use of the sticky bit today is on directories. When the sticky bit is set, only the item's owner, the directory's owner, or the superuser can rename or delete files. Without the sticky bit set, any user with write and execute permissions for the directory can rename or delete contained files, regardless of owner.

  2. This will print all world-writable files that do not have their sticky bit set.

    find / -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print
    

    This will also print all world writable files:

    find / -perm -2 ! -type l -ls
    
Rinzwind
  • 299,756
  • Thanks. I actually revised my question because I was told it was not clear, more-or-less. I guess what I'm looking for, are the permissions of a world-writable directory. However, I really don't know what would define a world-wriatble directory. Also, the output I am looking for needs to be the actual permissions and, I'm hoping the permissions listed, would be easily identifiable if they are not owned by root or a system account. – rob Dec 16 '13 at 15:40
  • Thing is... world-writable does not have to be a problem if the sticky bit it set. So if you, as a example, take falconer's script you will get a lot of lines that are not a problem (even when they are uid > 500) – Rinzwind Dec 16 '13 at 15:51
0

I think you want this script

#!/bin/bash
uids=`awk -F ":" '{print $3}' /etc/passwd`
for i in $uids; do
    if [ $i -gt 500 ]; then
            find / -uid $i -perm -002 -type d 2>/dev/null
    fi
done

It gets the uids from the passwd file, then loops through them, and if the uid is greater than 500 it will launch a find for directories with that uid and other writable bit set.

falconer
  • 15,026
  • 3
  • 48
  • 68
  • Thanks everyone!!! I think I will use all of your answers and come up with some sort of super-colosal script so I can use in my BladeLogic application. Thanks again everyone and if applicable, happy Holidays (and if not applicable, have a great remainder of the year). – rob Dec 16 '13 at 15:51
  • I think I'm stuck again. I'm not trying to get too fancy, but everyone's tips provided me with more ways to search for what I wish to see.

    I'm looking for directories that are world-writable and would like to run a find command that displays the directories where the permissions are set that make a directory world-writable in the first place.

    I ran the command below and it provides other directories that are not world-writable. How bad is my command?

    find / -XDEV -not -path "/proc/*" -type d ( -perm -g+w or -perm -o+w ) -ls -prune

    – rob Dec 16 '13 at 21:14