Post-kickstart.sh
From ChekMate Security Group
This script WILL require modifications as it defines generic names for things like YOUR-YAM-SERVER, YOUR-SYSLOG-SERVER, USERNAME-1, etc. Please read the entire script to see what may be required to change.
In the future, I may define variables to declare at the beginning of the script.
#####################################################################
#####################################################################
###
### Copyright (c) 2005 Shannon McNaught
###
### 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.
###------------------------------------------------------------------
### post_kickstart.sh : a bash script for hardening CentOS 4.2 OS
###------------------------------------------------------------------
### Most of this code has been designed, written and is maintained
### by Shannon McNaught. See online wiki for specific developer
### credit. Any questions or comments regarding this code should be
### directed to: smcnaught@axia.com
###
#####################################################################
#####################################################################
#####################################################################
#####################################################################
### Move to Terminal 3 and Set Up Logging
#####################################################################
#####################################################################
echo
echo
echo "#####################################################################"
echo "# Create directories for build process"
echo "#####################################################################"
mkdir -p /var/log/build
exec < /dev/tty3 > /dev/tty3
chvt 3
(
echo
echo
echo "#####################################################################"
echo "#####################################################################"
echo "### Question Function for User Specific Information"
echo "#####################################################################"
echo "#####################################################################"
question()
{
#####################################################################
# Ask for IP Address
#####################################################################
echo
echo -e "What is your IP Address : \c"
read IP
export IP
#####################################################################
# Ask for Default Gateway
#####################################################################
echo
echo -e "What is your Default Gateway : \c"
read DFG
export DFG
#####################################################################
# Ask for Netmask
#####################################################################
echo
echo -e "What is your Netmask : \c"
read NM
export NM
#####################################################################
# Ask for Domain Name
#####################################################################
echo
echo -e "What is your Domain : \c"
read DM
export DM
#####################################################################
# Ask for Hostname
#####################################################################
echo
echo -e "What is your Hostname : \c"
read HN
export HN
#####################################################################
# Ask for Primary DNS
#####################################################################
echo
echo -e "What is the Primary DNS : \c"
read NS1
export NS1
#####################################################################
#Ask for Secondary DNS
#####################################################################
echo
echo -e "What is Secondary DNS : \c"
read NS2
export NS2
#####################################################################
# Display All Variables
#####################################################################
echo
echo
echo
echo "Confirm Network Configuration:"
echo
echo -e "The IP Address is : $IP"
echo -e "The Default Gateway is : $DFG"
echo -e "The Netmask is : $NM"
echo -e "The Domain is : $DM "
echo -e "The Hostname is : $HN"
echo -e "The Primary DNS Server is : $NS1"
echo -e "The Secondary DNS Server is : $NS2"
echo -e "Please confirm by y/n or quit: \c"
read ANSW
case $ANSW in
y)
init
;;
n)
question
;;
quit)
echo $0" interrupted !!!"
exit 1
;;
*) echo "Invalid Choice - Loading Network Questions....."
sleep 5
question
esac
}
echo
echo
echo "#####################################################################"
echo "#####################################################################"
echo "### Init Function to Configure and Harden OS"
echo "#####################################################################"
echo "#####################################################################"
init()
{
echo
echo
echo "#####################################################################"
echo "# DNS configuration"
echo "#####################################################################"
cp /etc/resolv.conf /etc/resolv.conf.orig
echo "domain $DM" > /etc/resolv.conf.build
echo "search $DM" >> /etc/resolv.conf.build
echo "nameserver $NS1" >> /etc/resolv.conf.build
echo "nameserver $NS2" >> /etc/resolv.conf.build
cp /etc/resolv.conf.build /etc/resolv.conf
cat /etc/resolv.conf
echo
echo
echo "#####################################################################"
echo "# Build eth1 from variables"
echo "# NOTE: This will need to be configured to the server. ************
echo "#####################################################################"
cat << NETCONF > /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=$IP
NETMASK=$NM
GATEWAY=$DFG
NETCONF
cat /etc/sysconfig/network-scripts/ifcfg-eth0
echo
echo
echo "#####################################################################"
echo "# Network boots"
echo "#####################################################################"
echo "NETWORKING=yes" > /etc/sysconfig/network
echo "HOSTNAME=\"$HN\"" >> /etc/sysconfig/network
echo "GATEWAY=$DFG" >> /etc/sysconfig/network
cat /etc/sysconfig/network
echo
echo
echo "#####################################################################"
echo "# Capture the initial build network configuration"
echo "#####################################################################"
cp /etc/hosts /var/log/build/hosts.build
cp /etc/sysconfig/network /var/log/build/network.build
cp /etc/sysconfig/network-scripts/ifcfg-eth* /var/log/build/
cat /etc/hosts
echo
echo
echo "#####################################################################"
echo "# Capture the initial log files generated by anaconda"
echo "#####################################################################"
cp -p /root/* /var/log/build
echo
echo
echo "#####################################################################"
echo "# Configure SSH"
echo "#####################################################################"
cd /etc/ssh
awk '($1=="Protocol") { print "Protocol 2"; next };
{ print }' ssh_config >ssh_config.new
/bin/mv ssh_config.new ssh_config
/bin/chown root:root ssh_config
/bin/chmod 644 ssh_config
if [ "`egrep -l ^Protocol ssh_config`" == "" ]; then
echo 'Protocol 2' >>ssh_config
fi
echo "ssh_config:"
cat /etc/ssh/ssh_config
echo
awk '/^#?Protocol/ { print "Protocol 2"; next };
/^#?X11Forwarding/ \
{ print "X11Forwarding no"; next };
/^#?IgnoreRhosts/ \
{ print "IgnoreRhosts yes"; next };
/^#?RhostsAuthentication/ \
{ print " RhostsAuthentication no"; next };
/^#?RhostsRSAAuthentication/ \
{ print "RhostsRSAAuthentication no"; next };
/^#?HostbasedAuthentication/ \
{ print "HostbasedAuthentication no"; next };
/^#?PermitRootLogin/ \
{ print "PermitRootLogin no"; next };
/^#?PermitEmptyPasswords/ \
{ print "PermitEmptyPasswords no"; next };
{print}' sshd_config >sshd_config.new
/bin/mv sshd_config.new sshd_config
/bin/chown root:root sshd_config
/bin/chmod 600 sshd_config
echo "sshd_config:"
cat /etc/ssh/sshd_config
echo
echo
echo "#####################################################################"
echo "# Create User Accounts"
echo "#####################################################################"
/usr/sbin/useradd USERNAME-1 -u 501 -g 100 -p \$1\$s6M11111\$W8F11111111aUAAjMyK100
/usr/sbin/useradd USERNAME-2 -u 502 -g 100 -p \$1\$TDj22222\$f4.E2222222yZLkYqh3wY0
/usr/sbin/useradd USERNAME-3 -u 503 -g 100 -p \$1\$RiJ33333\$qkNK3333333BFeBQRARC51
mv /etc/group /etc/group.orig
sed "s/wheel:x:10:root/wheel:x:10:root,USERNAME-1,USERNAME-2,USERNAME-3/" /etc/group.orig > /etc/group
echo "passwd:"
cat /etc/passwd
echo
echo "group:"
cat /etc/group
echo
echo
echo "#####################################################################"
echo "# Install RPM Keys"
echo "#####################################################################"
cd /root
wget http://YAM-SERVER-IP/yam/RPM-GPG-KEY
wget http://YAM-SERVER-IP/yam/RPM-GPG-KEY-centos4
wget http://YAM-SERVER-IP/yam/RPM-GPG-KEY.dag.txt
rpm --import RPM-GPG-KEY
rpm --import RPM-GPG-KEY-centos4
rpm --import RPM-GPG-KEY.dag.txt
echo
echo
echo "#####################################################################"
echo "# Disable and stop services"
echo "#####################################################################"
for svc in autofs cpuspeed kudzu mdmonitor rhnsd rawdevices rpcsvcgssd rpcgssd smartd
do
chkconfig --level 12345 $svc off
/etc/init.d/$svc stop
done
echo
echo
echo "#####################################################################"
echo "# Stop and remove services"
echo "#####################################################################"
for svc in apmd atd anacron isdn pcmcia smartd
do
/etc/init.d/$svc stop
chkconfig --del $svc
done
echo
echo
echo "#####################################################################"
echo "# For some services, disable them but leave them running during the build"
echo "#####################################################################"
for svc in mdmpd netfs nfslock portmap sendmail smartd
do
chkconfig --level 12345 $svc off
done
echo
echo
echo "#####################################################################"
echo "# Network Parameter Modifications"
echo "#####################################################################"
cp -p /etc/sysctl.conf /etc/sysctl.conf.orig
cat <<END_SCRIPT >> /etc/sysctl.conf
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
END_SCRIPT
/bin/chown root:root /etc/sysctl.conf
/bin/chmod 0600 /etc/sysctl.conf
echo
echo
echo "#####################################################################"
echo "# Additional Network Parameter Modifications"
echo "#####################################################################"
cat <<END_SCRIPT >> /etc/sysctl.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
END_SCRIPT
/bin/chown root:root /etc/sysctl.conf
/bin/chmod 0600 /etc/sysctl.conf
echo "sysctl:"
cat /etc/sysctl.conf
echo
echo
echo "#####################################################################"
echo "# Correct Filesystem insecurities"
echo "#####################################################################"
cp -p /etc/fstab /etc/fstab.orig
echo
echo
echo "#####################################################################"
echo "# Add 'nodev. option to appropriate partitions in /etc/fstab"
echo "#####################################################################"
awk '($2 ~ /\/boot/) { $4 = $4 ",nodev,ro" }; { print }' /etc/fstab >/etc/fstab.new
/bin/mv /etc/fstab.new /etc/fstab
/bin/chown root:root /
/bin/chmod 0644 /etc/fstab
cat /etc/fstab
echo
echo
echo "#####################################################################"
echo "# Change default permission on /bin/rpm"
echo "#####################################################################"
chmod 700 /bin/rpm
echo
echo
echo "#####################################################################"
echo "# Disable user-mounted removable filesystems"
echo "#####################################################################"
cp -p /etc/security/console.perms /etc/security/console.perms.orig
awk '($1 == "<console>") && ($3 !~ /sound|fb|kbd|joystick|v4l|mainboard|gpm|scanner/) { $1 = "#<console>" };{print }' /etc/security/console.perms >/etc/security/console.perms.new
/bin/mv /etc/security/console.perms.new /etc/security/console.perms
/bin/chown root:root /etc/security/console.perms
/bin/chmod 0600 /etc/security/console.perms
cat /etc/security/console.perms
echo
echo
echo "#####################################################################"
echo "# Remove IP6 applications"
echo "#####################################################################"
rm /bin/ping6
rm /usr/sbin/ping6
rm /bin/traceroute6
rm /usr/sbin/traceroute6
rm /bin/tracepath6
rm /usr/sbin/tracepath6
echo
echo
echo "#####################################################################"
echo "# Disable the suid bits on selected programs"
echo "#####################################################################"
chmod a-s /usr/libexec/openssh/ssh-keysign
chmod a-s /usr/libexec/pt_chown
chmod a-s /usr/bin/rlogin
chmod a-s /usr/bin/wall
chmod a-s /usr/bin/gpasswd
chmod a-s /usr/bin/write
chmod a-s /usr/bin/chfn
chmod a-s /usr/bin/newgrp
chmod a-s /usr/bin/rsh
chmod a-s /usr/bin/chsh
chmod a-s /usr/bin/chage
chmod a-s /usr/bin/rcp
chmod a-s /usr/sbin/userhelper
chmod a-s /usr/sbin/usernetctl
chmod a-s /bin/traceroute
chmod a-s /bin/umount
chmod a-s /bin/mount
chmod a-s /sbin/netreport
echo
echo
echo "#####################################################################"
echo "# Restrict at/cron to authorized users"
echo "#####################################################################"
/bin/rm -f /etc/cron.deny /etc/at.deny
echo root >/etc/cron.allow
echo root >/etc/at.allow
/bin/chown root:root /etc/cron.allow /etc/at.allow
/bin/chmod 400 /etc/cron.allow /etc/at.allow
echo "cron.allow:"
cat /etc/cron.allow
echo
echo "at.allow:"
cat /etc/at.allow
echo
echo
echo "#####################################################################"
echo "# Restrict permissions on crontab files"
echo "#####################################################################"
/bin/chown root:root /etc/crontab
/bin/chmod 400 /etc/crontab
/bin/chown -R root:root /var/spool/cron
/bin/chmod -R go-rwx /var/spool/cron
/bin/chown -R root:root /etc/cron.*
/bin/chmod -R go-rwx /etc/cron.*
cat /etc/crontab
echo
echo
echo "#####################################################################"
echo "# Restrict root logins to system console"
echo "#####################################################################"
cp -p /etc/securetty /etc/securetty.orig
/bin/cp /dev/null /etc/securetty
echo tty1 >>/etc/securetty
for i in 2 3 4 5 6; do
echo "#tty$i" >>/etc/securetty
done
echo vc/1 >>/etc/securetty
for i in 2 3 4 5 6; do
echo "#tty$i" >>/etc/securetty
done
echo console >>/etc/securetty
/bin/chown root:root /etc/securetty
/bin/chmod 400 /etc/securetty
cat /etc/securetty
echo
echo
echo "#####################################################################"
echo "# Set GRUB permissions"
echo "#####################################################################"
/bin/chown root:root /etc/grub.conf
/bin/chmod 600 /etc/grub.conf
cat /etc/grub.conf
echo
echo
echo "#####################################################################"
echo "# Immunize the /etc/services file"
echo "#####################################################################"
chattr +i /etc/services
echo
echo
echo "#####################################################################"
echo "# Delete default users"
echo "#####################################################################"
userdel adm
userdel lp
userdel shutdown
userdel halt
userdel news
userdel uucp
userdel operator
userdel games
userdel gopher
userdel ftp
userdel haldaemon
userdel netdump
userdel mailnull
userdel rpc
userdel pcap
userdel xfs
echo
echo
echo "#####################################################################"
echo "# Delete default groups"
echo "#####################################################################"
groupdel adm
groupdel lp
groupdel news
groupdel uucp
groupdel games
groupdel dip
echo
echo
echo "#####################################################################"
echo "# Require authentication for single-user-mode"
echo "#####################################################################"
cd /etc
mv -f /etc/inittab /etc/inittab.orig
if [ "`grep -l sulogin inittab.orig`" = "" ]; then
awk '{ print }; /^id:[0123456sS]:initdefault:/{ print "~~:S:wait:/sbin/sulogin"}' /etc/inittab.orig > /etc/inittab.new
fi
sed "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab.new > /etc/inittab
/bin/chown root:root /etc/inittab
/bin/chmod 644 /etc/inittab
/sbin/init q
cat /etc/inittab
echo
echo
echo "#####################################################################"
echo "# Block system accounts"
echo "#####################################################################"
for name in `cut -d: -f1 /etc/passwd`; do
uid=`id -u $name`
if [ $uid -lt 500 -a $name != 'root' ]; then
/usr/sbin/usermod -L -s /dev/null $name
fi
done
echo
echo
echo "#####################################################################"
echo "# Set account expiration parameters on active accounts"
echo "#####################################################################"
cd /etc
awk '($1 ~ /^PASS_MAX_DAYS/) { $2="60" }
($1 ~ /^PASS_MIN_DAYS/) { $2="1" }
($1 ~ /^PASS_WARN_AGE/) { $2="7" }
($1 ~ /^PASS_MIN_LEN/) { $2="8" }
{ print } ' login.defs > login.defs.new
/bin/mv login.defs.new login.defs
/bin/chown root:root login.defs
/bin/chmod 640 login.defs
for name in `cut -d: -f1 /etc/passwd`; do
uid=`id -u $name`
if [ $uid -ge 500 -a $uid != 65534 ]; then
/usr/bin/chage -m 1 -M 60 -W 7 $name
fi
done
cat login.defs
echo
echo
echo "#####################################################################"
echo "# Disable core dumps"
echo "#####################################################################"
cat <<END_ENTRIES >>/etc/security/limits.conf
* soft core 0
* hard core 0
END_ENTRIES
cat /etc/security/limits.conf
echo
echo
echo "#####################################################################"
echo "# Configure yum.conf to point to local repositories"
echo "#####################################################################"
rm -f /etc/yum.repos.d/CentOS-Base.repo
cd /root
wget http://YAM-SERVER-IP/yam/yum.conf
mv -f /root/yum.conf /etc/yum.conf
cat /etc/yum.conf
echo
echo
echo "#####################################################################"
echo "# Remove unneeded rpm packages"
echo "#####################################################################"
yum -y remove authconfig ntsysv setuptool quota ash time acl attr autofs bc bind-utils comps cups cups-libs cyrus-sasl-plain dhcpv6_client dos2unix dosfstools dump fbset finger ftp gettext htmlview ipsec-tools irda-utils isdn4k-utils jwhois
yum -y remove kernel-utils krb5-workstation lftp lha libwvstreams lockdev logwatch man-pages mdadm mgetty minicom mtr mt-st nano nc netconfig netdump nfs-utils nscd nss_ldap pam_smb parted pax pdksh pinfo portmap ppp psacct rdate rdist redhat-lsb redhat-menus rhnlib rhpl rmt rp-pppoe
yum -y remove schedutils setarch specspo stunnel symlinks sysreport system-config-mouse system-config-network-tui system-config-securitylevel-tui talk telnet unix2dos unzip up2date wireless-tools wvdial xinetd ypbind yp-tools zip
echo
echo
echo "#####################################################################"
echo "# Install additional packages"
echo "# * Install sysstat"
echo "# * Install sendmail-cf"
echo "# * Install emacs"
echo "# * Install ntp"
echo "# * Install net-snmp"
echo "#####################################################################"
yum -y install sysstat sendmail-cf emacs ntp net-snmp
echo
echo
echo "#####################################################################"
echo "# Enable System Accounting"
echo "#####################################################################"
/sbin/chkconfig --level 12345 sysstat on
echo
echo
echo "#####################################################################"
echo "# Set up mail forwarding in aliases"
echo "#####################################################################"
echo "root: YOURNAME" >> /etc/aliases
echo "YOURNAME: YOURNAME@YOURDOMAIN" >> /etc/aliases
cat /etc/aliases
echo
echo
echo "#####################################################################"
echo "# Modify sendmail.mc for smart mail hosting"
echo "#####################################################################"
mv -f /etc/mail/sendmail.mc /etc/mail/sendmail.mc.orig
sed "s/smtp.your.provider/YOUR-MAIL-SERVER/" /etc/mail/sendmail.mc.orig > /etc/mail/sendmail.mc.temp
sed "s/mydomain.com/YOURDOMAIN/" /etc/mail/sendmail.mc.temp > /etc/mail/sendmail.mc
cat /etc/mail/sendmail.mc
echo
echo
echo "#####################################################################"
echo "# Start sendmail on boot"
echo "#####################################################################"
/sbin/chkconfig --level 12345 sendmail on
echo
echo
echo "#####################################################################"
echo "# Update RPM Packages"
echo "#####################################################################"
yum -y update
echo
echo
echo "#####################################################################"
echo "# Modify History and Timeout in /etc/profile"
echo "#####################################################################"
mv -f /etc/profile /etc/profile.orig
sed "s/HISTSIZE=1000/HISTSIZE=10/" /etc/profile.orig > /etc/profile
echo "HISTFILESIZE=0" >> /etc/profile
echo "TMOUT=7200" >> /etc/profile
cat /etc/profile
echo
echo
echo "#####################################################################"
echo "# Send syslog to central server"
echo "#####################################################################"
cat <<END_SCRIPT >> /etc/syslog.conf
kern.warning;*.err;authpriv.none @YOUR-SYSLOG-SERVER
*.info;mail.none;authpriv.none;cron.none @YOUR-SYSLOG-SERVER
*.emerg @YOUR-SYSLOG-SERVER
local7.* @YOUR-SYSLOG-SERVER
END_SCRIPT
cat /etc/syslog.conf
echo
echo
echo "#####################################################################"
echo "# Download and install banner for issue, issue.net and motd via rc.local"
echo "#####################################################################"
cd /root
wget http://YOUR-YAM-SERVER/yam/rc.local
rm /etc/rc.d/rc.local
mv -f /root/rc.local /etc/rc.d/rc.local
chmod 744 /etc/rc.d/rc.local
cat /etc/rc.d/rc.local
echo
echo
echo "#####################################################################"
echo "# Modify /etc/pam.d/su"
echo "#####################################################################"
mv /etc/pam.d/su /etc/pam.d/su.orig
cat <<END_SCRIPT >> /etc/pam.d/su
#%PAM-1.0
auth sufficient /lib/security/$ISA/pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient /lib/security/$ISA/pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required /lib/security/$ISA/pam_wheel.so use_uid
auth required /lib/security/$ISA/pam_stack.so service=system-auth
account required /lib/security/$ISA/pam_stack.so service=system-auth
password required /lib/security/$ISA/pam_stack.so service=system-auth
# pam_selinux.so close must be first session rule
session required /lib/security/$ISA/pam_selinux.so close
session required /lib/security/$ISA/pam_stack.so service=system-auth
# pam_selinux.so open and pam_xauth must be last two session rules
session required /lib/security/$ISA/pam_selinux.so open multiple
session optional /lib/security/$ISA/pam_xauth.so
END_SCRIPT
cat /etc/pam.d/su
echo
echo
echo "#####################################################################"
echo "# Modify /etc/pam.d/passwd"
echo "#####################################################################"
mv -f /etc/pam.d/passwd /etc/pam.d/passwd.orig
cat <<END_SCRIPT >> /etc/pam.d/passwd
#%PAM-1.0
auth required pam_stack.so service=system-auth
account required pam_stack.so service=system-auth
# password required pam_stack.so service=system-auth
password required pam_cracklib.so retry=3 minlen=12
password sufficient pam_unix.so nullok use_authtok md5 shadow
password required pam_deny.so
END_SCRIPT
cat /etc/pam.d/passwd
echo
echo
echo "#####################################################################"
echo "# Modify /etc/pam.d/system-auth"
echo "#####################################################################"
mv -f /etc/pam.d/system-auth /etc/pam.d/system-auth.orig
cat <<END_SCRIPT >> /etc/pam.d/system-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required /lib/security/$ISA/pam_env.so
auth sufficient /lib/security/$ISA/pam_unix.so likeauth nullok
auth required /lib/security/$ISA/pam_deny.so
auth required /lib/security/pam_tally.so onerr=fail no_magic_root
account required /lib/security/pam_tally.so deny=3 no_magic_root reset
account required /lib/security/$ISA/pam_unix.so
account sufficient /lib/security/$ISA/pam_succeed_if.so uid < 100 quiet
account required /lib/security/$ISA/pam_permit.so
#password requisite /lib/security/$ISA/pam_cracklib.so retry=3
#password sufficient /lib/security/$ISA/pam_unix.so nullok use_authtok md5 shadow
#password required /lib/security/$ISA/pam_deny.so
session required /lib/security/$ISA/pam_limits.so
session required /lib/security/$ISA/pam_unix.so
END_SCRIPT
cat /etc/pam.d/system-auth
echo
echo
echo "#####################################################################"
echo "# Modify /etc/pam.d/login"
echo "#####################################################################"
mv -f /etc/pam.d/login /etc/pam.d/login.orig
cat <<END_SCRIPT >> /etc/pam.d/login
#%PAM-1.0
auth required pam_securetty.so
auth required pam_stack.so service=system-auth
auth required pam_nologin.so
account required pam_stack.so service=system-auth
password required pam_stack.so service=system-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_stack.so service=system-auth
session required pam_loginuid.so
session optional pam_console.so
# pam_selinux.so open should be the last session rule
session required pam_selinux.so multiple open
END_SCRIPT
cat /etc/pam.d/login
echo
echo
echo "#####################################################################"
echo "# Allow special users "
echo "#####################################################################"
echo "-:ALL EXCEPT root USERNAME-1 USERNAME-2 USERNAME-3:ALL" >> /etc/security/access.conf
cat /etc/security/access.conf
echo
echo
echo "#####################################################################"
echo "# Disable console program access"
echo "#####################################################################"
rm -f /etc/security/console.apps/halt
rm -f /etc/security/console.apps/poweroff
rm -f /etc/security/console.apps/reboot
rm -f /etc/security/console.apps/shutdown
echo
echo
echo "#####################################################################"
echo "# Build disabling.sh and execute"
echo "#####################################################################"
cat <<END_SCRIPT >> /root/disabling.sh
#!/bin/sh
cd /etc/pam.d
for i in * ; do
echo \$i
sed '/[^#].*pam_console.so/s/^/#/' < \$i > foo && mv foo \$i
done
END_SCRIPT
chmod 700 /root/disabling.sh
/root/disabling.sh
rm -f /root/disabling.sh
echo
echo
echo "#####################################################################"
echo "# Configure ntp"
echo "#####################################################################"
echo "02 * * * * root ntpdate YOUR-NTP-SERVER > /dev/null 2>&1" >> /etc/crontab
cat /etc/crontab
echo
echo
echo "#####################################################################"
echo "# Configure snmp"
echo "#####################################################################"
echo "com2sec notConfigUser default PUBLIC-SECRET" >> /etc/snmp/snmpd.conf
echo "view systemview included .1.3.6.1.2.1.1" >> /etc/snmp/snmpd.conf
echo "view systemview included .1.3.6.1" >> /etc/snmp/snmpd.conf
echo "view systemview included .1.3.6.1.2.1.2" >> /etc/snmp/snmpd.conf
echo "view systemview included .1.3.6.1.2.1.25.1.1" >> /etc/snmp/snmpd.conf
echo "snmpd.conf"
cat /etc/snmp/snmpd.conf
echo
/sbin/chkconfig --level 12345 snmpd on
mv -f /etc/sysconfig/iptables /etc/sysconfig/iptables.orig
sed '/-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT/a\-A RH-Firewall-1-INPUT -p udp -m udp --dport 161 -j ACCEPT' /etc/sysconfig/iptables.orig > /etc/sysconfig/iptables.new
mv -f /etc/sysconfig/iptables.new /etc/sysconfig/iptables
chmod 600 /etc/sysconfig/iptables
chown root.root /etc/sysconfig/iptables
echo "iptables:"
cat /etc/sysconfig/iptables
echo
echo
echo "#####################################################################"
echo "# Tighten scripts under /etc/rc.d/init.d/"
echo "#####################################################################"
chmod -R 700 /etc/init.d/*
echo
echo
echo "#####################################################################"
echo "# Remove all documentation files"
echo "#####################################################################"
rm -rf /usr/share/doc/*
echo
echo
echo "#####################################################################"
echo "# Modify yum.conf to ignore kernel packages"
echo "#####################################################################"
mv -f /etc/yum.conf /etc/yum.conf.orig
sed "s/# exclude=kernel\*/exclude=kernel\*/" /etc/yum.conf.orig > /etc/yum.conf
cat /etc/yum.conf
echo
echo
echo "#####################################################################"
echo "# Capture the initial package listing"
echo "#####################################################################"
rpm -qa --queryformat '%{NAME}\n' |sort > /var/log/build/rpm-novers.`date +%Y-%m-%d`
rpm -qa |sort > /var/log/build/rpm-list.`date +%Y-%m-%d`
cat /var/log/build/rpm-list.`date +%Y-%m-%d`
echo
echo
echo "#####################################################################"
echo "# End of init function "
echo "#####################################################################"
}
echo
echo
echo "#####################################################################"
echo "#####################################################################"
echo "### Main Function to load Question"
echo "#####################################################################"
echo "#####################################################################"
Main()
{
question
exit 0
}
echo
echo
echo "#####################################################################"
echo "#####################################################################"
echo "### Execute Main"
echo "#####################################################################"
echo "#####################################################################"
Main
) 2>&1 | /usr/bin/tee /var/log/build/preinstall.log
echo
echo
echo "#####################################################################"
echo "#####################################################################"
echo "### Return to Terminal 1"
echo "#####################################################################"
echo "#####################################################################"
/usr/bin/chvt 1
echo
echo
echo "#####################################################################"
echo "# End of Post Kickstart Script "
echo "#####################################################################"




