3.7 The Snort Configuration File
Snort uses a configuration file at startup time. A sample configuration file snort.conf is included in the Snort distribution. You can use any name for the configuration file, however snort.conf is the conventional name. You use the -c command line switch to specify the name of the configuration file. The following command uses /opt/snort/snort.conf as the configuration file.
/opt/snort/snort -c /opt/snort/snort.conf
You can also save the configuration file in your home directory as .snortrc, but specifying it on the command line is the most widely used method. There are other advantages to using the configuration file name as a command line argument to Snort. For example, it is possible to invoke multiple Snort instances on different network interfaces with different configuration. This file contains six basic sections:
-
Variable definitions, where you define different variables. These variables are used in Snort rules as well as for other purposes, like specifying the location of rule files.
-
Config parameters. These parameters specify different Snort configuration options. Some of them can also be used on the command line.
-
Preprocessor configuration. Preprocessors are used to perform certain actions before a packet is operated by the main Snort detection engine.
-
Output module configuration. Output modules control how Snort data will be logged.
-
Defining new action types. If the predefined action types are not sufficient for your environment, you can define custom action types in the Snort configuration file.
-
Rules configuration and include files. Although you can add any rules in the main snort.conf file, the convention is to use separate files for rules. These files are then included inside the main configuration file using the include keyword. This keyword will be discussed later in this chapter.
Although the out-of-the-box configuration file works, you need to modify it to adapt it to your environment. A sample configuration file is presented later on.
3.7.1 Using Variables in Rules
In the configuration file, you can use variables. This is a very convenient way of creating rules. For example, you can define a variable HOME_NET in the configuration file.
var HOME_NET 192.168.1.0/24
Later on you can use this variable HOME_NET in your rules:
alert ip any any -> $HOME_NET any (ipopts: lsrr; msg: "Loose source routing attempt"; sid: 1000001;)
As you can see, using variables makes it very convenient to adapt the configuration file and rules to any environment. For example, you don't need to modify all rules when you copy rules from one network to another; you just need to modify a single variable.
3.7.1.1 Using a List of Networks in Variables
You can also define variables that contain multiple items. Consider that you have multiple networks in the company. Your intrusion detection system is right behind the company firewall connecting to the Internet. You can define a variable as a list of all of these networks. The following variable shows that HOME_NETWORK consists of two networks, 192.168.1.0/24 and 192.168.10.0/24.
var HOME_NET [192.168.1.0/24,192.168.10.0/24]
All networks in the variable name are separated by a comma.
3.7.1.2 Using Interface Names in Variables
You can also use interface names in defining variables. The following two statements define HOME_NET and EXTERNAL_NET variables on a Linux machine.
var HOME_NET $eth0_ADDRESS var EXTERNAL_NET $eth1_ADDRESS
The HOME_NET variable uses the IP address and network mask value assigned to interface eth0 and EXTERNAL_NET uses the IP address and network mask assigned to network interface eth1. This arrangement is more convenient since you can change IP addresses on the interfaces without modifying rules or even variables themselves.
3.7.1.3 Using the any Keyword
The any keyword can also be a variable. It matches to everything, just as it does in rules (such as addresses and port numbers). For example, if you want to test packets regardless of their source, you can define a variable like the following for EXTERNAL_NET.
var EXTERNAL_NET any
There are many variables defined in the snort.conf file that come with the Snort distribution. While installing Snort, you need to modify these variables according to your network.
3.7.2 The config Directives
The config directives in the snort.conf file allow a user to configure many general settings for Snort. Examples include the location of log files, the order of applying rules and so on. These directives can be used to replace many command line options as well. The general format of applying a config directive is as follows:
config directive_name[: value]
Table 3-6 shows a list of directives used in the snort.conf file.
Table 3-6. Snort config directives
Directive |
Description |
---|---|
order |
Changes the order in which rules are applied. It is equivalent to the –o command line option. |
alertfile |
Used to set the name of the alert file. Alert file is created in log directory (see logdir directive). |
classification |
Builds classification for rules. See explanation of the classtype keyword used in rules. |
decode_arp |
Equivalent to –a command line option. It turns ON arp decoding. |
dump_chars_only |
Equivalent –C command line option. |
dump_payload |
Equivalent to –d command line option. It is used to dump the data part of the packet. |
decode_data_link |
Equivalent to –e command line option. Using this directive you can decode data link layer headers (Ethernet header, for example). |
bpf_file |
Equivalent to –F command line option. |
set_gid |
Equivalent to –g command line option. Using this directive you can set the group ID under which Snort runs. For example, you can use “config set_gid: mygroup” |
daemon |
Equivalent to –D command line option. It invokes Snort as daemon instead of foreground process. |
reference_net |
Equivalent to –h command line option. It sets the home network address. |
interface |
Equivalent to –i command line option. It sets the interface for Snort. |
alert_with_interface_name |
Equivalent to –T command line option. This directive is used to append the interface name to the alert message. This is sometimes useful if you are monitoring multiple interfaces on the same sensor. |
logdir |
Equivalent to –l command line option. It sets the directory where Snort logs data. The default location of the log directory is /var/log/snort. |
umask |
Equivalent to –m command line option. Using this option you can set the UMASK while running Snort. |
pkt_count |
Equivalent to –n command line option. Using this directive you can exit from Snort after a defined number of packets. |
nolog |
Equivalent to –N command line option. Logging is disabled except alerts. Remember, alerts are really both alerts and logs. |
obfuscate |
Equivalent to –O command line option. It is used to obfuscate IP addresses so that you are able to send the logs for analysis to someone without disclosing the identity of your network. |
no_promisc |
Equivalent to –p command line option and is used to disable promiscuous mode. |
quiet |
Equivalent to –q command line option. This will disable banner information at Snort startup time and prevent statistical information from being displayed. |
chroot |
Equivalent to –t command line option. It is used to change root directory for Snort to a specific directory. |
checksum_mode |
Used to checksum for particular types of packets. It takes arguments such as none, noip, notcp, noicmp, noudp, and all. |
set_uid |
Equivalent to –u command line option and is used to set user ID for the Snort process. |
utc |
Equivalent to –U command line option and is used to use UTC instead of local time in alerts and logs. |
verbose |
Equivalent to –v command line option. It is used to log messages to standard output in addition to standard logging. |
dump_payload_verbose |
Equivalent to –X command line option. This dumps the received raw packet on the standard output. |
show_year |
Equivalent to –y command line option and is used to display year in the timestamp. |
stateful |
Used to set assurance mode for stream4 preprocessor. Preprocessors are discussed in detail in Chapter 4. |
You have already seen how the classification directive is used in the classification.config file. As another example, the following line is used to start Snort in the daemon mode.
config daemon
You can also use –D command line option to start Snort in the daemon mode.
3.7.3 Preprocessor Configuration
Preprocessors or input plug-ins operate on received packets before Snort rules are applied to them. The preprocessor configuration is the second major part of the configuration file. This section provides basic information about adding or removing Snort preprocessors. Detailed information about each preprocessor is found in the next chapter.
The general format of configuring a preprocessor is as follows:
preprocessor <preprocessor_name>[: <configuration_options>]
The first part of the line is the keyword preprocessor. The name of the preprocessor follows this keyword. If the preprocessor can accept some options or arguments, you can list these options after a colon character at the end of the name of preprocessor, which is optional.
The following is an example of a line in the configuration file for IP defragmentation preprocessor frag2.
preprocessor frag2
The following is an example of a stream4 preprocessor with an argument to detect port scans. The stream4 preprocessor has many other arguments as well, as described in Chapter 4.
preprocessor stream4: detect_scans
Both frag2 and stream4 are predefined preprocessors. You can also write your own preprocessors if you are a programmer. Guidelines for writing preprocessors are provided with the Snort source code.
3.7.4 Output Module Configuration
Output modules, also called output plug-ins, manipulate output from Snort rules. For example, if you want to log information to a database or send SNMP traps, you need output modules. The following is the general format for specifying an output module in the configuration file.
output <output_module_name>[: <configuration_options>]
For example, if you want to store log messages to a MySQL database, you can configure an output module that contains the database name, database server address, user name and password.
output database: alert, mysql, user=rr password=boota dbname=snort host=localhost
There may be additional steps to make the output module work properly. In the case of MySQL database, you need to setup a database, create tables, create user, set permissions and so on. More information on configuring output modules is found in Chapter 4.
3.7.5 Defining New Action Types
You already know that the first part of each Snort rule is the action item. Snort has predefined action types; however, you can also define your own action types in the configuration file. A new action type may use multiple output modules. The following action type creates alert messages that are logged into the database as well as in a file in the tcpdump format.
ruletype dump_database { type alert output database: alert, mysql, user=rr dbname=snort host=localhost output log_tcpdump: tcpdump_log_file }
This new action type can be used in rules just like other action types.
dump_database icmp any any -> 192.168.1.0/24 any (fragbits: D; msg: "Don't Fragment bit set";)
When a packet matches the criteria in this rule, the alert will be logged to the database as well as to the tcpdump_log_file.
3.7.6 Rules Configuration
The rules configuration is usually the last part of the configuration file. You can create as many rules as you like using variables already defined in the configuration file. All of the previous discussion in this chapter was about writing new rules. The rules configuration is the place in the configuration file where you can put your rules. However the convention is to put all Snort rules in different text files. You can include these text files in the snort.conf file using the “include” keyword. Snort comes with many predefined rule files. The names of these rule files end with .rule. You have already seen in the last chapter how to put these rule files in the proper place during the installation process.
3.7.7 Include Files
You can include other files inside the main configuration file using the include keyword. You can think of including a file as equivalent to inserting the contents of the included file into the main configuration file at the point where it is included. In fact, most of the predefined rules that come with the Snort distribution are found in include files. All files in the Snort distribution whose name ends with .rules contain rules and they are included in the snort.conf file. These rule files are included in the main snort.conf file using the “include” keyword. The following is an example of including myrules.rules file in the main configuration file.
include myrules.rules
It is not necessary that the name of the rules file must end with .rule. You can use a name of your choice for your rule file.
3.7.8 Sample snort.conf File
The following is a sample configuration file for Snort. All lines starting with the # character are comment lines. Whenever you modify the configuration file, you have to restart Snort for the changes to take effect.
# Variable Definitions var HOME_NET 192.168.1.0/24 var EXTERNAL_NET any var HTTP_SERVERS $HOME_NET var DNS_SERVERS $HOME_NET var RULE_PATH ./ # preprocessors preprocessor frag2 preprocessor stream4: detect_scans preprocessor stream4_reassemble preprocessor http_decode: 80 -unicode -cginull preprocessor unidecode: 80 -unicode -cginull preprocessor bo: -nobrute preprocessor telnet_decode preprocessor portscan: $HOME_NET 4 3 portscan.log preprocessor arpspoof # output modules output alert_syslog: LOG_AUTH LOG_ALERT output log_tcpdump: snort.log output database: log, mysql, user=rr password=boota dbname=snort host=localhost output xml: log, file=/var/log/snortxml # Rules and include files include $RULE_PATH/bad-traffic.rules include $RULE_PATH/exploit.rules include $RULE_PATH/scan.rules include $RULE_PATH/finger.rules include $RULE_PATH/ftp.rules include $RULE_PATH/telnet.rules include $RULE_PATH/smtp.rules include $RULE_PATH/rpc.rules include $RULE_PATH/dos.rules include $RULE_PATH/ddos.rules include $RULE_PATH/dns.rules include $RULE_PATH/tftp.rules include $RULE_PATH/web-cgi.rules include $RULE_PATH/web-coldfusion.rules include $RULE_PATH/web-iis.rules include $RULE_PATH/web-frontpage.rules include $RULE_PATH/web-misc.rules include $RULE_PATH/web-attacks.rules include $RULE_PATH/sql.rules include $RULE_PATH/x11.rules include $RULE_PATH/icmp.rules include $RULE_PATH/netbios.rules include $RULE_PATH/misc.rules include $RULE_PATH/attack-responses.rules include $RULE_PATH/myrules.rules