Commit Graph

26 Commits (0024de5e9ee868143916dabe82058c52ca2f9330)

Author SHA1 Message Date
Philippe Antoine 0024de5e9e src: new file detect-engine-buffer.h
Taken from detect-engine.h so that we can bindgen this smaller
unit.
2 years ago
Jeff Lucovsky 73dfc58772 detect/byte: Refactor endian, base
Issue: 6873

Refactor the enums for endian and base handling for broader use.
2 years ago
Jason Ish f0dbfe863d misc: prefix functions with SC not Sc 2 years ago
Philippe Antoine ce9bfba76a ci: fix and test with Wunused-macros
Ticket: 6937
2 years ago
Victor Julien 3ba8e2d3ea detect/byte: remove unneeded SIG_FLAG_APPLAYER sets
Flag will be set during list(s) setup if needed.
3 years ago
Victor Julien 83ed2c3b97 detect/bytemath: bump length to uint32_t
This puts the logic in line with the other payload inspection
functions.
3 years ago
Victor Julien 53591702aa detect/bytemath: pass match ctx directly
Adjust includes to enable this.
3 years ago
Philippe Antoine c272a646c5 detect: SigMatchAppendSMToList can fail
Ticket: #6104

And failures should be handled to say that the rule failed to load

Reverts the fix by 299ee6ed55
that was simple, but not complete (memory leak),
to have this bigger API change which simplifies code.
3 years ago
Jeff Lucovsky 690b65ae88 detect/byte_math: Permit var name for bytes value
Issue: 6145

Modifications to permit a variable name to be used for the byte_math
bytes value.
3 years ago
Victor Julien ad88efc2d8 detect: support multi buffer matching
Multi buffer matching is implemented as a way for a rule to match
on multiple buffers within the same transaction.

Before this patch a rule like:

    dns.query; content:"example"; dns.query; content:".com";

would be equivalent to:

    dns.query; content:"example"; content:".com";

If a DNS query would request more than one name, e.g.:

    DNS: [example.net][something.com]

Eeach would be inspected to have both patterns present. Otherwise,
it would not be a match. So the rule above would not match, as neither
example.net and somthing.com satisfy both conditions at the same time.

This patch changes this behavior. Instead of the above, each time the
sticky buffer is specified, it creates a separate detection unit. Each
buffer is a "multi buffer" sticky buffer will now be evaluated against
each "instance" of the sticky buffer.

To continue with the above example:

    DNS: [example.net] <- matches 'dns.query; content:"example";'
    DNS: [something.com] <- matches 'dns.query; content:".com"'

So this would now be a match.

To make sure both patterns match in a single query string, the expression
'dns.query; content:"example"; content:".com";' still works for this.

This patch doesn't yet enable the behavior for the keywords. That is
done in a follow up patch.

To be able to implement this the internal storage of parsed rules
is changed. Until this patch and array of lists was used, where the
index was the buffer id (e.g. http_uri, dns_query). Therefore there
was only one list of matches per buffer id. As a side effect this
array was always very sparsely populated as many buffers could not
be mixed.

This patch changes the internal representation. The new array is densely
packed:

    dns.query; content:"1"; dns.query; bsize:1; content:"2";

    [type: dns_query][list: content:"1";]
    [type: dns_query][list: bsize:1; content:"2";]

The new scheme allows for multiple instances of the same buffer.
These lists are then translated into multiple inspection engines
during the final setup of the rule.

Ticket: #5784.
4 years ago
Victor Julien df1cf8bbda detect/byte_math: reduce use of sm_list macro 4 years ago
Victor Julien 7ac623e0c5 detect/bytemath: fix newline in debug message 4 years ago
Jeff Lucovsky 38c5e89e29 detect/byte_math: fix bug in byte_math detection
Issue: 5945

Avoid division by zero when the byte_math operation is division and the
rvalue is 0.
4 years ago
Philippe Antoine 473ca6dcf4 detect: bytemath do not left shift more than 64
As it is undefined behavior by C standard.
In this case, zeroes the value.

Ticket: #5900
4 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 4 years ago
Philippe Antoine ad713246a9 src: remove double includes
Keep the unconditional include to be sure it works

git grep '#include "' src/*.c | sort | uniq -c | awk '$1 > 1'
4 years ago
Philippe Antoine 1f066cbbe8 unittest: fix unneeded includes as per cppclean
Especially because there is conditional inclusion from a header
4 years ago
Jeff Lucovsky ccd1063e43 detect/bytemath: convert parser to Rust
Issue: 5077

This commit
- Converts the PCRE based parser to Rust.
- Adds unit tests to the new Rust modules
- Removes the PCRE parser from detect-bytemath.c
- Adjusts the C source modules to refer to the Rust definitions
- Includes the multiply operator (missing from the C parser)
4 years ago
Philippe Antoine 02f2602dde src: rework includes as per cppclean 4 years ago
Philippe Antoine 56f664af6b pcre2: follow code naming style 5 years ago
Philippe Antoine 48dd0cf804 pcre2: check for PCRE2_ERROR_UNSET
Needs maybe to be generalized
5 years ago
Philippe Antoine 3de99a214c pcre2: migrate keywords parsing 5 years ago
Philippe Antoine 2b043150ed detect: initializes memory in bytemath parsing 6 years ago
Jeff Lucovsky 828bf6d1d6 detect: Treat offset as a signed value
This commit updates the detector to treat 'offset' as a signed value to
be compatible with Snort.
6 years ago
Victor Julien 6ab323d323 detect: hide RegisterTests behind ifdef UNITTESTS
Update all callers to more aggressively use UNITTESTS guards as well.
6 years ago
Jeff Lucovsky 0e4ba7b13e detect: Add byte_math detector 6 years ago