Commit Graph

1255 Commits (41dfa01e5fe98831a8a40c0bc17b95e5f8a2c09e)

Author SHA1 Message Date
Juliana Fajardini 747979c9ef docs: note about no config action support in fw mode
For Threat Detection rules

Part of
Ticket: #9041

(cherry picked from commit 98e205be0b)
1 week ago
Juliana Fajardini 9b73aef3a6 docs: note about no support of config kw in fw mode
For Threat Detection rules.

Part of
Ticket: #9041

(cherry picked from commit 4badfd13f4)
1 week ago
Lukas Sismis 6ac6a4e86a firewall: reject flow scope for the pre-flow hook
Action scopes for packet hook default policies were validated per hook
class, so `flow` was accepted for every packet hook. The pre_flow hook is
a special case as it is evaluated before Suricata obtains a flow record.
Firewall rules on the pre_flow hook were not validated at all, so `flow`
and `tx` scopes were accepted there as well.

This commit adds extra validation to scope parsing for the pre_flow
hook default policy and validates pre_flow firewall rules against the
same scopes.

Backport adaptation: the `suricata.yaml.in` hunk is left out, as the
8.0.x yaml has no `firewall.policies` example to extend.

Ticket: 8968
(cherry picked from commit a329e0a3b9)
1 week ago
Jason Ish 7be565ce06 doc: add ai tool guidelines to contribution guide
(cherry picked from commit d13d861d4e)
1 week ago
Juliana Fajardini fabdb43b54 docs/thresholding: clarify keywords limitations
Some details and differences for the types were missing or inconsistent
with the code.

Ticket: #9123
(cherry picked from commit 42d6aeada3)
3 weeks ago
Victor Julien 0362baf024 nfs: enforce max read/write queue size and count limits
Bound the per-file-transaction OOO queue, mirroring SMB: add
max-{read,write}-queue-{size,cnt} (0 disables, default 64 MiB / 64),
raise a queue event on overflow, and skip the truncated record's
remainder from the stream.

Ticket: #8791.
(cherry picked from commit b8aeaebcbd)
1 month ago
Giuseppe Longo c95ff7f54a swf: validate configured depth limits
SWF depth settings were previously limited only to values representable by
uint32_t. This is not sufficient for the buffer-size calculations performed
during SWF decompression.

The decompressed output requires an additional 8-byte FWS header. The
inspection buffer also grows by doubling a uint32_t size, so a required buffer
larger than 2 GiB can cause the growth calculation to wrap.

For LZMA input, a synthesized 13-byte header to the compressed
data is used. The configured compressed-data limit must leave room for this header.

This patch applies the following upper limits:

- decompress-depth: 2147483640 bytes
  (2 GiB minus the 8-byte FWS header)
- compress-depth: 4294967282 bytes
  (UINT32_MAX minus the 13-byte LZMA header

Ticket: #8914
(cherry picked from commit ae4341eb5f)
2 months ago
Giuseppe Longo 2be225662e swf: ignore FileLength when sizing output
SWF FileLength was used to determine the decompressed buffer size when
decompress-depth is set to zero, but this field can be manipulated and it can
lead to evasion.

This patch treat FileLength as metadata, the length bytes are just copied, and
when decompress-depth is set to 0, a maximum value of 50MB is considered for
the decompressed buffer.

Ticket: #8855
(cherry picked from commit e707b21e21)
2 months ago
Juliana Fajardini 9015bd3faa doc/configuration: add section about max-responses
Covering LDAP and PGSQL, and a brief overall explanation.

Part of
Ticket: #7263

(cherry picked from commit 30824032cf)
2 months ago
Juliana Fajardini 566861b97c doc/eve-format: document row_description fields
Add the pgsql.response fields: row_description_malformed and
field_count to the list, as they're relevant to the patch at hand.

Part of
Ticket: #8885

(cherry picked from commit a27c663de8)
2 months ago
Shivani Bhardwaj e7cf632588 mqtt: change the logging type of user properties
MQTT5 logs user properties wherein a user can send any metadata
over the wire in the form of key-value pairs.
MQTT logger used these key-value pairs directly to populate the common
"properties" field. But we do not want to use arbitrary json keys
(which may contain arbitrary characters)

1. A fixed new child object to the common "properties" called
   "user_properties" which carries a list of dicts.
2. Each key-value pair received as a part of the user properties is now
   saved as:

"properties": {
    ...
    "user_properties": [{"key": "mykey", "value": "myvalue"}]
    ...
}

instead of:

"properties": {
    ...
    "key": "value"
    ...
}

Ticket: 8785
(cherry picked from commit 9dfc132e33)
2 months ago
Jeff Lucovsky d727271202 doc/pcre: note that flow captures need a flow
Add a note to the pcre extraction section stating that a flow: capture
is dropped when the packet is inspected without a flow, and that such a
packet still alerts.

ICMPv4 error messages are one way to get such a packet: FlowCreateCheck
returns false for them, while DecodeICMPV4 has already set p->payload,
so they reach the detection engine with something to inspect and nowhere
to store a flow variable. A packet the flow engine could not give a flow
to once the memcap was reached and no used flow could be reclaimed is
the other.

The pkt: and alert: scopes described in the same section are unaffected,
because a packet variable is stored on the packet and an alert variable
on the alert.

Issue: 8862
(cherry picked from commit c717cc1e9b)
2 months ago
Yash Datre b800ace56f detect: add tcp.session keyword for unified TCP lifecycle matching
Introduce the tcp.session: keyword that accepts a comma-separated subset
of {setup, established, closing} and matches packets whose TCP session
state falls within the named phases.

This lets a rule writer cover the full TCP lifecycle in one rule instead
of separate flow:not_established + flow:established rules.

Changes:
- New detect-tcp-session.{c,h} with parser, match function, unit tests
- Register DETECT_TCP_SESSION in detect-engine-register.{c,h}
- Add to Makefile.am source list
- Extend engine-analyzer text output for tcp.session:
- Extend firewall.json keyword_info with tcp_session phase values
- Update flow-keywords.rst documentation
- Require TCP protocol and SIG_FLAG_REQUIRE_PACKET at setup

Ticket: 7704
(cherry picked from commit 398687d5d4)
2 months ago
Yash Datre 353885acc2 detect: extend app-layer-protocol to accept a pipe-separated value list
Extend the app-layer-protocol keyword to accept a pipe-separated list of
protocol values, so a single rule can match any of several protocols:

    app-layer-protocol:[!]<proto1>|<proto2>[|...][,<qualifier>]...;

A non-negated list matches when the flow's protocol equals any listed value
(OR); a negated list matches when it equals none of them (NOR). The
single-value form and the trailing mode qualifier are unchanged.

Matching keeps the historical AppProtoEquals() equivalences by default
(dns/doh2, http/http1/http2, dcerpc/smb, ...). An `exact` qualifier selects
strict identity matching with no equivalences and no http umbrella; it
combines with a direction mode in any order. Because a flow is never the
generic ALPROTO_HTTP, `http,exact` is rejected at load.

Values are expanded once at rule load into an effective match-set bitmask, so
the per-packet match is a single bitmask test. Single-value rules remain
prefilterable; multi-value rules are excluded from prefiltering and an
explicit prefilter on them is rejected. Conflicting keyword combinations
(duplicate or overlapping negations, mixed positive/negated) are rejected at
load. Engine-analysis reports the effective match set.

Ticket: 7705
(cherry picked from commit 43bc2db41e)
2 months ago
Philippe Antoine 51a6e69b4e rfb: limit strings length
Ticket: 8731

Adds a configurable limit to string lengths to avoid to retain
too much memory for too long, and avoid producing log events
that are too big

(cherry picked from commit f9515dc71d)
2 months ago
Lukas Sismis 4ca257b612 fw: document config action in FW mode
(cherry picked from commit 3f0d99d9c2)
2 months ago
Lukas Sismis d8cd5224c8 doc: update Rust installation instructions
Rust website has changed the location of the installer.
Additionally their installer now includes automatic append to
.bashrc to source the correct path to Rust binaries.

Cbindgen as an instruction is also removed as it is not needed
when building from the downloaded and packaged Suricata.

Ticket: 8344
(cherry picked from commit d7bf52e71c)
2 months ago
Jeff Lucovsky d22b91c451 doc/bytemath: document the result of wide shifts
Record beside the existing note about division by zero that << and >>
give 0 when rvalue is 64 or more, that a rule giving such an rvalue as
a number still loads with a warning, and that --strict-rule-keywords
makes it fail to load instead. rvalue can name a byte_extract or
byte_math variable rather than a number, and then the count is not
known until the rule runs, so the rule text does not say whether it
will reach 64.

The note on main stops at the result, because 89d09c457c rejects such
a rule there instead of warning about it.

Issue: 8845
Issue: 8902
(cherry picked from commit 4a647784c7)
2 months ago
Lukas Sismis efc82a67cb firewall: add default-policy to policy config
Every hook has a built-in default policy, but expressing anything other
than the built-in meant naming each hook explicitly.
This commit adds a `default-policy` setting that covers all hooks below it.
For any hook the most specific setting present wins.

Ticket: 8770
(cherry picked from commit 0aaa80d4f3)
2 months ago
Victor Julien df5c638251 firewall: add firewall.policies.accept-arp option
Add a minimal, non-intrusive config option firewall.policies.accept-arp
to allow ARP packets to be accepted in firewall mode without requiring
ARP detection rules. Default is false to preserve current behavior.

Ticket: #8314.
2 months ago
Lukas Sismis 9b63a588d7 detect/firewall: group policies under packet and app nodes
The policy config was a flat map mixing packet hooks and app-layer
protocols: `packet-filter` next to `dns`. There was no node that meant
"the packet hooks" or "the app-layer hooks", so a setting could not be
scoped to one group.

Move each group under its own node:

    packet-filter     -> packet.filter
    packet-pre-flow   -> packet.pre-flow
    packet-pre-stream -> packet.pre-stream
    <proto>.<hook>    -> app.<proto>.<hook>

Ticket: 8770
(cherry picked from commit b82b4496af)
2 months ago
Lukas Sismis 716f2958a0 detect/firewall: address HTTP/1 policies as http1
AppProtoToString(ALPROTO_HTTP1) returns "http", so an HTTP/1 policy had to
be written as `http:` while its rule hooks were already spelled `http1:`.
Use the same name in both places.

Ticket: 8770
(cherry picked from commit 04c9fd9e22)
2 months ago
Antoine Abou Faysal 1ca2b9188a doc/userguide: add dataset match subdomain documentation
Ticket: 8385
(cherry picked from commit b09b04857a)
2 months ago
Philippe Antoine 15bf91c5cc ftp: do not create more than max-tx transactions
Ticket: 8592

Fixes: 5ddd808e9b ("ftp: don't halt the flow when raising
too_many_transactions")

In the case we receive a big chunk of TCP data, we end up
creating much more than max-tx transactions, and have
quadratic complexity on this packet, even if all
these transactions get cleaned up at the end of the processing
of this packet.

(cherry picked from commit 82c4190558)
4 months ago
Jason Ish 0e650766b5 ftp: support STOU data transfers
Support STOU on the FTP data channel.

With STOU a filename is optional. If no filname is provided, use
"<stou>". The server does respond with the filename to use, but there
can be a race condition in getting this filename and setting up file
storage before data starts flowing.

Ticket: #8664
(cherry picked from commit f59960d42b)
4 months ago
Jason Ish c729bddc1e ftp: support APPE data transfers
Support the APPE (append) command on the ftp data channel. Like STOR,
APPE uploads file content on the data channel.

Ticket: #8664
(cherry picked from commit e65bf4c905)
4 months ago
Jason Ish c95c99b83b ftp: support LIST and MLSD data channels
Support LIST and MLSD on the ftp data channel.

Ticket: #8664
(cherry picked from commit 5856ced29c)
4 months ago
Samaresh Kumar Singh 6bcf958e20 pcap-file: skip setvbuf on non-seekable streams
Reading a pcap from /dev/stdin or a named pipe currently fails with "failed to get first packet timestamp. pcap_next_ex(): -1" because InitPcapFile calls setvbuf on the FILE* underlying the pcap handle after libpcap has already consumed the pcap header. On a non-seekable fd glibc cannot recover from that and the next read returns -1.

Detect non-regular files via fstat and skip setvbuf in that case so the read keeps working on pipes, fifos and stdin.

Accept pcap-file.buffer-size values of 0, which disables setvbuf buffering as an explicit opt-out, or PCAP_FILE_BUFFER_SIZE_MIN (4 KiB) to PCAP_FILE_BUFFER_SIZE_MAX (64 MiB). Treat any non-zero setvbuf return value as an error, not just negative values.

When pcap-file.buffer-size fails to parse, retain the default buffer size instead of falling through and setting it to 0. The branches are now mutually exclusive so only one of the parse-error, accepted, or out-of-range messages is logged.

Update the user guide: --pcap-file-buffer-size now documents valid values of 0 (disables setvbuf buffering) or 4 KiB to 64 MiB, and pcap-file.rst notes that 0 is the opt-out for non-seekable sources such as stdin and named pipes.
Bug: #8464.

(cherry picked from commit 565e138754)
4 months ago
Shivani Bhardwaj 36fb9ae59a flowbits: add deprecation notice for toggle command
Task 8638
4 months ago
Andreas Dolp 3e4bc398ae doc: improve manpage of suricatasc
- describe all options
- describe optional socket path

Redmine ticket: #8563

(cherry picked from commit 2f972b6759)
4 months ago
Victor Julien 48ab24cba8 doc/userguide: add new constructs to firewall examples
(cherry picked from commit 0a84015214)
5 months ago
Victor Julien 05b9fd6969 doc/userguide: document firewall lte rule support
(cherry picked from commit 8728f9ffc0)
5 months ago
Victor Julien 166707f2f2 doc/userguide: fix default policies for pre_* hooks
Minor other cleanups.

(cherry picked from commit ac59883c26)
5 months ago
Victor Julien b0004fb7e1 doc: update firewall design
Bring in line with recent changes.

(cherry picked from commit da6af0879e)
5 months ago
Victor Julien 08376ae63a detect/firewall: update discarded logic
Only count alert queue overflow here, not alerts in the queue after a drop.

(cherry picked from commit 90a837cef3)
5 months ago
Juliana Fajardini d950432d2e docs: add firewall stats doc
Related to
Ticket #7699

(cherry picked from commit 234172a93c)
5 months ago
Juliana Fajardini 1664b0960e docs/configuration: add firewall mode settings
Partly related to
Ticket #7699

(cherry picked from commit 32d89072d2)
5 months ago
Philippe Antoine 82cf3d67b1 ldap: bound the number of responses
Ticket: 8405
(cherry picked from commit e98d419d96)
5 months ago
Jason Ish 53e594ef46 ntp: expose logged fields to lua
This includes:
- version
- mode
- stratum
- reference_id

Ticket: #8533
(cherry picked from commit 899e9f045e)
5 months ago
Jason Ish 587e4871b8 ntp: convert reference_id to buffer and add keyword
Store the NTP reference ID as raw network-order bytes so it can be
exposed as a sticky buffer and matched with payload keywords. The
reference ID is often a 4 character string, or an IP address and not
just an integer identifier.

Updates the log reference ID to be a string of colon separated hex
digits as this matches what tshark does.

Ticket: #8488
(cherry picked from commit 713e4eb900)
5 months ago
Jason Ish 2a9a57378c ntp: add ntp.mode keyword
This keyword also accepts strings for known mode names.

Ticket: #8429
(cherry picked from commit 991e7f3b1d)
5 months ago
Jason Ish 545070ad61 ntp: add ntp.stratum keyword
Ticket: #8431
(cherry picked from commit c10c482290)
5 months ago
Jason Ish 4f427c30be ntp: add ntp.version keyword
SNMP was used as a template.

Ticket: #8430
(cherry picked from commit ec344fe68d)
5 months ago
Jason Ish fd742034a6 ntp: add transaction logging
Adds basic NTP transaction logging for the current supported message
types.

Includes small cleanups around reference ID.

Ticket: #8425
(cherry picked from commit 31b967b089)
5 months ago
Jason Ish 1a09a059dc eve: add rule generation source to alert record
When an alert is generated from firewall context, add an engine value of
"fw", otherwise "td" (for threat detect).

The engine field is only added when firewall mode is enabled.

Ticket: #8456
(cherry picked from commit 029fd1be59)
6 months ago
Jeff Lucovsky 2841bcf330 doc/config: Update flushing description
Update output flushing description to reflect EVE based approach in
documentation and config template.

Added: Provide update callout for out-of-tree output plugins.

Issue: 8286
(cherry picked from commit e7dc0d885b)
6 months ago
Victor Julien 7f7ab9299c detect/snmp: add snmp.trap_type keyword
Implemented as a U8 integer keyword.

Ticket: #8482.
(cherry picked from commit 670fdabd32)
6 months ago
Lukas Sismis e0f2cdf7c3 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: 7893
(cherry picked from commit 15c83be61a)

hs: suppress TOCTOU stat use

To explain a bit more the TOCTOU issue found, we can consider
a case where Suricata starts to prune, yet externally somebody also
starts erasing cache files.
Right after Suricata checks the file age with the stat function,
somebody may delete or update the file of our interest.

Suricata aging decision doesn't reflect the actual state of the file.
This commit additionally adds a check for noent failure of the unlink operation
(considered as a success). The code can still delete a file that is recently
updated but was considered stale.

In the documentation-following deployments this should not happen anyway as
one cache folder should only be used by a single Suricata instance (and within
Suricata instance only one thread handles cache eviction).
Additionally, the `stat` and `unlink` command are immediatelly followed, making
this scenario extra unlikely.

Additional comment in the code explains problems of using fstat and potential
issues on Windows.

Ticket: 8244
(cherry picked from commit 0fe0390a2f)

hs/cache: cleaner and more detailed output

Reduce logging level of a minor informational message.

Split tracking of pruning by age and by version and log those
separately, where the logging only appears if something has been
removed.

Ticket: 8323
(cherry picked from commit 569ba3d26f)

hs: remove redundant file handle in HSLoadCache

HSLoadCache opened the cache file but never used the resulting handle
for reading. The actual read was done by HSReadStream which opened
the same file independently.

Removed the unused fopen/fclose pair and flattened the control flow.

Ticket: 8326
(cherry picked from commit d754b28717)

hs: use binary mode for cache file I/O

HSSaveCache wrote serialized Hyperscan databases using text mode ("w")
while HSReadStream already read them with binary mode ("rb").
Matched file reading modes to the binary format and simplified
write-size check.

Ticket: 8326
(cherry picked from commit 0cdc77b707)

hs: warn about the same cache directory

This is especially relevant for multi-instance simultaneous setups
as we might risk read/write races.

(cherry picked from commit 56c1552c3e)

hs: validate cached database against current HS installation

After deserializing a cached Hyperscan database, verify that its
version, CPU features, and mode match the current Hyperscan
installation by comparing hs_database_info output against a
reference database. Reject loading incompatible caches.

Ticket: 8326
(cherry picked from commit 2e7b12dda4)

hs: include HS platform info in cache file hash

Hash Hyperscan installation info (version, CPU features, mode)
into the cache filename. A Hyperscan upgrade or platform change
would now produce a different filename, so stale caches from an
older installation are never opened.

Ticket: 8326
(cherry picked from commit d640719413)

hs: address coverity warning in a reference string

Move the locking mechanism outside of the getter function and hold the
lock until the reference string is no longer reused.

** CID 1682023:       Concurrent data access violations  (MISSING_LOCK)
/src/util-mpm-hs-cache.c: 139           in HSGetReferenceDbInfo()

(cherry picked from commit 6ec9e5c957)
8 months ago
Philippe Antoine 354d0b2a5c doc/stream: explain absent reassembly.depth means unlimited
Ticket: 8343
8 months ago
Philippe Antoine 984c69b5d6 doc: be more precise for decompress transforms
Ticket: 7846
(cherry picked from commit 1e0f344ab7)
8 months ago