Commit Graph

1649 Commits (3bc2a14fbfefddbfc241bf6d961a57c3b24835a3)

Author SHA1 Message Date
Philippe Antoine 5c93291565 rust: generated bindings depend on cbindgen.toml
make should rerun cbindgen if cbindgen.toml is modified
1 month ago
Alice Akaki 8416289752 detect: add ldap.responses.count
ldap.responses.count matches on the number of LDAP responses
This keyword maps to the eve field len(ldap.responses[])
It is an unsigned 32-bit integer
Doesn't support prefiltering

Ticket: #7453
1 month ago
Alice Akaki da593abd99 detect: add ldap.responses.operation
ldap.responses.operation matches on Lightweight Directory Access Protocol response operations
This keyword maps to the eve field ldap.responses[].operation
It is an unsigned 8-bit integer
Doesn't support prefiltering

Ticket: #7453
1 month ago
Alice Akaki cdb043810f detect: add ldap.request.operation
ldap.request.operation matches on Lightweight Directory Access Protocol request operations
This keyword maps to the eve field ldap.request.operation
It is an unsigned 8-bit integer
Doesn't support prefiltering

Ticket: #7453
1 month ago
Alice Akaki 824c5d4f06 rustfmt: rust/src/ldap/types.rs 1 month ago
Jason Ish 5d9fad5edf rust/ssh: rustfmt 1 month ago
Jason Ish 9c87ac1b9b ssh: cleanup rust visibility and naming
Remove pub and no_mangle from non-exported functions and rename to
Rust as-needed.

Ticket: 7498
1 month ago
Jason Ish f8d27992f7 rust/ntp: rustfmt 1 month ago
Jason Ish f023b3a6f1 ntp: cleanup visibility and naming
Remove pub and no_mangle from non-exported functions and rename to
Rust as-needed.

Ticket: 7498
1 month ago
Jason Ish 4cca135793 pgsql: cleanup visibility and naming
Remove pub and no_mangle from non-exported functions and rename to
Rust style as needed.

Ticket: 7498
1 month ago
Jason Ish a7f7dc5296 rust/dhcp: rustfmt 1 month ago
Jason Ish c5089ac5f4 dhcp: cleanup visibility and naming
- remove "rs_" prefix from functions that are not exported
- prefix exported functions with "SC"
- don't export functions that are only used by pointer

Ticket: 7498
1 month ago
Jason Ish c86b2608aa rust/applayer: clean visibility of export macros
Both the macros export_tx_data_get and export_state_data_get can
generate non-pub functions as the function they generate is only used
as a pointer during registration.

Remove "pub" and "no_mangle" from the generated functions and update
the names of the generated functions to follow Rust rules as they are
no longer exported into the global C namespace.

Ticket: 7498
1 month ago
Jason Ish c93bba8e2c rust/transforms: remove no_mangle from non-pub functions
Ticket: 7498
1 month ago
Jason Ish f370afb5bd rust/ldap: cleanup no_mangle and extern C pub functions
If a function is extern "C" and not pub, remove no_mangle so its not
exposed as-is into the global name space.

Ticket: 7498
1 month ago
Jason Ish c207cfc67e rust/detect: remove nested unsafe around keyword registration
Just a cleanup, I'm not sure why Rust wasn't warning on these
nested/unneeded unsafe's.
1 month ago
Jason Ish 2bcc66da58 rust/log: move rust log and debug utils to debug module
Move Rust logging, and debug_validation to a debug module to mirrow
the C side.
1 month ago
Jason Ish f62be374ea rust/direction: move direction to own file (cleanup)
Move the implementation of Direction to its own file, direction.rs.
1 month ago
Jason Ish 7ef4caf90e rust/flow: move flow support to its own file (cleanup)
Move the Rust Flow support from core.rs to flow.rs.
1 month ago
Philippe Antoine 8f6795d049 rust: remove unneeded mut for tx in detect
Detection does not change transactions, it reads only.
1 month ago
Philippe Antoine af4e1e8888 rust: remove unneeded mut for tx in loggers
Loggers do not change transactions, they read only.
1 month ago
Philippe Antoine edfe0ccbe1 ldap: implement abandon request
Ticket: #7477
2 months ago
Philippe Antoine 770a75911f ldap: update ldap-parser crate
so that we can implement abandon request support

Ticket: #7477
2 months ago
Alice Akaki b1c2643c87 detect: add vlan.id keyword
vlan.id matches on Virtual Local Area Network IDs
It is an unsigned 16-bit integer
Valid range = [0-4095]
Supports prefiltering

Ticket: #1065
2 months ago
Philippe Antoine e6be049c5d app-layer: move ALPROTO_FAILED definition
Because some alprotos will remain static and defined as a constant,
such as ALPROTO_UNKNOWN=0, or ALPROTO_FAILED.

The regular already used protocols keep for now their static
identifier such as ALPROTO_SNMP, but this could be made more
dynamic in a later commit.

ALPROTO_FAILED was used in comparison and these needed to change to use
either ALPROTO_MAX or use standard function AppProtoIsValid
2 months ago
Philippe Antoine 6291e220e4 dns: improved handling of corrupt additionals
Ticket: 7228

That means log the rest of queries and answers, even if the
final field additionals is corrupt.
Set an event in this case.
2 months ago
Philippe Antoine 494d7bfe99 ldap: truly enforce max-tx
Ticket: 7465

If a bug chunk of data is parsed in one go, we could create many
transactions even if marking them as complete, and have
quadratic complexity calling find_request.

Proposed solution is to fail on creating a new transaction if too
many already exist.
2 months ago
Philippe Antoine fd7e2e5e9a doh2: really enforce 65K dns message limit
Ticket: #7464
2 months ago
Jason Ish 604e3c7422 rust/jsonbuilder: make set_uint generic over Into<u64>
Allow `set_uint` to accept any number value that can be converted to a
u64. Prevents callers from having to do `as u64`.

This required fixing up any callers that used `.into()` to just pass in
their value without the into conversion.

Most calls using `as u64` can have that cast removed, with the exception
of `usize` values which must still be cast is conversion can't be
guaranteed to be non-fallible.
2 months ago
Philippe Antoine 5da2b5d7a4 dns/probe: check that a request has at least one query
Ticket: 7279
2 months ago
Philippe Antoine 9b40446bea dns/probe: adds check for 0 records and big size
Ticket: 7279

Make dns probing function stricter to avoid matching on non-DNS
on port 53 and later returning a app-layer error.
2 months ago
Shivani Bhardwaj 2c0d3b83c4 dns: fix clippy lint warnings
Fix vector lint issues:
- same_item_push
- vec_init_then_push
3 months ago
Jason Ish 19cf0f8133 dns: provide events for recoverable parse errors
Add events for the following resource name parsing issues:

- name truncated as its too long
- maximum number of labels reached
- infinite loop

Currently these events are only registered when encountered, but
recoverable. That is where we are able to return some of the name,
usually in a truncated state.

As name parsing has many code paths, we pass in a pointer to a flag
field that can be updated by the name parser, this is done in
addition to the flags being set on a specific name as when logging we
want to designate which fields are truncated, etc. But for alerts, we
just care that something happened during the parse. It also reduces
errors as it won't be forgotten to check for the flags and set the
event if some new parser is written that also parses names.

Ticket: #7280
3 months ago
Jason Ish 37f4c52b22 eve/dns: add truncation flags for fields that are truncated
If rrname, rdata or mname are truncated, set a flag field like
'rrname_truncated: true' to indicate that the name is truncated.

Ticket: #7280
3 months ago
Jason Ish 3a5671739f dns: truncate names larger than 1025 characters
Once a name has gone over 1025 chars it will be truncated to 1025
chars and no more labels will be added to it, however the name will
continue to be parsed up to the label limit in attempt to find the end
so parsing can continue.

This introduces a new struct, DNSName which contains the name and any
flags which indicate any name parsing errors which should not error
out parsing the complete message, for example, infinite recursion
after some labels are parsed can continue, or truncation of name where
compression was used so we know the start of the next data to be
parsed.

This limits the logged DNS messages from being over our maximum size
of 10Mb in the case of really long names.

Ticket: #7280
3 months ago
Philippe Antoine f426ee3ee2 detect: rename stream_log variables
to better reflect their true meaning
3 months ago
Philippe Antoine b02557ac7d app-layer: track modified/processed txs
To optimize detection, and logging, to avoid going through
all the live transactions when only a few were modified.

Two boolean fields are added to the tx data: updated_tc and ts
The app-layer parsers are now responsible to set these when
needed, and the logging and detection uses them to skip
transactions that were not updated.

There may some more optimization remaining by when we set
both updated_tc and updated_ts in functions returning
a mutable transaction, by checking if all the callers
are called in one direction only (request or response)

Ticket: 7087
3 months ago
Philippe Antoine e62c7d733b rust/ftp: handle NULL inputs
Completes Ticket 7013
3 months ago
Philippe Antoine 38d7900fa9 sip: remove UPDATE method for detection
As it is also used for HTTP/1
Remove it only for TCP and keep it for UDP.

Ticket: 7436
3 months ago
Philippe Antoine b58b886db7 detect/transforms: in place modifications of buffers
As is the case when chaining multiple transforms.
Avoids using memcpy in these cases.

Add tests for these cases.

Ticket: 7409
3 months ago
Jason Ish 289ff25f5b requires: support requires check for keyword
For example:

    requires: keyword foo;

Will require that Suricata supports the "foo" keyword.

Ticket: #7403
3 months ago
Jason Ish 820a3e51b7 requires: treat unknown requires keywords as unmet requirements
For example, "requires: foo bar" is an unknown requirement, however
its not tracked, nor an error as it follows the syntax. Instead,
record these unknown keywords, and fail the requirements check if any
are present.

A future version of Suricata may have new requires keywords, for
example a check for keywords.

Ticket: #7418
3 months ago
Jason Ish 4c12165816 rust: allow static_mut_refs for now
But we should fix all these soon.
3 months ago
Jason Ish aa6e94fc73 rust/smb: fix rustdoc line
'///' style rust comments/documentation come before the item being
documented.

Spotted by clippy.
3 months ago
Jason Ish 7bdbe7ed32 rust: remove unnecessary lifetimes
Fix provided by cargo clippy --fix.
3 months ago
Jason Ish 8e408d3730 rust: update num-derive to 0.4.2
This prevents the clippy warning:

508 | #[derive(FromPrimitive, Debug)]
    |          ^------------
    |          |
    |          `FromPrimitive` is not local
    |          move the `impl` block outside of this constant `_IMPL_NUM_FromPrimitive_FOR_IsakmpPayloadType`
509 | pub enum IsakmpPayloadType {
    |          ----------------- `IsakmpPayloadType` is not local
    |
    = note: the derive macro `FromPrimitive` defines the non-local `impl`, and may need to be changed
    = note: the derive macro `FromPrimitive` may come from an old version of the `num_derive` crate, try updating your dependency with `cargo update -p num_derive`
    = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint
    = note: this warning originates in the derive macro `FromPrimitive` (in Nightly builds, run with -Z macro-backtrace for more info)
3 months ago
Pierre Chifflier bd7d38e91e ldap: add support for STARTTLS to make certificate information available
Ticket: #7394.
3 months ago
Pierre Chifflier 3341907125 ldap: add port 3268 (used by Active Directory) 3 months ago
Philippe Antoine c26cb9abd3 detect/transform: fix leak in xor transform parse
Fixes: 8984bc6801 ("transforms: move xor to rust")
3 months ago
Jason Ish 13841c0b9e rust: put all rust/cargo env vars in CARGO_ENV
To ensure that all calls to cargo use the same environment variables,
put the environment variables in CARGO_ENV so every call to cargo can
easily use the same vars.

The Cargo build system is smarter than make, it can detect a change in
an environment variable that affects the build, and the setting of
SURICATA_LUA_SYS_HEADER_DST changing could cause a rebuild.

Also update suricata-lua-sys, which is smarter about copying headers. It
will only copy if the destination does not exist, or the source header
is newer than the target, which can also prevent unnecessary rebuilds.

This is mainly to fix an issue where subsequent builds may fail,
especially when running an editor with a LSP enabled:

    Update lua crate to 0.1.0-alpha.5. This update will force a rewrite of
    the headers if the env var SURICATA_LUA_SYS_HEADER_DST changes. This
    fixes the issue where the headers may not be written.

    The cause is that Rust dependencies are cached, and if your editor is
    using rust-analyzer, it might cache the build without this var being
    set, so these headers are not available to Suricata. This crate update
    forces the re-run of the Lua build.rs if this env var changes, fixing
    this issue.
3 months ago
Victor Julien 543429f176 smb: use lru for ssn2vec_map
Generic ssn2vec_map was a HashMap used for mapping session key to
different types of vector data:
- GUID
- filename
- share name

Turn this into a bounded LruCache. Rename to ssn2vec_cache.

Size of the cache is 512 by default, and can be configured using:

`app-layer.protocols.smb.max-session-cache-size`

Ticket: #5672.
4 months ago
Victor Julien ba7a4ece76 smb: use lru for ssnguid2vec_map; rename
Reimplement the ssnguid2vec_map HashMap as a LruCache.

Since this is a DCERPC record cache, name it as such.

Default size is 128. Can be controlled by
`app-layer.protocols.smb.max-dcerpc-frag-cache-size`.

Ticket: #5672.
4 months ago
Victor Julien 0f23557ef7 smb: use lru for ssn2tree; rename
Turn the map mapping the smb session key to smb tree into a lru cache,
limited to 1024 by default.

Add `app-layer.protocols.smb.max-tree-cache-size` option to control the
limit.

Ticket: #5672.
4 months ago
Victor Julien ce44d38ca8 smb: use lru for ssn2vecoffset_map; rename
Rename to read_offset_cache.

Add `app-layer.protocols.smb.max-read-offset-cache-size` option to
control the limit.

Ticket: #5672.
4 months ago
Victor Julien 91828ec00b smb: use lru for guid2name map; rename
Use `lru` crate. Rename to reflect this.

Add `app-layer.protocols.smb.max-guid-cache-size` to control the max
size of the LRU cache.

Ticket: #5672.
4 months ago
Victor Julien 23f2317c6a smb1: remove name on close
Ticket: #5672.
4 months ago
Victor Julien 85987aaad6 smb2: remove filename on close
Ticket: #5672.
4 months ago
Victor Julien c2124f0b9e smb: update to GAP handling
Don't tag the session as gap'd when the GAP is in a precise location:

1. in "skip" data, where the GAP just fits the skip data

2. in file data, where we pass the GAP on to the file

This reduces load of GAP post-processing that is unnecessary in these
case.
4 months ago
Victor Julien d535d7f768 smb2: use if let for read/write parsing 4 months ago
Victor Julien 5bd2289008 rust: update crates 4 months ago
Philippe Antoine 63324b7368 transforms: move urldecode to rust
Ticket: 7229
4 months ago
Philippe Antoine 8984bc6801 transforms: move xor to rust
Ticket: 7229
4 months ago
Philippe Antoine 45e0acf772 transforms: move http headers transforms to rust
Ticket: 7229
4 months ago
Philippe Antoine f0414570d2 transforms: move casechange to rust
Ticket: 7229
4 months ago
Philippe Antoine 0e5b49d20f transforms: move hash transforms to rust
md5, sha1 and sha256

Ticket: 7229
4 months ago
Philippe Antoine 71da38e702 transforms: move dotprefix to rust
Ticket: 7229
4 months ago
Philippe Antoine 966f659201 transforms: move compress_whitespace to rust
Ticket: 7229
4 months ago
Philippe Antoine 4985ebc0e0 transforms: move strip_whitespace to rust
Ticket: 7229
4 months ago
Jason Ish b1c26dccf3 http2: rename event variant to match rule
Rename InvalidHTTP1Settings to InvalidHttp1Settings so it gets the
expected name transformation of "invalid_http1_settings".

Ticket: #7361
4 months ago
Sascha Steinbiss 5d8252117f mqtt: double-check detection directions
Ticket: #7323
4 months ago
Sascha Steinbiss 377d4705e1 mqtt: add reason code support for SUBACK
Ticket: #7323
4 months ago
Jason Ish 3a7eef8121 lua: update to newer lua crate
This crate lets us instruct it where to copy the header files instead
of our Makefile trying to find the correct ones and copying them into
place.

Can prevent the simultaneous copy errors sometimes seen on a make
without a clean.
4 months ago
Jason Ish ab6dcb3fc1 app-layer: use uint8_t consistent for event IDs
Introduce a common function for mapping names to IDs that performs
bounds checking.

Note: For event IDs in the enum that are larger than a uint8_t, -1
will be returned instead of -4. -4 has special meaning during
signature parsin that means requirements were not met. -4 has no
special handling prior to requirements, or the meaning has been lost.
4 months ago
Alice Akaki 5e563b0c8b detect/analyzer: add more details for flow_age
Ticket: #6312
4 months ago
Jason Ish 45384ef969 rust/applayer: use c_int as return type for get_info_by_id
Rust was using i8 as the return type, while C uses int. As of Rust
1.82, the return value is turned to garbage over the FFI boundary.

Ticket: #7338
4 months ago
Philippe Antoine b5fcf16d97 enip/detect: remove double registration of enip_command keyword
As found with
./src/suricata --list-keywords | sort | uniq -c | awk '$1 > 1'
4 months ago
Philippe Antoine 2fb89f1b79 ldap: improve some rust style 5 months ago
Victor Julien f334532063 rust: update dependencies 5 months ago
Philippe Antoine 7d854bd97f template/detect: allow empty buffers 5 months ago
Philippe Antoine 96c8470cdd template: move detect keywords to pure rust
Ticket: 3195

Also remove unused src/tests/detect-template-buffer.c

Completes commit 4a7567b3f0
to remove references to template-rust
5 months ago
Philippe Antoine 3f0512ebeb rust: unpin serde
As oss-fuzz uses a newer compatible rustc version
5 months ago
Philippe Antoine 1e152d1f10 ja4: handles non alphanumeric alpn
Ticket: 7267

Follows more closely the specification :
https://github.com/FoxIO-LLC/ja4/blob/main/technical_details/JA4.md#alpn-extension-value

Also fixes the case with a single-char alpn.
5 months ago
Philippe Antoine 521928e2a3 sip: use pure rust function
For internal function that is not part of C FFI
5 months ago
Shivani Bhardwaj cbb571a61c rust/base64: add decoder
Add a pure rust base64 decoder. This supports 3 modes of operation just
like the C decoder as follows.
1. RFC 2045
2. RFC 4648
3. Strict

One notable change is that "strict" mode is carried out by the rust
base64 crate instead of native Rust. This crate was already used for
encoding in a few places like datasets of string type. As a part of this
mode, now, only the strings that can be reliably converted back are
decoded.

The decoder fn is available to C via FFI.

Bug 6280
Ticket 7065
Ticket 7058
5 months ago
Giuseppe Longo d43154adbe sip: add sip.content_length sticky buffer
This adds a sticky (multi) buffer to match the "Content-Length" header field in
both requests and responses.

Ticket #6374
5 months ago
Giuseppe Longo 6f727ab970 sip: add sip.content_type sticky buffer
This adds a sticky (multi) buffer to match the "Content-Type" header field in
both requests and responses.

Ticket #6374
5 months ago
Giuseppe Longo 5e8e61bb3b sip: add sip.user_agent sticky buffer
This adds a sticky (multi) buffer to match the "User-Agent" header field in
both requests and responses.

Ticket #6374
5 months ago
Giuseppe Longo 6ddc7d6223 sip: add sip.via sticky buffer
This adds a sticky (multi) buffer to match the "Via" header field in
both requests and responses.

Ticket #6374
5 months ago
Giuseppe Longo c205e87911 sip: add sip.to sticky buffer
This adds a sticky (multi) buffer to match the 'To' header field in
both requests and responses.

Ticket #6374
5 months ago
Giuseppe Longo e3fefcf55c sip: add sip.from sticky buffer
This adds a sticky (multi) buffer to match the "From" header field
in both requests and responses.

Ticket #6374
5 months ago
Giuseppe Longo fbc3cd1b3f rust/sip: store response headers
To match on response SIP headers, those headers must be stored.

Ticket #6374
5 months ago
Giuseppe Longo cfb793ce28 rust/sip: store multiple header values
According to RFC 3261, a single header can be repeated one or more times,
and its name can also be specified using the 'compact form.'

This patch updates the hashmap used for storing headers to accommodate multiple
values instead of just one.

Additionally, if a header name is defined in the compact form, it is expanded
into its long form (i.e., the standard name).

This conversion simplifies the logic for matching a given header
and ensures 1:1 parity with keywords.

Ticket #6374
5 months ago
Giuseppe Longo 969f4d131f sip: rustify sticky buffers
Ticket #7204
5 months ago
Juliana Fajardini 2b1ad81cf5 pgsql: trigger raw stream reassembly at tx completion
Once we are tracking tx progress per-direction for PGSQL, we can trigger
the raw stream reassembly, for detection purposes, as soon as the
transactions are completed in the given direction.

Task #7000
5 months ago
Juliana Fajardini dcccbb1196 pgsql: track transaction progress per direction
PGSQL's current implementation tracks the transaction progress without
taking into consideration flow direction, and also has indirections
that make it harder to understand how the progress is tracked, as well
as when a request or response is actually complete.

This patch introduces tracking such progress per direction and adds
completion status per direction, too. This will help when triggering
raw stream reassembly or for unidirectional transactions, and may be
useful when we implement sub-protocols that can have multiple requests
per transaction, as well.

CancelRequests and TerminationRequests are examples of unidirectional
transactions. There won't be any responses to those requests, so we can
also mark the response side as done, and set their transactions as
completed.

Bug #7113
5 months ago
Juliana Fajardini 2c7824a41f pgsql: use new API style for extern C functions 5 months ago
Juliana Fajardini 3ba179422d pgsql: order StateProgress enum per direction
Related to
Bug #7113
5 months ago
Juliana Fajardini 7aeb718dd7 pgsql: apply rust fmt changes 5 months ago
Philippe Antoine de9413c654 detect: safety for app-layer logging of stream-only rules
If a stream-only rule matches, and we find a tx where we
want to log the app-layer data, store into the tx data that
we already logged, so that we do not log again the app-layer metadata

Ticket: 7085
5 months ago
Philippe Antoine d3eb6569d2 rust: pin serde version
because oss-fuzz does not support newer rust nightly
and newer serde does not support oss-fuzz old nightly
6 months ago