-
Notifications
You must be signed in to change notification settings - Fork 84
/
hardening-script.spec
214 lines (179 loc) · 5.92 KB
/
hardening-script.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# HARDENING SCRIPT SPEC FILE
# License: GPL (see COPYING)
# Copyright: Red Hat Consulting, Aug 2014
# Author: Frank Caviggia <fcaviggi (at) redhat.com>
########################################
# Global Definitions
########################################
%define DATE /bin/date +\%s
%define HDATE /bin/date -Iminute
%define SCRIPT_NAME hardening-script
%define PKG_VERSION 1.0
%define PKG_RELEASE el6
%define BASE_DIR /opt/%{SCRIPT_NAME}
%define BASE_BIN %{BASE_DIR}
%define BASE_CONFIG %{BASE_DIR}/config
%define BASE_BACKUP %{BASE_DIR}/backups/
%define BASE_LOGDIR /var/log
%define SCRIPT %{BASE_BIN}/apply.sh
%define LOGFILE %{BASE_LOGDIR}/%{SCRIPT_NAME}.log
########################################
# RPM Spec File
########################################
Name: %{SCRIPT_NAME}
Version: %{PKG_VERSION}
Release: %{PKG_RELEASE}
Vendor: Red Hat
Distribution: Red Hat Enterprise Linux
Packager: [email protected]
Summary: RHEL 6 Hardening Scripts
Group: Applications/System
License: 2013, GPL
URL: http://www.redhat.com/
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
BuildArch: noarch
#BuildRequires:
Requires: logwatch
Requires: scrub
Requires: aide
Requires: vlock
Requires: screen
Requires: ntp
Requires: openswan
Requires: rsyslog
Requires: logrotate
#Obsoletes:
#Conflicts:
%description
RHEL 6 Hardening Script - Applies DISA UNIX STIG/NIST 800-53/NSA SNAC policies to system in order to automate DIACAP/ICD503 C&A/A&A process.
%prep
%setup -q
%build
%install
%{__make} INSTROOT=${RPM_BUILD_ROOT} install
%clean
rm -rf ${RPM_BUILD_ROOT}
%pre
%post
###------------------------- Common Definitions ----------------------------###
DATE=`%{DATE}`
HDATE=`%{HDATE}`
NAME=%{SCRIPT_NAME}
# INSTALL RPM
if [ $1 -eq 1 ]; then
if [ ! -d %{BASE_DIR} ]; then
mkdir -p %{BASE_DIR}
fi
if [ ! -d %{BASE_CONFIG} ]; then
mkdir -p %{BASE_CONFIG}
fi
if [ ! -d %{BASE_BACKUP} ]; then
mkdir -p %{BASE_BACKUP}
fi
touch %{LOGFILE}
echo -n "Installing ${NAME} RPM: " >> %{LOGFILE} 2>&1
echo ${HDATE} >> %{LOGFILE}
ln -sf %{BASE_BIN}/apply.sh /sbin/system-hardening
ln -sf %{BASE_BIN}/checkpoint.sh /sbin/system-hardening-checkpoint
ln -sf %{BASE_BIN}/toggle_ipv6.sh /sbin/toggle_ipv6
ln -sf %{BASE_BIN}/toggle_usb.sh /sbin/toggle_usb
ln -sf %{BASE_BIN}/toggle_udf.sh /sbin/toggle_udf
ln -sf %{BASE_BIN}/toggle_nousb.sh /sbin/toggle_nousb
fi
# UPGRADE RPM
if [ $1 -gt 1 ]; then
echo -n "Upgrading ${NAME} RPM: " >> %{LOGFILE} 2>&1
echo ${HDATE} >> %{LOGFILE}
if [ ! -L /sbin/system-hardening ]; then
ln -sf %{BASE_BIN}/apply.sh /sbin/system-hardening
fi
if [ ! -L /sbin/system-hardening-checkpoint ]; then
ln -sf %{BASE_BIN}/checkpoint.sh /sbin/system-hardening-checkpoint
fi
if [ ! -L /sbin/toggle_ipv6 ]; then
ln -sf %{BASE_BIN}/toggle_ipv6.sh /sbin/toggle_ipv6
fi
if [ ! -L /sbin/toggle_usb ]; then
ln -sf %{BASE_BIN}/toggle_usb.sh /sbin/toggle_usb
fi
if [ ! -L /sbin/toggle_udf ]; then
ln -sf %{BASE_BIN}/toggle_udf.sh /sbin/toggle_udf
fi
if [ ! -L /sbin/toggle_nousb ]; then
ln -sf %{BASE_BIN}/toggle_nousb.sh /sbin/toggle_nousb
fi
fi
%preun
###------------------------- Common Definitions ----------------------------###
DATE=`%{DATE}`
HDATE=`%{HDATE}`
KERNEL=`uname -r`
KERNEL_MODULE="/lib/modules/${KERNEL}/kernel/drivers/usb/storage/usb-storage.ko"
NAME=%{SCRIPT_NAME}
# REMOVE RPM
if [ $1 -eq 0 ]; then
echo -n "Removing ${NAME} RPM: " >> %{LOGFILE} 2>&1
echo ${HDATE} >> %{LOGFILE} 2>&1
# RESTORE ORIGINAL CONFIGURATIONS
cp %{BASE_BACKUP}/sysctl.conf.orig /etc/sysctl.conf
cp %{BASE_BACKUP}/login.defs.orig /etc/login.defs
cp %{BASE_BACKUP}/audit.rules.orig /etc/audit/audit.rules
cp %{BASE_BACKUP}/auditd.conf.orig /etc/audit/auditd.conf
cp %{BASE_BACKUP}/limits.conf.orig /etc/security/limits.conf
cp %{BASE_BACKUP}/sshd_config.orig /etc/ssh/sshd_config
cp %{BASE_BACKUP}/ssh_config.orig /etc/ssh/ssh_config
cp %{BASE_BACKUP}/smb.conf.orig /etc/samba/smb.conf
cp %{BASE_BACKUP}/sudoers.orig /etc/sudoers
cp %{BASE_BACKUP}/system-auth.orig /etc/pam.d/system-auth
cp %{BASE_BACKUP}/password-auth.orig /etc/pam.d/password-auth
cp %{BASE_BACKUP}/gnome-screensaver.orig /etc/pam.d/gnome-screensaver
cp %{BASE_BACKUP}/hosts.allow.orig /etc/hosts.allow
cp %{BASE_BACKUP}/hosts.deny.orig /etc/hosts.deny
cp %{BASE_BACKUP}/ntp.conf.orig /etc/ntp.conf
cp %{BASE_BACKUP}/iptables.orig /etc/sysconfig/iptables
cp %{BASE_BACKUP}/ip6tables.orig /etc/sysconfig/ip6tables
restorecon -R /etc
if [ ! -e ${KERNEL_MODULE} ]; then
cp %{BASE_BACKUP}/usb-storage.ko.${KERNEL} ${KERNEL_MODULE}
fi
rm -f /etc/modprobe.d/usgcb-blacklist.conf
rm -f /etc/profile.d/autologout*
rm -f /sbin/%{SCRIPT_NAME}
rm -f /sbin/system-hardening-checkpoint
rm -f /sbin/toggle_usb
rm -f /sbin/toggle_udf
rm -f /sbin/toggle_nousb
rm -f /sbin/toggle_ipv6
fi
# UPGRADE REMOVE RPM
#if [ $1 -gt 0 ]; then
# echo -n "Upgrading ${NAME} RPM: " >> %{LOGFILE} 2>&1
# echo ${HDATE} >> %{LOGFILE} 2>&1
#fi
%postun
###------------------------- Common Definitions ----------------------------###
DATE=`%{DATE}`
HDATE=`%{HDATE}`
NAME=%{SCRIPT_NAME}
# REMOVE RPM
if [ $1 -eq 0 ]; then
rm -rf %{BASE_BACKUP}
rm -rf %{BASE_CONFIG}
if [ -e %{LOGFILE} ]; then
echo -n "Removed ${NAME} RPM: " >> %{LOGFILE} 2>&1
echo ${HDATE} >> %{LOGFILE} 2>&1
mv -f %{LOGFILE} %{LOGFILE}.${HDATE} ;
fi
fi
# UPGRADE REMOVE RPM
#if [ $1 -gt 0 ]; then
# echo -n "Upgrading ${NAME} RPM: " >> %{LOGFILE} 2>&1
# echo ${HDATE} >> %{LOGFILE} 2>&1
#fi
%files
%defattr(-,root,root,-)
%attr(0700,root,root) %{BASE_BIN}/*
%attr(0600,root,root) %{BASE_CONFIG}/*
%doc README.md COPYING AUTHORS CHANGELOG STIG_SCRIPT_LIST TRACEABILITY
%doc hardening-script.spec