The byte_math Keyword
The byte_math keyword performs a mathematical operation on an extracted
value and a specified value or existing variable, and stores the outcome in a new resulting
variable. You can then use the resulting variable as an argument in other keywords.
You can use multiple byte_math keywords in a rule
to perform multiple byte_math operations.
The following table describes the
arguments required by the byte_math keyword.
|
Argument |
Description |
|---|---|
|
Bytes |
The number of bytes to calculate from the packet. If used without DCE/RPC, the allowed values are 1 to 10:
If used with DCE/RPC, allowed values are 1, 2, and 4. |
|
Offset |
The number of bytes into the
payload to start processing. The You can specify -65535 to 65535 bytes. You can also specify the |
|
Operator |
+, -, *, /, <<, or >> |
|
RValue |
The value following the operator. This can be an unsigned integer
or a variable passed from |
|
Result Variable |
The name of the variable into which the result
of the This value is stored as an unsigned integer. This variable name:
|
The following table describes options you can use to define how the system interprets the values you specified for the required arguments.
|
Argument |
Description |
|---|---|
|
Relative |
Makes the offset relative to the last pattern found in the last successful content match instead of the beginning of the payload. |
|
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. |
You can specify only one of DCE/RPC, Endian, or Number Type.
If you want to define how the byte_math keyword
calculates the bytes, you can choose from the
arguments described in the following table. If you
do not select a byte-ordering argument, the rules
engine uses big endian byte order.
|
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 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
|
Define how the system views string data in a packet by using one of the arguments in the following table.
|
Argument |
Description |
|---|---|
|
Hexadecimal String |
Represents string data in hexadecimal format. |
|
Decimal String |
Represents string data in decimal format. |
|
Octal String |
Represents string data in octal format. |
For example, if the values you set for byte_math are as follows:
-
Bytes = 2
-
Offset = 0
-
Operator = *
-
RValue = height
-
Result Variable = area
the rules engine extracts the number
described in the first two bytes in the packet and multiplies it by the RValue (which uses
the existing variable, height) to create the new variable,
area.
|
Keyword |
Argument |
|---|---|
|
byte_jump |
Offset |
|
byte_test |
Offset, Value |
|
byte_extract |
Offset |
|
isdataat |
Offset |