Introduction to Intrusion Detection With SnortAmy Rich, September 2005 Abstract: After a brief discussion of intrusion detection systems (IDS), this article focuses on a pattern-matching network-based IDS, Snort. Contents:
As soon as someone discovers a new computer security vulnerability, hordes of crackers start knocking at the doors of computers worldwide to see if they can penetrate their defenses. Many sites employ a combination of border router firewalls and host-based packet filters and wrappers to protect themselves, but what if the vulnerability is in the very mechanism that's used to secure a service? How can systems administrators know that their machines are under attack and/or have been compromised? The best way to catch the crackers in the act is to use an intrusion detection system (IDS). What Is Intrusion Detection?Intrusion detection is the methodology by which undesirable or aberrant activity is detected on a host or a network. The two main approaches to intrusion detection systems are host-based (HIDS) and network-based (NIDS). A combination of both provides the most complete coverage, but a site's needs and resources may dictate that it uses one or the other. Host-based intrusion detection systems, as the name implies, are installed on each end host and look for attacks directed directly at the host. Most HIDS employ automated checks of log files, file checksums, file and directory permissions, local network port activity, and other basic host security items. HIDS offer the benefit of being able to detect attacks local to the machine or on an encrypted or switched network where a NIDS might have issues. HIDS provide a wealth of forensic data and can often determine whether or not an attack, originating from the local host or the network, succeeded or failed. Some disadvantages to HIDS include the administrative and computing overhead of running them on each machine and the potential compromise of the HIDS in the event of a successful attack. Some popular HIDS include Tripwire, COPS, Tiger, and AIDE. Under the Solaris 10 Operating System, systems administrators can use BART, the Basic Audit Reporting Tool, to track files at a system level. On earlier versions of Solaris, checksums for system files can be matched against the Solaris Fingerprint Database. While neither of these is a full-blown HIDS, they do provide some basic functionality for detecting modified files. Network-based intrusion detection systems run on one or several critically placed hosts and view the network as a whole. NIDS use NICs running in promiscuous mode to capture and analyze raw packet data in real time. Most NIDS use one of two methods to identify an attack, statistic anomaly detection or pattern-matching detection. In the statistic anomaly detection model, the software discovers intrusions by looking for activity that is different from a user's or system's normal behavior. The baseline for normal behavior is established by profiling user, host, or network activity for some learning period. After the learning period ends, the anomaly detection-based IDS scans for usage which deviates from the baseline. The advantage to an anomaly-based IDS is that it does not have to be specifically trained to look for a given attack and can often spot new attacks before they are well publicized. The downside, of course, is that there is also a good chance of receiving false positives even with an extensive learning period and frequent tweaking. Because an anomaly-based IDS is relatively high maintenance, professionals whose sole job function is not site security are more likely to employ some form of pattern-matching detection. In this case, the IDS compares activity to signatures of known attacks and flags them when it finds a match. The attack signatures are usually stored in some form of database and regularly updated as new attacks emerge. The advantages to a pattern-matching IDS include an easier and shorter implementation time and learning curve for the administrator as well as the reporting of fewer false positives. On the downside, these systems rely on frequent rule upgrades, often from outside sources, and cannot detect attacks until they have a pattern to do so. They're also more easily fooled by the obfuscation and evasion attempts of crackers. Snort, a Pattern-Matching NIDS Since the topic of IDS covers a lot of ground, I'll limit the scope of this article to the discussion of one of the more popular pieces of NIDS software, Snort. Snort can perform real-time packet logging, protocol analysis, and content searching/matching. It can be used to detect a variety of attacks and probes such as stealth port scans, CGI-based attacks, Address Resolution Protocol (ARP) spoofing, and attacks on daemons with known weaknesses. Snort utilizes descriptive rules to determine what traffic it should monitor and a modularly designed detection engine to pinpoint attacks in real time. When an attack is identified, Snort can take a variety of actions to alert the systems administrator to the threat. Several important components are at work behind the Snort NIDS: the packet sniffer, preprocessors, detection engine, logging and alerting mechanisms, and output processors. The packet sniffer listens to all IP packets on the wire and decodes them. The preprocessors take the decoded packets and perform some preliminary tasks, such as defragmentation. The detection engine, the heart of the Snort IDS, performs pattern matches on the data stream to identify known attack signatures. The logging and alerting mechanisms define how recognized attacks will be handled. The output processors define how the output of the logging and alerting system looks. The Snort web site includes the free source code, subscription access to Sourcefire VRT Certified Rule Updates, documentation, user forums, training resources, and a wealth of other information. Installing Snort and Supporting SoftwareSnort has a few prerequisites that need to be installed before
compilation. The instructions below assume that the build machine already has
a well-defined development tool chain installed ( wget http://www.tcpdump.org/release/libpcap-0.8.3.tar.gz tar zxf libpcap-0.8.3.tar.gz cd libpcap-0.8.3 ../configure make make install Next, download, unpack, and install the Perl Compatible Regular Expressions (PCRE) library. Go to http://prdownloads.sourceforge.net/pcre/pcre-6.1.tar.bz2 and select a mirror from which to download. Once you have the file, run: bzcat pcre-6.1.tar.bz2 | tar xf - cd pcre-6.1 ../configure make make install Finally, download the source to Snort, unpack it, configure it, and install
it (if your wget http://www.snort.org/dl/current/snort-2.3.3.tar.gz tar zxf snort-2.3.3.tar.gz cd snort-2.3.3 ../configure make make install Now that you have a successful Snort installation, let's take a look at how it operates and what it can do. Running Snort as a Simple Packet Sniffer/LoggerUnder the Solaris OS, Snort runs in three different modes: sniffer mode,
packet logger mode, and NIDS mode. In sniffer mode, Snort operates much like
a basic snoop or snort -v To view packet data as well, add the snort -vde snort -e -v -d In packet logger mode, the captured data is logged to the directory
hierarchy, which you specify with the mkdir /tmp/snort.log snort -de -l /tmp/snort.log -h 192.168.1.0/24 If both the source and destination host of the recorded packet are on the home network, the packet is logged to the directory of the machine with the higher source/destination port number. If both machines are on the home network, and the source and destination port are the same, the packet is logged to the subdirectory of the source machine. For any serious logging, it's highly suggested to store the logs in
snort -l /tmp/snort.binarylog -b The packets can be read back from the log file by running Snort in playback mode: snort -dvr /tmp/snort.binarylog Snort as an IDS: the Snort Configuration FileIn NIDS mode, Snort matches packet bytes against a set of rules and takes
the specified action if a match occurs. When running as an IDS, the
administrator needs to specify the name of a rules file. The Snort source
code comes with a default rules file called snort -b -A fast -c /usr/local/etc/snort.confLooking at this file, you'll notice several types of directives: include, var, and config,
preprocessor, and output.
The var <name> <value> var RULE_PATH /usr/local/etc/snort/rules Variables can be referenced as follows:
The default
include classification.config include reference.config include $RULE_PATH/local.rules include $RULE_PATH/bad-traffic.rules .... The config flowbits_size: 256 config classification: not-suspicious,Not Suspicious Traffic,3 config reference: bugtraq http://www.securityfocus.com/bid/ The If we're looking for realistic attacks, Snort often needs to be able to massage the data before it tries to find matches against its rules database. Perhaps the packets are fragmented, part of a portscan, or an ARP spoof, or have encoded characters in a telnet stream or URI. This is where the preprocessors come into play. Snort's modular preprocessor architecture consists of small C programs which
take some action on a packet. These C routines are compiled into a library
when you build Snort. The routines are each called after Snort decodes a packet but
before it is sent to the detection engine. Developers can also write their
own specialized preprocessor modules and recompile them into Snort as detailed
in the
Detailed information on each of the supplied preprocessors can be found in the preprocessor section of the Snort manual. Snort's output modules run when the alert or logging modules of Snort are called and format the output data. When multiple plug-ins of the same type (log or alert) are specified, they are handled in sequence. The output modules supplied with Snort are:
Snort Rules, Configuring the Detection EngineThe detection engine is truly the heart of Snort's functionality. Snort
uses a simple, flexible rules description language to describe how data should
be handled. Snort rules are usually written in one line but may, like shell
code, span multiple lines by appending the backslash (\) character to the end
of an incomplete line. Let's take a look at the following rule from
alert tcp $EXTERNAL_NET any -> $HOME_NET 53 \ (msg:"DNS EXPLOIT named 8.2->8.2.1"; flow:to_server,established; \ content:"../../../"; reference:bugtraq,788; reference:cve,1999-0833; \ classtype:attempted-admin; sid:258; rev:6;) This rule says to look for packets from any external source to any internal source on port 53 (DNS) where the content matches "../../../". This is an attempted exploit for an old version of BIND 8 which is documented by bugtraq and CVE. If a packet matches this rule, then Snort triggers an alert. Each rule is divided into two sections, the header (everything before the open paren) and the options (everything enclosed in the parens). Let's break the rule down into its different components. The header contains some criteria for matching the rule against a packet and dictates what action a rule will take if a match occurs. The general structure of the header is shown in Table 1.
The action must be one of the following or user defined:
The specified protocol must be one of these: icmp, ip, tcp, or udp. The two address sections may contain a single IP address, CIDR blocks, or a
list comprising any combination of the two. The single IP or CIDR block
notation may also be negated with the 192.168.1.0/24 !192.168.1.0/24 10.1.1.1 [192.168.1.0/24,10.1.1.1] ![192.168.1.0/24,10.1.1.1] The address section may also contain the keyword The port number fields define the port or range of ports applied to the
preceding address. If the left side of a port range is left blank, Snort
assumes that it should match on all ports less than or equal to that specified
on the right side of the port range. If the right side of a port range is
left blank, Snort assumes that it should match on all ports greater than or
equal to that specified on the left side of the port range. Lists of ports
are not yet supported but are planned for future code releases. Like
addresses, ports and port ranges may also be negated with the 111 !443 :1023 1024: 6000:6010 The direction field determines the direction of traffic flow. If the
direction field is Rule options are separated from each other using a semicolon
(
Let's go back and look at our example rule: alert tcp $EXTERNAL_NET any -> $HOME_NET 53 \ (msg:"DNS EXPLOIT named 8.2->8.2.1"; flow:to_server,established; \ content:"../../../"; reference:bugtraq,788; reference:cve,1999-0833; \ classtype:attempted-admin; sid:258; rev:6;) This rule includes eight options, two of which are the same but with different values (as shown in Table 2).
The The The As we previously covered, the The config classification: attempted-admin,Attempted Administrator Privilege Gain,1 The Managing and Updating RulesOnce Snort is running and triggering alerts, you can spot many of the attempted attacks on your machines. Since Snort is a pattern-matching IDS, though, you need up-to-date rules in order to catch the latest vulnerabilities. Sourcefire, the company behind Snort development, offers four ways to obtain Snort rules. The first method is to retrieve the latest Snort source distribution and use the rules contained therein. In addition, you can download newer rules from the Snort Download Rules page. To receive rules in real time, you need to purchase a subscription to the VRT rules. These rules are later released without cost to the registered Snort users. Lastly, there are Snort rules submitted by the open source community. Any registered Snort user may also submit a rule for consideration or discuss Snort rules on the Snort-sigs mailing list. Once you have new rules, you can either merge them by hand, do a straight
replace (assuming you've made no customizations at all), or use a tool to do
the work in an automated fashion. One of the more popular rule management
tools is a perl script called oinkmaster. Oinkmaster
downloads a specified file, unpacks it, and looks for a Resources
Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License. |
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||