Agenda: exercises-snort.txt

File exercises-snort.txt, 13.4 KB (added by admin, 7 years ago)
Line 
1% Security topics
2%
3% Basic Snort Exercise
4
5# Introduction
6
7In this exercise we will set up Snort, a popular Intrusion Detection System,
8in order to demonstrate how to monitor traffic and receive alarms for
9network traffic patterns that could be related to an intrusion.
10
11## Notes
12
13* Commands preceded with "$" imply that you should execute the command as
14  a general user - not as root.
15* Commands preceded with "#" imply that you should be working as root.
16* Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>")
17  imply that you are executing commands on remote equipment, or within
18  another program.
19
20## Goals
21
22* Learn how to install the Snort package on Ubuntu
23* Learn the locations of the different configuration files and logs
24* Learn how to read alerts and identify rules that triggered them
25* Learn how to disable rules and suppress alerts
26* Use a port scanning tool to generate alerts on other PCs in the
27  classroom
28
29# Installation
30
31Log in to the PC assigned to you, and install the Snort package:
32
33~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34$ sudo apt-get install snort
35~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
37You will see a window prompting you to provide the "Address range for the
38local network". Type the network address of your particular group.
39
40For example, for pc1, pc2, pc3 and pc4, the network block is:
41
42    10.10.1.0/24
43
44For pc5, pc6, pc7 and pc8, the network block is
45
46    10.10.2.0/24
47
48etc...
49
50Check that the snort deaemon is running:
51
52~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53$ ps -ef |grep snort
54~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
56You should see something like this:
57
58~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59snort     1523     1  0 16:22 ?        00:00:01 /usr/sbin/snort -m 027 -D -d \
60-l /var/log/snort -u snort -g snort -c /etc/snort/snort.conf \
61-S HOME_NET=[10.10.1.0/24] -i eth0
62~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63
64The configuration is read from the file /etc/snort/snort.conf, which we
65discuss below.
66
67Notice the variable "HOME_NET". It should reflect the value you used for
68your network during the installation.
69
70Also, notice that the logs are sent to "/var/log/snort".
71
72The Ubuntu package creates an additional configuration file that you should
73know of:
74
75~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76$ cat /etc/snort/snort.debian.conf
77# This file is used for options that are changed by Debian to leave
78# the original lib files untouched.
79# You have to use "dpkg-reconfigure snort" to change them.
80
81DEBIAN_SNORT_STARTUP="boot"
82DEBIAN_SNORT_HOME_NET="10.10.1.0/24"
83DEBIAN_SNORT_OPTIONS=""
84DEBIAN_SNORT_INTERFACE="eth0"
85DEBIAN_SNORT_SEND_STATS="true"
86DEBIAN_SNORT_STATS_RCPT="root"
87DEBIAN_SNORT_STATS_THRESHOLD="1"
88~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
90# Operation
91
92## Overview
93
94Let's take a look at the logs directory:
95
96~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97$ ls -l /var/log/snort
98total 8
99-rw-r--r-- 1 root  adm 371 2012-03-12 16:39 alert
100-rw-r----- 1 snort adm 106 2012-03-12 16:39 tcpdump.log.1331569367
101~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102
103The file "alert" is where Snort will write its alert messages when the traffic
104on eth0 matches patterns in one of the configured rules.
105
106The other file "tcpdump.log.*" is a binary file in tcpdump capture format.
107Let's see what is in that file. We need to install tcpdump first.
108
109NOTE: YOU MAY NOT HAVE ANY ALERTS YET. This is just an example. Keep reading!
110
111~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112$ sudo apt-get install tcpdump
113~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114
115Now, if you do have a file under /var/log/snort/, let's use tcpdump that we
116want to read the packets stored in that file:
117
118~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
119$ tcpdump -nv -r /var/log/snort/tcpdump.log.1331569367
120~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121
122Result:
123
124~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125reading from file /var/log/snort/tcpdump.log.1331569367, link-type EN10MB \
126(Ethernet)
12716:39:33.296390 IP (tos 0x0, ttl 64, id 39949, offset 0, flags [DF], proto \
128TCP (6), length 52)
129    10.10.1.1.33154 > 10.10.0.250.3142: Flags [.], cksum 0x1b59 (correct), \
130ack 1505459219, win 5208, options [nop,nop,TS val 1533593 ecr 20155833], length 0
131~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132
133This is telling us that Snort found some traffic that matched one of its rules.
134In particular, TCP traffic from IP 10.10.1.1 going to 10.10.0.250, towards port
1353142.
136
137Let's see what is in the alert file:
138
139~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140$ cat /var/log/snort/alert
141~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142
143You might see:
144
145~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146[**] [1:100000160:2] COMMUNITY SIP TCP/IP message flooding directed to SIP proxy [**]
147[Classification: Attempted Denial of Service] [Priority: 2]
14803/12-16:39:33.296390 10.10.1.1:33154 -> 10.10.0.250:3142
149TCP TTL:64 TOS:0x0 ID:39949 IpLen:20 DgmLen:52 DF
150***A**** Seq: 0xA6FCD5A  Ack: 0x59BB7C13  Win: 0x1458  TcpLen: 32
151TCP Options (3) => NOP NOP TS: 1533593 20155833
152~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153
154The first line is important. It's revealing information about the Snort rule
155that caused this alert. The numbers [1:100000160:2] represent [gid:sid:rev]
156where:
157
158gid = Generator ID: Indicates what part of Snort generates the event
159sid = Signature ID: Uniquely identifies Snort rules
160rev = Revision: The version number of this rule
161
162We can quickly determine the location of this particular rule by grepping for
163that sid number in the directory where Snort stores its rules:
164
165~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
166$ grep -r sid:100000160 /etc/snort/rules/*
167~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168
169~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
170/etc/snort/rules/community-sip.rules:alert ip any any -> any 5060 \
171(msg:"COMMUNITY SIP TCP/IP message flooding directed to SIP proxy"; \
172threshold: type both, track by_src, count 300, seconds 60; \
173classtype:attempted-dos; sid:100000160; rev:2;)
174~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175
176There's a problem with this rule. It says "alert ip any -> any 5060".
177The problem is that it should be looking for TCP or UDP traffic destined to
178port 5060, not just "ip" traffic.
179
180NOTE: This rule exists in the Snort package for Ubuntu 10.04. It has been removed
181in more recent versions of the package.
182
183## Supressing alerts
184
185You will notice that Snort will initially generate lots of invalid alerts like
186the one above (false positives). If your alerts file gets filled up with junk,
187it won't be very useful, so you'll need to fine-tune Snort to suit your needs.
188
189### Method 1: Disable the rules file.
190
191In the example shown above, all the rules in the file community-sip.rules are
192incorrect. In that case, the easiest thing is to just not include that file
193when loading Snort. For that, do the following:
194
195~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
196$ sudo editor /etc/snort/snort.conf
197~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
198
199find this line:
200
201~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
202include $RULE_PATH/community-sip.rules
203~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
204
205and comment it out like this:
206
207~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208#include $RULE_PATH/community-sip.rules
209~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210
211then, save and restart Snort
212
213~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214$ sudo service snort restart
215~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216
217### Method 2: Supress the specific rule in the configuration file
218
219* To suppress the above rule so that it doesn't match traffic from/to any hosts,
220the configuration syntax is:
221
222~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223supress gen_id <gid>, sig_id <sid>
224~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
225
226* If, on the other hand, you wanted to supress events from this rule that match
227a specific origin or destination host, the syntax is:
228
229~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
230suppress gen_id <gid>, sig_id <sid>, track <by_src|by_dst>, ip <ip-list>
231~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232
233Let's suppress events from our broken rule using the first option:
234
235~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
236$ sudo EDITOR /etc/snort/snort.conf
237~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
238
239At the end of the file, add the following line:
240
241~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
242suppress gen_id 1, sig_id 100000160
243~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
244
245then, save and exit. Restart Snort
246
247~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
248$ sudo service snort restart
249~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250
251## Simulate intrusion attempts
252
253Let's generate some traffic towards your classmates' PCs in other groups.
254
255First, install the nmap package:
256
257~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
258$ sudo apt-get install nmap
259~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
260
261Now we are going to scan all the TCP ports in another machine to see what
262could be potentially vulnerable.
263
264NOTE: Change "pc#" to the name of a PC in a group _different_ than yours.
265Otherwise, the alerts will not trigger because Snort is looking at traffic
266coming from EXTERNAL networks.
267
268~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
269$ sudo nmap -sS pc#
270~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
271
272Repeat the above commands for as many PCs as you can (in other groups).
273
274Wait a little bit, and check your alerts:
275
276~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
277$ less /var/log/snort/alert
278~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
279
280If someone is scanning your PC, you should start seeing some entries.
281
282If not, ask a person from another group to scan your PC: remember that other
283people in the class may not yet be ready with the Snort part of their labs, so
284just ask them to scan you instead.
285
286
287For example, you might find:
288
289~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
290[**] [1:469:3] ICMP PING NMAP [**]
291[Classification: Attempted Information Leak] [Priority: 2]
29203/12-18:30:21.185863 10.10.4.13 -> 10.10.1.1
293ICMP TTL:55 TOS:0x0 ID:44605 IpLen:20 DgmLen:28
294Type:8  Code:0  ID:3517   Seq:0  ECHO
295[Xref => http://www.whitehats.com/info/IDS162]
296~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
297
298Let's see where that came from:
299
300~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
301$ grep 'sid:469' /etc/snort/rules/*
302~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
303
304You should see something like this:
305
306~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
307/etc/snort/rules/icmp.rules:alert icmp $EXTERNAL_NET any -> $HOME_NET any \
308(msg:"ICMP PING NMAP"; dsize:0; itype:8; reference:arachnids,162; \
309classtype:attempted-recon; sid:469; rev:3;)
310~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311
312Here, the interesting information is "dsize:0". This alert is triggered when
313the size of the data in the ping packet is zero (0). The tool nmap typically
314pings the host via ICMP if the user has root privileges.
315
316Also, you may see this in your alerts:
317
318~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
319[**] [122:1:0] (portscan) TCP Portscan [**]
320[Priority: 3]
32103/12-18:30:21.305881 10.10.4.13 -> 10.10.1.1
322PROTO:255 TTL:0 TOS:0x0 ID:0 IpLen:20 DgmLen:155 DF
323~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
324
325If you try searching for this rule (122:1) in /etc/snort/rules, you will not
326find it. The reason is that this alert is not triggered by a standard rule
327but by a Snort "preprocessor". In these cases, you may find it easier to
328learn more about the mechanism that triggered this alert by searching the
329gid and sid in the snort search engine:
330
331~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
332http://www.snort.org/search/
333~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
334
335For example, you will find details about this alert by searching for "sid:122-1"
336
337# More information
338
339The Snort website contains lots of useful information
340
341~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
342http://www.snort.org
343~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~