Commit Graph

41 Commits (77b94b8713d8fb3e88c445be69b9ecf9f2f2e521)

Author SHA1 Message Date
Jeff Lucovsky e45204aecf detect/transform: Refactor setup/apply pattern
git grep -A 1 -w InspectionBufferSetup shows many cases of the following
call patterns:
    - InspectionBufferSetup
    - InspectionBufferApplyTransforms

Refactor the implementations of those functions into
InspectionBufferSetupAndApplyTransforms to reduce function call count.

Issue: 2290 (related to changed for this issue)
6 months ago
Jeff Lucovsky 95e8427bae gen: Remove _AL_ usage in detect keywords
This commit removes the `_AL_` usage in detect keywords for improved
readability.

Some of the HTTP rule keywords already had counterparts without using
"_AL_". These rule keywords are the legacy content modifier keywords
that now have sticky buffer equivalents.

For these, "_AL_" was removed and a suffix was added to the #define:
src/detect-engine-register.h:151:    DETECT_HTTP_COOKIE_CM
src/detect-engine-register.h:153:    DETECT_HTTP_METHOD_CM
src/detect-engine-register.h:161:    DETECT_HTTP_HEADER_CM
src/detect-engine-register.h:173:    DETECT_HTTP_RAW_HEADER_CM
src/detect-engine-register.h:175:    DETECT_HTTP_URI_CM
src/detect-engine-register.h:179:    DETECT_HTTP_STAT_MSG_CM
src/detect-engine-register.h:181:    DETECT_HTTP_STAT_CODE_CM
src/detect-engine-register.h:185:    DETECT_HTTP_HOST_CM
7 months ago
Jeff Lucovsky cb56752bf7 config/ja3: Eliminate warnings when JA3 is disabled
This commit eliminates warnings when either ja3, ja4 or both are
disabled.
1 year ago
Sascha Steinbiss 120313f4da ja4: implement for TLS and QUIC
Ticket: OISF#6379
1 year ago
Sascha Steinbiss 9d0db71ebf ja3: make feature compile time configurable 1 year ago
Jason Ish b11bb1c412 detect: rename DetectAppLayerInspectEngineRegister2
Rename DetectAppLayerInspectEngineRegister2 to
DetectAppLayerInspectEngineRegister as there is no other variant of
this function, and the versioning with lack of supporting
documentation can lead to confusion.
2 years ago
Jason Ish 50be098839 detect: rename DetectAppLayerMpmRegister2 to DetectAppLayerMpmRegister
The old DetectAppLayerMpmRegister has not been around since 4.1.x.
Rename the v2 of this function to a versionless function as there is no
documentation referring to what the 2 means.
2 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.
2 years ago
Victor Julien 2c0e434bb8 detect: pass de_ctx to DetectBufferSetActiveList 2 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 3 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'
3 years ago
Philippe Antoine 4706083929 detect: avoids memory leak on ja3 signature parsing
If a later keyword enforces a protocol incompatible with ja3
3 years ago
Philippe Antoine c09ca7d171 clean: use SC_MD5_HEX_LEN instead of magic number 32 3 years ago
Philippe Antoine f75d18b077 quic: ja3 code deduplication
As quic transactions are unidirectional, the same function is
used to get ja3 from client or from server.
3 years ago
Philippe Antoine 7cb40a1dfc quic: allow ja3.hash keyword
Ticket: #5624
3 years ago
Victor Julien 214e466b29 tls: remove incomplete tests
These tests are incompatible with the incomplete API usage and should
have been pcap based tests in the first place.
3 years ago
Victor Julien e250ef6402 debug: remove empty header 3 years ago
Eric Leblond debdff0375 detect/tls: fix descriptions
Most keywords were presented as content modifiers when they
were in fact sticky buffers.
3 years ago
Philippe Antoine eb189e805a src: use u8_tolower everywhere
Ticket: 4516

Instead of basic to_lower to get the cast to avoid warning
about integer

Sames goes for u8_toupper
4 years ago
Jeff Lucovsky 1eeb96696b general: Cleanup bool usage 4 years ago
Victor Julien 13cebb1857 detect: fix heap overflow issue with buffer setup
In some cases, the InspectionBufferGet function would be followed by
a failure to set the buffer up, for example due to a HTTP body limit
not yet being reached. Yet each call to InspectionBufferGet would lead
to the matching list_id to be added to the
DetectEngineThreadCtx::inspect.to_clear_queue. This array is sized to
add each list only once, but in this case the same id could be added
multiple times, potentially overflowing the array.
5 years ago
Victor Julien 26bcc97515 detect/keywords: dynamic version part of doc URL 5 years ago
Jeff Lucovsky be4c6b85de general: Convert _Bool to bool
This commit addresses task 3167 and changes usages of '_Bool` to `bool`.
The latter is included from `suricata-common.h`
6 years ago
Victor Julien 0771eb1e0e detect/ja3: print error for one rule only
Use 'silent error' logic for any other rules using ja3 as well.
6 years ago
Victor Julien ca5226f0c7 tls/ja3: try to enable ja3 if rule keywords need it 6 years ago
Mats Klepsland a4471987ba app-layer-ssl: generate JA3S fingerprints
Generate JA3S fingerprints based on fields in the ServerHello record.
6 years ago
Mats Klepsland 74a7b7e3cf detect-tls-ja3-hash: move unittests to tests/ 6 years ago
Mats Klepsland 12d37b8b2c detect-tls: tidy up unittests
By doing the following:
- removing unnecessary locks
- moving variable declarations
- removing redundant function 'SigCleanSignatures'
6 years ago
Mats Klepsland 15012fc908 ja3: check if JA3 is disabled on one line 6 years ago
Mats Klepsland 285855d928 detect-tls: remove NULL settings from keyword registration 6 years ago
Mats Klepsland 008f08c1b3 detect-tls: declare ssl_state as const in GetData() 6 years ago
Mats Klepsland 0f7f35bd85 detect-tls: check return values of functions on setup
Check the return values of DetectBufferSetActiveList() and
DetectSignatureSetAppProto().
6 years ago
Mats Klepsland 1c04d7cdae detect-tls: remove confusing underscores from variables
Remove confusing underscore prefix from variables in GetData() for
all tls keywords.
6 years ago
Jeff Lucovsky 7f102d95b6 detect: Modernize TLS keywords
This changeset adds keywords for "tls.<name>" and moves the existing
value of "tls_<name>" to an alias.
6 years ago
Eric Leblond 8c1b16e22d doc: fix some links in list-keywords command 7 years ago
Victor Julien 0b3220a0df detect: improve inspect buffer handling
Fix and Optimize cleanup. For the simple single inspect buffer optimize
the cleanup by keeping track of the actually used buffers. This avoid
looping over unused buffers.

Fix the case of cleaning not being done after a tx if the next tx is
also inspected in the context of the same packet.

Fix cleanup of the multi-inspect buffers. Optimize in 2 ways. First
like with single keep track of which multi-inspect buffers have been
used. Second, keep a max of the buffers within a multi-inspect buffer.
Use this max to limit (nested) looping.
7 years ago
Mats Klepsland 16643befe7 detect-tls-ja3-hash: add another unit test
Add unit test that covers the JA3 bug in TLS extensions decoding.
7 years ago
Mats Klepsland f36d578ee0 detect-tls-ja3-hash: add setup callback to lowercase content
Add setup callback that lowercase the content that follows 'ja3_hash'.
7 years ago
Mats Klepsland 5b954212f7 detect-tls-ja3-hash: add warning if nocase is used 7 years ago
Mats Klepsland 4c9d448fa1 detect-tls-ja3-hash: add content validation callback
Validate that the content that follows the 'ja3_hash' keyword has
the correct length.
7 years ago
Mats Klepsland 6c7aacce9e detect: add (mpm) keyword ja3_hash
Match on JA3 hash using ja3_hash keyword, e.g:

alert tls any any -> any any (msg:"JA3 hash test";
        ja3_hash;
        content:"e7eca2baf4458d095b7f45da28c16c34";
        sid:1;)
8 years ago