Subsections

3.6 Non-Payload Detection Rule Options


3.6.1 fragoffset

The fragoffset keyword allows one to compare the IP fragment offset field against a decimal value. To catch all the first fragments of an IP session, you could use the fragbits keyword and look for the More fragments option in conjunction with a fragoffset of 0.

3.6.1.1 Format

    fragoffset:[!|<|>]<number>;

3.6.1.2 Example

    alert ip any any -> any any \
        (msg:"First Fragment"; fragbits:M; fragoffset:0;)

3.6.2 ttl

The ttl keyword is used to check the IP time-to-live value. This option keyword was intended for use in the detection of traceroute attempts. This keyword takes numbers from 0 to 255.

3.6.2.1 Format

    ttl:[<, >, =, <=, >=]<number>;
    ttl:[<number>]-[<number>];

3.6.2.2 Example

This example checks for a time-to-live value that is less than 3.

    ttl:<3;

This example checks for a time-to-live value that between 3 and 5.

    ttl:3-5;

This example checks for a time-to-live value that between 0 and 5.

    ttl:-5;

This example checks for a time-to-live value that between 5 and 255.

    ttl:5-;

Few other examples are as follows:

    ttl:<=5;
    ttl:>=5;
    ttl:=5;

The following examples are NOT allowed by ttl keyword:

    ttl:=>5;
    ttl:=<5;
    ttl:5-3;

3.6.3 tos

The tos keyword is used to check the IP TOS field for a specific value.

3.6.3.1 Format

    tos:[!]<number>;

3.6.3.2 Example

This example looks for a tos value that is not 4

    tos:!4;

3.6.4 id

The id keyword is used to check the IP ID field for a specific value. Some tools (exploits, scanners and other odd programs) set this field specifically for various purposes, for example, the value 31337 is very popular with some hackers.

3.6.4.1 Format

    id:<number>;

3.6.4.2 Example

This example looks for the IP ID of 31337.

    id:31337;

3.6.5 ipopts

The ipopts keyword is used to check if a specific IP option is present.

The following options may be checked:

rr
- Record Route
eol
- End of list
nop
- No Op
ts
- Time Stamp
sec
- IP Security
esec
- IP Extended Security
lsrr
- Loose Source Routing
lsrre
- Loose Source Routing (For MS99-038 and CVE-1999-0909)
ssrr
- Strict Source Routing
satid
- Stream identifier
any
- any IP options are set

The most frequently watched for IP options are strict and loose source routing which aren't used in any widespread internet applications.

3.6.5.1 Format

    ipopts:<rr|eol|nop|ts|sec|esec|lsrr|lsrre|ssrr|satid|any>;

3.6.5.2 Example

This example looks for the IP Option of Loose Source Routing.

    ipopts:lsrr;

3.6.5.3 Warning

Only a single ipopts keyword may be specified per rule.

3.6.6 fragbits

The fragbits keyword is used to check if fragmentation and reserved bits are set in the IP header.

The following bits may be checked:

M
- More Fragments
D
- Don't Fragment
R
- Reserved Bit

The following modifiers can be set to change the match criteria:

+
match on the specified bits, plus any others
*
match if any of the specified bits are set
!
match if the specified bits are not set

3.6.6.1 Format

    fragbits:[+*!]<[MDR]>;

3.6.6.2 Example

This example checks if the More Fragments bit and the Do not Fragment bit are set.

    fragbits:MD+;

3.6.7 dsize

The dsize keyword is used to test the packet payload size. This may be used to check for abnormally sized packets that might cause buffer overflows.

3.6.7.1 Format

    dsize:min<>max;
    dsize:[<|>]<number>;

3.6.7.2 Example

This example looks for a dsize that is between 300 and 400 bytes (inclusive).

    dsize:300<>400;

3.6.7.3 Warning

Note that segmentation makes dsize less reliable for TCP based protocols such as HTTP. Furthermore, dsize will fail on stream rebuilt packets, regardless of the size of the payload, unless protocol aware flushing (PAF) marks this packet as the start of a message.

3.6.8 flags

The flags keyword is used to check if specific TCP flag bits are present.

The following bits may be checked:

F
- FIN - Finish (LSB in TCP Flags byte)
S
- SYN - Synchronize sequence numbers
R
- RST - Reset
P
- PSH - Push
A
- ACK - Acknowledgment
U
- URG - Urgent
C
- CWR - Congestion Window Reduced (MSB in TCP Flags byte)
E
- ECE - ECN-Echo (If SYN, then ECN capable. Else, CE flag in IP header is set)
0
- No TCP Flags Set

The following modifiers can be set to change the match criteria:

+
- match on the specified bits, plus any others
*
- match if any of the specified bits are set
!
- match if the specified bits are not set

To handle writing rules for session initiation packets such as ECN where a SYN packet is sent with CWR and ECE set, an option mask may be specified by preceding the mask with a comma. A rule could check for a flags value of S,CE if one wishes to find packets with just the syn bit, regardless of the values of the reserved bits.

3.6.8.1 Format

    flags:[!|*|+]<FSRPAUCE0>[,<FSRPAUCE>];

3.6.8.2 Example

This example checks if just the SYN and the FIN bits are set, ignoring CWR (reserved bit 1) and ECN (reserved bit 2).

    alert tcp any any -> any any (flags:SF,CE;)

Note:  

The reserved bits '1' and '2' have been replaced with 'C' and 'E', respectively, to match RFC 3168, "The Addition of Explicit Congestion Notification (ECN) to IP". The old values of '1' and '2' are still valid for the flag keyword, but are now deprecated.


3.6.9 flow

The flow keyword is used in conjunction with session tracking (see Section [*]). It allows rules to only apply to certain directions of the traffic flow.

This allows rules to only apply to clients or servers. This allows packets related to $HOME_NET clients viewing web pages to be distinguished from servers running in the $HOME_NET.

The established keyword will replace the flags:+A used in many places to show established TCP connections.

Options

Option Description
to_client Trigger on server responses from A to B
to_server Trigger on client requests from A to B
from_client Trigger on client requests from A to B
from_server Trigger on server responses from A to B
established Trigger only on established TCP connections
not_established Trigger only when no TCP connection is established
stateless Trigger regardless of the state of the stream processor (useful for packets that are designed to cause machines to crash)
no_stream Do not trigger on rebuilt stream packets (useful for dsize and stream5)
only_stream Only trigger on rebuilt stream packets
no_frag Do not trigger on rebuilt frag packets
only_frag Only trigger on rebuilt frag packets

3.6.9.1 Format

    flow:[(established|not_established|stateless)] 
        [,(to_client|to_server|from_client|from_server)]
        [,(no_stream|only_stream)]
        [,(no_frag|only_frag)];

3.6.9.2 Examples

    alert tcp !$HOME_NET any -> $HOME_NET 21 (msg:"cd incoming detected"; \
        flow:from_client; content:"CWD incoming"; nocase;)

    alert tcp !$HOME_NET 0 -> $HOME_NET 0 (msg:"Port 0 TCP traffic"; \
        flow:stateless;)


3.6.10 flowbits

The flowbits keyword is used in conjunction with conversation tracking from the Session preprocessor (see Section[*]). It allows rules to track states during a transport protocol session. The flowbits option is most useful for TCP sessions, as it allows rules to generically track the state of an application protocol.

There are several keywords associated with flowbits. Most of the options need a user-defined name for the specific state that is being checked. Some keyword uses group name. When no group name is specified the flowbits will belong to a default group. A particular flowbit can belong to more than one group. Flowbit name and group name should be limited to any alphanumeric string including periods, dashes, and underscores.

3.6.10.1 General Format

    flowbits:[set|setx|unset|toggle|isset|isnotset|noalert|reset][, <bits/bats>][, <GROUP_NAME>];
    bits ::= bit[|bits]
    bats ::= bit[&bats]

Option Description
set Sets the specified states for the current flow and assign them to a group when a GROUP_NAME is specified.
setx Sets the specified states for the current flow and clear other states in the group
unset Unsets the specified states for the current flow.
toggle For every state specified, sets the specified state if the state is unset and unsets it if the state is set.
isset Checks if the specified states are set.
isnotset Checks if the specified states are not set.
noalert Cause the rule to not generate an alert, regardless of the rest of the detection options.
reset Reset all states on a given flow.

3.6.10.2 set

This keyword sets bits to group for a particular flow. When no group specified, set the default group. This keyword always returns true.

Syntax:
    flowbits:set,bats[,group]
Usage:  
    flowbits:set,bit1,doc;
    flowbits:set,bit2&bit3,doc;
    First rule sets bit1 in doc group, second rule sets bit2 and bit3 in doc group. 
    So doc group has bit 1, bit2 and bit3 set

3.6.10.3 setx

This keyword sets bits to group exclusively. This clears other bits in group. Group must present.This keyword always returns true.
Syntax:
    flowbits:setx,bats,group
Usage:  
    flowbits: setx, bit1, doc
    flowbits: setx, bit2&bit3, doc
    First rule sets bit1 in doc group, second rule sets bit2 and bit3 in doc group.
    So doc group has bit2 and bit3 set, because bit1 is cleared by rule 2.

3.6.10.4 unset

This keyword clears bits specified for a particular flow or clears all bits in the group (Group must present). This keyword always returns true.

Syntax:
   flowbits:unset,bats
   flowbits:unset,all,group
   
Usage:  
   flowbits: unset, bit1  
   Clear bit1.
   
   flowbits: unset, bit1&bit2
   Clear bit1 and bit2
   
   flowbits: unset, all, doc
   This clears all bits in the doc group.

3.6.10.5 toggle

If flowbit is set, unset it. If it is unset, set it. Toggle every bit specified or toggle all the bits in group (Group must be present). This keyword always returns true.

Syntax:  
   flowbits:toggle,bats
   flowbits:toggle,all,group
   
Usage:
   flowbits: toggle, bit1&bit2
   If bit1 is 0 and bit2 is 1 before, after this rule, bit1 is 1 and bit2 is 0.
   
   flowbits:toggle,all,doc
   Toggle all the bits in group doc as described above.

3.6.10.6 isset

This keyword checks a bit or several bits to see if it is set. It returns true or false based on the following syntax.

Syntax:  
   flowbits:isset, bits => Check whether any bit is set
   flowbits:isset, bats => Check whether all bits are set
   flowbits:isset, any, group => Check whether any bit in the group is set.
   flowbits:isset, all, group => Check whether all bits in the group are set. 
   
Usage
   flowbits:isset, bit1|bit2 => If either bit1 or bit2 is set, return true
   flowbits:isset, bit1&bit2 => If both bit1 and bit2 are set, return true, otherwise false
   flowbits:isset, any, doc => If any bit in group doc is set, return true
   flowbits:isset, all, doc => If all the bits in doc group are set, return true

3.6.10.7 isnotset

This keyword is the reverse of isset. It returns true if isset is false, it returns false if isset is true. Isnotset works on the final result, not on individual bits.

Syntax:  
   flowbits:isnotset, bits => Check whether not any bit is set
   flowbits:isnotset, bats => Check whether not all bits are set
   flowbits:isnotset, any, group => Check whether not bit in the group is set.
   flowbits:isnotset, all, group => Check whether not all bits in the group are set. 
   
Usage
   flowbits:isnotset, bit1|bit2 => If either bit1 or bit2 is set, return true
   flowbits:isnotset, bit1&bit2 => If both bit1 and bit2 are set, return true, otherwise false
   flowbits:isnotset, any, doc => If any bit in group doc is set, return true
   flowbits:isnotset, all, doc => If all the bits in doc group are set, return true

3.6.10.8 noalert

This keyword always returns false. It allows users to write rules that set, unset, and toggle bit without generating an alert. This is most useful for writing flowbit rules that set bit on normal traffic and significantly reduces unwanted alerts. There is no bit specified with this keyword.

  flowbits:noalert;

3.6.10.9 reset

This keyword resets all of the states on a given flow if no group specified, otherwise, reset all the bits in a group. This always returns true. There is no bit specified with this keyword.

Syntax: 
   flowbits:reset[,group]

Usage:  
   flowbits:reset => reset all the bits in the flow
   flowbits: reset, doc => reset all the bits in the doc group

3.6.10.10 Examples

    alert tcp any 143 -> any any (msg:"IMAP login"; 
        content:"OK LOGIN"; flowbits:set,logged_in; 
        flowbits:noalert;)
      
    alert tcp any any -> any 143 (msg:"IMAP LIST"; content:"LIST"; 
        flowbits:isset,logged_in;)

3.6.11 seq

The seq keyword is used to check for a specific TCP sequence number.

3.6.11.1 Format

    seq:<number>;

3.6.11.2 Example

This example looks for a TCP sequence number of 0.

    seq:0;

3.6.12 ack

The ack keyword is used to check for a specific TCP acknowledge number.

3.6.12.1 Format

    ack:<number>;

3.6.12.2 Example

This example looks for a TCP acknowledge number of 0.

    ack:0;

3.6.13 window

The window keyword is used to check for a specific TCP window size.

3.6.13.1 Format

    window:[!]<number>;

3.6.13.2 Example

This example looks for a TCP window size of 55808.

    window:55808;

3.6.14 itype

The itype keyword is used to check for a specific ICMP type value.

3.6.14.1 Format

    itype:min<>max;
    itype:[<|>]<number>;

3.6.14.2 Example

This example looks for an ICMP type greater than 30.

    itype:>30;

3.6.15 icode

The icode keyword is used to check for a specific ICMP code value.

3.6.15.1 Format

    icode:min<>max;
    icode:[<|>]<number>;

The <> operator in the first format checks for an ICMP code within a specified range (exclusive). That is, strictly greater than the min value and strictly less than the max value. Note that the min value can a -1 allowing an ICMP code of zero to be included in the range.

Numerical values are validated with respect to permissible ICMP code values between 0 and 255 and other criteria.

    icode:min<>max
        -1 <= min <= 254
         1 <= max <= 256
         (max - min) > 1

    icode:number
        0 <= number <= 255

    icode:<number
        1 <= number <= 256

    icode:>number
        0 <= number <= 254

3.6.15.2 Examples

This example looks for an ICMP code greater than 30.

    icode:>30;

This example looks for an ICMP code greater than zero and less than 30.

    icode:-1<>30;

3.6.16 icmp_id

The icmp_id keyword is used to check for a specific ICMP ID value.

This is useful because some covert channel programs use static ICMP fields when they communicate. This particular plugin was developed to detect the stacheldraht DDoS agent.

3.6.16.1 Format

    icmp_id:<number>;

3.6.16.2 Example

This example looks for an ICMP ID of 0.

    icmp_id:0;

3.6.17 icmp_seq

The icmp_seq keyword is used to check for a specific ICMP sequence value.

This is useful because some covert channel programs use static ICMP fields when they communicate. This particular plugin was developed to detect the stacheldraht DDoS agent.

3.6.17.1 Format

    icmp_seq:<number>;

3.6.17.2 Example

This example looks for an ICMP Sequence of 0.

    icmp_seq:0;

3.6.18 rpc

The rpc keyword is used to check for a RPC application, version, and procedure numbers in SUNRPC CALL requests.

Wildcards are valid for both version and procedure numbers by using '*';

3.6.18.1 Format

    rpc:<application number>, [<version number>|*], [<procedure number>|*]>;

3.6.18.2 Example

The following example looks for an RPC portmap GETPORT request.

    alert tcp any any -> any 111 (rpc:100000, *, 3;);

3.6.18.3 Warning

Because of the fast pattern matching engine, the RPC keyword is slower than looking for the RPC values by using normal content matching.

3.6.19 ip_proto

The ip_proto keyword allows checks against the IP protocol header. For a list of protocols that may be specified by name, see /etc/protocols.

3.6.19.1 Format

    ip_proto:[!|>|<] <name or number>;

3.6.19.2 Example

This example looks for IGMP traffic.

    alert ip any any -> any any (ip_proto:igmp;)

3.6.20 sameip

The sameip keyword allows rules to check if the source ip is the same as the destination IP.

3.6.20.1 Format

    sameip;

3.6.20.2 Example

This example looks for any traffic where the Source IP and the Destination IP is the same.

    alert ip any any -> any any (sameip;)

3.6.21 stream_reassemble

The stream_reassemble keyword allows a rule to enable or disable TCP stream reassembly on matching traffic.

Note:  

The stream_reassemble option is only available when the Stream preprocessor is enabled.

3.6.21.1 Format

    stream_reassemble:<enable|disable>, <server|client|both>[, noalert][, fastpath];

3.6.21.2 Example

For example, to disable TCP reassembly for client traffic when we see a HTTP 200 Ok Response message, use:

    alert tcp any 80 -> any any (flow:to_client, established; content:"200 OK";
       stream_reassemble:disable,client,noalert;)

3.6.22 stream_size

The stream_size keyword allows a rule to match traffic according to the number of bytes observed, as determined by the TCP sequence numbers.

Note:  

The stream_size option is only available when the Stream preprocessor is enabled.

3.6.22.1 Format

    stream_size:<server|client|both|either>, <operator>, <number>;

Where the operator is one of the following:

3.6.22.2 Example

For example, to look for a session that is less that 6 bytes from the client side, use:

    alert tcp any any -> any any (stream_size:client,<,6;)

3.6.23 Non-Payload Detection Quick Reference

Table: Non-payload detection rule option keywords
Keyword Description
fragoffset

The fragoffset keyword allows one to compare the IP fragment offset field against a decimal value.

ttl

The ttl keyword is used to check the IP time-to-live value.

tos

The tos keyword is used to check the IP TOS field for a specific value.

id

The id keyword is used to check the IP ID field for a specific value.

ipopts

The ipopts keyword is used to check if a specific IP option is present.

fragbits

The fragbits keyword is used to check if fragmentation and reserved bits are set in the IP header.

dsize

The dsize keyword is used to test the packet payload size.

flags

The flags keyword is used to check if specific TCP flag bits are present.

flow

The flow keyword allows rules to only apply to certain directions of the traffic flow.

flowbits

The flowbits keyword allows rules to track states during a transport protocol session.

seq

The seq keyword is used to check for a specific TCP sequence number.

ack

The ack keyword is used to check for a specific TCP acknowledge number.

window

The window keyword is used to check for a specific TCP window size.

itype

The itype keyword is used to check for a specific ICMP type value.

icode

The icode keyword is used to check for a specific ICMP code value.

icmp_id

The icmp_id keyword is used to check for a specific ICMP ID value.

icmp_seq

The icmp_seq keyword is used to check for a specific ICMP sequence value.

rpc

The rpc keyword is used to check for a RPC application, version, and procedure numbers in SUNRPC CALL requests.

ip_proto

The ip_proto keyword allows checks against the IP protocol header.

sameip

The sameip keyword allows rules to check if the source ip is the same as the destination IP.