Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions doc/userguide/rules/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,89 @@ the buffer.
local sub = string.sub(input, offset + 1, offset + bytes)
return string.upper(sub), bytes
end

subslice
--------

This transform creates a slice of the input buffer.

The subslice transform requires parameters:

* `offset` Specifies the starting offset at which to create the
subslice. When negative, expresses how far from the end of the
input buffer to begin. [REQUIRED]
* `nbytes` Specifies the size of the subslice. When negative,
specifies that the subslice will end that many bytes from
the end of the input buffer. The default value is the
size of the input buffer minus the value of ``offset``. [OPTIONAL]
* `truncate` Specifies behavior when ``offset + nbytes`` is larger
than the input buffer size. When specified, the result will
be trimmed as though ``offset + nbyfes == buffer_length``. When
not specified [DEFAULT], an empty buffer will be produced on
which ``bsize:0`` will match. [OPTIONAL]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explicit more the behavior of truncate when we have negative values ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add discussion.


Specify the subslice desired -- `nbytes` and `truncate` are optional:

Format::

subslice: offset <, nbytes>, <, truncate>;;

When `nbytes` is not specified, the size of the subslice will be the size
of the input buffer minus the `offset` value.

When ``truncate`` is not specified and the value of ``offset + nbytes`` exceeds
the buffer length, and empty buffer will be produced such that ``bsize: 0`` will
match.

The following examples use an input buffer of ``This is Suricata``.

Examples

The subslice will be a copy of the input buffer but omit the input buffer's first byte.
The subslice is ``his is Suricata``::

subslice: 1;

This example creates the subslice ``This is Suric``::

subslice: 0, 13;

This example starts at offset ``10`` and ends at 5 bytes from the end
of the buffer which creates a subslice from offset ``10`` to offset ``12``.
The length of the input buffer is ``17`` bytes; ``5`` bytes from the end
is ``12``::

subslice: 10, -5;

This example will create a subslice from the last 3 bytes of the input
buffer and create ``ata``::

subslice: -3;

When the buffer has less bytes than ``offset + nbytes``, the transform
will either trim the resulting buffer as though ``offset + nbytes == buffer_length``
or produce an empty buffer on which `bsize:0` would match. The behavior
is determined by the inclusion of ``truncate`` with the keyword.

This example receives an input buffer with the value ``curl/7.64.1`` and
produces ``curl/7.64.1``::

subslice: 0, 30;

With truncation off, the default, the buffer produced by the transform
with the same input buffer would be the empty string: ``""`` and
``bsize:0`` would match::

subslice: 0, 30;

When ``truncate`` is specified, ``nbytes + offset`` is reduced
such that they equal the input buffer length. In the following example,
the transform produces ``curl/7.64.1``::

subslice: 0, 30, truncate;

Specifying ``truncate`` does not require ``nbytes`` to be specified:
such that they equal the input buffer length. In the following example,
the transform produces ``curl/7.64.1``::

subslice: 0, truncate;
1 change: 1 addition & 0 deletions rust/src/detect/transforms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ pub mod http_headers;
pub mod strip_whitespace;
pub mod urldecode;
pub mod xor;
pub mod subslice;
Loading
Loading