The byte_test Keyword

The byte_test keyword tests the specified byte segment against the Value argument and its operator.

The following table describes the required arguments for the byte_test keyword.

Required byte_test Arguments

Argument

Description

Bytes

The number of bytes to calculate from the packet.

If used without DCE/RPC, the allowed values are 1 to 10. However, if you specify a number of bytes other than 1, 2, or 4, you must specify a Number Type (hexadecimal, octal, or decimal.).

If used with DCE/RPC, allowed values are 1, 2, and 4.

Value

Value to test, including its operator.

Supported operators: <, >, =, !, &, ^, !>, !<, !=, !&, or !^.

For example, if you specify !1024, byte_test would convert the specified number, and if it did not equal 1024, it would generate an event (if all other keyword parameters matched).

Note that ! and != are equivalent.

You can also use an existing byte_extract variable or byte_math result to specify the value for this argument.

Offset

The number of bytes into the payload to start processing. The offset counter starts at byte 0, so calculate the offset value by subtracting 1 from the number of bytes you want to count forward from the beginning of the packet payload or the last successful content match.

You can use an existing byte_extract variable or byte_math result to specify the value for this argument.

You can further define how the system uses byte_test arguments with the arguments described in the following table.

Additional Optional byte_test Arguments

Argument

Description

Bitmask

Applies the specified hexadecimal bitmask using the AND operator to the bytes extracted from the Bytes argument.

A bitmask can be 1 to 4 bytes.

The result will be right-shifted by the number of bits equal to the number of trailing zeros in the mask.

Relative

Makes the offset relative to the last successful pattern match.

You can specify only one of DCE/RPC, Endian, or Number Type.

To define how the byte_test keyword calculates the bytes it tests, choose from the arguments in the following table. If you do not select a byte-ordering argument, the rules engine uses big endian byte order.

Byte-Ordering byte_test Arguments

Argument

Description

Big Endian

Processes data in big endian byte order, which is the default network byte order.

Little Endian

Processes data in little endian byte order.

DCE/RPC

Specifies a byte_test keyword for traffic processed by the DCE/RPC preprocessor.

The DCE/RPC preprocessor determines big endian or little endian byte order, and the Number Type and Endian arguments do not apply.

When you enable this argument, you can also use byte_test in conjunction with other specific DCE/RPC keywords.

You can define how the system views string data in a packet by using one of the arguments in the following table.

Number Type byte-test Arguments

Argument

Description

Hexadecimal String

Represents converted string data in hexadecimal format.

Decimal String

Represents converted string data in decimal format.

Octal String

Represents converted string data in octal format.

For example, if the value for byte_test is specified as the following:

  • Bytes = 4

  • Operator and Value > 128

  • Offset = 8

  • Relative enabled

The rules engine calculates the number described in the four bytes that appear 9 bytes away from (relative to) the last successful content match, and, if the calculated number is larger than 128 bytes, the rule is triggered.