|
Home | Switchboard | Unix Administration | Red Hat | TCP/IP Networks | Neoliberalism | Toxic Managers |
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and bastardization of classic Unix |
News | SUID Attribute | Recommended Links | File Permissions Hardening | World writable files problem |
Finding SUID/SGUID files | Findsuid | Suidcontrol | Humor | Etc |
|
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.
In ls listing file permissions for file with SUID attribute looks like: -rwsr-xr-x
Examples of SUID root programs:
|
SUID/SGID files can be a security hazard. To reduce the risks, we have previously already removed the s bits from root-owned programs that won't absolutely require such privilege, but future and existing files may be set with these s bits enabled without your notification.
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.
for part in \ `awk '($4 == "ufs") {print $3 }' /etc/vfstab` do find $part \( -perm -04000 -o -perm -02000\) \ -type f -xdev -print doneThe proper way of doing this is actually by using 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 }
|
Switchboard | ||||
Latest | |||||
Past week | |||||
Past month |
Code Listing 1: Finding world-writable files and directories
# /usr/bin/find / -type f \( -perm -2 -o -perm -20 \) \ -exec ls -lg {} \; 2>/dev/null >writable.txt # /usr/bin/find / -type d \( -perm -2 -o -perm -20 \) \ -exec ls -ldg {} \; 2>/dev/null >>writable.txtThis will create a huge file with permission of all files having either write permission set to the group or everybody. Check the permissions and eliminate world writable files to everyone, by executing /bin/chmod o-w on the files.
6.c. SUID/SGID files
Files with the SUID or SGID bit set execute with privileges of the owning user or group and not the user executing the file. Normally these bits are used on files that must run as root in order to do what they do. These files can lead to local root compromises (if they contain security holes). This is dangerous and files with the SUID or SGID bits set should be avoided at any cost. If you do not use these files, use chmod 0 on them or unmerge the package that they came from (check which package they belong to by using equery; if you do not already have it installed simply type emerge gentoolkit). Otherwise just turn the SUID bit off with chmod -s.
Code Listing 2: Finding setuid files
# /usr/bin/find / -type f \( -perm -004000 -o -perm -002000 \) \ -exec ls -lg {} \; 2>/dev/null >suidfiles.txtThis will create a file containing a list of all the SUID/SGID files.
To find all SGID files:
find / -xdev -type f -perm +g=s -printTo find all SUID files
find / -xdev -type f -perm +u=s -printTo find all Writable dirs:
find / -xdev -perm +o=w ! \( -type d -perm +o=t \) ! -type l -print
World writable files problem
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 \) -lsIf 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 \) -lsA 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 .\* -lsNOTE: 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
Hidden Files
In Unix, "hidden" files are ones with a leading dot, e.g. ".ssh". These don't show up in a normal directory listing (ls), but do with the "all" option (ls -a). Usually, these are used to hide things like login scripts and control files to prevent one's home directory appearing cluttered, but may be used by intruders to hide files.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.
suid programs
suid root programs are an especial concern, since they execute with root privilege. If such a program can be fooled into executing an arbitrary command, perhaps by a buffer-overrun exploit, it can be used to create new user IDs or open network holes. On some systems (gnu) find may be used to locate these programs, e.g.find /bin -perm +6000 -printor perhapsfind /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).Precautions
Non-system disk volumes should be mounted nosuid. This is a special concern for Linux users who may have obsolete live systems mounted on CD-ROM.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
[email protected]
Google matched content |
fix-modes
Casper Dik wrote a tool consiting of a set of scripts which modifies file permissions in an effort to make things more secure. The tool removes group and world write permissions of all files, devices, and directories listed in /var/sadm/install/contents, with the exception of those files listed in exceptions.h, and changes ownership of most files to root.
NOTE: the script has been tested under Solaris 2.2-8 Operating Environment and will purposely fail on other releases. Casper Dik works for Sun in Holland, but the tool is not officially recognized by Sun so it is distributed from Casper's personal account.
An advantage in using fix-modes is it creates an audit trail and the changes can be undone which is important if you are embarking on an upgrade.
The fix-modes tar-bundle comes with a README with installation instructions.
Download fix-modes
Alternate download from CERIAS for fix-modes
There is a Sun BluePrints[tm] paper discussing fix-modes.
Fix-modes is incorporated in JumpStart[tm] Architecture and Security Scripts (JASS) toolkit.
- Solaris Security Toolkit (JASS)
- Sun Blueprint for JASS
Fix-modes is also part of the Titan OS hardening tool.
University of Waterloo also has some Bourne Shell scripts for Solaris 2.6, Solaris 7 and Solaris 8 Setuid/Setgid in addition to other Security: How to Documents"
[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
Society
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
Quotes
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Bulletin:
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
History:
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
Classic books:
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D
Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|
You can use PayPal to to buy a cup of coffee for authors of this site |
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.
Created: May 16, 1997; Last modified: March 12, 2019