1 | % Security topics |
---|
2 | % |
---|
3 | % Snort Exercise - Setting up a web front-end |
---|
4 | |
---|
5 | # Introduction |
---|
6 | |
---|
7 | We will set up Snort together with BASE (Basic Analysis and Security |
---|
8 | Engine). This application provides a web front-end to query and analyze |
---|
9 | the alerts coming from a SNORT IDS system. BASE is the evolution of a |
---|
10 | previous 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 | |
---|
30 | Log in to the PC assigned to you, and install the the lamp-server group |
---|
31 | of packages: |
---|
32 | |
---|
33 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
34 | sudo tasksel install lamp-server |
---|
35 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
36 | |
---|
37 | The above command is a shortcut to install a set of predefined packages, |
---|
38 | that offer the "Linux Apache Mysql PHP" services, i.e. LAMP. Some or most of |
---|
39 | these packages may have already been installed during previous labs, but it |
---|
40 | doesn't hurt to run it. |
---|
41 | |
---|
42 | If you are curious which packages this "set" includes, you can run: |
---|
43 | |
---|
44 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
45 | tasksel --task-packages lamp-server |
---|
46 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
47 | |
---|
48 | If you haven't already done so before, you will be prompted to create a MySQL |
---|
49 | root password during the installation process. Please use the same password you |
---|
50 | used to log in to your virtual PC, and which was given in class. |
---|
51 | |
---|
52 | Now, create the database to be used by Snort: |
---|
53 | |
---|
54 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
55 | $ mysql -u root -p |
---|
56 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
57 | |
---|
58 | Type the password you provided earlier while installing. Then, at the mysql |
---|
59 | prompt, type the following: |
---|
60 | |
---|
61 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
62 | mysql>create database snort; |
---|
63 | mysql>GRANT ALL PRIVILEGES ON snort.* TO 'snort'@'localhost' IDENTIFIED BY 'snortpwd'; |
---|
64 | mysql>FLUSH PRIVILEGES; |
---|
65 | mysql>quit |
---|
66 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
67 | |
---|
68 | NOTE: Notice that we used 'snortpwd' here. This is the password that Snort |
---|
69 | will use to connect to the Mysql database. We will also use it later for the |
---|
70 | web front-end. Instead of 'snortpwd', you may want to use the default password |
---|
71 | used to log in to your machine. |
---|
72 | |
---|
73 | Install Snort with mysql support: |
---|
74 | |
---|
75 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
76 | $ sudo apt-get -y install snort-mysql |
---|
77 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
78 | |
---|
79 | You will see a window prompting you to provide the "Address range for the |
---|
80 | local network". Type the network address of your particular group. |
---|
81 | |
---|
82 | For example, for pc1, pc2, pc3 and pc4, the network block is: |
---|
83 | |
---|
84 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
85 | 10.10.1.0/24 |
---|
86 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
87 | |
---|
88 | At the end of Snort's installation, you will be asked if you wish to set up |
---|
89 | a database for use with Snort. Choose No. We will manually configure Snort to |
---|
90 | connect to our previously created database. |
---|
91 | |
---|
92 | You will receive a warning like the following: "Snort will not start as its |
---|
93 | database is not yet configured". That's OK. Go on. |
---|
94 | |
---|
95 | Create 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 | |
---|
108 | Edit the Snort configuration to include the database parameters: |
---|
109 | |
---|
110 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
111 | $ sudo editor /etc/snort/snort.conf |
---|
112 | |
---|
113 | find this line: |
---|
114 | |
---|
115 | output 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 | |
---|
123 | output database: log, mysql, user=snort password=snortpwd dbname=snort host=localhost |
---|
124 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
125 | |
---|
126 | Remember to use the SAME password here that you picked during database creation |
---|
127 | earlier! |
---|
128 | |
---|
129 | Save and exit the editor. |
---|
130 | |
---|
131 | Remove the pending Snort database configuration file. |
---|
132 | |
---|
133 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
134 | $ sudo rm -rf /etc/snort/db-pending-config |
---|
135 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
136 | |
---|
137 | Start the Snort service. |
---|
138 | |
---|
139 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
140 | $ sudo service snort start |
---|
141 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
142 | |
---|
143 | Verify 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 | |
---|
152 | Next we will install a web front-end (BASE) to monitor Snort's output. |
---|
153 | |
---|
154 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
155 | sudo apt-get -y install acidbase |
---|
156 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
157 | |
---|
158 | During the installation process you will be prompted to configure a database |
---|
159 | for acidbase. Choose "yes" and use "MySQL" for the database type. |
---|
160 | |
---|
161 | You will be prompted for the password of the database administrator. This is |
---|
162 | the same password we used when MySQL was initially installed. |
---|
163 | |
---|
164 | Upon entering the database administrator password, you will be prompted to |
---|
165 | create a MySQL password for acidbase to connect to the database. In this |
---|
166 | exercise we will use the same password as the snort user: "snortpwd" (please |
---|
167 | double check that you are using the correct password, write it down if |
---|
168 | necessary for now!) |
---|
169 | |
---|
170 | ## BASE (acidbase) Configuration |
---|
171 | |
---|
172 | When installed, the acidbase web front-end is configured to only allow access |
---|
173 | from the localhost. Modify acidbase's configuration to allow other workstations |
---|
174 | to connect: |
---|
175 | |
---|
176 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
177 | sudo editor /etc/acidbase/apache.conf |
---|
178 | |
---|
179 | find this line: |
---|
180 | |
---|
181 | allow 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 | |
---|
185 | allow from 10.10.1.0/255.255.255.0 |
---|
186 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
187 | |
---|
188 | Save the file and exit the editor. Then restart Apache: |
---|
189 | |
---|
190 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
191 | sudo service apache2 restart |
---|
192 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
193 | |
---|
194 | Navigate to your new BASE webpage (substitute pc# with the number of your PC): |
---|
195 | |
---|
196 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
197 | http://pc#.ws.nsrc.org/acidbase |
---|
198 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
199 | |
---|
200 | You will now see a message like the following: |
---|
201 | |
---|
202 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
203 | The underlying database snort@ appears to be incomplete/invalid. |
---|
204 | |
---|
205 | The database version is valid, but the BASE DB structure (table: acid_ag) |
---|
206 | is not present. Use the Setup page to configure and optimize the DB. |
---|
207 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
208 | |
---|
209 | Follow the directions in that page to update the database. Then, use the link |
---|
210 | provided to navigate to the "Main page". |
---|
211 | |
---|
212 | You 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 | |
---|
221 | In a production install, Snort alerts are very sensitive information, so |
---|
222 | we need to add authentication to this web front-end. Let's create a user |
---|
223 | for 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 | |
---|
233 | Now, we need to configure BASE so that it requires authentication. |
---|
234 | |
---|
235 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
236 | sudo 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 | |
---|
247 | Save and exit. |
---|
248 | |
---|
249 | ## Setup Apache2 SSL |
---|
250 | |
---|
251 | We have set up acidbase to require authentication. However, we are now |
---|
252 | vulnerable to password sniffing because the web server is not encrypting |
---|
253 | the communications channel. To fix that, let's enable SSL for Apache2: |
---|
254 | |
---|
255 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
256 | $ sudo a2enmod ssl |
---|
257 | $ sudo a2ensite default-ssl |
---|
258 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
259 | |
---|
260 | Then, tell Apache that SSL is required for the acidbase pages: |
---|
261 | |
---|
262 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
263 | sudo editor /etc/acidbase/apache.conf |
---|
264 | |
---|
265 | add the following line inside the <DirectoryMatch> section: |
---|
266 | |
---|
267 | SSLRequireSSL |
---|
268 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
269 | |
---|
270 | Save and restart Apache: |
---|
271 | |
---|
272 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
273 | $ sudo service apache2 restart |
---|
274 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
275 | |
---|
276 | You should be able to view your BASE using the https:// method in the URL: |
---|
277 | |
---|
278 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
279 | https://pc#.ws.nsrc.org/acidbase |
---|
280 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
281 | |
---|
282 | (Since we are using the default self-signed certificate, you will probably have |
---|
283 | to create an exception in your browser). |
---|
284 | |
---|
285 | You 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 | |
---|
291 | BASE does not send automatic e-mail alerts, but you can set it up so that |
---|
292 | you can select one or more alerts and send their details to your colleagues |
---|
293 | in an e-mail message. |
---|
294 | |
---|
295 | For 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 | |
---|
305 | Also, make sure that you have the PHP mail module installed: |
---|
306 | |
---|
307 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
308 | $ sudo apt-get -y install php-mail |
---|
309 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
310 | |
---|
311 | Then, proceed to set some necessary variables in the BASE configuration file. |
---|
312 | The following values should work (substitute pc# with you actual pc name): |
---|
313 | |
---|
314 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
315 | sudo 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 | |
---|
328 | Now, 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 | |
---|
338 | Check 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 | |
---|
346 | The BASE project homepage includes links to mailing lists, online forums, |
---|
347 | etc: |
---|
348 | |
---|
349 | http://base.secureideas.net/ |
---|
350 | |
---|