#!/bin/sh
# Audit SuSE Linux v1.5 (c) 2001-2012 by Marc Heuse <mh@mh-sec.de>
# Source repository: http://www.baseline-security.de/audit/
# Note: This script is for checking the system configuration, NOT for forensic!
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
PATH="/sbin:/usr/sbin:/bin:/usr/bin:$PATH"
HOSTNAME=`hostname`
AUDIT_NAME="AUDIT-$HOSTNAME"
AUDIT_DIR="/tmp/$AUDIT_NAME"
OUTFILE="$AUDIT_DIR.tar.gz"

[ "`id -u`" -ne 0 ] && echo "Not running as root, some information might not be extracted"

FILE_LIST_ETC="/etc/aliases /etc/sendmail.cf /etc/passwd /etc/group \
 /etc/cron* /etc/export* /etc/profile /etc/login* /etc/shad* /etc/postfix \
 /etc/*ftp* /etc/host* /etc/inittab /etc/issue* /etc/motd /etc/csh* \
 /etc/shells /etc/securetty /etc/sock* /etc/yp* /etc/*conf* /etc/*cfg* /etc/*.d \
 /etc/rc* /etc/apache /etc/httpd /etc/default /etc/security /etc/init.d \
 /sbin/init.d /etc/*ssh*/ssh*conf* /etc/sudoers /etc/samba /usr/local/etc \
 /etc/*/*conf /etc/xinetd* /etc/squid /etc/sysconfig /etc/export* "

OLD_UMASK=`umask`
OLD_ENV=`env`
umask 077
set -o noclobber
> "$OUTFILE" || exit 1
if [ -e "$AUDIT_DIR" ]; then
    mv "$AUDIT_DIR" "$AUDIT_DIR".old
fi
mkdir "$AUDIT_DIR" || exit 1
cd "$AUDIT_DIR" || exit 1
set +o noclobber

df -k > disk.out 2>&1
uptime > uptime.out  2>&1
cat /proc/meminfo > memory.out  2>&1
sar 5 2 > sar.out  2>&1
vmstat > vmstat.out  2>&1

tar cf etc.tar $FILE_LIST_ETC 2> /dev/null
tar cf var.tar /var/yp /var/nis/data /var/spool/cron 2> /dev/null
tar cf home.tar /.*bash* /.netrc /.rhosts /.log* /.*csh* /.Xa* \
 /.prof* /home/*/.*bash* /home/*/.netrc /home/*/.rhosts \
 /home/*/.log* /home/*/.*csh* /home/*/.Xa* /home/*/.prof* \
 /root/.*bash* /root/.netrc /root/.rhosts /root/.log* /root/.*csh* \
 /root/.Xa* /root/.prof* 2> /dev/null

find / \( -perm -4000 -o -perm -2000 \) -type f -exec /bin/ls -ld {} \; > find-s_id.out
find / -perm -2 '!' -type l -exec /bin/ls -ld {} \; > find-write.out

/bin/ls -alR /etc > ls-etc.out
/bin/ls -alRL /dev > ls-dev.out
/bin/ls -al /tmp > ls-tmp.out
/bin/ls -alR /var/log /var/adm /var/spool /var/spool/mail > ls-var.out
/bin/ls -lL /dev/*rmt* /dev/*floppy* /dev/fd0* /dev/*audio* /dev/*mix* > ls-dev-spec.out 2> /dev/null
/bin/ls -alR /opt /software /usr/local > ls-software.out 2> /dev/null
/bin/ls -alR /vmlin* /boot > ls-boot.out 2>&1
/bin/ls -alRL /home /root > ls-home.out 2>&1

mount > mount.out
rpcinfo -p > rpcinfo.out 2>/dev/null
ps auxwww > ps.out
lsmod > lsmod.out
rpm -qa > rpm.out 2> /dev/null
uname -a > uname.out 
cat /etc/*release* >> uname.out  2> /dev/null
last -25 > last_25.out
last -5 root > last_root.out
history > history.out
xhost > xhost.out 2> /dev/null
xauth list >xauth.out  2>&1
echo "$OLD_ENV" > env.out
echo "$OLD_UMASK" > umask.out
netstat -an > netstat-an.out
netstat -rn > netstat-rn.out
netstat -anp > netstat-anp.out
which lsod > /dev/null 2>&1 && lsof -i -n -P > lsof.out 2>&1

ipfwadm  -L -n -v > ipfwadm.out 2> /dev/null
iptables -L -n -v > iptables.out 2> /dev/null
ipchains -L -n -v > ipchains.out 2> /dev/null

for i in icmp_echo_ignore_broadcasts icmp_echo_ignore_all tcp_syncookies \
 ip_always_defrag ip_forward igmp_max_memberships icmp_destunreach_rate; do
    echo -n "/proc/sys/net/ipv4/$i: " >> proc.out 
    cat /proc/sys/net/ipv4/$i >> proc.out 2> /dev/null
    echo "" >> proc.out
done
for i in /proc/sys/net/ipv4/conf/*; do
    for j in accept_redirects accept_source_route rp_filter bootp_relay \
     mc_forwarding log_martians proxy_arp secure_redirects; do
        echo -n "$i/$j: " >> proc.out
        cat $i/$j >> proc.out 2> /dev/null
        echo "" >> proc.out
    done
done

cd /tmp
tar czf "$OUTFILE" "$AUDIT_NAME"
echo
echo "$OUTFILE" is finished, you may delete "$AUDIT_DIR" now.

