|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
|
| News | Recommended Links | |||
| Thor | Findsuid | Suidcontrol |
What is SUID?
SUID stands for set user id. When a SUID file executed, the process which runs it is granted access to system resources based on the user who owns the file and not the user who created the process. When a file is SUID root it allows a program/script to perform functions that regular users are not allowed to do themselves. Many buffer overflow exploits are the result of SUID programs.
SGID stands for set group id. When looking at files SGID they behave much the same as SUID files, and must be executable for it to have any effect. The SGID bit on a directory means files created in that directory will have their group set to the directory's group.
Use find to obtain a list of set-UID and set-GID prorgrams
installed on a system
# error : it will rescan every partition
for part in \
`awk '($4 == "ufs") {print $3 }' /etc/vfstab`
do
find $part \( -perm -04000 -o -perm -02000\) \
-type f -xdev -print
done
: The proper way of doing this is actully not find by ncheck
Checksuid () {
if [ -x /usr/sbin/ncheck ]; then
current_suid=`/usr/sbin/ncheck -F ufs -s |wc -l`
known_suid=276
if [ ${known_suid} != ${current_suid} ]; then
echo "Current listing of SUID files does not match the known listing - FAILS CHECK"
echo " "
exit 1
else
echo " Current SUID listing equals known listing - PASSES CHECK"
fi
fi
}
[DISAPPEARED FROM THE WEB] thor.pl keeps tabs on suid and sgid files on your file system. It also keeps track of the checksums of your binaries and the root accounts on the system as well as a few other things. It's a handy script that helps you find possible security risks, or breakins.
| Download: | http://www.linuxscripts.com/arc/thor1.0.tar.gz |
| Homepage: | http://www.linuxscripts.com/ |
findsuid, pcheck Directory of -pub-unix-sec8 This little shell script can be adapted to run from cron in oprder to report setuid and setgid changes (very handy and simple script because main enemy of sysadmins is not hackers, but he himself and his colleagues ;-). The directory contains a lot of other useful for sysadmin scripts ! Here is full INDEX
23-Aug-98 Suidcontrol-0.1 utility has been released. The suidcontrol is an experimental utility for managing suid/sgid policy under FreeBSD. It actually generated the list and script to check it. In this particular case the idea is not that impressive. http://www.watson.org/fbsd-hardening/suidcontrol.html
|
Gentoo Linux Documentation -- File Permissions
|
To find all SGID files:
find / -xdev -type f -perm +g=s -print
To find all SUID files
find / -xdev -type f -perm +u=s -print
To find all Writable dirs:
find / -xdev -perm +o=w ! \( -type d -perm +o=t \) ! -type l -print
You can use the find command to search for files that are group writable by a particular group, and to print a list of these files. For example, to search for all files that are writable by the group user, you might specify a command in the following form:
# find / -perm -020 -group user \! \( -type l -o -type p -o -type s \) -ls
If you have NFS, be sure to use the longer version of the command:
# find / \( -local -o -prune \) -perm -002 -group user \! \( -type l -o -type p -o -type s \) -ls
A more security-conscious site can further generalize this rule:
Files that begin with a period should not be readable or writable by anyone other than the file's owner and group (that is, they should be mode 620).
Use the following form of the find command to search for all files beginning with a period in the /u filesystem that are either group writable or world writable:
# find /u -perm -2 -o -perm -20 -name .\* -ls
NOTE: As noted earlier, if you're using NFS, be sure to add the -local or -xdev option to each of the find commands above and run them on each of your servers, or use the fstype/prune options.
Shell script to find all world-writable files and directories on Linux or FreeBSD system
#!/bin/bash
# Shell script to find all world-writable files and
directories on Linux or
# FreeBSD system
#
# TIP:
# Set 'umask 002' so that new files created will not be
world-writable
# And use command 'chmod o-w filename' to disable
world-wriable file bit
#
# Copyright (c) 2005 nixCraft project
# This script is licensed under GNU GPL version 2.0 or
above
# For more info, please visit:
#
http://cyberciti.biz/shell_scripting/bmsinstall.php
#
-------------------------------------------------------------------------
# This script is part of nixCraft shell script
collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more
information.
#
-------------------------------------------------------------------------
SPATH="/usr/local/etc/bashmonscripts"
INITBMS="$SPATH/defaults.conf"
[ !
-f $INITBMS
] &&
exit 1
|| .
$INITBMS
[ $#
-eq 1 ] && : || die "Usage: $($BASENAME $0) directory" 1
DIRNAME="$1"
$FIND $DIRNAME
-xdev -perm
+o=w
! \(
-type d -perm
+o=t
\) !
-type l -print
| find / -perm -2 -a !
-type l /* Find files writable by 'others' */ |
2005-04-12 |
| find / -perm -0777 -type
d -ls /* Find all your writable directories */ |
2005-03-22 |
Normal Unix commands such as find and ls may be used to locate such files, e.g.
find /usr -name '.*' -type d -printto find "hidden" files and directories. find may also be used to search by modification time, e.g.
find /bin -ctime -365 -printwill find anything changed in the last year, similarly for /sbin /usr/kvm /usr/local/bin etc.
In Win95, hidden files are also possible; BackOrifice uses this technique to hide, using a blank icon and blank prefix, ".exe" does not show up in a icon-based directory.
find /bin -perm +6000 -printor perhaps
find /bin -perm +6000 -exec ls -lg {} \;
On systems where find does not support the perm option, ls may be
used, e.g.
ls -latg /usr/bin/* /sbin/* /usr/sbin/* /usr/local/bin/* | grep '^...s'The point here is to find system files that appear to have been modified since the system was installed, or unauthorized programs, such as an suid shell (which executes a user's every command with root privilege).
Data disks may be mounted noexec. This means that files in these directories cannot be executed.
Linux users may use the ext2fs utility chattr to make system directories or files "immutable", or create append-only logfiles. An intruder would first have to gain root, then change the filesystem attributes, before creating a file.
A.Daviel
Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.
Created: May 16, 1997; Last modified: June 05, 2008