Commit Graph

1243 Commits (b800ace56fb08c29aadb0f68a3bad1fe3e4a0d67)

Author SHA1 Message Date
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)
4 days 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)
4 days 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)
4 days ago
Lukas Sismis 4ca257b612 fw: document config action in FW mode
(cherry picked from commit 3f0d99d9c2)
4 days 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)
1 week 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 weeks 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 weeks 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 weeks 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)
3 weeks 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)
3 weeks ago
Antoine Abou Faysal 1ca2b9188a doc/userguide: add dataset match subdomain documentation
Ticket: 8385
(cherry picked from commit b09b04857a)
3 weeks 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)
2 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)
2 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)
2 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)
2 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)
3 months ago
Shivani Bhardwaj 36fb9ae59a flowbits: add deprecation notice for toggle command
Task 8638
3 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)
3 months ago
Victor Julien 48ab24cba8 doc/userguide: add new constructs to firewall examples
(cherry picked from commit 0a84015214)
3 months ago
Victor Julien 05b9fd6969 doc/userguide: document firewall lte rule support
(cherry picked from commit 8728f9ffc0)
3 months ago
Victor Julien 166707f2f2 doc/userguide: fix default policies for pre_* hooks
Minor other cleanups.

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

(cherry picked from commit da6af0879e)
3 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)
3 months ago
Juliana Fajardini d950432d2e docs: add firewall stats doc
Related to
Ticket #7699

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

(cherry picked from commit 32d89072d2)
3 months ago
Philippe Antoine 82cf3d67b1 ldap: bound the number of responses
Ticket: 8405
(cherry picked from commit e98d419d96)
4 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)
4 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)
4 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)
4 months ago
Jason Ish 545070ad61 ntp: add ntp.stratum keyword
Ticket: #8431
(cherry picked from commit c10c482290)
4 months ago
Jason Ish 4f427c30be ntp: add ntp.version keyword
SNMP was used as a template.

Ticket: #8430
(cherry picked from commit ec344fe68d)
4 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)
4 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)
4 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)
4 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)
5 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)
6 months ago
Philippe Antoine 354d0b2a5c doc/stream: explain absent reassembly.depth means unlimited
Ticket: 8343
6 months ago
Philippe Antoine 984c69b5d6 doc: be more precise for decompress transforms
Ticket: 7846
(cherry picked from commit 1e0f344ab7)
6 months ago
Jason Ish f2def20eb1 doc: add more public datasets
Add:
- UNSW-NB15
- CIC-IDS2017
- CSE-CIC-IDS2018
- CIC-DDoS2019

Update formatting for better display.

(cherry picked from commit 66473f6ad7)
6 months ago
Victor Julien de64874e86 doc/userguide: add missing ipopts values
(cherry picked from commit 7e6fd09e90)
6 months ago
Victor Julien 046ee16062 doc: fix dcerpc.opnum documentation
Docs were claiming greater than, less than, etc. support even though this was never supported.

Fixes: 51be8f0238 ("doc/dcerpc: add proto keywords")

Ticket: #8330.
(cherry picked from commit 2480f8c038)
6 months ago
Sven Cuyt 1b504d0650 doc/userguide: add link to differences-from-snort
Ticket: #8031.
(cherry picked from commit 1246f1cf8c)
7 months ago
Sven Cuyt 8dd1653e91 doc/userguide: fix table showing example payload
Ticket: #8031.
(cherry picked from commit a0cc534471)
7 months ago
Sven Cuyt f83b169d4a doc/userguide: add example with non-zero offset for relative isdataat
Ticket: #8031.
(cherry picked from commit 2d662538e5)
7 months ago
Victor Julien abd08a21c8 doc/userguide: explain isdataat absolute vs relative difference
Ticket: #8031.
(cherry picked from commit 7c5285e5e6)
7 months ago
Juliana Fajardini fbd2832c81 userguide: fix Deprecations, warn about syslog
The Deprecation note on Syslog was partly conveying the opposite
message, and we were missing a deprecation notice on the Syslog output
section.

(cherry picked from commit 926fde859e)
7 months ago
Philippe Antoine 254ba73e65 detect/transforms: add zlib_deflate transform
Ticket: 7846
(cherry picked from commit 539e4ee665)
7 months ago
Philippe Antoine 609a289e46 detect/transforms: add gunzip transform
Ticket: 7846
(cherry picked from commit dbea660729)
7 months ago
Jason Ish 49a418df46 userguide/Makefile: don't add "install" to EXTRA_DIST
Adding the directory "install" to EXTRA_DIST, actually triggers make
to run "make install", which is not what we want. Instead, avoid this
magic keyword and list the files in the install directory
individually.

If the user doesn't have permission to install files to the prefix,
like "/usr", then "make dist" can fail. Worse, even they do have
permission to write into the prefix, a "make dist" will install files
there when it shouldn't.

Ticket: #8279
(cherry picked from commit 2defd5ae5a)
7 months ago
Juliana Fajardini c8e2301922 devguide: add chapter about exception policies
Adds a chapter indicating what are the main steps when adding exception
policies, how is it possible to extend them, as well as main aspects and
files to consider when doing so.

Task #5612

(cherry picked from commit 48b15ac152)
7 months ago