ccesar2
(usa Outra)
Enviado em 31/03/2011 - 14:08h
Segue o código!
#!/bin/bash
#CaiO
#Remove unnecessary SUID Files (hijack root using SUID privileges/buffer overflow)
/usr/bin/find / -type f \( -perm -004000 -o -perm -002000 \) -exec ls -lg {} \; 2>/dev/null >/tmp/suidfiles.txt
/bin/chmod -s /usr/bin/chsh /usr/bin/gpasswd /usr/bin/chfn /usr/bin/wall /usr/bin/screen /usr/bin/rcp /usr/bin/rsh /sbin/umount.nfs4 /sbin/mount.nfs /sbin/umount.nfs /sbin/mount.nfs4 /bin/ping /bin/ping6 /bin/umount /bin/mount
# Disable trusted relation
/bin/echo >/etc/hosts.equiv
/bin/echo >/etc/.netrc
/bin/echo >/etc/.rhosts
/bin/echo > ~/.rhosts
/bin/chmod 400 /etc/hosts.equiv
/bin/chmod 400 /etc/.netrc
/bin/chmod 400 /etc/.rhosts
/bin/chmod 400 ~/.rhosts
# Restrict read and write in the audit files
for a in /var/log/*; do [ -f $a ] && chmod 600 $a; [ -d $a ] && chmod 700 $a; done
# Lock system users passwords
/usr/sbin/usermod -L bin
/usr/sbin/usermod -L daemon
/usr/sbin/usermod -L adm
/usr/sbin/usermod -L lp
/usr/sbin/usermod -L mail
/usr/sbin/usermod -L news
/usr/sbin/usermod -L uucp
/usr/sbin/usermod -L operator
/usr/sbin/usermod -L games
/usr/sbin/usermod -L gopher
/usr/sbin/usermod -L rpm
/usr/sbin/usermod -L dbus
/usr/sbin/usermod -L avahi
/usr/sbin/usermod -L mailnull
/usr/sbin/usermod -L smmsp
/usr/sbin/usermod -L nscd
/usr/sbin/usermod -L haldaemon
/usr/sbin/usermod -L ntp
/usr/sbin/usermod -L pcap
# Restrict SU command
/bin/echo 'auth required pam_wheel.so use_uid' >> /etc/pam.d/su
# SYN floods (instead of using recent or limit)
count=`grep "net.ipv4.tcp_syncookies=1" /etc/sysctl.conf | wc -l`
if test ! $count -eq 0
then
echo
else
echo net.ipv4.tcp_syncookies=1 >>/etc/sysctl.conf
fi
# Restrict CC/GCC usr
/bin/chmod go-rwx /usr/bin/gcc
# Block Broadcast response
count=`grep "net.ipv4.icmp_/bin/echo_ignore_broadcasts=1" /etc/sysctl.conf | wc -l`
if test ! $count -eq 0
then
echo
else
echo net.ipv4.icmp_/bin/echo_ignore_broadcasts=1 >>/etc/sysctl.conf
fi
# Configure Sticky bit in temporary directories
/bin/chmod 1777 /var/tmp /tmp
# Restrict "Ctrl+Alt+Del" command
cat /etc/inittab | sed 's/ca::ctrlaltdel:/#ca::ctrlaltdel:/' >>/tmp/inittab.new
rm -f /etc/inittab
mv /tmp/inittab.new /etc/inittab
# Block interface spoof
count=`grep "net.ipv4.conf.all.rp_filter=1" /etc/sysctl.conf | wc -l`
if test ! $count -eq 0
then
echo
else
echo net.ipv4.conf.all.rp_filter=1 >>/etc/sysctl.conf
fi
# Block package routing between interfaces (still IP Spoofing)
count=`grep "net.ipv4.conf.all.forwarding=0" /etc/sysctl.conf | wc -l`
if test ! $count -eq 0
then
echo
else
echo net.ipv4.conf.all.forwarding=0 >>/etc/sysctl.conf
fi
# Block packages with source-route (still IP Spoofing)
count=`grep "net.ipv4.conf.all.accept_source_route=0" /etc/sysctl.conf | wc -l`
if test ! $count -eq 0
then
echo
else
echo net.ipv4.conf.all.accept_source_route=0 >>/etc/sysctl.conf
fi
# Log suspicious packages
count=`grep "net.ipv4.conf.all.log_martians=1" /etc/sysctl.conf | wc -l`
if test ! $count -eq 0
then
echo
else
echo net.ipv4.conf.all.log_martians=1 >>/etc/sysctl.conf
fi
# Restrict crontab access only for super users
/bin/echo root >/etc/cron.allow
# Restrict at only for super-users
/bin/echo root >/etc/at.allow
# Disable ICMP routing redirects
count=`grep "net.ipv4.conf.all.accept_redirects=0" /etc/sysctl.conf | wc -l`
if test ! $count -eq 0
then
echo
else
echo net.ipv4.conf.all.accept_redirects=0 >>/etc/sysctl.conf
fi
# Remove write permission to "others" in the directory /etc
/bin/chmod -fR o-w /etc/*
# Define restricted default umask
echo 'if [ `id -u` != 0 ]; then umask 027; else umask 077; fi' >> /etc/bashrc
# Apple Parameters Kernel Changes
/sbin/sysctl -p /etc/sysctl.conf
# Add disclaimer
/bin/echo "The information on this computer and network is the property of XXXXXXXXX and is protected by intellectual property rights.
Your activities will be monitored and logged, be aware that you must be assigned an account on this computer to access information and are only allowed
to access information defined by the information security team.
" >> /tmp/testediscl
# Enforce password history = 10 last passwords in system-auth-ac
# Password Complexity
# Account Lockout Threshold = 3 invalid login attempts
# Password aging controls
mv -f /tmp/baseline/system-auth-ac /etc/pam.d/
chown root.root /etc/pam.d/system-auth-ac
chmod 644 /etc/pam.d/system-auth-ac
mv -f /tmp/baseline/login.defs /etc/
chown root.root /etc/login.defs
chmod 644 /etc/login.defs
# Configure logrotate perm
mv -f /tmp/logrotate.conf /etc/
chown root.root /etc/logrotate.conf
chmod 644 /etc/logrotate.conf