Home > Articles > Security > Network Security

This chapter is from the book

3.5 Rule Headers

As mentioned earlier, a rule header consists of the section of the rule before starting parentheses and has many parts. Let us take a detailed look at different parts used in the rule header, starting with rule actions.

3.5.1 Rule Actions

The action is the first part of a Snort rule. It shows what action will be taken when rule conditions are met. An action is taken only when all of the conditions mentioned in a rule are true. There are five predefined actions. However, you can also define your own actions as needed. As a precaution, keep in mind that Snort versions 1.x and 2.x apply rules in different ways. In Snort 1.x, if multiple rules match a given packet, only the first one is applied. After applying the first rule, no further action is taken on the packet. However in Snort version 2, all rules are applied before generating an alert message. The most severe alert message is then generated.

3.5.1.1 Pass

This action tells Snort to ignore the packet. This action plays an important role in speeding up Snort operation in cases where you don't want to apply checks on certain packets. For example, if you have a vulnerability assessment host on your own network that you use to find possible security holes in your network, you may want Snort to ignore any attacks from that host. The pass rule plays an important part in such a case.

3.5.1.2 Log

The log action is used to log a packet. Packets can be logged in different ways, as discussed later in this book. For example, a message can be logged to log files or in a database. Packets can be logged with different levels of detail depending on the command line arguments and configuration file. To find available command line arguments with your version of Snort, use “snort -?” command.

3.5.1.3 Alert

The alert action is used to send an alert message when rule conditions are true for a particular packet. An alert can be sent in multiple ways. For example, you can send an alert to a file or to a console. The functional difference between Log and Alert actions is that Alert actions send an alert message and then log the packet. The Log action only logs the packet.

3.5.1.4 Activate

The activate action is used to create an alert and then to activate another rule for checking more conditions. Dynamic rules, as explained next, are used for this purpose. The activate action is used when you need further testing of a captured packet.

3.5.1.5 Dynamic

Dynamic action rules are invoked by other rules using the “activate” action. In normal circumstances, they are not applied on a packet. A dynamic rule can be activated only by an “activate” action defined in another role.

3.5.1.6 User Defined Actions

In addition to these actions, you can define your own actions. These rule actions can be used for different purposes, such as:

  • Sending messages to syslog. Syslog is system logger daemon and creates log file in /var/log directory. Location of these files can be changed using /etc/syslog.conf file. For more information, use “man syslog” and “man syslog.conf” commands on a UNIX system. Syslog may be compared to the event logger on Microsoft Windows systems.

  • Sending SNMP traps. SNMP traps are sent to a network management system like HP OpenView or Open NMS at http://www.opennms.org.

  • Taking multiple actions on a packet. As you have seen earlier in the structure of Snort rules, a rule only takes one action. User defined rules can be used to take multiple actions. For example, a user defined rule can be used to send an SNMP trap as well as to log the alert data to the syslog daemon.

  • Logging data to XML files.

Logging messages into a database. Snort is able to log messages to MySQL, Postgress SQL, Oracle and Microsoft SQL server.

These new action types are defined in the configuration file snort.conf. A new action is defined in the following general structure:

ruletype action_name
{
     action definition
}

The ruletype keyword is followed by the action name. Two braces enclose the actual definition of the action, just like a function in C programming. For example, an action named smb_db_alert that is used to send SMB pop-up window alert messages to hosts listed in workstation.list file and to MySQL database named “snort” is defined below:

ruletype smb_db_alert
{
   type alert
   output alert_smb: workstation.list
   output database: log, mysql, user=rr password=rr      dbname=snort host=localhost
}

Theses types of rules will be discussed in the next chapter in detail. Usually they are related to configuration of output plug-ins.

3.5.2 Protocols

Protocol is the second part of a Snort rule. The protocol part of a Snort rule shows on which type of packet the rule will be applied. Currently Snort understands the following protocols:

  • IP

  • ICMP

  • TCP

  • UDP

If the protocol is IP, Snort checks the link layer header to determine the packet type. If any other type of protocol is used, Snort uses the IP header to determine the protocol type. Different packet headers are discussed in Appendix C.

The protocols only play a role in specifying criteria in the header part of the rule. The options part of the rule can have additional criteria unrelated to the specified protocol. For example, consider the following rule where the protocol is ICMP.

alert icmp any any -> any any (msg: "Ping with TTL=100";  ttl: 100;)

The options part checks the TTL (Time To Live) value, which is not part of the ICMP header. TTL is part of IP header instead. This means that the options part can check parameters in other protocol fields as well. Header fields for common protocols and their explanation is found in Appendix C.

3.5.3 Address

There are two address parts in a Snort rule. These addresses are used to check the source from which the packet originated and the destination of the packet. The address may be a single IP address or a network address. You can use any keyword to apply a rule on all addresses. The address is followed by a slash character and number of bits in the netmask. For example, an address 192.168.2.0/24 represents C class network 192.168.2.0 with 24 bits in the network mask. A network mask with 24 bits is 255.255.255.0. Keep the following in mind about number of bits in the netmask:

  • If the netmask consists of 24 bits, it is a C class network.

  • If the netmask consists of 16 bits, it is a B class network.

  • If the netmask consists of 8 bits, it is an A class network.

  • For a single host, use 32 bits in the netmask field.

You can also use any number of bits in the address part allowed by Classless Inter-Domain Routing or CIDR. Refer to RFC 791 at http://www.rfc-editor.org/rfc/rfc791.txt for structure of IP addresses and netmasks and to RFC 1519 at http://www.rfc-editor.org/rfc/rfc1519.txt for more information on CIDR.

As mentioned earlier, there are two address fields in the Snort rule. One of them is the source address and the other one is the destination address. The direction part of the rule determines which address is source and which one is destination. Refer to the explanation of the direction part to find more information about how this selection is made.

Following are some examples of how addresses are mentioned in Snort rules:

  • An address 192.168.1.3/32 defines a single host with IP address 192.168.1.3.

  • An address 192.168.1.0/24 defines a class C network with addresses ranging from 192.168.1.0 to 192.168.1.255. There are 24 bits in the netmask, which is equal to 255.255.255.0.

  • An address 152.168.0.0/16 defines a class B network with addresses ranging from 152.168.0.0 to 152.168.255.255. There are 16 bits in the netmask, which is equal to 255.255.0.0.

  • An address 10.0.0.0/8 defines a class A network with addresses ranging from 10.0.0.0 to 10.255.255.255. There are 8 bits in the netmask, which is equal to 255.0.0.0.

  • An address 192.168.1.16/28 defines an address range of 192.168.1.16 to 192.168.1.31. There are 28 bits in the netmask field, which is equal to 255.255.255.240, and the network consists of 16 addresses. You can place only 14 hosts in this type of network because two of the total 16 addresses are used up in defining the network address and the broadcast address. Note that the first address in each network is always the network address and the last address is the broadcast address. For this network 192.168.1.16 is the network address and 192.168.1.31 is the broadcast address.

For example, if you want to generate alerts for all TCP packets with TTL=100 going to web server 192.168.1.10 at port 80 from any source, you can use the following rule:

alert tcp any any -> 192.168.1.10/32 80 (msg: "TTL=100";  ttl: 100;)

This rule is just an example to provide information about how IP addresses are used in Snort rules.

3.5.3.1 Address Exclusion

Snort provides a mechanism to exclude addresses by the use of the negation symbol !, an exclamation point. This symbol is used with the address to direct Snort not to test packets coming from or going to that address. For example, the following rule is applied to all packets except those that originate from class C network 192.168.2.0.

alert icmp ![192.168.2.0/24] any -> any any    (msg: "Ping with TTL=100";  ttl: 100;)

This rule is useful, for instance, when you want to test packets that don't originate from your home network (which means you trust everyone in your home network!).

3.5.3.2 Address Lists

You can also specify list of addresses in a Snort rule. For example, if your home network consists of two C class IP networks 192.168.2.0 and 192.168.8.0 and you want to apply the above rule to all addresses but hosts in these two, you can use the following modified rule where the two addresses are separated by a comma.

alert icmp ![192.168.2.0/24,192.168.8.0/24] any -> any     any (msg: "Ping with TTL=100";  ttl: 100;)

Note that a square bracket is used with the negation symbol. You don't need to use brackets if you are not using the negation symbol.

3.5.4 Port Number

The port number is used to apply a rule on packets that originate from or go to a particular port or a range of ports. For example, you can use source port number 23 to apply a rule to those packets that originate from a Telnet server. You can use the keyword any to apply the rule on all packets irrespective of the port number. Port number is meaningful only for TCP and UDP protocols. If you have selected IP or ICMP as the protocol in the rule, port number does not play any role. The following rule is applied to all packets that originate from a Telnet server in 192.168.2.0/24, which is a class C network and contains the word “confidential”:

alert tcp 192.168.2.0/24 23 -> any any     (content: "confidential"; msg: "Detected confidential";)

The same rule can be applied to traffic either going to or originating from any Telnet server in the network by modifying the direction to either side as shown below:

alert tcp 192.168.2.0/24 23 <> any any     (content: "confidential"; msg: "Detected confidential";)

Port numbers are useful when you want to apply a rule only for a particular type of data packet. For example, if a vulnerability is related to only a HTTP (Hyper Text Transfer Protocol) web server, you can use port 80 in the rule to detect anybody trying to exploit it. This way Snort will apply that rule only to web server traffic and not to any other TCP packets. Writing good rules always improves the performance of IDS.

3.5.4.1 Port Ranges

You can also use a range of ports instead of only one port in the port field. Use a colon to separate starting and ending port numbers. For example, the following rule will create an alert for all UDP traffic coming from ports 1024 to 2048 from all hosts.

alert udp any 1024:2048 -> any any (msg: "UDP ports";)

3.5.4.2 Upper and Lower Boundaries

While listing port numbers, you can also use only the starting port number or the ending port number in the range. For example, a range specified as :1024 includes all port numbers up to and including port 1024. A port range specified as 1000: will include all ports numbers including and above port 1000.

3.5.4.3 Negation Symbol

As with addresses, you can also use the negation symbol with port numbers to exclude a port or a range of ports from the scope of the Snort rule. The following rule logs all UDP traffic except for source port number 53.

log udp any !53 -> any any log udp

You can't use comma character in the port filed to specify multiple ports. For example, specifying 53,54 is not allowed. However you can use 53:54 to specify a port range.

3.5.4.4 Well-Known Port Numbers

Well-known port numbers are used for commonly used applications. Some of these port numbers and their applications are listed in Table 3-1.

Table 3-1. Well-Known Port Numbers

Port Number

Description

20

FTP data

21

FTP

22

SSH or Secure shell

23

Telnet

25

SMTP, used for e-mail server like Sendmail

37

NTP (Network Time Protocol) used for synchronizing time on network hosts

53

DNS server

67

BootP/DHCP client

68

BootP/DHCP server

69

TFTP

80

HTTP, used for all web servers

110

POP3, used for e-mail clients like Microsoft Outlook

161

SNMP

162

SNMP traps

443

HTTPS or Secure HTTP

514

Syslog

3306

MySQL

You can also look into /etc/services file on the UNIX platform to see more port numbers. Refer to RFC 1700 for a detailed list at http://www.rfc-editor.org/rfc/rfc1700.txt. The Internet Corporation for Assigned Names and Numbers (ICANN) now keeps track of all port numbers and names. You can find more information at http://www.icann.org.

3.5.5 Direction

The direction field determines the source and destination addresses and port numbers in a rule. The following rules apply to the direction field:

  • A -> symbol shows that address and port numbers on the left hand side of the direction field are the source of the packet while the address and port number on the right hand side of the field are the destination.

  • A <- symbol in the direction field shows that the packet is traveling from the address and port number on the right hand side of the symbol to the address and port number on the left hand side.

  • A <> symbol shows that the rule will be applied to packets traveling on either direction. This symbol is useful when you want to monitor data packets for both client and server. For example, using this symbol, you can monitor all traffic coming from and going to a POP or Telnet server.

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