File: BastilleBackEnd

package info (click to toggle)
bastille 1%3A2.1.1-13
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,376 kB
  • ctags: 514
  • sloc: perl: 13,477; sh: 2,199; ansic: 951; makefile: 195; csh: 17; python: 9
file content (373 lines) | stat: -rwxr-xr-x 15,015 bytes parent folder | download | duplicates (3)
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/usr/bin/perl
##############################################################################
# Copyright (C) 1999, 2000 Jay Beale
# Copyright (C) 2001-2003 Hewlett Packard Company
# Licensed under the GNU General Public License
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#############################################################################

##############################################################################
# This is the Back End to Bastille Linux, a hardening program for Linux.     #
# Its counterpart is found in the InteractiveBastille or AutomatedBastille   #
# program, which writes the configuration file used for this.                #
#                                                                            #
# The Bastille Front End and Back End were written by and are currently      #
# maintained by Bastille Linux's Lead Developer, Jay Beale.                  #
#                                                                            #
# The original content for Bastille was assembled by Jay Beale using many    #
# documents, including SANS' Securing Linux Step by Step, Kurt Seifried's    #
# Linux Administrators Security Guide, and many other pieces, including the  #
# Security HOWTO, the Unix Security Handbook, the Solaris Security FAQ and   #
# various magazine articles in LinuxWorld and SunWorld.                      #
#                                                                            #
##############################################################################


## Our use of modules is somewhat strange for Perl: we have a main routine
## in each module which runs on the "use" command.

use lib "/usr/lib";
push (@INC,"/usr/lib/perl5/site_perl/");
push (@INC,"/usr/lib/Bastille");

use Getopt::Long;
use File::Copy;

require Bastille::API;
import Bastille::API;    


# Process command-line arguments...
my $nodisclaim = 0;
my $verbose = 0;
my $force = 0;
my $log_only = 0;
my $debug = 0;

if( Getopt::Long::GetOptions( "n"     => \$nodisclaim,
                              "v"     => \$verbose,
                              "force" => \$force,
			      "log"   => \$log_only, 
			      "debug" => \$debug) ) {
    $error = 0; # no parse error

} else {
    $error = 1; # parse error
}

&setOptions($debug,$log_only,$verbose);
&ConfigureForDistro;

if ( $error ) { # GetOptions couldn't parse all of the args
    &ErrorLog(&getGlobal('ERROR',"usage") . "\n");
    exit(1);
}

print "NOTE:    Bastille is scanning the system configuration...\n\n";

require Bastille::IOLoader;
import Bastille::IOLoader;

&PrepareToRun;

&showDisclaimer($nodisclaim);

# Data Checking
# Loading Questions database for investigation and data validation
$Question{"Title_Screen"}{'proper_parent'}="Title_Screen";
$Question{"Title_Screen"}{'yes_child'}="End_Screen";

$Question{"End_Screen"}{'proper_parent'}="Title_Screen";
$Question{"End_Screen"}{'yes_child'}="End_Screen";


my $first_question = &Load_Questions('Y');

# Load in user's config file
unless (&ReadConfig) {
   &ErrorLog("ERROR:   Could not read config file: " . &getGlobal('BFILE', "config") . "\n");
   exit(1);
}

if($force) {
    &compareQandA($first_question,$force);
}
else {
    &compareQandA($first_question,$force);
    &validateAnswers;
}

unless ( $GLOBAL_LOGONLY ) {
# Since logonly should not make any changes (not even to configuration, mind you)
# lockfiles are not needed (jfs)
	if (-e &getGlobal('BFILE',"lockfile")){ # protect against simultaneous runs of Bastille
		&ErrorLog ("ERROR:  Another copy of bastille is currently making changes.\n".
				"        If you are sure yours is the only Bastille process running, \n".
				"        delete the file\n" . 
				"           " . &getGlobal('BFILE','lockfile')."\n".
				"        to reset lock.\n");
		exit 1;
	}else{
		system (&getGlobal('BIN',"touch")." ". &getGlobal('BFILE',"lockfile"));
	}
	print "Bastille is now locking down your system in accordance with your\n";
	print "answers in the \"config\" file.  Please be patient as some modules\n"; 
	print "may take a number of minutes, depending on the speed of your machine.\n\n";


} # of unless GLOBAL_LOGONLY
#######################################################################
##     Network Interface Protection/IPCHAINS/Personal Firewalling    ##
#######################################################################
if(exists $GLOBAL_CONFIG{Firewall}){
    print "Executing Firewall Specific Configuration\n";
    require Bastille::Firewall;
    import Bastille::Firewall;
}

#######################################################################
##                      Port Scan Attack Detection                   ##
#######################################################################

if(exists $GLOBAL_CONFIG{PSAD}){
    print "Executing PSAD Specific Configuration\n";
    require Bastille::PSAD;
    import Bastille::PSAD;
}

#######################################################################
##                            File Permissions                       ##
#######################################################################
if(exists $GLOBAL_CONFIG{FilePermissions}){
    print "Executing File Permissions Specific Configuration\n";
    require Bastille::FilePermissions;
    import Bastille::FilePermissions;
}

#######################################################################
##                     Account Creation/Security                     ##
#######################################################################
if(exists $GLOBAL_CONFIG{AccountSecurity}){
    print "Executing Account Security Specific Configuration\n";
    require Bastille::AccountSecurity;
    import Bastille::AccountSecurity; 
}

#######################################################################
##                Protecting LILO and single user mode               ##
#######################################################################
if(exists $GLOBAL_CONFIG{BootSecurity}){
    print "Executing Boot Security Specific Configuration\n";
    require Bastille::BootSecurity;
    import Bastille::BootSecurity;
}

#######################################################################
##                    inetd / TCP Wrappers Configuration             ##
#######################################################################

if(exists $GLOBAL_CONFIG{SecureInetd}){
    print "Executing Inetd Specific Configuration\n";
    require  Bastille::SecureInetd; 
    import Bastille::SecureInetd;
}

#######################################################################
##                      Disabling of User Space Tools                ##
#######################################################################
if(exists $GLOBAL_CONFIG{DisableUserTools}){
    print "Executing User Tool Specific Configuration\n";
    require Bastille::DisableUserTools;   
    import Bastille::DisableUserTools;
}

#######################################################################
##    Misc. Pluggable Authentication Modules (PAM) Configuration     ##
#######################################################################

if(exists $GLOBAL_CONFIG{ConfigureMiscPAM}){
    print "Executing PAM Specific Configuration\n";
    require Bastille::ConfigureMiscPAM; 
    import Bastille::ConfigureMiscPAM;
}

#######################################################################
##                               Logging                             ##
#######################################################################
if(exists $GLOBAL_CONFIG{Logging}){
    print "Executing Logging Specific Configuration\n";
    require  Bastille::Logging; 
    import Bastille::Logging;
}

#######################################################################
#######################################################################
####                            System Daemons                     ####
#######################################################################
#######################################################################

#######################################################################
##                          Miscellaneous Daemons                    ##
#######################################################################
if(exists $GLOBAL_CONFIG{MiscellaneousDaemons}){
    print "Executing Daemon Specific Configuration\n";
    require  Bastille::MiscellaneousDaemons;  
    import Bastille::MiscellaneousDaemons;
}

#######################################################################
##                               Sendmail                            ##
#######################################################################
if(exists $GLOBAL_CONFIG{Sendmail}){
    print "Executing Sendmail Specific Configuration\n";
    require Bastille::Sendmail; 
    import Bastille::Sendmail;
}

#######################################################################
##                            Remote Access                          ##
#######################################################################

# version 1.2.0 -- removed this module temporarily from run -- let's
# 		   make this smarter
#
#use Bastille::RemoteAccess;

#######################################################################
##                             DNS/BIND/NAMED                        ##
#######################################################################
if(exists $GLOBAL_CONFIG{DNS}){
    print "Executing DNS Specific Configuration\n";
    require Bastille::DNS;  
    import Bastille::DNS;
}

#######################################################################
##                              HTTP/APACHE                          ##
#######################################################################
if(exists $GLOBAL_CONFIG{Apache}){
    print "Executing Apache Specific Configuration\n";
    require  Bastille::Apache; 
    import Bastille::Apache; 
}

#######################################################################
##                                lpr/lpd                            ##
#######################################################################
if(exists $GLOBAL_CONFIG{Printing}){
    print "Executing Printing Specific Configuration\n";
    require  Bastille::Printing;
    import Bastille::Printing;
}

#######################################################################
##                                  FTP                              ##
#######################################################################

if(exists $GLOBAL_CONFIG{FTP}){
    print "Executing FTP Specific Configuration\n";
    require Bastille::FTP;
    import Bastille::FTP; 
}

#######################################################################
##                                 TMPDIR			    ## 
#######################################################################
if(exists $GLOBAL_CONFIG{TMPDIR}){
    print "Executing Temporary Directory Specific Configuration\n";
    require Bastille::TMPDIR;
    import Bastille::TMPDIR; 
}

#######################################################################
##            HP-UX Security Patch Check Configuration               ##
#######################################################################
if(exists $GLOBAL_CONFIG{Patches}){
    print "Executing HP-UX's Security Patch Check Configuration\n";
    require Bastille::Patches;
    import Bastille::Patches;
}

#######################################################################
##                       IPFilter Configuration                      ##
#######################################################################
if(exists $GLOBAL_CONFIG{IPFilter}){
    print "Executing IPFilter Configuration\n";
    use Bastille::IPFilter;
    &Bastille::IPFilter::run;
}

#######################################################################
##                            HP-UX OS Specific                      ##
#######################################################################
if(exists $GLOBAL_CONFIG{HP_UX}){
    print "Executing HP-UX Specific Configuration\n";
    require Bastille::HP_UX;
    import Bastille::HP_UX; 
}


#######################################################################
##                            Patch Download                         ##
#######################################################################
# Note: currently comented since both RedHat and Debian implementations
# do not work ok.

#use Bastille::PatchDownload;

#######################################################################
##          Setting all file sums recorded to a post bastille state  ##
#######################################################################
for my $file (sort keys %GLOBAL_SUM) {
    &B_set_sum($file);
}

#######################################################################
##              Point user at TODO list, if it exists                ##
#######################################################################
if ( -e &getGlobal('BFILE','TODO') ) {
   print("\nPlease check\n" . 
         &getGlobal('BFILE','TODO') . 
         "\nfor further instructions on how to secure your system.\n\n");
}

unless (unlink &getGlobal('BFILE',"lockfile")){  # Remove lockfile
    &ErrorLog ("ERROR:   Unable to delete Bastille lock file: ".
	       &getGlobal('BFILE','lockfile')."\n");
}

#######################################################################
##              Copying current config to last.config for            ##
##              logging purposes                                     ##
#######################################################################
copy(&getGlobal('BFILE',"config") , &getGlobal('BFILE',"last.config"));

#######################################################################
##              Point user at the ErrorLog, if it was used           ##
#######################################################################
if( defined $errorFlag ) {
    print STDERR "########################################################\n" . 
	         "Errors have occurred in the configuration.\n" . 
		 "Please view the following file for more details:\n\t" .
		 &getGlobal('BFILE',"error-log") . "\n" .
		 "########################################################\n\n"; 

    # Exiting with a warning flag as non fatal errors have occured.
    exit(2);
}

# Execution went without warning or fatal error.
exit(0);