Home > Articles > Security > Network Security

This chapter is from the book

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

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020