Agenda: exercises-snort-BASE.txt

File exercises-snort-BASE.txt, 12.6 KB (added by admin, 7 years ago)
Line 
1% Security topics
2%
3% Snort Exercise - Setting up a web front-end
4
5# Introduction
6
7We will set up Snort together with BASE (Basic Analysis and Security
8Engine). This application provides a web front-end to query and analyze
9the alerts coming from a SNORT IDS system. BASE is the evolution of a
10previous project called ACID.
11
12## Notes
13
14* Commands preceded with "$" imply that you should execute the command as
15  a general user - not as root.
16* Commands preceded with "#" imply that you should be working as root.
17* Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>")
18  imply that you are executing commands on remote equipment, or within
19  another program.
20
21## Goals
22
23* Learn how to install the Snort package with MySQL support
24* Learn how to install and configure the acidbase package on Ubuntu
25* Set up authentication
26* Set up e-mail exports
27
28# Snort-MySQL Installation
29
30Log in to the PC assigned to you, and install the the lamp-server group
31of packages:
32
33~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34sudo tasksel install lamp-server
35~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
37The above command is a shortcut to install a set of predefined packages,
38that offer the "Linux Apache Mysql PHP" services, i.e. LAMP. Some or most of
39these packages may have already been installed during previous labs, but it
40doesn't hurt to run it.
41
42If you are curious which packages this "set" includes, you can run:
43
44~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45tasksel --task-packages lamp-server
46~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
48If you haven't already done so before, you will be prompted to create a MySQL
49root password during the installation process. Please use the same password you
50used to log in to your virtual PC, and which was given in class.
51
52Now, create the database to be used by Snort:
53
54~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55$ mysql -u root -p
56~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57
58Type the password you provided earlier while installing. Then, at the mysql
59prompt, type the following:
60
61~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62mysql>create database snort;
63mysql>GRANT ALL PRIVILEGES ON snort.* TO 'snort'@'localhost' IDENTIFIED BY 'snortpwd';
64mysql>FLUSH PRIVILEGES;
65mysql>quit
66~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67
68NOTE: Notice that we used 'snortpwd' here. This is the password that Snort
69will use to connect to the Mysql database. We will also use it later for the
70web front-end. Instead of 'snortpwd', you may want to use the default password
71used to log in to your machine.
72
73Install Snort with mysql support:
74
75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76$ sudo apt-get -y install snort-mysql
77~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
79You will see a window prompting you to provide the "Address range for the
80local network". Type the network address of your particular group.
81
82For example, for pc1, pc2, pc3 and pc4, the network block is:
83
84~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8510.10.1.0/24
86~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87
88At the end of Snort's installation, you will be asked if you wish to set up
89a database for use with Snort. Choose No. We will manually configure Snort to
90connect to our previously created database.
91
92You will receive a warning like the following: "Snort will not start as its
93database is not yet configured". That's OK. Go on.
94
95Create the database table structure.
96~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97$ sudo -s
98
99  type your account password to become root
100
101$ zcat /usr/share/doc/snort-mysql/create_mysql.gz |  mysql -u snort -p snort
102
103  type the snort database password: "snortpwd"
104
105$ exit
106~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107
108Edit the Snort configuration to include the database parameters:
109
110~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111$ sudo editor /etc/snort/snort.conf
112 
113  find this line:
114
115output log_tcpdump: tcpdump.log
116
117  and comment it out like this:
118
119#output log_tcpdump: tcpdump.log
120
121  Then, add this line:
122
123output database: log, mysql, user=snort password=snortpwd dbname=snort host=localhost
124~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125
126Remember to use the SAME password here that you picked during database creation
127earlier!
128
129Save and exit the editor.
130
131Remove the pending Snort database configuration file.
132
133~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134$ sudo rm -rf /etc/snort/db-pending-config
135~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136
137Start the Snort service.
138
139~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140$ sudo service snort start
141~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142
143Verify that the Snort daemon successfull started:
144
145~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146$ sudo /etc/init.d/snort status
147$ tail /var/log/daemon.log
148~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149
150# BASE Installation
151
152Next we will install a web front-end (BASE) to monitor Snort's output.
153
154~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155sudo apt-get -y install acidbase
156~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157
158During the installation process you will be prompted to configure a database
159for acidbase. Choose "yes" and use "MySQL" for the database type.
160
161You will be prompted for the password of the database administrator. This is
162the same password we used when MySQL was initially installed.
163
164Upon entering the database administrator password, you will be prompted to
165create a MySQL password for acidbase to connect to the database. In this
166exercise we will use the same password as the snort user: "snortpwd" (please
167double check that you are using the correct password, write it down if
168necessary for now!)
169
170## BASE (acidbase) Configuration
171
172When installed, the acidbase web front-end is configured to only allow access
173from the localhost. Modify acidbase's configuration to allow other workstations
174to connect:
175
176~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177sudo editor /etc/acidbase/apache.conf
178
179  find this line:
180
181allow from 127.0.0.0/255.0.0.0
182
183  and change it to match your group's network. For example, for pc1:
184
185allow from 10.10.1.0/255.255.255.0
186~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187
188Save the file and exit the editor. Then restart Apache:
189
190~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191sudo service apache2 restart
192~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
193
194Navigate to your new BASE webpage (substitute pc# with the number of your PC):
195
196~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
197http://pc#.ws.nsrc.org/acidbase
198~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
199
200You will now see a message like the following:
201
202~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203The underlying database snort@ appears to be incomplete/invalid.
204
205The database version is valid, but the BASE DB structure (table: acid_ag)
206is not present. Use the Setup page to configure and optimize the DB.
207~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208
209Follow the directions in that page to update the database. Then, use the link
210provided to navigate to the "Main page".
211
212You will see a dashboard containing the following:
213
214* On the top left corner, a list of links to alert reports, classified by
215  various criteria
216* Below that, alert statistics, including percent bars of traffic by type
217* At the bottom, a menu with several administrative options.
218
219## Set up authentication
220
221In a production install, Snort alerts are very sensitive information, so
222we need to add authentication to this web front-end. Let's create a user
223for us to log in with.
224
225* Go to the bottom menu and click on "Administration"
226* Click on "Create a User"
227* Login: "sysadm"
228* Full Name: "System Administrator"
229* Password: Type the sysadm password you used to log in to the PC
230* Role: "Admin"
231* Click on "Submit Query"
232
233Now, we need to configure BASE so that it requires authentication.
234
235~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
236sudo editor /etc/acidbase/base_conf.php
237
238  find this line
239
240$Use_Auth_System = 0;
241
242  and change it to:
243
244$Use_Auth_System = 1;
245~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246
247Save and exit.
248
249## Setup Apache2 SSL
250
251We have set up acidbase to require authentication. However, we are now
252vulnerable to password sniffing because the web server is not encrypting
253the communications channel. To fix that, let's enable SSL for Apache2:
254
255~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
256$ sudo a2enmod ssl
257$ sudo a2ensite default-ssl
258~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259
260Then, tell Apache that SSL is required for the acidbase pages:
261
262~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
263sudo editor /etc/acidbase/apache.conf
264
265  add the following line inside the <DirectoryMatch> section:
266
267SSLRequireSSL
268~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
269
270Save and restart Apache:
271
272~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273$ sudo service apache2 restart
274~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
275
276You should be able to view your BASE using the https:// method in the URL:
277
278~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
279https://pc#.ws.nsrc.org/acidbase
280~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281
282(Since we are using the default self-signed certificate, you will probably have
283to create an exception in your browser).
284
285You will be asked to authenticate. Log in with the "sysadm" account you created.
286
287# Operation
288
289## Exporting to e-mail for collaboration
290
291BASE does not send automatic e-mail alerts, but you can set it up so that
292you can select one or more alerts and send their details to your colleagues
293in an e-mail message.
294
295For this to work, you will need to install a mail transfer agent. For example:
296
297~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
298$ sudo apt-get -y install postfix
299~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
300
301* When asked about the type of mail configuration, select "Internet Site".
302* System mail name: It should be the full name of your server, for example
303  "pc1.ws.nsrc.org"
304
305Also, make sure that you have the PHP mail module installed:
306
307~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
308$ sudo apt-get -y install php-mail
309~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
310
311Then, proceed to set some necessary variables in the BASE configuration file.
312The following values should work (substitute pc# with you actual pc name):
313
314~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
315sudo editor /etc/acidbase/base_conf.php
316
317$action_email_smtp_host = 'localhost';
318$action_email_smtp_localhost = 'localhost';
319$action_email_smtp_auth = 0;
320$action_email_smtp_user = 'username';
321$action_email_smtp_pw = 'password';
322$action_email_from = 'snort@pc#.ws.nsrc.org';
323$action_email_subject = 'BASE Incident Report';
324$action_email_msg = '';
325$action_email_mode = 0;
326~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
327
328Now, let's test it sending e-mails.
329
330* In the dashboard, click on "Today's Alerts: unique"
331* Select one or more alerts.
332  (if you don't have any alerts today, ask the members of a different group
333  to scan your computer's ports with nmap, for example).
334* In the drop-down menu on the bottom, select "Email alerts (full)"
335* In the ACTION box, type "sysadm@pc#.ws.nsrc.org"
336* Click on the "Selected" button
337
338Check your mail. Either use a mail client like mutt, or simply type:
339
340~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
341$ sudo cat /var/mail/sysadm
342~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
343
344# More information
345
346The BASE project homepage includes links to mailing lists, online forums,
347etc:
348
349http://base.secureideas.net/
350