#!/bin/bash
# Name          : rh5-pci1_2.sh
# Summary       : Datapipe PCI-DSS Hardening Standards Script
# Author        : Kenny Lo
# Date          : September 06 2011
# $Id: rh5-pci1_2.sh,v 1.7 2011/09/05 06:58:26 klo Exp klo $

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin 

# Sanity check : OS version check
version=`cat /etc/redhat-release |grep -c "release 5"`

if [ $version -lt 1 ]; then
        echo "This script will only work on Cent OS 5 or Red Hat ES 5.  Please"
        echo "check your OS and version number."
        sleep 2
        exit
fi


# Install required packages for hardening script
yum -y install ntp sysstat rcs

# Confirm packages installed
if [ ! -f /usr/bin/rcs ]; then
echo "RCS did not install successfully.  Please"
echo "manually install the following packages"
echo "and re-run hardening script.  Type:"
echo ""
echo "yum -y install ntp sysstat rcs"
echo "--"
echo "No modifications have been made to the system."
sleep 5
exit
fi

if [ ! -f /usr/bin/sar ]; then
echo "Sysstat did not install successfully.  Please"
echo "manually install the following packages"
echo "and re-run hardening script.  Type:"
echo ""
echo "yum -y install ntp sysstat rcs"
echo "--"
echo "No modifications have been made to the system."
sleep 5
exit
fi

if [ ! -f /usr/sbin/ntpd  ]; then
echo "NTP did not install successfully.  Please"
echo "manually install the following packages"
echo "and re-run hardening script.  Type:"
echo "" 
echo "yum -y install ntp sysstat rcs"
echo "--"
echo "No modifications have been made to the system."
sleep 5
exit
fi


# Fix date and time
ntpdate -u time.datapipe.net

cat /etc/ntp.conf | sed -e 's/^server/# server/g' | sed -e 's/fudge/# fudge/g' > /etc/ntp.conf.tmp
mv -f /etc/ntp.conf.tmp /etc/ntp.conf

cat << EOF >> /etc/ntp.conf
server time.datapipe.net
server ntp.ewr.datapipe.net
server ntp.sjc.datapipe.net
EOF

cat << EOF > /etc/cron.daily/ntpdate
#!/bin/sh
/sbin/service ntpd stop
/usr/sbin/ntpdate time.datapipe.net
/sbin/service ntpd start
EOF

chmod 700 /etc/cron.daily/ntpdate

ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
service ntpd restart
chkconfig ntpd on


mkdir /root/cis

#!/bin/bash 
cishome="/root/cis" 
echo "Creating $cishome/do-restore.sh" 
cat <<END_SCRIPT > $cishome/do-restore.sh 
#!/bin/bash 
 
# This script restores those files changed by hardening IAW the CISecurity  
# Benchmark 
# Built by the RHEL Linux Benchmark do-backup.sh script. 
# Errors for unalias get sent to the console when not 'set' 
unalias rm mv cp    2> /dev/null 
 
/usr/bin/chattr  -i  /etc/fstab /boot/grub/menu.lst /boot/grub/grub.conf 
sed -n "39,9999p" $cishome/do-restore.sh | while read LINE; do 
    # 
    ####  When a file didn't exist before doing the back up 
    ####  then the REPAIR should ensure the existing one is removed. 
    # 
    FILE=\`echo \$LINE | awk '{print \$1}'\` 
    PERMS=\`echo \$LINE | awk '{print \$2}'\` 
    echo "Restoring \$FILE with \$PERMS permissions" 
    [ -f \${FILE}-preCIS ] && /bin/cp -pf \${FILE}-preCIS \${FILE} 
    /bin/chmod \${PERMS} \${FILE} 
    [ -f \${FILE}-preCIS ] && /bin/rm \${FILE}-preCIS 
done 
 
echo "Completed file restoration - restoring directories" 
# Manually sorted the CIS file/dir list alphabetically, removed duplicates, and  
# corrected 
#       spacing to ease the finding/adding of new ones. 
for DIR in \
    /etc/cron.*      \
    /etc/pam.d       \
    /etc/rc.d        \
    /etc/skel        \
    /etc/xinetd.d    \
    /var/spool/cron; 
do 
    if [ -d \${DIR}-preCIS ]; then 
        echo "Restoring \${DIR}" 
        /bin/cp -pr \${DIR}-preCIS \${DIR} 
        /bin/rm -rf \${DIR}-preCIS 
    fi 
done 
 
echo "If you installed Bastille, please run " 
echo "'/usr/sbin/RevertBastille'; and examine its list of changed files as well." 
exit 0 
 
### END OF SCRIPT.  DYNAMIC DATA FOLLOWS.  ### 
END_SCRIPT
chown root:root $cishome/do-restore.sh 
chmod 0700      $cishome/do-restore.sh 
echo " " 

echo "Performing a modified 'do-backup.sh' (taken from the CIS v1.0.6 Benchmark)."

echo "Backing up individual system files, `date`" 
# Manually sorted the CIS file/dir list alphabetically, removed duplicates, and  
# corrected 
#       spacing to ease the finding/adding of new ones. 
# Files that don't natively exist in a virgin RHEL5 system: 
        # /etc/at.allow 
        # /etc/audit.rules 
        # /etc/auditd.conf 
        # /etc/cron.allow 
        # /etc/ftpaccess 
        # /etc/ftpusers 
        # /etc/vsftpd.conf 
        # /etc/vsftpd.ftpusers 
        # /etc/vsftpd/vsftpd.conf 
        # /etc/X11/xdm/Xservers 
        # /etc/X11/gdm/gdm.conf 
        # /etc/X11/gdm/PreSession/Default 
        # /etc/X11/xinit/xserverrc 
        # /etc/X11/xdm/Xresources 
        # /etc/X11/xdm/kdmrc 
        # /etc/xinetd.conf 
        # /var/spool/cron 
 
for FILE in \
    /boot/grub/grub.conf                             \
    /etc/aliases                                     \
    /etc/at.allow                                    \
    /etc/at.deny                                     \
    /etc/audit.rules                                 \
    /etc/auditd.conf                                 \
    /etc/audit/audit.rules                           \
    /etc/audit/auditd.conf                           \
    /etc/bashrc                                      \
    /etc/cron.allow                                  \
    /etc/cron.deny                                   \
    /etc/crontab                                     \
    /etc/csh.cshrc                                   \
    /etc/csh.login                                   \
    /etc/cups/cupsd.conf                             \
    /etc/exports                                     \
    /etc/fstab                                       \
    /etc/ftpaccess                                   \
    /etc/ftpusers                                    \
    /etc/group                                       \
    /etc/grub.conf                                   \
    /etc/gshadow                                     \
    /etc/hosts.allow                                 \
    /etc/hosts.deny                                  \
    /etc/inittab                                     \
    /etc/issue                                       \
    /etc/issue.net                                   \
    /etc/login.defs                                  \
    /etc/mail/sendmail.cf                            \
    /etc/motd                                        \
    /etc/pam.d/su                                    \
    /etc/pam.d/system-auth                           \
    /etc/passwd                                      \
    /etc/profile                                     \
    /etc/proftpd.conf                                \
    /etc/securetty                                   \
    /etc/security/access.conf                        \
    /etc/security/console.perms                      \
    /etc/security/console.perms.d/50-default.perms   \
    /etc/security/limits.conf                        \
    /etc/shadow                                      \
    /etc/skel/.bashrc                                \
    /etc/ssh/ssh_config                              \
    /etc/ssh/sshd_config                             \
    /etc/sudoers                                     \
    /etc/sysconfig/sendmail                          \
    /etc/sysconfig/init				     \
    /etc/sysctl.conf                                 \
    /etc/syslog.conf                                 \
    /etc/vsftpd.conf                                 \
    /etc/vsftpd.ftpusers                             \
    /etc/vsftpd/vsftpd.conf                          \
    /etc/X11/xdm/Xservers                            \
    /etc/X11/gdm/gdm.conf                            \
    /etc/X11/gdm/PreSession/Default                  \
    /etc/X11/xinit/xserverrc                         \
    /etc/X11/xdm/Xresources                          \
    /etc/X11/xdm/kdmrc                               \
    /etc/xinetd.conf                                 \
    /root/.bash_profile                              \
    /root/.bashrc                                    \
    /root/.cshrc                                     \
    /root/.tcshrc                                    \
    /usr/share/config/kdm/Xservers                   \
    /var/spool/cron; 
    do 
        if [ -f ${FILE} ]; then 
             # Backup files that exist (some might not) 
             echo "Protected: `ls -lad ${FILE}`"    >> $cishome/do-restore.savelog 
             /bin/cp -pf ${FILE} ${FILE}-preCIS 
             # Add it to the do-restore script 
             echo ${FILE} `find ${FILE} -printf "%m"`    >> $cishome/do-restore.sh 
  else 
             # This helps to compare various OS updates for correctness. 
             echo "FILE didnt exist on this system ($FILE)." | tee -a \
                  $cishome/do-restore.savelog 
        fi 
    done 
 
echo "Completed CIS file backups - backing up applicable directories" 
 
# Manually sorted the CIS-provided file/dir list alphabetically, removed 
# duplicates, and corrected spacing to ease the finding/adding/organization of new  
# ones. 
for DIR in \
    /etc/cron.*     \
    /etc/pam.d      \
    /etc/rc.d       \
    /etc/skel       \
    /etc/xinetd.d   \
    /var/spool/cron; 
do 
    # echo ${DIR} 
    [ -d ${DIR} ] && /bin/cp -pr ${DIR} ${DIR}-preCIS 
done 
echo "Completed CIS RHEL Benchmark directory backups." 
 
echo "(CIS) Recording log permissions" 
find /var/log -printf "%h/%f %m\n" >> $cishome/do-restore.sh 
 
echo "CIS Red Hat Enterprise Linux Backup protections are complete---`date`" 
echo ""  


# Sanity check : Sync data/time
ntpdate -u time.datapipe.net


# Create RCS directories

for DIRECTORY in \
	/etc/ \
	/etc/ssh \
	/etc/rc.d/init.d \
	/etc/sysconfig \
	/etc/rc.d \
	/usr/share/hal/fdi \
	/etc/vsftpd \
	/etc/X11/xdm \
	/etc/X11/xinit \
	/etc/X11/gdm \
	/boot/grub \
	/etc/default \
	/etc/skel \
	/etc/security \
	/etc/audit \
	/etc/pam.d \
	/root;
do
	mkdir $DIRECTORY/RCS
done

# Check in every file to be modified by the PCI script:
for FILE in \
	/etc/ssh/ssh_config \
	/etc/ssh/sshd_config \
	/etc/crontab \
	/etc/hosts.deny \
	/etc/hosts.allow \
	/etc/rc.d/init.d/functions \
	/etc/sysconfig/init \
	/etc/sysconfig/sendmail \
	/etc/inittab \
	/etc/sysctl.conf \
	/etc/syslog.conf \
	/etc/vsftpd.conf \
	/etc/rc.d/rc.sysinit \
	/etc/fstab \
	/usr/share/hal/fdi/95userpolicy \
	/usr/share/hal/fdi/polilcy/20thirdparty \
	/etc/ftpaccess \
	/etc/ftpusers \
	/etc/vsftpd/vsftpd.conf \
	/etc/vsftpd.ftpusers \
	/etc/X11/xdm/Xservers \
	/etc/X11/xinit/xserverrc \
	/etc/X11/xinit \
	/etc/at.allow \
	/etc/at.deny \
	/etc/cron.allow \
	/etc/cron.deny \
	/etc/securetty \
	/etc/X11/gdm/gdm.conf \
	/boot/grub/grub.conf \
	/etc/inittab \
	/etc/exports \
	/etc/default/useradd \
	/etc/passwd \
	/etc/shadow \
	/etc/group \
	/etc/gshadow \
	/etc/login.defs \
	/etc/bashrc \
	/etc/csh.cshrc \
	/etc/csh.login \
	/etc/profile \
	/etc/skel/.bashrc \
	/root/.bash_profile \
	/root/.bashrc \
	/root/.bash_profile \
	/root/.cshrc \
	/root/.tcshrc \
	/etc/security/limits.conf \
	/etc/pam.d/su \
	/etc/security/access.conf \
	/etc/issue \
	/etc/motd \
	/etc/ntp.conf \
	/etc/issue.net \
	/etc/vsftpd.conf \
	/etc/audit/audit.rules \
	/etc/audit/auditd.conf \
	/etc/pam.d/system-auth;
do
ci -l -wsecurity $FILE <<EOF
Original State Before Datapipe PCI-DSS Hardening Standards Were Applied.
.
EOF
done


PATH=/bin:/sbin:/usr/bin:/usr/sbin 
cishome='/root/cis'; export cishome
set +o noclobber
tmpcis=`mktemp -d -t cis.XXXXXXXXXX`
chown root:root $tmpcis
chmod 0700      $tmpcis

rm  -rf  /var/tmp 
ln  -s   /tmp  /var/tmp 


# 2 Patches, Packages and Initial Lockdown
# 2.1 Apply Latest OS Patches

yum -y update


## PCI 2.2.4.53 Requires this to be disabled
service    yum-updatesd  stop
chkconfig  yum-updatesd  off


# 2.2 Validate The System Before Making Changes
# For the time being, assuming new system, no
# checks to perform


# 2.3 Configure SSH

useradd admin
usermod -G wheel admin

SSH_CONFIG='/etc/ssh/ssh_config' 
SSHD_CONFIG='/etc/ssh/sshd_config' 
if [ -e $SSH_CONFIG ]; then 
   echo "Securing $SSH_CONFIG" 
   grep -v "^Host \*" /etc/ssh/ssh_config-preCIS | grep -v "#   Protocol 2,1" \
           > $tmpcis/ssh_config.tmp 
   awk '/^#.* Host /               { print "Host *"; print "Protocol 2"; next }; 
        /^#.*Port /                { print "Port 22"; next }; 
                                   { print }' $tmpcis/ssh_config.tmp  \
                                            > $tmpcis/ssh_config.tmp2 
 
   if [ "`egrep -l ^Protocol $tmpcis/ssh_config.tmp2`" == "" ]; then 
        echo 'Protocol 2' >> $tmpcis/ssh_config.tmp2 
   fi 
   /bin/cp -pf $tmpcis/ssh_config.tmp2 $SSH_CONFIG 
   chown root:root $SSH_CONFIG 
   chmod 0644      $SSH_CONFIG 
   echo "diff $SSH_CONFIG-preCIS $SSH_CONFIG" 
         diff $SSH_CONFIG-preCIS $SSH_CONFIG 
else 
   echo "OK - No $SSH_CONFIG to secure." 
fi 
 
if [ -e $SSHD_CONFIG ]; then 
   echo "Securing $SSHD_CONFIG" 
   # Had to put the " no" in for the RhostsRSAAuthentication source pattern 
   # match, as otherwise the change was taking place twice so the file ended 
   # up with TWO records like that.  The " no" pattern made the one unique. 
   # That 2nd record was a combination of comments in the default original file. 
   # Some lines ARE duplicated in the original config file, one is commented 
   # out, the next one isn't. 
   # Also, the spacing below is a little off so lines fit on the page. 
   awk '/^#.*Port /                     { print "Port 22"; next }; 
        /^#.*Protocol /                 { print "Protocol 2"; next }; 
        /^#.*LogLevel /                 { print "LogLevel VERBOSE"; next }; 
        /^#PermitRootLogin /            { print "PermitRootLogin yes"; next }; 
		/^#PasswordAuthentication /            { print "PasswordAuthentication yes"; next };
     /^#RhostsRSAAuthentication no / { print "RhostsRSAAuthentication no"; next }; 
        /^#HostbasedAuthentication / { print "HostbasedAuthentication no"; next }; 
        /^#.*IgnoreRhosts /             { print "IgnoreRhosts yes"; next }; 
        /^#.*PermitEmptyPasswords /     { print "PermitEmptyPasswords no"; next }; 
        /^#.*Banner /                   { print "Banner /etc/issue.net"; next }; 
                                        { print }' /etc/ssh/sshd_config-preCIS  \
                                                   > $SSHD_CONFIG 
   chown root:root $SSHD_CONFIG 
   chmod 0600      $SSHD_CONFIG 
   echo "diff $SSHD_CONFIG-preCIS $SSHD_CONFIG" 
         diff $SSHD_CONFIG-preCIS $SSHD_CONFIG 
else 
   echo "OK - No $SSHD_CONFIG to secure." 
fi 
chmod -R 0400 $tmpcis/*
unset SSH_CONFIG SSHD_CONFIG CONFIGITEM 


# 2.4 Enable System Accounting
# Enabled when sysstat is installed.  So we just have to correct directory permissions
chmod 700 /var/log/sa/*


# 3 Minimize xinetd network services
# 3.1 Disable Standard Services

for SERVICE in    \
    amanda        \
    chargen       \
    chargen-udp   \
    cups          \
    cups-lpd      \
    daytime       \
    daytime-udp   \
    echo          \
    echo-udp      \
    eklogin       \
    ekrb5-telnet  \
    finger        \
    gssftp        \
    imap          \
    imaps         \
    ipop2         \
    ipop3         \
    klogin        \
    krb5-telnet   \
    kshell        \
    ktalk         \
    ntalk         \
    rexec         \
    rlogin        \
    rsh           \
    rsync         \
    talk          \
    tcpmux-server \
    telnet        \
    tftp          \
    time-dgram    \
    time-stream   \
    uucp; 
do 
    if [ -e /etc/xinetd.d/$SERVICE ]; then 
         echo "Disabling SERVICE($SERVICE) - `ls -la /etc/xinetd.d/$SERVICE`." 
         chkconfig ${SERVICE} off 
    else 
         echo "OK.  SERVICE doesn't exist on this system ($SERVICE)." 
    fi 
done 


# 3.2 Configure TCP Wrappers and Firewall to Limit Access
# 3.2.1 Check /etc/hosts.deny for deny all statement
echo "ALL: ALL" >> /etc/hosts.deny

# 3.2.2 Check /etc/hosts.allow:  Allow Access to Locally Connected Networks
echo "ALL: localhost" >> /etc/hosts.allow
echo "sshd : ALL : allow" >> /etc/hosts.allow
echo "bpcd : ALL : allow" >> /etc/hosts.allow
echo "vnetd : ALL : allow" >> /etc/hosts.allow
echo "snmpd : ALL : allow" >> /etc/hosts.allow
echo "pbx_exchange : ALL : allow" >> /etc/hosts.allow

# 3.3 Only Enable telnet If Absolutely Necessary
# Leaving disabled

# 3.4 Only Enable FTP, If Absolutely Necessary
# Leaving disabled

# 3.5 Only Enable rlogin/rsh/rcp, If Absolutely Necessary
# Leaving disabled

# 3.6 Only Enable TFTP Server, If Absolutely Necessary
# Leaving disabled


# 4 Minimize boot services
# 4.1 Set Daemon umask

# sed 's/022/027/'  /etc/rc.d-preCIS/init.d/functions > /etc/rc.d/init.d/functions
# echo "umask 027"  >> /etc/sysconfig/init
 
chown root:root   /etc/sysconfig/init 
chmod 0755        /etc/sysconfig/init 
echo "diff /etc/sysconfig/init-preCIS  /etc/sysconfig/init" 
      diff /etc/sysconfig/init-preCIS  /etc/sysconfig/init 


# 4.2 Disable xinetd, If Possible

echo "The 'chkconfig' status of 'xinetd' is shown before it is turned off and" 
echo "then after so it can visually be compared." 
echo "Note: The remaining chkconfig checks, in this hardening script, do the" 
echo "same thing." 
chkconfig  --list   xinetd 
chkconfig  --level  12345  xinetd  off 
chkconfig  --list   xinetd 


# 4.3 Ensure sendmail is only listening to the localhost, If Possible
# This is going under the assumption sendmail is not needed.
# NOTE:  The email server need not be running to send outgoing mail.

echo "DAEMON=no"  > /etc/sysconfig/sendmail
echo "QUEUE=1h"  >> /etc/sysconfig/sendmail 
chkconfig  --list   sendmail 
chkconfig  --level  12345  sendmail off 
chkconfig  --list   sendmail 
chown root:root     /etc/sysconfig/sendmail 
chmod 0644          /etc/sysconfig/sendmail 
echo "diff /etc/sysconfig/sendmail-preCIS /etc/sysconfig/sendmail" 
      diff /etc/sysconfig/sendmail-preCIS /etc/sysconfig/sendmail 


# 4.4 Disable GUI Login, If Possible

echo "RunLevel was (`grep initdefault /etc/inittab | grep -v NOT`)." 
sed  -e  's/id:5:initdefault:/id:3:initdefault:/'  /etc/inittab-preCIS  > /etc/initab 
chown  root:root  /etc/inittab 
chmod  0600       /etc/inittab 
echo "diff /etc/inittab-preCIS /etc/inittab" 
      diff /etc/inittab-preCIS /etc/inittab 
echo "New runLevel will be (`grep initdefault /etc/inittab | grep -v NOT`)." 


# 4.5 Disable X Font Server, If Possible

chkconfig  --list   xfs 
chkconfig  --level  12345  xfs  off 
chkconfig  --list   xfs 


# 4.6 Disable Standard Boot Services

echo " When doing this from within X windows the display will slow to a horrible" 
echo " crawl as soon as the xfs service is disabled.  Recommend doing this" 
echo " script from init 3 (runlevel 3)." 
# From a scripted perspective, this will be backwards from what the CIS Benchmark 
# recommends.  Philosophy is to leave the few known/necessary services on, that 
# do remain in the minimialized baseline, and then as each other step/procedure 
# below is covered, it will disable what we know we don't need for a secure and 
# hardened baseline. 
# 
# The following services ARE stopped/disabled using the following effort for the 
# baseline: 
# 
# This affects network/NFS mapping during system building and/or during kickstart 
# %post processing. 
#     autofs 
#     automount 
#     iptables 
#     portmap 
#     NFS services 
#     NFS statd 
#     system message bus 
# ** Warning** Disabling 'nfs' at this point in the script forcefully unmounts 
#              any NFS network mounts. 
# The following services should normally be enabled, unless there is a compelling 
# reason not to:  (which is why this hardening section does not alter their state) 
 
   for SERVICE in                \
       acpid                     \
       amd                       \
       anacron                   \
       apmd                      \
       arptables_jf              \
       aprwatch                  \
       atd                       \
       autofs                    \
       avahi-daemon              \
       avahi-dnsconfd            \
       bpgd                      \
       bluetooth                 \
       bootparamd                \
       capi                      \
       conman                    \
       cups                      \
       cyrus-imapd               \
       dc_client                 \
       dc_server                 \
       dhcdbd                    \
       dhcp6s                    \
       dhcpd                     \
       dhcrelay                  \
       dovecot                   \
       dund                      \
       firstboot                 \
       gpm                       \
       haldaemon                 \
       hidd                      \
       hplip                     \
       httpd                     \
       ibmasm                    \
       ip6tables                 \
       ipmi                      \
       irda                      \
       iscsi                     \
       iscsid                    \
       isdn                      \
       kadmin                    \
       kdump                     \
       kprop                     \
       krb524                    \
       krb5kdc                   \
       kudzu                     \
       ldap                      \
       lisa                      \
       lm_sensors                \
       mailman                   \
       mcstrans                  \
       mdmonitor                 \
       mdmpd                     \
       microcode_ctl             \
       multipathd                \
       mysqld                    \
       named                     \
       netfs                     \
       netplugd                  \
       NetworkManager            \
       nfs                       \
       nfslock                   \
       nscd                      \
       openibd                   \
       ospf6d                    \
       ospfd                     \
       pand                      \
       pcscd                     \
       portmap                   \
       postgresql                \
       privoxy                   \
       psacct                    \
       radvd                     \
       rarpd                     \
       rdisc                     \
       readahead_early           \
       readahead_later           \
       ripd                      \
       ripngd                    \
       rpcgssd                   \
       rpcidmapd                 \
       rpcsvcgssd                \
       rstatd                    \
       rusersd                   \
       rwhod                     \
       saslauthd                 \
       setroubleshoot            \
       smartd                    \
       smb                       \
       snmpd                     \
       snmptrapd                 \
       spamassassin              \
       squid                     \
       tog-pegasus               \
       tomcat5                   \
       tux                       \
       winbind                   \
       wine                      \
       wpa_supplicant            \
       xend                      \
       xendomains                \
       ypbind                    \
       yppasswdd                 \
       ypserv                    \
       ypxfrd                    \
       zebra; 
   do 
        if [ -e /etc/init.d/$SERVICE ]; then 
             # Doing business this way causes less needless errors that a 
             # reviewer of the hardening process doesn't need to deal with. 
             service $SERVICE stop 
             chkconfig  --level  12345  $SERVICE  off 
        else 
             echo "SERVICE doesn't exist on this system ($SERVICE)." 
        fi 
   done 


# 4.7 Only Enable SMB (Windows File Sharing) Processes, If Absolutely Necessary
# Leaving disabled


# 4.8 Only Enable NFS Server Processes, If Absolutely Necessary
# Leaving disabled


# 4.9 Only Enable NFS Client Processes, If Absolutely Necessary
# Leaving disabled


# 4.10 Only Enable NIS Client Processes, If Absolutely Necessary
# Leaving disabled


# 4.11 Only Enable NIS Server Processes, If Absolutely Necessary
# Leaving disabled


# 4.12 Only Enable RPC Portmap Process, If Absolutely Necessary
# Leaving disabled


# 4.13 Only Enable netfs Script, If Absolutely Necessary
# Leaving disabled


# 4.14 Only Enable Printer Daemon Processes, If Absolutely Necessary
# Leaving disabled

rpm -e bluez-utilz-cups 
rpm -e cups 
rpm -e libgnomecups 
rpm -e cups-libs 
rpm -e hal-cups-utils 


# 4.15 Only Enable Web Server Processes, If Absolutely Necessary
# Leaving disabled, but need to revisit this one to doc the
# http://cisecurity.org/bench_apache.html


# 4.16 Only Enable SNMP Processes, If Absolutely Necessary
# Leaving disabled


# 4.17 Only Enable DNS Server Process, If Absolutely Necessary
# Leaving disabled


# 4.18 Only Enable SQL Server Processes, If Absolutely Necessary
# Leaving disabled


# 4.19 Only Enable Squid Cache Server, If Absolutely Necessary
# Leaving disabled


# 4.20 Only Enable Kudzu Hardware Detection, If Absolutely Necessary
# Leaving disabled


# 4.21 Only Enable cyrus-imapd, If Absolutely Necessary
# Leaving disabled


# 4.22 Only Enable dovecot, If Absolutely Necessary
# Leaving disabled


# 5 System Network Parameter Tuning
# 5.1 Network Parameter Modifications

cat <<END_SCRIPT  >>  /etc/sysctl.conf 
# The following 11 lines added, per CIS Red Hat Enterprise Linux Benchmark sec 5.1: 
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
#net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.conf.all.rp_filter = 1
#net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.accept_source_route = 0
#net.ipv4.conf.default.accept_source_route = 0
# The following line added to address the tcp timestamp vulnerability reported by Nexpose
net.ipv4.tcp_timestamps = 0
END_SCRIPT
chown root:root /etc/sysctl.conf 
chmod 0600      /etc/sysctl.conf 
echo "diff /etc/sysctl.conf-preCIS /etc/sysctl.conf" 
      diff /etc/sysctl.conf-preCIS /etc/sysctl.conf 


# 5.2 Additional Network Parameter Modifications

cat <<END_SCRIPT  >>  /etc/sysctl.conf 
# The following 4 lines added, per CIS Red Hat Enterprise Linux Benchmark sec 5.2: 
#net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.icmp_ignore_bogus_error_responses = 1
END_SCRIPT
chown root:root /etc/sysctl.conf 
chmod 0600      /etc/sysctl.conf 
echo "diff /etc/sysctl.conf-preCIS /etc/sysctl.conf" 
      diff /etc/sysctl.conf-preCIS /etc/sysctl.conf 


# 6 Logging
# 6.1 Capture Messages Sent To syslog AUTHPRIV Facility

if [ `grep -v '^#' /etc/syslog.conf | grep -v authpriv\.none | grep -c  \
     'authpriv'` -eq 0 ]; then 
      echo "Established the following record in /etc/syslog.conf" 
      echo "authpriv.*\t\t\t\t/var/log/secure" 
      echo -e "authpriv.*\t\t\t\t/var/log/secure" >> /etc/syslog.conf 
else 
      echo "syslog OK.  Didn't have to change syslog.conf for authpriv; the" 
echo "following record is good:" 
      grep "^authpriv" /etc/syslog.conf | grep '/var/log/secure' 
fi 
# Add record for 'auth.*', too, placing it after the authpriv record 
if [ `grep -v '^#' /etc/syslog.conf | grep -c 'auth.\*'` -eq 0 ]; then 
     ed /etc/syslog.conf  <<END_SCRIPT 
1 
/^authpriv 
a 
auth.*       /var/log/messages 
. 
w 
q 
END_SCRIPT
else 
echo "syslog OK.  Didn't have to change syslog.conf for auth.*; the" 
echo "following record is good:" 
      grep 'auth.\*' /etc/syslog.conf 
fi 
chown root:root /etc/syslog.conf 
# Original/default permissions are 0644. 
chmod 0600      /etc/syslog.conf 
echo "diff /etc/syslog.conf-preCIS /etc/syslog.conf" 
      diff /etc/syslog.conf-preCIS /etc/syslog.conf 
# Create the log file if it doesn't already exist.
touch /var/log/secure 
chown root:root /var/log/secure 
chmod 0600      /var/log/secure 
echo "Restarting syslog service to immediately implement the latest configuration." 
service syslog stop 
service syslog start


# 6.2 Turn On Additional Logging For FTP Daemon

FILE="" 
if [ -f /etc/vsftpd.conf ]; then 
     FILE="/etc/vsftpd.conf" 
else 
     FILE="/etc/vsftpd/vsftpd.conf" 
fi 
if [ -f $FILE ]; then 
    awk '/^#?xferlog_std_format/ \
        { print "xferlog_std_format=NO"; next }; 
    /^#?log_ftp_protocol/ \
        { print "log_ftp_protocol=YES"; next }; 
    { print }' ${FILE}-preCIS > ${FILE} 
    if [ `egrep -c log_ftp_protocol ${FILE}` == 0 ]; then 
        echo "log_ftp_protocol=YES" >> ${FILE} 
    fi 
    chown root:root $FILE 
    chmod 0600      $FILE 
    echo "diff ${FILE}-preCIS $FILE" 
          diff ${FILE}-preCIS $FILE 
else 
     echo "OK - No /etc/vsftpd.conf." 
fi 
 

# 6.3 Confirm Permissions On System Log Files

echo "Some errors MAY appear here for directories, logs and/or files not installed 
on this system." 
cd /var/log 
 
# Part 1 
echo "Extra---Ensure the btmp log file for 'lastb' is in place and with proper" 
echo "        permissions." 
touch /var/log/btmp 
chown root:root  /var/log/btmp 
chmod 0600       /var/log/btmp 
 
echo "Before listing of the log directory [explicit]." 
ls -la /var/log 
 
# Part 2 
echo "LogPerms Part 1." 
for LogFile in \
    boot.log         \
    btmp             \
    cron             \
    dmesg            \
    ksyms            \
    httpd            \
    lastlog          \
    maillog          \
    mailman          \
    messages         \
    news             \
    pgsql            \
    rpmpkgs          \
    sa               \
    samba            \
    scrollkeeper.log \
    secure           \
    spooler          \
    squid            \
    vbox             \
    wtmp 
do 
    # This check allows only entries that exist to have permissions set. 
    # Visually cleaner for the person running it. 
    if [ -e ${LogFile} ]; then 
         # Utilizing recursive here is harmless when applied to a single file. 
         chmod -R  o-rwx  ${LogFile}* 
    else 
         echo "LogFile didn't exist ($LogFile)." 
    fi 
done 
echo "LogPerms Part 2." 
for LogFile in \
    boot.log          \
    cron              \
    dmesg             \
    gdm               \
    httpd             \
    ksyms             \
    lastlog           \
    maillog           \
    mailman           \
    messages          \
    news              \
    pgsql             \
    rpmpkgs           \
    samba             \
    sa                \
    scrollkeeper.log  \
    secure            \
    spooler           \
    squid             \
    vbox 
do 
    if [ -e ${LogFile} ]; then 
         chmod -R  g-w  ${LogFile}* 
    else 
         echo "LogFile didn't exist ($LogFile)." 
    fi 
done 
 
echo "LogPerms Part 3." 
for LogFile in \
    boot.log         \
    cron             \
    httpd            \
    lastlog          \
    maillog          \
    mailman          \
    messages         \
    pgsql            \
    sa               \
    samba            \
    secure           \
    spooler 
do 
    if [ -e ${LogFile} ]; then 
         chmod -R  g-rx  ${LogFile}* 
    else 
         echo "LogFile didn't exist ($LogFile)." 
    fi 
done 
 
echo "LogPerms Part 4." 
for LogFile in \
    gdm        \
    httpd      \
    news       \
    samba      \
    squid      \
    sa         \
    vbox 
do 
    if [ -e ${LogFile} ]; then 
         chmod -R  o-w  ${LogFile}* 
    else 
         echo "LogFile didn't exist ($LogFile)." 
    fi 
done 

echo "LogPerms Part 5." 
for LogFile in \
    httpd      \
    samba      \
    squid      \
    sa 
do 
    if [ -e ${LogFile} ]; then 
         chmod -R  o-rx  ${LogFile}* 
    else 
         echo "LogFile didn't exist ($LogFile)." 
    fi 
done 
 
echo "LogPerms Part 6." 
for LogFile in \
    kernel     \
    lastlog    \
    mailman    \
    syslog     \
    loginlog 
do 
    if [ -e ${LogFile} ]; then 
         chmod -R  u-x  ${LogFile}* 
    else 
         echo "LogFile didn't exist ($LogFile)." 
    fi 
done 
 
echo "LogPerms Part 7." 
# Removing group write permissions to btmp and wtmp 
chgrp utmp btmp 
chmod g-w btmp 
chgrp utmp wtmp 
chmod g-w wtmp 
# Fixing "/etc/rc.d/rc.sysinit", as it unsecures permissions for wtmp. 
awk '( $1 == "chmod" && $2 == "0664" && $3 == "/var/run/utmp" && $4 == "/var/log/wtmp" ) {
       print "chmod 0600 /var/run/utmp /var/log/wtmp"; next }; 
     ( $1 == "chmod" && $2 == "0664" && $3 == "/var/run/utmpx" && $4 == "/var/log/wtmpx" ) {
       print "  chmod 0600 /var/run/utmpx /var/log/wtmpx"; next }; 
     { print }'  /etc/rc.d-preCIS/rc.sysinit  >  /etc/rc.d/rc.sysinit 
chown root:root /etc/rc.d/rc.sysinit 
 
chmod 0700      /etc/rc.d/rc.sysinit 
echo "diff /etc/rc.d-preCIS/rc.sysinit /etc/rc.d/rc.sysinit" 
      diff /etc/rc.d-preCIS/rc.sysinit /etc/rc.d/rc.sysinit 
 
echo "LogPerms Part 8." 
[ -e news ]    && chown -R news:news news 
[ -e pgsql ]   && chown postgres:postgres pgsql 
[ -e squid ]   && chown -R squid:squid squid 
[ -e lastlog ] && chmod 0600 lastlog 
chown -R root:root . 
echo "" 
 
echo "Follow-on listing of the log directory [explicit]." 
ls -la /var/log 


# 6.4 Configure syslogd to Send Logs to a Remote LogHost
# I have nothing in place for this yet, will have to revisit


# 7 File and Directory Permissions/Access
# 7.1 Add 'nodev' Option To Appropriate Partitions In /etc/fstab

awk '( $3 ~ /^ext[23]$/ && $2 != "/" ) { $4 = $4 ",nodev" };         \
     { printf "%-26s %-22s %-8s %-16s %-1s %-1s\n",$1,$2,$3,$4,$5,$6 }' \
       /etc/fstab  >  $tmpcis/fstab.tmp2 
# Kept  $tmpcis/fstab.tmp2  as input to the next step (CIS 7.2). 
chown root:root /etc/fstab 
chmod 0644      /etc/fstab 
# Note: the diff IS not for the same pair of files, as this step is treated 
# as an intermediary.  But, we'll show the users the damage done so far and 
# they see the progress. 
# When accomplishing this step standalone, send it to the /etc/fstab file. 
echo "diff  /etc/fstab-preCIS  /etc/fstab" 
      diff  /etc/fstab         $tmpcis/fstab.tmp2 
chmod -R 0400 $tmpcis/* 


# 7.2 Add 'nosuid' and 'nodev' Option For Removable Media In /etc/fstab

# Part 1 
# Additional devices this section 'might' consider could be a DVD or cd recorder 
awk '( $2 ~ /^\/m.*\/(floppy|cdrom|corder)$/ )  &&  ( $4 !~ /,nodev,nosuid/ )  \
     { $4 = $4 ",nodev,nosuid" };                                          \
     { printf "%-26s%-22s%-8s%-16s %-1s %-1s\n",$1,$2,$3,$4,$5,$6 }'       \
     $tmpcis/fstab.tmp2  >  $tmpcis/fstab.tmp3 
mv   $tmpcis/fstab.tmp3     /etc/fstab 
chown root:root  /etc/fstab 
chmod 0644       /etc/fstab 
echo "diff /etc/fstab-preCIS /etc/fstab" 
      diff /etc/fstab-preCIS /etc/fstab 
 
 
# Part 2 
fdiPATH='unknown' 
if [ -e /usr/share/hal/fdi/95userpolicy ]; then 
     # Apply this to RHEL AS4 system 
     fdiPATH="/usr/share/hal/fdi/95userpolicy" 
else 
     if [ -e /usr/share/hal/fdi/policy/20thirdparty ]; then 
          # apply this for RHEL5 
          fdiPATH="/usr/share/hal/fdi/policy/20thirdparty" 
     fi 
fi 
if [ "$fdiPATH" == 'unknown' ]; then 
     echo "Neither path was available, fdi for hal NOT secured." 
     echo "RHEL AS4: /usr/share/hal/fdi/95userpolicy" 
     echo "RHEL5:    /usr/share/hal/fdi/polilcy/20thirdparty" 
else 
     echo "Placing floppycdrom.fdi at: ($fdiPATH)." 
     cat <<END_SCRIPT >> $fdiPATH/floppycdrom.fdi 
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- -*- SGML -*- --> 
<deviceinfo version="0.2"> 
  <!-- Default policies merged onto computer root object  --> 
  <device> 
    <match key="info.udi" string="/org/freedesktop/Hal/devices/computer"> 
      <merge key="storage.policy.default.mount_option.nodev" 
type="bool">true</merge> 
      <merge key="storage.policy.default.mount_option.nosuid" 
type="bool">true</merge> 
    </match> 
  </device> 
</deviceinfo> 
END_SCRIPT
     chown root:root   $fdiPATH/floppycdrom.fdi 
     chmod 0640        $fdiPATH/floppycdrom.fdi 
     echo "Established $fdiPATH/floppycdrom.fdi" 
fi 


# 7.3 Disable User-Mounted Removable File Systems

cd /etc/security 
   CONS_PERM_FILE="console.perms" 
   DEF_FILE="console.perms.d/50-default.perms" 
   # If the test below passes, the 2nd file is changed, not the first. 
   # Need to protect both. 
   test -f $DEF_FILE && CONS_PERM_FILE="$DEF_FILE" 
# Each entry listed below will NOT be commented out in the "console.perms" file. 
# The remaining entries in that file WILL be commented out and thus disabled 
# post-reboot. 
# Further, "memstick" and "diskonkey" were not part of the original CIS 
# specification to be left alone, but have been included to tailor the hardened 
# build for usage of normal system USB requirements (such as keyboards and mice). 
awk '( $1 == "<console>" ) && ( $3 !~/sound|fb|kbd|joystick|v4l|mainboard|gpm|scanner|memstick|diskonkey/ ) \
    { $1 = "#<console>" }; { print }' ${CONS_PERM_FILE}-preCIS > $CONS_PERM_FILE 
# Virgin default permissions were 0644 & 0600 respectively...  Just noting the difference
chown root:root $CONS_PERM_FILE 
chmod 0600      $CONS_PERM_FILE 
echo "diff  ${CONS_PERM_FILE}-preCIS  $CONS_PERM_FILE" 
      diff  ${CONS_PERM_FILE}-preCIS  $CONS_PERM_FILE 
cd $cishome 


# 7.4 Verify passwd, shadow, and group File Permissions

ls -la /etc/group /etc/gshadow /etc/passwd   /etc/shadow 
chown root:root   /etc/group   /etc/gshadow  /etc/passwd   /etc/shadow 
chmod 0644        /etc/group   /etc/passwd 
chmod 0400                                   /etc/gshadow  /etc/shadow 
 
ls -la /etc/group /etc/gshadow /etc/passwd /etc/shadow 


# 7.5 Ensure World-Writable Directories Have Their Sticky Bit Set
# This will just output the files, no changes will be made

for PART in `awk '( $3 ~ "ext[23]" ) { print  $2 }'  /etc/fstab`; 
do 
     find $PART -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print 
done 


# 7.6 Find Unauthorized World-Writable Files
# This will just output the files, no changes will be made

for PART in $( grep -v '^#' /etc/fstab | awk '( $3 ~ "ext[23]" ) { print $2 }' ); 
do 
    find $PART -xdev -type f  \( -perm -0002 -a ! -perm -1000 \) -print 
done 


# 7.7 Find Unauthorized SUID/SGID System Executables
# This will just output the files, no changes will be made

# Part1 
echo "Generate list of SUID/SGID files that exist on the system..." 
for PART in $( grep -v '^#' /etc/fstab | awk '($3 ~ "ext[23]" ) { print $2 }' ); 
do 
    find $PART -xdev \( -perm -04000 -o -perm -02000 \) -print | sort  \
         >>  $tmpcis/CIS_7.7_f1 
done 
 
# Part2 
for FILE in                              \
    /bin/mount                           \
    /bin/ping                            \
    /bin/ping6                           \
    /bin/su                              \
    /bin/traceroute                      \
    /bin/traceroute6                     \
    /bin/umount                          \
    /media/.hal-mtab-lock                \
    /sbin/mount.nfs                      \
    /sbin/mount.nfs4                     \
    /sbin/netreport                      \
    /sbin/pam_timestamp_check            \
    /sbin/pwdb_chkpwd                    \
    /sbin/umount.nfs                     \
    /sbin/umount.nfs4                    \
    /sbin/unix_chkpwd                    \
    /usr/X11R6/bin/Xorg                  \
    /usr/bin/at                          \
    /usr/bin/chage                       \
    /usr/bin/chfn                        \
    /usr/bin/chsh                        \
    /usr/bin/crontab                     \
    /usr/bin/cu                          \
    /usr/bin/gataxx                      \
    /usr/bin/glines                      \
    /usr/bin/gnibbles                    \
    /usr/bin/gnobots2                    \
    /usr/bin/gnomine                     \
    /usr/bin/gnotravex                   \
    /usr/bin/gnotski                     \
    /usr/bin/gpasswd                     \
    /usr/bin/gtali                       \
    /usr/bin/iagno                       \
    /usr/bin/kgrantpty                   \
    /usr/bin/kon                         \
    /usr/bin/kpac_dhcp_helper            \
    /usr/bin/locate                      \
    /usr/bin/lockfile                    \
    /usr/bin/lppasswd                    \
    /usr/bin/mahjongg                    \
    /usr/bin/newgrp                      \
    /usr/bin/newvc                       \
    /usr/bin/passwd                      \
    /usr/bin/rcp                         \
    /usr/bin/rlogin                      \
    /usr/bin/rsh                         \
    /usr/bin/same-gnome                  \
    /usr/bin/screen                      \
    /usr/bin/sg                          \
    /usr/bin/slocate                     \
    /usr/bin/sperl5.8.5                  \
    /usr/bin/ssh-agent                   \
    /usr/bin/sudo                        \
    /usr/bin/sudoedit                    \
    /usr/bin/uucp                        \
    /usr/bin/uuname                      \
    /usr/bin/uuname                      \
    /usr/bin/uustat                      \
    /usr/bin/uux                         \
    /usr/bin/wall                        \
    /usr/bin/write                       \
    /usr/bin/xterm                       \
    /usr/kerberos/bin/ksu                \
    /usr/lib/amanda/amqde                \
    /usr/lib/amanda/calcsize             \
    /usr/lib/amanda/dumper               \
    /usr/lib/amanda/killpgrp             \
    /usr/lib/amanda/planner              \
    /usr/lib/amanda/rundump              \
    /usr/lib/amanda/runtar               \
    /usr/lib/cyrus-imapd/deliver         \
    /usr/lib/mc/cons.saver               \
    /usr/lib/mgetty+sendfax/faxq-helper  \
    /usr/lib/news/bin/inndstart          \
    /usr/lib/news/bin/rnews              \
    /usr/lib/news/bin/startinnfeed       \
    /usr/lib/vte/gnome-pty-helper        \
    /usr/libexec/openssh/ssh-keysign     \
    /usr/libexec/pt_chown                \
    /usr/libexec/utempter/utempter       \
    /usr/lib64/vte/gnome-pty-helper      \
    /usr/bin/locate                      \
    /usr/bin/screen                      \
    /usr/bin/Xorg                        \
    /usr/lib/squid/ncsa_auth             \
    /usr/lib/squid/pam_auth              \
    /usr/libexec/libvirt_proxy           \
    /usr/libexec/mc/cons.saver           \
    /usr/libexec/openssh/ssh-keysign     \
    /usr/libexec/utempter/utempter       \
    /usr/sbin/amcheck                    \
    /usr/sbin/ccreds_validate            \
    /usr/sbin/exim                       \
    /usr/sbin/gnome-pty-helper           \
    /usr/sbin/lockdev                    \
    /usr/sbin/postdrop                   \
    /usr/sbin/postqueue                  \
    /usr/sbin/sendmail.sendmail          \
    /usr/sbin/suexec                     \
    /usr/sbin/userhelper                 \
    /usr/sbin/userisdnctl                \
    /usr/sbin/usernetctl                 \
    /usr/sbin/utempter                   \
    /usr/sbin/uucico                     \
    /usr/sbin/uuxqt                      \
    /usr/sbin/utempter 
do 
    # Valid files with either SUID or SGID set are listed above, so this 
    # next piece will remove them from what's been found. 
    grep -v ${FILE} $tmpcis/CIS_7.7_f1 > $tmpcis/CIS_7.7_f2 
    # Put the file back and continue searching 
    /bin/cp -pf $tmpcis/CIS_7.7_f2 $tmpcis/CIS_7.7_f1 
done 
x=`wc -c $tmpcis/CIS_7.7_f1 | cut -d" " -f1` 
if [ $x == 0 ]; then 
     echo "($x) OK - No inappropriate SUID or SGID files found." 
else 
     sed 's/^.*/ls -lad &/'  $tmpcis/CIS_7.7_f1 > $tmpcis/CIS_7.7_f2 
     echo "The following files have either the SUID and/or the SGID bit set." 
     echo "These are not in the list of approved files/executables to have either" 
     echo "of those bits set.  Recommend removing the SUID/SGID bits on them." 
     /bin/bash $tmpcis/CIS_7.7_f2 
fi 


# 7.8 Find All Unowned Directories and Files
# This will only show the files, no changes will be made

for PART in $(grep -v '^#' /etc/fstab | awk '( $3 ~ "ext[23]" ) { print $2 }' ); 
do 
    find $PART -xdev -nouser -o -nogroup -print > $tmpcis/CIS_7.8_f1 
done 
sed 's/^.*/ls -lad &/'  $tmpcis/CIS_7.8_f1 > $tmpcis/CIS_7.8_f2 
cat $tmpcis/CIS_7.8_f2 
chmod -R 0400 $tmpcis/* 


# 7.9 Disable USB Devices
# Need to revisit this one as this may mess up the dc techs
# DEF_KERN=$( grubby --default-kernel) 
#grubby --update-kernel=$DEF_KERN --args="nousb" 


# 8 System Access, Authentication, and Authorization
# 8.1 Remove .rhosts Support In PAM Configuration Files

ls -la  /etc/pam.d/*  >  $tmpcis/CIS_8.1.Before.tmp 
cd /etc/pam.d 
for FILE in `find .  -type f -exec grep -l rhosts_auth {} \;`; do 
    echo "Removing .rhosts support in ${FILE}." 
    grep -v rhosts_auth $FILE > $tmpcis/${FILE}.tmp 
    /bin/cp -f $tmpcis/${FILE}.tmp $FILE 
    chown root:root $FILE 
    chmod 0644      $FILE 
done 
ls -la  /etc/pam.d/*  >  $tmpcis/CIS_8.1.After.tmp 
echo "The following entries changed under '/etc/pam.d'" 
echo "diff $tmpcis/CIS_8.1.Before.tmp $tmpcis/CIS_8.1.After.tmp" 
      diff $tmpcis/CIS_8.1.Before.tmp $tmpcis/CIS_8.1.After.tmp 
chmod -R 0400 $tmpcis/* 
cd $cishome 


# 8.2 Create ftpusers Files

if [ -f /etc/ftpaccess ]; then 
   for NAME in `cut -d: -f1 /etc/passwd`; do 
       if [ `id -u $NAME` -lt 500 ]; then 
            echo $NAME >> /etc/ftpusers 
       fi 
   done 
   chown root:root /etc/ftpusers 
   chmod 0600      /etc/ftpusers 
   echo "diff /etc/ftpusers-preCIS /etc/ftpusers" 
         diff /etc/ftpusers-preCIS /etc/ftpusers 
 
   VSFTP_CONF="/etc/vsftpd/vsftpd.conf" 
     ALT_CONF="/etc/vsftpd/vsftpd.conf" 
   test -f $ALT_CONF && VSFTP_CONF=$ALT_CONF 
   if [ -e $VSFTP_CONF ] && ! grep -q "^userlist_deny=NO" $VSFTP_CONF; then 
        /bin/cp -fp /etc/ftpusers /etc/vsftpd.ftpusers 
        chown root:root /etc/vsftpd/vsftpd.conf 
        chgrp 0600      /etc/vsftpd/vsftpd.conf 
        [ -e /etc/vsftpd.ftpusers-preCIS ] && echo "diff /etc/vsftpd.ftpusers-preCIS /etc/vsftpd.ftpusers"
        [ -e /etc/vsftpd.ftpusers-preCIS ] &&       diff /etc/vsftpd.ftpusers-preCIS /etc/vsftpd.ftpusers
   fi 
else 
     echo "OK - No /etc/ftpaccess to tailor." 
fi 


# 8.3 Prevent X Server From Listening On Port 6000/tcp

if [ -e /etc/X11/xdm/Xservers ]; then 
    cd /etc/X11/xdm 
    awk '( $1 !~ /^#/ && $3 == "/usr/X11R6/bin/X" ) { $3 = $3 " -nolisten tcp" }; 
    { print }' Xservers-preCIS > Xservers 
    chown root:root Xservers 
    chmod 0444      Xservers 
    echo "diff Xservers-preCIS Xservers" 
          diff Xservers-preCIS Xservers 
    cd $cishome 
else 
    echo "No /etc/X11/xdm/Xservers file to secure." 
fi 
if [ -d /etc/X11/xinit ]; then 
    cd /etc/X11/xinit 
    if [ -e xserverrc ]; then 
         echo "Fixing /etc/X11/xinit/xserverrc" 
         awk '/X/ && !/^#/ { print $0 " :0 -nolisten tcp \$@"; next }; \
         { print }' xserverrc-preCIS > xserverrc 
    else 
         cat <<END_SCRIPT > xserverrc 
#!/bin/bash 
exec X :0 -nolisten tcp \$@ 
END_SCRIPT
    fi 
    chown root:root xserverrc 
    chmod 0755      xserverrc 
    [ -e xserverrc-preCIS ] && echo "diff xserverrc-preCIS xserverrc" 
    [ -e xserverrc-preCIS ] &&       diff xserverrc-preCIS xserverrc 
    cd $cishome 
else 
    echo "No /etc/X11/xinit file to secure." 
fi 


# 8.4 Restrict at/cron To Authorized Users

# With x.allow only users listed can use 'at' or 'cron' 
# {where 'x' indicates either 'at' or 'cron'} 
# Without x.allow then x.deny is checked, members of x.deny are excluded 
# Without either (x.allow and x.deny), then only root can use 'at' and 'cron' 
# At a minimum x.allow should exist and list root 
echo "Attempting to list the following files for the 'before' picture." 
echo "Any 'errors' are alright, as we are simply looking to see what exists." 
ls -la /etc/at.allow /etc/at.deny /etc/cron.allow /etc/cron.deny 
rm -f /etc/at.deny /etc/cron.deny 
echo  root  >  /etc/at.allow 
echo  root  >  /etc/cron.allow 
chown  root:root  /etc/at.allow  /etc/cron.allow 
chmod  0400       /etc/at.allow  /etc/cron.allow 
if [ -e /etc/at.allow-preCIS ]; then 
   echo "diff /etc/at.allow-preCIS  /etc/at.allow" 
   diff /etc/at.allow-preCIS        /etc/at.allow 
fi 
if [ -e /etc/cron.allow-preCIS ]; then 
   echo "diff /etc/cron.allow-preCIS  /etc/cron.allow" 
   diff /etc/cron.allow-preCIS  /etc/cron.allow 
fi 
echo "Listing the state of these AFTER imposing restrictions..." 
echo "Missing file 'errors' are ok here too." 
ls -la /etc/at.allow /etc/at.deny /etc/cron.allow /etc/cron.deny 


# 8.5 Restrict Permissions On crontab Files

ls -lad /etc/cron* /var/spool/cron* 
chown  root:root  /etc/crontab 
chmod  0400       /etc/crontab 
chown  -R  root:root  /var/spool/cron 
chmod  -R  go-rwx     /var/spool/cron 
cd /etc 
ls | grep cron | grep -v preCIS | xargs chown -R root:root 
ls | grep cron | grep -v preCIS | xargs chmod -R go-rwx 
cd $cishome 
ls -lad /etc/cron* /var/spool/cron* 


# 8.6 Restrict Root Logins To System Console

echo ttyS0 >> /etc/securetty 
echo ttyS1 >> /etc/securetty 

echo console > /etc/securetty 
# These are acceptable for the GUI and runlevel 3, when trimmed down to 6 
for i in `seq 1 6`; do 
     echo vc/$i >> /etc/securetty 
done

for i in `seq 1 6`; do
     echo tty$i >> /etc/securetty
done

# 
#### Commented this out to be more secure as it denies root logins to the physical 
# TEXT console. 
#    Check pg 14 in Hardening Linux for additional safety in the /etc/inittab 
# file. 
# Do we want this as a required argument submitted on the command line? 
# 
#  for i in `seq 1 6`; do 
#       echo tty$i >> /etc/securetty 
#  done 
chown  root:root  /etc/securetty 
chmod  0400       /etc/securetty 
echo "diff /etc/securetty-preCIS /etc/securetty" 
      diff /etc/securetty-preCIS /etc/securetty 

# Part 2 
# Second modification of gdm.conf, if it exists. 
if [ -e /etc/X11/gdm/gdm.conf ]; then 
     #### There is another file to consider: "/etc/X11/gdm/gdm.conf" 
     # "AllowRoot=true" should be set to false to prevent root from logging in to 
     # the gdm GUI. 
     # "AllowRemoteRoot=true" should be set to false to prevent root logins from 
     # remote systems. 
     # Doing this change is supportive of logging in as a regular user and using 
     # 'su' to get to root. 
     # Before allowing a reboot, ensure at least one account is created for a 
     # SysAdmin type. 
     cd /etc/X11/gdm 
     /bin/cp -pf gdm.conf $tmpcis/gdm.conf.tmp 
     sed -e 's/AllowRoot=true/AllowRoot=false/'             \
         -e 's/AllowRemoteRoot=true/AllowRemoteRoot=false/' \
         -e 's/^#Use24Clock=false/Use24Clock=true/'   
         $tmpcis/gdm.conf.tmp  >  gdm.conf 
     chown root:root gdm.conf 
     chmod 0644      gdm.conf 
     echo "diff gdm.conf-preCIS gdm.conf" 
           diff gdm.conf-preCIS gdm.conf 
     cd $cishome 
else 
    echo "No /etc/X11/gdm/gdm.conf file to further secure." 
fi 
 
# Part 3 
echo "The following is only required when a serial console is used for this server."
echo "Either of these would be added manually post-baseline compliance, depending" 
echo "on the COM port the serial cable is physically attached to." 
echo "#    echo ttyS0 >> /etc/securetty" 
echo "#    echo ttyS1 >> /etc/securetty" 
chmod -R 0400 $tmpcis/* 


# 8.7 Set GRUB Password
# Need to revisit this.  Most likely I'll be skipping this.

chown root:root /boot/grub/grub.conf 
chmod 0600      /boot/grub/grub.conf


# 8.8 Require Authentication For Single-User Mode
# Need to revisit this.

cd /etc 
if [ "`grep -l sulogin inittab`" = "" ]; then 
     awk '{ print }; /^id:[0123456sS]:initdefault:/ { print "~~:S:wait:/sbin/sulogin" }' \
         inittab > $tmpcis/inittab.tmp
     /bin/cp -pf $tmpcis/inittab.tmp inittab 
     chown root:root inittab 
     chmod 0600      inittab 
     echo "diff inittab-preCIS inittab" 
           diff inittab-preCIS inittab 
else 
     echo "OK.  /etc/inittab already properly configured for Single-User" 
     echo "Mode Authentication." 
fi 
cd $cishome 
chmod -R 0400 $tmpcis/* 


# 8.9 Restrict NFS Client Requests To Privileged Ports

echo "/etc/exports size is (`wc -c /etc/exports | cut -d' ' -f1`)." 
if [ `wc -c /etc/exports | cut -d' ' -f1` == 0 ]; then 
     echo "Ok - No changes were necessary to /etc/exports." 
else 
     echo "Size (for /etc/exports) is greater than 0" 
     ls -la  /etc/export* 
     perl -i.orig -pe 'next if (/^\s*#/ || /^\s*$/); 
          ($res, @hst) = split(" "); 
          foreach $ent (@hst) { 
          undef(%set); 
          ($optlist) = $ent =~ /\((.*?)\)/; 
          foreach $opt (split(/,/, $optlist)) { 
          $set{$opt} = 1; 
          } 
          delete($set{"insecure"}); 
          $set{"secure"} = 1; 
          $ent =~ s/\(.*?\)//; 
          $ent .= "(" .  join(",", keys(%set)) .  ")"; 
          } 
          $hst[0] = "(secure)" unless (@hst); 
          $_ = "$res\t" .  join(" ", @hst) .  "\n";'    /etc/exports 
fi 
chown root:root /etc/exports 
chmod 0644      /etc/exports 
echo "diff /etc/exports-preCIS /etc/exports" 
      diff /etc/exports-preCIS /etc/exports 


# 8.10 Only Enable syslog To Accept Messages, If Absolutely Necessary
# Is this machine a log server, or does it need to receive Syslog messages via the network from other 
# systems? 


# 9 User Accounts and Environment
# 9.1 Block Login of System Accounts

echo "Basically change the '/sbin/nologin' portion to '/dev/null' in /etc/passwd" 
echo "  and add an exclamation point to the password field in /etc/shadow." 
cd /etc 
for NAME in `cut -d: -f1 /etc/passwd`; do 
     MyUID=`id -u $NAME` 
     if [ $MyUID -lt 500 -a $NAME != 'root' ]; then 
         usermod -L -s /dev/null $NAME 
     fi 
done 
ls -la /etc/passwd 
echo "sdiff passwd-preCIS passwd" 
echo "--------------------------" 
chown root:root /etc/passwd 
chmod 0644      /etc/passwd 
sdiff passwd-preCIS passwd 
 
ls -la /etc/shadow 
echo "sdiff shadow-preCIS shadow" 
echo "--------------------------" 
chown root:root  /etc/shadow 
chmod 0400       /etc/shadow 
sdiff shadow-preCIS shadow 
cd $cishome 


# 9.2 Verify That There Are No Accounts With Empty Password Fields
# This will only display info..

awk -F: '( $2 == "" ) { print $1 }' /etc/shadow


# 9.3 Set Account Expiration Parameters On Active Accounts

# The login.defs manpage indicates these functions are now # all handled by PAM. 
# This changes the defaults applicable to new accounts added to the system after 
# this point. 
cd /etc 
awk  '($1 ~ /^PASS_MAX_DAYS/)  { $2="90" } 
      ($1 ~ /^PASS_MIN_DAYS/)  { $2="7" } 
      ($1 ~ /^PASS_WARN_AGE/)  { $2="14" } 
      ($1 ~ /^PASS_MIN_LEN/)   { $2="9" } 
      { print }' login.defs-preCIS  >  login.defs 
useradd  -D  -f  7 
# This applies the same basis of changes to existing accounts. 
# -m: (7)  The number of days between permitted password changes. 
# -M: (90) The maximum number of days a password is valid. 
# -W: (14) The maximum number of days of advanced warning before a password is no 
# longer valid. 
# -I: (7)  The maximum number of days of inactivity, after a password has expired,  
# before the account is locked. 
for  NAME  in  `cut  -d:  -f1  /etc/passwd`;  do 
                uid=`id  -u  $NAME` 
                if  [  $uid  -ge  500  -a  $uid  !=  65534 ];  then 
                       chage  -m  7  -M  90  -W  14  -I  7  $NAME 
                fi 
done 
cat <<END_SCRIPT  >> login.defs 
 
# The following 2 lines added, per CIS Red Hat Enterprise Linux Benchmark sec 9.3 
# Establish a forced five-second minimum delay between failed logins 
FAIL_DELAY  5 
END_SCRIPT
chown  root:root  login.defs 
chmod  0640       login.defs 
echo "diff shadow-preCIS shadow" 
      diff shadow-preCIS shadow 
cd $cishome 


# 9.4 Verify No Legacy '+' Entries Exist In passwd, shadow, And group Files

# Do a context specific diff to only show differences related to having plus signs 
# in the file. 
# Otherwise the output is too much 
grep -v ^+:   /etc/group     > $tmpcis/group.tmp 
grep -v ^+:   /etc/gshadow   > $tmpcis/gshadow.tmp 
grep -v ^+:   /etc/passwd    > $tmpcis/passwd.tmp 
grep -v ^+:   /etc/shadow    > $tmpcis/shadow.tmp 
# Express the essence of what is compared. 
echo "diff /etc/group-preCIS    /etc/group" 
      diff /etc/group-preCIS    $tmpcis/group.tmp 
echo "diff /etc/gshadow-preCIS  /etc/gshadow" 
      diff /etc/gshadow-preCIS  $tmpcis/gshadow.tmp 
echo "diff /etc/passwd-preCIS   /etc/passwd" 
      diff /etc/passwd-preCIS   $tmpcis/passwd.tmp 
echo "diff /etc/shadow-preCIS   /etc/shadow" 
      diff /etc/shadow-preCIS   $tmpcis/shadow.tmp 
chown root:root $tmpcis/group.tmp  $tmpcis/gshadow.tmp  $tmpcis/passwd.tmp $tmpcis/shadow.tmp
chmod 0644      $tmpcis/group.tmp                        $tmpcis/passwd.tmp 
chmod 0400                          $tmpcis/gshadow.tmp $tmpcis/shadow.tmp
/bin/cp -pf  $tmpcis/group.tmp     /etc/group 
/bin/cp -pf  $tmpcis/gshadow.tmp   /etc/gshadow 
/bin/cp -pf  $tmpcis/passwd.tmp    /etc/passwd 
/bin/cp -pf  $tmpcis/shadow.tmp    /etc/shadow 


# 9.5 No '.' or Group/World-Writable Directory In Root's $PATH

echo $PATH | egrep '(^|:)(\.|:|$)'
# Part 1 
echo "Any entries listed here should be fixed (other than an error for missing /root/bin)."
echo "PATH($PATH)." 
echo "Any entries listed next indicated a period exists in the PATH environment variable (BAD)."
echo $PATH | egrep '(^|:)(\.|:|$)' 
# Part 2 
echo "Here, are paths with group/world writeable directories in root's PATH (BAD)."
echo "(roots PATH variable contains '/root/bin', even though that directory doesn't exist, by default)"
echo "(Errors regarding /mnt/sysimage, are ghosts held over from a kickstarted system build"
echo " implementation and can be safely ignored)" 
find `echo $PATH | tr ':' ' '` -type d \( -perm -002 -o -perm -020 \) -ls 
echo "" 


# 9.6 User Home Directories Should Be Mode 0750 or More Restrictive

for DIR in `awk -F: '( $3 >= 500 ) { print $6 }' /etc/passwd | grep -v soap`; do
    if [ $DIR != /var/lib/nfs ]; then 
         chmod -R g-w   $DIR 
         chmod -R o-rwx $DIR 
    fi 
done 


# 9.7 No User Dot-Files Should Be World-Writable

for DIR in `awk -F: '($3 >= 500) { print $6 }' /etc/passwd`; do 
    for FILE in $DIR/.[A-Za-z0-9]*; do 
        if [ ! -h "$FILE" -a -f "$FILE" ]; then 
             chmod go-w "$FILE" 
        fi 
    done 
done 


# 9.8 Remove User .netrc Files

find  /  -name  .netrc  -exec grep -il password {} \;  >  \
      $tmpcis/LISTof.netrcFiles 2>&1 


# 9.9 Set Default umask For Users
## THIS SECTION NEEDS TO BE CLEANED UP

# Forced umask assignment into /etc/skel/.bashrc for consistency 
# (though the CIS scoring tool doesn't check here yet) 
# CISum=077
# sed  -e  "s/002/$CISum/"  -e  "s/022/$CISum/"  /etc/bashrc-preCIS            > /etc/bashrc 
# sed  -e  "s/002/$CISum/"  -e  "s/022/$CISum/"  /etc/csh.cshrc-preCIS         > /etc/csh.cshrc 
# sed      "s/027/$CISum/g" -e  "s/022/$CISum/" -e "s/002/$CISum/" /etc/csh.login-preCIS         > /etc/csh.login
# sed      "s/027/$CISum/"                       /etc/profile-preCIS           > /etc/profile
# echo	 "umask $CISum"			       				    >> /etc/profile

# PCI 8.5.15 Log out users idle for 15 minutes
echo	 "TMOUT=900"						            >> /etc/profile
# echo     "umask $CISum"                                                     >> /etc/skel/.bashrc
# echo	 "umask $CISum"							    >> /root/.bash_profile
# sed      "s/027/077/"                          /root/.bash_profile-preCIS    > /root/.bash_profile
# echo "umask 077" >> /root/.bashrc 
# echo "umask 077" >> /root/.bash_profile
# echo "umask 077" >> /root/.cshrc 
# echo "umask 077" >> /root/.tcshrc 
chown root:root  /etc/bashrc /etc/csh.cshrc /etc/csh.login /etc/profile 
chmod 0444       /etc/bashrc /etc/csh.cshrc /etc/csh.login /etc/profile 
chown root:root  /root/.bash_profile /root/.bashrc /root/.cshrc /root/.tcshrc 
chmod 0400       /root/.bash_profile /root/.bashrc /root/.cshrc /root/.tcshrc 
echo "diff /etc/bashrc-preCIS /etc/bashrc" 
      diff /etc/bashrc-preCIS /etc/bashrc 
echo "diff /etc/csh.cshrc-preCIS /etc/csh.cshrc" 
      diff /etc/csh.cshrc-preCIS /etc/csh.cshrc 
echo "diff /etc/csh.login-preCIS /etc/csh.login" 
      diff /etc/csh.login-preCIS /etc/csh.login 
echo "diff /etc/profile-preCIS /etc/profile" 
      diff /etc/profile-preCIS /etc/profile 
echo "diff /root/.bash_profile-preCIS /root/.bash_profile" 
      diff /root/.bash_profile-preCIS /root/.bash_profile 
echo "diff /etc/skel/.bashrc-preCIS /etc/skel/.bashrc" 
      diff /etc/skel/.bashrc-preCIS /etc/skel/.bashrc 
echo "diff /root/.bashrc-preCIS /root/.bashrc" 
      diff /root/.bashrc-preCIS /root/.bashrc 
echo "diff /root/.cshrc-preCIS /root/.cshrc" 
      diff /root/.cshrc-preCIS /root/.cshrc 
echo "diff /root/.tcshrc-preCIS /root/.tcshrc" 
      diff /root/.tcshrc-preCIS /root/.tcshrc 
# 
# Suggest a process that walks all existing user accounts (> 500) and force's the 
# same permissions into their profile scripts.


# 9.10 Disable Core Dumps
awk '( $1 == "#*" && $2 == "soft" && $3 == "core" && $4 == "0" ) {  \
       print "*                soft    core            0";          \
       print "*                hard    core            0"; next  }  \
     { print }'  /etc/security/limits.conf-preCIS > /etc/security/limits.conf
chown root:root /etc/security/limits.conf
chmod 0644      /etc/security/limits.conf
echo "diff /etc/security/limits.conf-preCIS /etc/security/limits.conf"
      diff /etc/security/limits.conf-preCIS /etc/security/limits.conf


# 9.11 Limit Access To The Root Account From su
# Set the value for "$AdminsComma " to a local approved list of SysAdmins, and only separate
# each entity with commas.
# Example:  "userID1,userID2,userID3"

$AdminsComma=admin
 
# Part 1 
echo "Note: By executing this ONLY members of the wheel group can su to root." 
cd /etc/pam.d/ 
awk '( $1=="#auth" && $2=="required" && $3~"pam_wheel.so" ) \
     { print "auth\t\trequired\t",$3,"\tuse_uid"; next }; 
     { print }' /etc/pam.d/su-preCIS > /etc/pam.d/su 
chown root:root /etc/pam.d/su 
chmod 0644      /etc/pam.d/su 
echo "diff /etc/pam.d/su-preCIS /etc/pam.d/su" 
      diff /etc/pam.d/su-preCIS /etc/pam.d/su 
cd $cishome 
 
# Part 2 
# The process is beneficial when using kickstart for building of systems, then 
# deliberately go back to all those systems and forcefully change the 
# root/SysAdmin passwords to be in new. 
echo "(${AdminsComma}) are to be System Administrators for this system." 
 
for USERID in `echo $AdminSP` 
    do 
      echo "1.  Dealing with userid($USERID)..." 
      ID=`cat /etc/passwd | cut -d: -f1 | grep $USERID 2>&1` 
      if [ "$ID" != "$USERID" ]; then 
         # The user-id was NOT found 
         echo "2a  Adding new user ($USERID) 'procedure-compliant'." 
         # Use grub-md5-crypt to generate the encrypted password 
         useradd -f 7 -m -p '$1$PyDA7$L81b0Sp1u.DyGnjbRUp/3/' $USERID 
         chage  -m  7  -M  90  -W  14  -I  7  $USERID 
      else 
         echo "2b  User ($USERID) already in the system." 
         chage  -m  7  -M  90  -W  14  -I  7  $USERID 
      fi 
      ls -la /home 
    done 
echo "Doing pwck -r" 
pwck -r 
echo "" 

# Part 3 
# Perform steps to ensure any users identified in $Admins are added to the "wheel" 
# group.  This is probably only going to add the example 'tstuser' account, or 
# whichever userID the system builder names during the initial system build. 
# Note: /etc/group requires entries to be comma-separated. 
if [ "$Admins" != "" ]; then 
     echo "At least one AdminID has been identified to be added to the wheel group."
     echo "Admins(${Admins}), AdminSP(${AdminSP}), AdminsComma(${AdminsComma})." 
     cd /etc 
     # Resultant /etc/group file is now nicely sorted as well 
     /bin/cp -pf group $tmpcis/group.tmp 
     awk -F: '($1~"wheel" && $4~"root") { print $0 "," Adds }; \
              ($1 != "wheel") {print}' Adds="`echo $AdminsComma`" \
             $tmpcis/group.tmp | sort -t: -nk 3 >  $tmpcis/group.tmp1 
     chown root:root $tmpcis/group.tmp1 
     chmod 0644      $tmpcis/group.tmp1 
     /bin/cp -pf $tmpcis/group.tmp1  group 
     echo "sdiff group-preCIS group" 
           sdiff group-preCIS group 
     cd $cishome 
else 
        echo "BAD.  No SysAdmin IDs were identified to be added to the wheel group."
fi 
 
# Part 4 
echo "#### This is done in concert with Bastille that was executed before this step in the"
echo "#### standard baseline hardening.  This will add SPACE-delimited SysAdmin userIDs to"
echo "#### the /etc/security/access.conf file.  These are the same names as are added to"
echo "#### the wheel group in the /etc/group file.  This action prohibits any user NOT in"
echo "#### the wheel group from logging in to the system on the physical console." 
echo "#### Can treat this as a known entity with one entry to deal with since the state of"
echo "#### this system up to this point is well known." 
echo "#### No differences may appear, if the same users are listed here, as were added by Bastille."
#    The line in question resembles the following, 3 colon-separated fields: 
#    -:ALL EXCEPT root tstuser:LOCAL 
#    To be turned into something that looks like the following (sorted IDs are  
# easier to read): 
#    -:ALL EXCEPT abc-Admin root def-Admin tstuser:LOCAL 
# 
cd /etc/security 
# Check if there are any uncommented lines to ADD $Admins to. 
x="`grep -v ^# access.conf | wc -l | cut -d: -f1`" 
echo "x($x)" 
if [ "$x" == "0" ]; then 
     # Most likely the Bastille hardening hasn't been applied yet. 
     # Must manually add the users, as the file is otherwise 'empty'. 
     echo "Manually adding the ($Admins); none previously existed there." 
     echo "-:ALL EXCEPT root" $AdminSP":LOCAL" >> access.conf 
else 
     # Extract just the userIDs 
     x="`grep -v ^# access.conf | cut -d: -f2 | cut -d' ' -f3-`" 
     # Bundle in the new SysAdmin IDs passed during script invocation, and sort the names alphabetically.
     # Need a piece here to compare what's there with what we have to add, to avoid duplicates.
          y="`echo $AdminsComma $x | tr -s ',' ' ' | tr ' ' '\012' | sort -u | tr '\012' ' '`"
     echo "x($x), y($y)";echo "" 
     # 2nd -e is to eliminate the extra space before the final colon, if one exists.
       sed -e "s/$x/$y/" -e 's/ :L/:L/' access.conf-preCIS > access.conf 
     # sed "s/$x/$y/" access.conf-preCIS | sed 's/ :L/:L/' > access.conf 
fi 
echo "diff /etc/security/access.conf-preCIS /etc/security/access.conf" 
      diff /etc/security/access.conf-preCIS /etc/security/access.conf 
chown root:root /etc/security/access.conf 
chmod 0640      /etc/security/access.conf 
cd $cishome 
chmod -R 0400 $tmpcis/* 


# 10 Warning Banners
# 10.1 Create Warnings For Network And Physical Access Services

cat << EOF > /etc/issue

                           !!WARNING!!!
              READ THIS BEFORE ATTEMPTING TO LOGON

This system is for the use of authorized users only. Individuals
using this computer without authority, or in excess of their authority,
are subject to having all of their activities on this system monitored
and recorded by system personnel.  In the course of monitoring individuals
improperly using this system, or in the course of system maintenance,
the activities of authorized users may also be monitored.  Anyone using
this system expressly consents to such monitoring and is advised that if
such monitoring reveals possible criminal activity, system personnel may
provide the evidence of such monitoring to law enforcement officials.

EOF
 
# Create banners for network access: 
/bin/cp -pf /etc/issue  /etc/issue.net 
 
# Protect banner files: 
chown  root:root  /etc/issue  /etc/issue.net  /etc/motd 
chmod  0644       /etc/issue  /etc/issue.net  /etc/motd 
echo "diff /etc/issue-preCIS     /etc/issue" 
      diff /etc/issue-preCIS     /etc/issue 
echo "diff /etc/issue.net-preCIS /etc/issue.net" 
      diff /etc/issue.net-preCIS /etc/issue.net 
echo "diff /etc/motd-preCIS      /etc/motd" 
      diff /etc/motd-preCIS      /etc/motd 


# 10.2 Create Warnings For GUI-Based Logins
# This is optional and we are not using GUI's

# 10.3 Create "authorized only" Banners For vsftpd, proftpd, If Applicable

cd /etc 
if [ -d vsftpd ]; then 
    cd vsftpd 
fi 
if [ -e vsftpd.conf ]; then 
   echo "ftpd_banner=Authorized users only.  All activity may be monitored and \
         reported." >> vsftpd.conf 
   echo "diff vsftpd.conf-preCIS vsftpd.conf" 
   diff vsftpd.conf-preCIS vsftpd.conf 
   chown root:root vsftpd.conf 
   chmod 0600      vsftpd.conf 
else 
   echo "OK - No vsftpd to change." 
fi 
cd $cishome 


# 11  Misc odds and ends
# 11.1 Configure and enable the auditd and sysstat services, if possible
# PCI:  Modified from CIS to meet PCI Requirements:
# - 2.2.3.93
# - 10.2.0.10
# - 10.2.0.11
# - 10.2.0.12
# - 10.2.0.13
# - 10.2.0.14

echo "Configure and enable the auditd and sysstat services, if possible." 
auditPATH='/etc/audit' 
# Part 1 
echo "Enforce auditing minimums." 
# This will enforce auditing minimums. 
/bin/cp -pf                  $auditPATH/audit.rules    $tmpcis/audit.rules.tmp 
cat <<END_SCRIPT   >         $auditPATH/audit.rules 
## This file contains the auditctl rules that are loaded 
## whenever the audit daemon is started via the initscripts. 
## The rules are simply the parameters that would be passed 
## to auditctl. 
## 
## First rule - delete all 
-D 
 
## Increase the buffers to survive stress events. 
## Make this bigger for busy systems 
-b 1024
 
## Set failure mode to syslog notice {these two are mutually exclusive} 
-f 1 
 
## Set failure mode to panic {these two are mutually exclusive} 
## -f 2 
 
## NOTE: 
## 1) if this is being used on a 32 bit machine, comment out the b64 lines 
## 2) These rules assume that login under the root account is not allowed. 
## 3) It is also assumed that 500 represents the first usable user account. 
## 4) If these rules generate too much spurious data for your tastes, limit the 
##    the syscall file rules with a directory, like -F dir=/etc 
## 5) You can search for the results on the key fields in the rules 
## 
## (GEN002880: CAT II) The IAO will ensure the auditing software can 
## record the following for each audit event:  
##- Date and time of the event  
##- Userid that initiated the event  
##- Type of event  
##- Success or failure of the event  
##- For I&A events, the origin of the request (e.g., terminal ID)  
##- For events that introduce an object into a user’s address space, and 
##  for object deletion events, the name of the object, and in MLS 
##  systems, the object’s security level. 
## 
## Things that could affect time 
-a always,exit -F arch=b32 -S adjtimex -S settimeofday -S stime -k time-change 
-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change 
#-a always,exit -F arch=b32 -S clock_settime -k time-change 
#-a always,exit -F arch=b64 -S clock_settime -k time-change 
-w /etc/localtime -p wa -k time-change 
 
## Things that affect identity 
-w /etc/group -p wa -k identity 
-w /etc/passwd -p wa -k identity 
-w /etc/gshadow -p wa -k identity 
-w /etc/shadow -p wa -k identity 
-w /etc/security/opasswd -p wa -k identity 
 
## Things that could affect system locale 
-a exit,always -F arch=b32 -S sethostname -S setdomainname -k system-locale 
-a exit,always -F arch=b64 -S sethostname -S setdomainname -k system-locale 
-w /etc/issue -p wa -k system-locale 
-w /etc/issue.net -p wa -k system-locale 
-w /etc/hosts -p wa -k system-locale 
-w /etc/sysconfig/network -p wa -k system-locale 
 
## Things that could affect MAC policy 
-w /etc/selinux/ -p wa -k MAC-policy 
 
## The SysAdmin will configure the auditing system to audit the following events 
## for all users and root: 
## - Logon (unsuccessful and successful) and logout (successful) 
##   This is handled by pam, sshd, login, and gdm 
##   Might also want to watch these files if needing extra information 
#    -w /var/log/faillog -p wa -k logins 
#    -w /var/log/lastlog -p wa -k logins 
 
##- Process and session initiation (unsuccessful and successful) 
## 
## The session initiation is audited by pam without any rules needed. 
## Might also want to watch this file if needing extra information 
#-w /var/run/utmp -p wa -k session 
#-w /var/log/btmp -p wa -k session 
#-w /var/log/wtmp -p wa -k session 
 
##- Discretionary access control permission modification (unsuccessful 
## and successful use of chown/chmod) 

-a always,exit -F arch=b32 -S chmod -S fchmod -S fchmodat -F auid>=500 -F auid!=4294967295 -k perm_mod
-a always,exit -F arch=b64 -S chmod -S fchmod -S fchmodat -F auid>=500 -F auid!=4294967295 -k perm_mod
-a always,exit -F arch=b32 -S chown -S fchown -S fchownat -S lchown -F auid>=500 -F auid!=4294967295 -k perm_mod 
-a always,exit -F arch=b64 -S chown -S fchown -S fchownat -S lchown -F auid>=500 -F auid!=4294967295 -k perm_mod
-a always,exit -F arch=b32 -S setxattr -S lsetxattr -S fsetxattr -S removexattr -S lremovexattr -S fremovexattr -F auid>=500 -F auid!=4294967295 -k perm_mod
-a always,exit -F arch=b64 -S setxattr -S lsetxattr -S fsetxattr -S removexattr -S lremovexattr -S fremovexattr -F auid>=500 -F auid!=4294967295 -k perm_mod
 
##- Unauthorized access attempts to files (unsuccessful)  
-a always,exit -F arch=b32 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EACCES -F auid>=500 -F auid!=4294967295 -k access
-a always,exit -F arch=b32 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EPERM -F auid>=500 -F auid!=4294967295 -k access
-a always,exit -F arch=b64 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EACCES -F auid>=500 -F auid!=4294967295 -k access
-a always,exit -F arch=b64 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EPERM -F auid>=500 -F auid!=4294967295 -k access
 
##- Use of privileged commands (unsuccessful and successful) 
##  use find /bin -type f -perm -04000 2>/dev/null and put all those files in 
##  a rule like this 
-a always,exit -F path=/bin/ping -F perm=x -F auid>=500 -F auid!=4294967295 -k privileged
 
##- Use of print command (unsuccessful and successful)  
 
##- Export to media (successful) 
## You have to mount media before using it. You must disable all automounting 
## so that its done manually in order to get the correct user requesting the 
## export 
-a always,exit -F arch=b32 -S mount -F auid>=500 -F auid!=4294967295 -k export 
-a always,exit -F arch=b64 -S mount -F auid>=500 -F auid!=4294967295 -k export 
 
##- System startup and shutdown (unsuccessful and successful) 
 
##- Files and programs deleted by the user (successful and unsuccessful) 
-a always,exit -F arch=b32 -S unlink -S unlinkat -S rename -S renameat -F auid>=500 -F auid!=4294967295 -k delete
-a always,exit -F arch=b64 -S unlink -S unlinkat -S rename -S renameat -F auid>=500 -F auid!=4294967295 -k delete

##- All system administration actions  
##- All security personnel actions 
##  
## Look for pam_tty_audit and add it to your login entry point's pam configs. 
## If that is not found, use sudo which should be patched to record its 
## commands to the audit system. Do not allow unrestricted root shells or 
## sudo cannot record the action. 
-w /etc/sudoers -p wa -k actions 
 
## Optional - could indicate someone trying to do something bad or 
## just debugging 
#-a entry,always -F arch=b32 -S ptrace -k tracing 
#-a entry,always -F arch=b64 -S ptrace -k tracing 

## Optional - could be an attempt to bypass audit or simply legacy program 
#-a always,exit -F arch=b32 -S personality -k bypass 
#-a always,exit -F arch=b64 -S personality -k bypass 
 
## Put your own watches after this point 
# -w /your-file -p rwxa -k mykey 
 
## Make the configuration immutable - reboot is required to change audit rules 
-e 1

## FOR PCI: 10.2.0.11
# -a exit,always -S stime -S acct -S reboot -S swapon -S settimeofday

## For PCI: 10.2.0.12
# -a exit,always -S setrlimit -S setdomainname -S sched_setparam -S sched_setscheduler

## For PCI: 10.2.0.13
# -a exit,always -S chmod -S fchmod -S chown -S chown32 -S fchown

## For PCI: 10.2.0.14
# -a exit,always -S fchown32 -S lchown -S lchown32

## For PCI: 10.2.3.1
# -w /var/log/audit/

## For PCI: 10.2.3.2
# -w /etc/audit/auditd.conf

## For PCI: 10.2.3.3
# -w /etc/audit/audit.rules

## For PCI: 10.2.4.1
# -a exit,always -S open -F success=0

## For PCI: 10.2.7.1
# -a exit,always -S unlink -S rmdir


END_SCRIPT
chown root:root $auditPATH/audit.rules 
chmod 0600      $auditPATH/audit.rules 
echo "diff $auditPATH/audit.rules-preCIS  $auditPATH/audit.rules" 
      diff $auditPATH/audit.rules-preCIS  $auditPATH/audit.rules 
 
# Part 2 
echo "Strengthen auditd.conf settings." 
sed -e "s/num_logs = 4/num_logs = 5/"                            \
    -e "s/max_log_file = 5/max_log_file = 100/"                  \
    -e "s/space_left = 75/space_left = 125/"                     \
    -e "s/admin_space_left = 50/admin_space_left = 75/"          \
    -e "s/space_left_action = SYSLOG/space_left_action = email/" \
       $auditPATH/auditd.conf-preCIS > $auditPATH/auditd.conf 
chown root:root $auditPATH/auditd.conf 
# Default permissions were originally 0640. 
chmod 0600      $auditPATH/auditd.conf 
echo "diff $auditPATH/auditd.conf-preCIS  $auditPATH/auditd.conf" 
      diff $auditPATH/auditd.conf-preCIS  $auditPATH/auditd.conf 
 
# Part 3 
echo "Make auditd applicable across reboots." 
chkconfig --list auditd 
chkconfig --list sysstat 
echo "-------" 
chkconfig --level 35 auditd  on 
chkconfig --level 35 sysstat on 
echo "-------" 
# Enable auditd and sysstat services, good even if rebooting soon 
service auditd  restart 
service sysstat restart 
echo "-------" 
chkconfig --list auditd 
chkconfig --list sysstat 
chmod -R 0400 $tmpcis/* 
echo "" 


# 11.2 Verify no duplicate userIDs exist

echo "Verify no duplicate userIDs exist." 
#dup username 
x=`cut -f1 -d: /etc/passwd | sort | uniq -d | tr "\n" " "` 
if [ "x$x" != "x" ] 
then 
echo "The following duplicate usernames found: $x" 
fi 
#dup uid 
x=`cut -f3 -d: /etc/passwd | sort | uniq -d | tr "\n" " "` 
if [ "x$x" != "x" ] 
then 
echo "The following duplicate uids found: $x" 
fi 
#dup groupname 
x=`cut -f1 -d: /etc/group | sort | uniq -d | tr "\n" " "` 
if [ "x$x" != "x" ] 
then 
echo "The following duplicate group names found: $x" 
fi 
#dup uid 
x=`cut -f3 -d: /etc/group | sort | uniq -d | tr "\n" " "` 
if [ "x$x" != "x" ] 
then 
echo "The following duplicate gids found: $x" 
fi 
echo "" 


# 11.3 Force permissions on root's home directory to be 0700

ls -lad /root 
chown root:root /root 
chmod 0700      /root 
ls -lad /root 


# 11.4 Utilize PAM to Enforce UserID password complexity
# PCI:  Modified requirements for 8.5.10 - 8.5.14

cd /etc/pam.d 
/bin/cp -pf /etc/pam.d/system-auth $tmpcis/system-auth.tmp 

cat << EOF > /etc/pam.d/system-auth
auth        required      pam_env.so
# PCI 8.5.13 Limit repeated access attempts after 6 failed attempts
# PCI 8.5.14 Set lockout duration to 30 minutes after 6 failed attempts
auth        required      pam_tally.so onerr=fail deny=6 unlock_time=1800
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 500 quiet
auth        required      pam_deny.so

account     required      pam_unix.so
account     sufficient    pam_succeed_if.so uid < 500 quiet
account     required      pam_permit.so

# PCI 8.5.10 Require a minimum password length of 8 characters
# PCI 8.5.11 Use passwords containing both numeric and alphabetic characters
password    required      pam_passwdqc.so min=disabled,disabled,7,7,7 passphrase=3 match=4 similar=deny random=0 enforce=everyone retry=3
# PCI 8.5.12 New password can not be the same as any of the last 4 passwords
password    sufficient    pam_unix.so remember=4 md5 shadow nullok try_first_pass use_authtok
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so
EOF


chown root:root /etc/pam.d/system-auth 
chmod 0644      /etc/pam.d/system-auth 
echo "diff /etc/pam.d-preCIS/system-auth /etc/pam.d/system-auth" 
      diff /etc/pam.d-preCIS/system-auth /etc/pam.d/system-auth 
echo " system-auth {original contents} --------------------------------" 
cat /etc/pam.d-preCIS/system-auth 
echo " system-auth {updated contents} ---------------------------------" 
cat /etc/pam.d/system-auth 
echo "-----------------------------------------------------------------" 
echo "Protecting a hardened copy of /etc/pam.d/system-auth" 
/bin/cp -pf /etc/pam.d/system-auth  /etc/pam.d/system-auth.HardenedProtectedCopy 
ls -la /etc/pam.d/system-auth* 
cd $cishome 
chmod -R 0400 $tmpcis/* 


# 11.5 Ensure perms on man and doc pages prevent modification by unprivileged users

# echo "Restrict permissions to 0644 on /usr/share/man and /usr/share/doc content" 
# date 
# chmod -R go-w /usr/share/doc  /usr/local/share/doc 
# chmod -R go-w /usr/share/man  /usr/local/share/man 


# 13.1 Remove CIS benchmark hardening backup files

for i in `find / -xdev |grep preCIS`; do rm -rf $i; done


################
# PCI SPECIFIC #
################

# PCI: 2.2.3.34 Verify that 'immutable' flag is added to /etc/fstab

chattr +i /etc/fstab


# PCI: 2.2.3.39 Find SUID System Executables and remove SUID bit

for PART in `awk '($1 !~ /#/ && $3 ~ "ext2|ext3|reiserfs") { print $2 }' /etc/fstab`; do find $PART \( -perm -04000 \) -type f -xdev -print 2>/dev/null | sort >> /tmp/CIS_7.7_f1; done; for FILE in /bin/mount /bin/ping /bin/ping6 /bin/su /bin/traceroute /bin/traceroute6 /bin/umount /media/.hal-mtab-lock /sbin/mount.nfs /sbin/mount.nfs4 /sbin/netreport /sbin/pam_timestamp_check /sbin/pwdb_chkpwd /sbin/umount.nfs /sbin/umount.nfs4 /sbin/unix_chkpwd /usr/X11R6/bin/Xorg /usr/bin/at /usr/bin/chage /usr/bin/chfn /usr/bin/chsh /usr/bin/crontab /usr/bin/cu /usr/bin/gataxx /usr/bin/glines /usr/bin/gnibbles /usr/bin/gnobots2 /usr/bin/gnomine /usr/bin/gnotravex /usr/bin/gnotski /usr/bin/gpasswd /usr/bin/gtali /usr/bin/iagno /usr/bin/kgrantpty /usr/bin/kon /usr/bin/kpac_dhcp_helper /usr/bin/locate /usr/bin/lockfile /usr/bin/lppasswd /usr/bin/mahjongg /usr/bin/newgrp /usr/bin/newvc /usr/bin/passwd /usr/bin/rcp /usr/bin/rlogin /usr/bin/rsh /usr/bin/same-gnome /usr/bin/screen /usr/bin/sg /usr/bin/slocate /usr/bin/sperl5.8.5 /usr/bin/ssh-agent /usr/bin/sudo /usr/bin/sudoedit /usr/bin/uucp /usr/bin/uuname /usr/bin/uuname /usr/bin/uustat /usr/bin/uux /usr/bin/wall /usr/bin/write /usr/bin/xterm /usr/kerberos/bin/ksu /usr/lib/amanda/amqde /usr/lib/amanda/calcsize /usr/lib/amanda/dumper /usr/lib/amanda/killpgrp /usr/lib/amanda/planner /usr/lib/amanda/rundump /usr/lib/amanda/runtar /usr/lib/cyrus-imapd/deliver /usr/lib/mc/cons.saver /usr/lib/mgetty+sendfax/faxq-helper /usr/lib/news/bin/inndstart /usr/lib/news/bin/rnews /usr/lib/news/bin/startinnfeed /usr/lib/vte/gnome-pty-helper /usr/libexec/openssh/ssh-keysign /usr/libexec/pt_chown /usr/libexec/utempter/utempter /usr/lib64/vte/gnome-pty-helper /usr/bin/locate /usr/bin/screen /usr/bin/Xorg /usr/lib/squid/ncsa_auth /usr/lib/squid/pam_auth /usr/libexec/libvirt_proxy /usr/libexec/mc/cons.saver /usr/libexec/openssh/ssh-keysign /usr/libexec/utempter/utempter /usr/sbin/amcheck /usr/sbin/ccreds_validate /usr/sbin/exim /usr/sbin/gnome-pty-helper /usr/sbin/lockdev /usr/sbin/postdrop /usr/sbin/postqueue /usr/sbin/sendmail.sendmail /usr/sbin/suexec /usr/sbin/userhelper /usr/sbin/userisdnctl /usr/sbin/usernetctl /usr/sbin/utempter /usr/sbin/uucico /usr/sbin/uuxqt /usr/sbin/utempter; do grep -v ${FILE} /tmp/CIS_7.7_f1 > /tmp/CIS_7.7_f2; /bin/cp -pf /tmp/CIS_7.7_f2 /tmp/CIS_7.7_f1; done; x=`wc -c /tmp/CIS_7.7_f1 | cut -d" " -f1`; if [ $x != 0 ]; then sed 's/^.*/ls -lad &/' /tmp/CIS_7.7_f1 > /tmp/CIS_7.7_f2; echo "The following files have the SUID bit set. Recommend removing the SUID bit on them:"; /bin/bash /tmp/CIS_7.7_f2; fi; 

for i in `cat /tmp/CIS_7.7_f2 |awk '{print $3}'`; do chmod u-s $i; done  ; rm -f /tmp/CIS_7.7_f1 /tmp/CIS_7.7_f2


# PCI: 2.2.3.45-46 Verify wu-ftpd and vsftp FTP Users Settings
# This restricts system accounts rom transferring data via ftp

SYSACCT="daemon ident bin sys adm smtp uucp nuucp listen lpd lp ingres oracle oracle7 oracle8 oracle9 oracle9i informix news nobody nobody4 noaccess sybase tivoli www ftp tftp hpdb sshd invscout gccs secm an sysadmin install staff COE tracker predmail snmp inews smmsp sm spmadmin share BIF GCCS JDISS SA SSO SM ftp gccsrv gtnsmint irc Imadmin imadmin netadmin oradba halt mail rpm vcsa nscd rpc rpcuser mailnull pcap xfs ntp gdm sync shutdown halt operator gopher nfsnobody dbus haldaemon netdump webalizer pvm mysql mailman dovecot cyrus amanda pegasus HPSMH hpsmh webadmind webadmin webservd avahi beagleidx hsqldb postfix hacluster named canna wnn fax quagga htt root"
for userid in $SYSACCT; do echo $userid >> /etc/ftpusers; done


# PCI: 7.1.1.8 Verify /etc/cups/cupsd.conf Permissions
chmod 600 /etc/cups/cupsd.conf
chown lp:sys /etc/cups/cupsd.conf

# PCI: 7.1.1.13 - Verify /var/log/btmp Permissions
chmod 600 /var/log/btmp
chown root:utmp /var/log/btmp

# PCI: 7.1.1.49 - Verify /etc/security/console.perms Permissions
chmod 600 /etc/security/console.perms
chown root:root /etc/security/console.perms

# PCI: 7.1.1.65 - Verify /etc/pam.d/system-auth Permissions
chmod 644 /etc/pam.d/system-auth
chown root:root /etc/pam.d/system-auth

# PCI: 7.1.1.94 - Ensure Perms on man and doc pages prevent modifications by unprivileged users
# for i in `find /usr/share/doc /usr/local/share/man /usr/share/man /usr/local/share/doc -follow  \( ! -perm -u+r -o ! -perm -u+w -o ! -perm -g+r -o ! -perm -o+r -o -perm -u+x -o -perm -g+w -o -perm -g+x -o -perm -o+w -o -perm -o+x \) 2>/dev/null`; do chmod 644 $i; done

# PCI: 8.5.9 - Change user passwords at least every 90 days
cat <<END_SCRIPT  > /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=7
EXPIRE=90
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
END_SCRIPT

# PCI: 8.5.11.1 - Passwords Must Contain at Least One Numeric Character
# PCI: 8.5.11.2 - Passwords Must Contain at Least One Alphabetic Character
##
## Refer to CIS section where this was corrected:
## 11.4 Utilize PAM to Enforce UserID password complexity
##

# PCI: 8.5.15 - If a session is idle for 15 minutes, require user to log back in.
# Due to permissions, handled this up in CIS section: # 9.9 Set Default umask For Users

# PCI: 10.2.0.10 - 10.2.0.14 audit.rules
# PCI: 10.2.3.1 - 10.2.3.3
# PCI: 10.2.4.1
# PCI: 10.2.7.1
##
## Refer to CIS section where this was corrected:
## 11.1 Configure and enable the auditd and sysstat services, if possible

# PCI: 10.2 Audit Trail Automation
# The following line satisfies requirements:
# PCI: 10.2.0.2 - 10.2.0.9

cat << EOF >> /etc/syslog.conf

# Datapipe Event Management
# kern.warning;*.err;authpriv.none;*.info;mail.none;cron.none;*.emerg;local7.*            @x.x.x.x

EOF


# Check all changes made by PCI script into RCS:
for FILE in \
        /etc/ssh/ssh_config \
        /etc/ssh/sshd_config \
        /etc/crontab \
        /etc/hosts.deny \
        /etc/hosts.allow \
        /etc/rc.d/init.d/functions \
        /etc/sysconfig/init \
        /etc/sysconfig/sendmail \
        /etc/inittab \
        /etc/sysctl.conf \
        /etc/syslog.conf \
        /etc/vsftpd.conf \
        /etc/rc.d/rc.sysinit \
        /etc/fstab \
        /usr/share/hal/fdi/95userpolicy \
        /usr/share/hal/fdi/polilcy/20thirdparty \
        /etc/ftpaccess \
        /etc/ftpusers \
        /etc/vsftpd/vsftpd.conf \
        /etc/vsftpd.ftpusers \
        /etc/X11/xdm/Xservers \
        /etc/X11/xinit/xserverrc \
        /etc/X11/xinit \
        /etc/at.allow \
        /etc/at.deny \
        /etc/cron.allow \
        /etc/cron.deny \
        /etc/securetty \
        /etc/X11/gdm/gdm.conf \
        /boot/grub/grub.conf \
        /etc/inittab \
        /etc/exports \
        /etc/default/useradd \
        /etc/passwd \
        /etc/shadow \
        /etc/group \
        /etc/gshadow \
        /etc/login.defs \
        /etc/bashrc \
        /etc/csh.cshrc \
        /etc/csh.login \
        /etc/profile \
        /etc/skel/.bashrc \
        /root/.bash_profile \
        /root/.bashrc \
        /root/.bash_profile \
        /root/.cshrc \
        /root/.tcshrc \
        /etc/security/limits.conf \
        /etc/pam.d/su \
        /etc/security/access.conf \
        /etc/issue \
        /etc/motd \
        /etc/issue.net \
        /etc/vsftpd.conf \
        /etc/audit/audit.rules \
        /etc/audit/auditd.conf \
        /etc/pam.d/system-auth;
do
	ci -l -wsecurity $FILE <<EOF
Datapipe PCI-DSS Hardening Standards Applied.
.
EOF
done

# Fix permissions of files as RCS will change the files to writable by the owner:
# This will be corrected in next version of this script.

chmod 755 /etc/sysconfig/init
chown root:root /etc/sysconfig/init
chmod 600 /etc/inittab
chown root:root /etc/inittab
chmod 600 /etc/sysctl.conf
chown root:root /etc/sysctl.conf
chmod 700 /etc/rc.d/rc.sysinit
chown root:root /etc/rc.d/rc.sysinit
chmod 600 /etc/syslog.conf
chown root:root /etc/syslog.conf
chmod 400 /etc/at.allow
chown root:root /etc/at.allow
chmod 400 /etc/cron.allow
chown root:root /etc/cron.allow
chmod 400 /etc/crontab
chown root:root /etc/crontab
chmod 400 /etc/securetty
chown root:root /etc/securetty
chmod 640 /etc/login.defs
chown root:root /etc/login.defs
chmod 400 /etc/shadow
chown root:root /etc/shadow
chmod 400 /etc/gshadow
chown root:root /etc/gshadow
chmod 444 /etc/profile
chown root:root /etc/profile
chmod 444 /etc/csh.login
chown root:root /etc/csh.login
chmod 444 /etc/csh.cshrc
chown root:root /etc/csh.cshrc
chmod 444 /etc/bashrc
chown root:root /etc/bashrc
chmod 400 /root/.bashrc
chown root:root /root/.bashrc
chmod 400 /root/.cshrc
chown root:root /root/.csh
chmod 400 /root/.tcshrc
chown root:root /root/.tcshrc
chmod 400 /root/.bash_profile
chown root:root /root/.bash_profile
chmod 640 /etc/security/access.conf
chown root:root /etc/security/access.conf
chmod 600 /etc/audit/auditd.conf
chown root:root /etc/audit/auditd.conf

# Modification to PCI - 8.5.9.2 Verify PASS_MAX_DAYS Setting for Non-system 
# Accounts.  This is for our Retina service and for general support issues.

#
for newusers in dpscanner admin dpretinaadmin ec2-user
do
grep -qi $newusers /etc/passwd
if [ $? -ne 0 ];then
useradd $newusers
usermod -a -G wheel $newusers
chage -I -1 -m 7 -M -1 -E -1 $newusers
else
usermod -a -G wheel $newusers
chage -I -1 -m 7 -M -1 -E -1 $newusers
fi
done

for newusers in dpadmin1 dpadmin2 dpadmin3 clientadmin
do
grep -qi $newusers /etc/passwd
if [ $? -eq 0 ];then
usermod -a -G wheel $newusers
chage -I -1 -m 7 -M -1 -E -1 $newusers
fi
done

touch  /.autorelabel 

# remove the hardening script if found
for file in /rh5-pci1_3.sh /tmp/rh5-pci1_3.sh /root/rh5-pci1_3.sh; do if [ -e $file ]; then rm -f $file; fi; done
#
# END
