#!/bin/sh ######################################################################### # # FILE : findholes # DATE : 18.1.2000 # AUTHOR : Patrick Meier / patrick.meier@gmx.net # DESCRIPTION : find security holes # # Copyrigth (C) 2001 by Patrick Meier, Switzerland # ######################################################################### PN=`basename "$0"` file=".findholes" startPath="." ######################################################################### # Usage ######################################################################### Usage() { echo "$PN - find security holes" echo "usage: $PN [-s path (default:$startPath)] [-f filename (default:$file)]" exit 1 } ######################################################################### # ParameterFailed ######################################################################### ParameterFailed() { echo "${STARTSTRING}Parameter faild: $1 ..."; echo "" Usage } ######################################################################### # getTitle ######################################################################### getTitle() { num=0 while read l do if [ -z "${l%%==>*}" ] then title=$l fi if [ "$2" = "$((num))" ] then if [ "$title" != "$oldtitle" ] then oldtitle=$title echo echo $title fi return 0 fi num=$((num=num+1)) done < $1 } ######################################################################### # searchHoles ######################################################################### searchHoles() { log="$1" startDir="$2" echo "checking the file system:" > $log echo "=========================" >> $log echo "==>finding world-writable files..." >> $log find $startDir -perm 2 -print >> $log 2>/dev/null echo >> $log echo "==>finding unowned files..." >> $log find $startDir -nouser -print >> $log 2>/dev/null find $startDir -nouser -o -nogroup -print >> $log 2>/dev/null echo >> $log echo "==>finding .rhosts Files..." >> $log find $startDir -name .rhosts -print >> $log 2>/dev/null echo >> $log echo "==>findig suid-programmes..." >> $log find $startDir -type f -a \( -perm -4000 -o -perm -2000 \) -print >> $log 2>/dev/null echo >> $log } ######################################################################### # parseLogFile : parse the diff-file ######################################################################### parseLogFile() { # read diff-file and parse the output first= while read line do if [ -z "$first" ] then echo "checking the file system:" echo "=========================" first="no" fi if [ -n "`echo $line | grep \"> \"`" ] then if [ -n "${oldline##> *}" ] then getTitle $1 ${oldline%a*} fi echo $line | grep "> " | sed 's/> //' | awk '{ print "removed\t: " $0 }' elif [ -n "`echo $line | grep \"< \"`" ] then if [ -n "${oldline##> *}" ] then getTitle $1 ${oldline%d*} fi echo $line | grep "< " | sed 's/< //' | awk '{ print "added\t: " $0 }' fi oldline=$line done < $1 } ######################################################################### # main ######################################################################### while [ $# -gt 0 ] do case "$1" in -s) if [ $# -gt 1 ] ; then startPath="$2"; shift; else ParameterFailed "$1"; fi;; -f) if [ $# -gt 1 ] ; then file="$2"; shift; else ParameterFailed "$1"; fi;; -h) Usage; exit 1;; -*) Usage; exit 1;; *) break;; esac shift done if [ -r $file ] then cp $file ${file}.old searchHoles $file $startPath # get diff diff $file $file.old > /tmp/diff$$ parseLogFile /tmp/diff$$ rm /tmp/diff$$ else searchHoles $file $startPath fi ######################################################################### # EOF #########################################################################