Commit Graph

18437 Commits (15c83be61ac3f47bf198fe24eb908db5a84b7ccd)
 

Author SHA1 Message Date
Lukas Sismis 15c83be61a hs: prune stale MPM cache files
Hyperscan MPM can cache the compiled contexts to files.
This however grows as rulesets change and leads to bloating
the system. This addition prunes the stale cache files based
on their modified file timestamp.

Part of this work incorporates new model for MPM cache stats
to split it out from the cache save function and aggregate
cache-related stats in one place (newly added pruning).

Ticket: 7830
3 months ago
Lukas Sismis 08f5abe5e9 detect-engine: make mpm & spm part of MT stub ctx
As a intermediary step for Hyperscan (MPM) caching,
the MPM config initialization should be part of the default
detect engine context for later dynamic retrieval.

Ticket: 7830
3 months ago
Lukas Sismis 7031c26865 hs: touch cache files on use to signal activity
Ticket: 7830
3 months ago
Lukas Sismis fd3847db72 path: signal last use of the file (touch)
To have a system-level overview of when was the last time the file was
used, update the file modification timestamp to to the current time.

This is needed to remove stale cache files of the system.

Access time is not used as it may be, on the system level, disabled.

Ticket: 7830
3 months ago
Lukas Sismis 85f0382072 conf: add time parsing conf function 3 months ago
Lukas Sismis 3e4fdb2118 misc: time unit parsing function 3 months ago
Lukas Sismis c282880174 hs: change hash in the cache name to SHA256 3 months ago
Lukas Sismis 2a313ff429 hs: reduce cache filename size to max file limit 3 months ago
Lukas Sismis 47fc78eeae hs: update the file description 3 months ago
Philippe Antoine 251d10fa42 util-spm-hs: add missing deallocator
Add missing deallocator when hs_alloc_scratch fails.

Bug: #8146
3 months ago
Sergey Zhidkih 799f01f78f util-spm-hs: add missing deallocator
Add missing deallocator for expr when hs_compile fails.

Bug: #8146
3 months ago
Sergey Zhidkih 11073a0190 hyperscan: move error logging for hs_compile
Move error logging from util-mpm-hs to reuse it in util-spm-hs as it
has proper hs_compile error handling.

Bug: #8146.
3 months ago
Philippe Antoine 5bb9a0c3af dcerpc/tcp: fix fragmentation handling
Really count the fragments, and set it done when last was received
3 months ago
Philippe Antoine f64aec9d11 dcerpc: use different header for different directions
Header handling is wrong in the case
packet A to server is fragmented (return AppLayerResult::incomplete)
packet B is to client, but uses the header of the to_server packet

Bug 7547
3 months ago
Philippe Antoine 1832b50506 nfs: log read/write/rename whatever the nfs version
These were previously logged correctly only for nfs v3

Now, the correct opcodes are used for v2 and v4 as well

Ticket: 8222
3 months ago
Victor Julien c20c7c1dfa detect/content: pretty print pattern directly 3 months ago
Philippe Antoine 374c191268 detect/port: fix use-after-free in case of alloc failure
If recursive call to DetectPortInsert (in case DetectPortCut returned
a c != NULL) failed, we had successfullt inserted `new` but
we return error, leading to freeing DetectPort `new` in
DetectPortParseInsertString but it
will be freed again by DetectPortCleanupList from DetectPortParse

Ticket: 6187
3 months ago
Philippe Antoine fcec08a178 detect/port: remove unused variable 3 months ago
Philippe Antoine 83acf3ca53 detect: remove unset flag PORT_FLAG_ANY 3 months ago
Victor Julien d1c16a0cc8 spm/bs: use memmem when available
Memmem is generally much more optimized.
3 months ago
Victor Julien ddfeef2897 spm: add mm, a memmem based spm
Wrapper around `memmem`.

The case sensitive search is implemented by directly calling `memmem`.

As there is no case insensitieve variant available, a wrapper around
memmem is created, that takes a sliding window approach:

1. take a slice of the haystack
2. convert it to lowercase
3. search it using memmem
4. move window forward
3 months ago
Victor Julien 73a873ecfe doc/userguide: endswith can be mixed with offset/distance/within
Bug: #5030.
3 months ago
Victor Julien 2a2b98650b firewall: fix rules not loading w/o commandline opts
Firewall rules were supposed to also load when using a config like

        ##
        ## Suricata as a Firewall options (experimental)
        ##
        firewall:
          # toggle to enable firewall mode
          enabled: yes

          # Firewall rule file are in their own path and are not managed
          # by Suricata-Update.
          rule-path: /etc/suricata/firewall/

          # List of files with firewall rules. Order matters, files are loaded
          # in order and rules are applied in that order (per state, see docs)
          rule-files:
            - firewall.rules

But they were not because of a missing check.

Bug: #8206.
3 months ago
Philippe Antoine dd6baccabd src: doc: remove more double-space typos
Found with git grep -E '[a-z]  [a-z]'
3 months ago
Juliana Fajardini a1f088cc65 docs: use correct suricata version mentions
Found with 'git grep suricata-7'

Task #8113
3 months ago
Philippe Antoine feea984872 app-layer: test bypass set for udp
Ticket: 8116

quic parsing on udp can request bypass.
But such a bypass was only handled for TCP protocols in
AppLayerParserParse
3 months ago
Philippe Antoine b0850efd67 rust: from_str implementation for EncryptionHandling
To move non-specific quic code to the right place
3 months ago
Philippe Antoine 89b6ab6730 rust: rename EncryptionHandling
as it is no longer specific to SSH
3 months ago
Philippe Antoine 7acfea57a9 rust: move EncryptionHandling definition to its own file
as it is not specific to ssh anymore
3 months ago
Philippe Antoine 7422c97bf2 quic: encryption-handling config parameters
Ticket: 8116
3 months ago
Victor Julien 844f6011b1 datasets: fix compile warnings
datasets-string.c:53:20: error: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Werror,-Wshorten-64-to-32]
        return len + 2;
        ~~~~~~ ~~~~^~~
1 error generated.
3 months ago
Victor Julien ff3def130c rust/htp: formatting fixup 3 months ago
Victor Julien b1fe6a4ceb rust: update lru to 0.16.3; update lock
RUSTSEC-2026-0002

Ticket: #8210.
3 months ago
Philippe Antoine a48200b9e5 dcerpc: use saturating_add to count fragments
And do not overflow if we have traffic with more than 65K fragments
3 months ago
Shivani Bhardwaj 6702791a9c doc: add dcerpc.max-stub-size config param 3 months ago
Shivani Bhardwaj e412215af9 dcerpc: add upper limit on stub data
DCERPC parsers had no upper bounds when it came to extending the stub
data buffer. Traffic can be crafted to bypass some internal parser
conditions to create an indefinite buffering in the stub_data array that
can make Suricata crash.

Add a default limit of 1MiB and make it configurable for the user.

Security 8182

Co-authored-by: Philippe Antoine <pantoine@oisf.net>
3 months ago
Jason Ish 2c95f1ff44 dnp3: bound the maximum number of objects per tx
Default to 2048, but provide a user configuration value.

Ticket: #8181
3 months ago
Jason Ish 3a32bb5743 dnp3: set a bound on the number of points per message
16384 is used as the max, but a configuration parameter has been
provided. The reason for setting an upper bound is that bit flags can
create a memory amplification as we parse them into individual data
structures.

Ticket: #8181
3 months ago
Jason Ish a16f087b93 dnp3: reduce flood threshold to 32 and make configurable
Lower the number of unreplied requests from 500 to 32 to consider a
flood. At the very least this is an anomaly given the DNP3 spec mentions
that DNP3 should only have one outstanding request at a time, with an
exception for unsolicited responses, so in practice no more than 2
should be seen.

Additionally make this value configurable by introducing the max-tx
parameter.

Ticket: #8181
3 months ago
Jason Ish d61eef9a8a dnp3: check done state, not complete state for progress
Complete is a flag used to tell if the message was completely parsed,
as not all messages may be completely parsed if we don't know all
their objects. However, they are still "done".

In the alstate-progress callback, check the done flag, not the
complete flag.

Ticket: #8181
3 months ago
Philippe Antoine fa5a4a994a http: limit the number of folded lines per header
Ticket: 8201

Limits the quadratic complexity if each packet, restarting the
header parsing, just adds a new folded line.
This was previously bounded by the configurable max header length
3 months ago
Shivani Bhardwaj ac1eb39418 detect/alert: check alert queue capacity before expanding
So far, the alert queue was expanded by doubling in size w/o any
boundary checks in place. This led to situations where doubling
the alert_queue_capacity meant overflow of the very same value
stored in det_ctx.
This led to heap-use-after-free in some conditions where
det_ctx->alert_queue_capacity overflowed.

Fix this by capping the max of alert_queue_capacity by checking if its
expansion could result in an overflow.

Security 8190
3 months ago
Philippe Antoine f2a45c4216 http: do not use recursion in decompression
just loop and iterate

Ticket: 8185
4 months ago
Philippe Antoine ab2e128176 output: use tx iterator for finding alert http xff
Ticket: 8156

Allows better performance.
4 months ago
Philippe Antoine 3b1a6c1711 output: optimize loop for finding alert http xff
Ticket: 8156

In case of non-tx alerts, we try to loop over all the txs to find
the xff header. Do not start from tx_id 0, but from min_id
as AppLayerParserTransactionsCleanup to skip txs that were freed
4 months ago
Philippe Antoine d6bc718e30 datasets: allocates on the heap if string base64 is long
Ticket: 8110
4 months ago
Philippe Antoine 0eff242137 datasets: explicitly errors on too long string
Also avoids stack allocation

Ticket: 8110
4 months ago
Shivani Bhardwaj 1d7b0d9b7a tls/subjectaltname: use byte arr instead of string
TLS parsers use x509-parser crate which parses X.509 certificates that
use ASN.1 DER encoding that can allow arbitrary byte sequences. An
attacker could inject null byte in a certificate anywhere to stump the
common language parsers terminating the string at a null byte leading to
a bypass of a possibly malicious certificate.

So far, the rust TLS parser for "subjectaltname" used a pattern that involved:
-> Get ASN.1 DER encoded raw data from the x509-parser crate
-> Convert this raw data to a decoded string (Rust)
-> Convert the Rust string to CString
-- The problem lies here. CString only accepts proper strings/byte
buffers and converts it into an owned C-compatible, null-terminated
string. However, if any null byte occurs in the string passed to the
CString then it panics.
In the rust TLS parser, this panic is handled by returning NULL.

This means that the parser will error out during the decoding of the
certificate. However, Suricata must be able to detect the null byte
injection attack being an IDS/IPS.

Hence, replace all such string patterns w.r.t. TLS SAN with a byte
array.

Bug 7887
4 months ago
Shivani Bhardwaj 9c3ed7d31c tls/sni: use byte array instead of string
Bug 7887
4 months ago
Shivani Bhardwaj 24f5b7dab2 tls/serial: use byte array instead of string
Bug 7887
4 months ago