Commit Graph

1652 Commits (b18622554da33f988e4a60f36aacff4153b3cecd)

Author SHA1 Message Date
Jeff Lucovsky dd344bd07c ftp: Move config file handling to Rust
Issue: 4082

Move the configuration file handling to Rust.

These changes will no longer terminate Suricata when there's an invalid
value for ftp.memcap. Like earlier Suricata releases, an error message
is logged "Invalid value <value> for ftp.memcap" but Suricata will no
longer terminate execution. It will use a default value of "0" instead.
4 days ago
Jeff Lucovsky f0410c93d0 ftp: convert enumerations to Rust
As part of the effort to convert the FTP/FTPDATA parser to rust, move
the enums from C to rust.

Issue: 4082
4 days ago
Philippe Antoine 8c3bd3e8a0 dcerpc: consume bytes after gap resync
Ticket: 7567

After a gap, we search a new record that may start later than
the beginning of current stream slice.
If so, consume the first bytes before the start of the record,
so that AppLayerResult::incomplete can be consistent and not
trigger assertion !((res.needed + res.consumed < input_len))
4 days ago
Philippe Antoine 3bc2a14fbf rust: fix clippy 1.85 precedence warnings
warning: operator precedence can trip the unwary
   --> src/jsonbuilder.rs:781:36
    |
781 |                 buf[offset] = HEX[(x >> 4 & 0xf) as usize];
    |                                    ^^^^^^^^^^^^ help: consider parenthesizing your expression: `(x >> 4) & 0xf`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence
    = note: `#[warn(clippy::precedence)]` on by default
1 week ago
Philippe Antoine 726de5520f quic: discard late retry packets
Ticket: 7556

See RFC 9000 section 17.2.5.2 :
After the client has received and processed an Initial
or Retry packet from the server,
it MUST discard any subsequent Retry packets that it receives.
1 week ago
Shivani Bhardwaj a551674eae dcerpc: add iface to dcerpc request event
so as to avoid extra steps for correlation among events to find
this information.

Feature 7565
1 week ago
Jason Ish 4cdb879538 rust/bindgen: use temp file to generating bindings
Prefixing a file with sed doesn't appear to be portable. Instead, make
use of a temporary file.

Fixes generating the bindings on FreeBSD and Mac.
1 week ago
Alice Akaki 73ae6e997f detect: add ldap.responses.dn
ldap.responses.dn matches on LDAPDN from responses operations
This keyword maps the following eve fields:
ldap.responses[].search_result_entry.base_object
ldap.responses[].bind_response.matched_dn
ldap.responses[].search_result_done.matched_dn
ldap.responses[].modify_response.matched_dn
ldap.responses[].add_response.matched_dn
ldap.responses[].del_response.matched_dn
ldap.responses[].mod_dn_response.matched_dn
ldap.responses[].compare_response.matched_dn
ldap.responses[].extended_response.matched_dn
It is a sticky buffer
Supports prefiltering

Ticket: #7471
1 week ago
Alice Akaki 16dcee46fc detect: add ldap.request.dn
ldap.request.dn matches on LDAPDN from request operations
This keyword maps the following eve fields:
ldap.request.bind_request.name
ldap.request.add_request.entry
ldap.request.search_request.base_object
ldap.request.modify_request.object
ldap.request.del_request.dn
ldap.request.mod_dn_request.entry
ldap.request.compare_request.entry
It is a sticky buffer
Supports prefiltering

Ticket: #7471
1 week ago
Alice Akaki 7b350e9933 misc: fix name prefix in detect register functions 1 week ago
Philippe Antoine d61f36c66f quic: decrypt only initial packets
Ticket: 7556

Avoids failed_decrypt events when the first packet seen is not
a Quic Initial packet
1 week ago
Philippe Antoine 6d8910d245 quic: handle retry packets
Ticket: 7556
1 week ago
Philippe Antoine f295cc059d quic: handle fragmented hello over multiple packets
Ticket: 7556

To do so, we need to add 2 buffers (one for each direction)
to the QuicState structure, so that on parsing the second packet
with hello/crypto fragment, we still have the data of the first
hello/crypto fragment.

Use a hardcoded limit so that these buffers cannot grow indefinitely
and set an event when reaching the limit
1 week ago
Philippe Antoine 68adc87bd2 quic: parse ack frame number 3
cf rfc9000 section 19.3. ACK Frames

Ticket: 7556
1 week ago
Philippe Antoine ee04d667b5 quic: move all_consuming check to callee
Will alow to have decode_frames accept one additional parameter
with past fragment data
1 week ago
Philippe Antoine 294a33a890 quic: rustfmt 1 week ago
Juliana Fajardini ae00181736 pgsql/parser: fix type complexity clippy warning
Cf https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity
1 week ago
Juliana Fajardini a4ce9cfe15 pgsql/logger: don't log empty transactions
This may happen in some situations if the app-layer parser only sees
unknown messages and sets an event: there will be an empty transaction,
but nothing to log.

Related to
Task #5566
1 week ago
Juliana Fajardini d676d711ee pgsql: add case for Unknown response message state
No state change, but since we added Unknown responses, we should handle
that case -- should we have a specific state for such cases?

Related to
Bug #5524
Task #5566
1 week ago
Juliana Fajardini 1b6f4da23b pgsql: add events
Events for:
- parsing error when parsing pgsql packet length
- parsing error for pgsql requests (post length parsing)
- parsing error for pgsql responses (post length parsing)
- too many transactions

Include `pgsql-events.rules` file, and PGSQL events SID range definition

Task #5566
1 week ago
Juliana Fajardini 6eadb752ec pgsql/parser: add more debug statements 1 week ago
Juliana Fajardini 38f8508bf5 pgsql: apply rustfmt changes 1 week ago
Juliana Fajardini ff8d4e972c pgsql: don't always return error for parsing errors
This allows the app-proto to continue onto parsing next PDUs, if
possible.

Bug #5524
1 week ago
Juliana Fajardini 4fed424d74 pgsql: don't fail if proto parses unknown message
Even if unknown, if the message is properly parsed, allow the parser to
proceed.

Related to
Bug #5524
1 week ago
Juliana Fajardini cc841e66db pgsql/parser: always use fn for parsing PDU length
Some inner parsers were using it, some weren't. Better to standardize
this. Also take the time to avoid magic numbers for representing the
expected lengths for pgsql PDUs.
Also throwing PgsqlParseError and allowing for incomplete results.

Related to
Task #5566
Bug #5524
1 week ago
Juliana Fajardini 29d3aa7a6a pgsql: add PgsqlParserError
Building on top of work done by Jason Ish.

Related to
Bug #5524
1 week ago
Juliana Fajardini 737fea751f pgsql/parser: simplify response parsing
The initial parsing for message type checking was more complex than
needed be.

Related to
Bug #5524
1 week ago
Juliana Fajardini 24375a1fef pgsql/parser: fix response message length
Some backend messages can be the shortest pgsql length possible,
4 bytes, but the parser expectd all messages to be longer than that.

Related to
Bug #5524
1 week ago
Philippe Antoine b514b25165 detect/flow: move keyword parsing code to rust
for flow.pkts and flow.bytes keywords

Ticket: 7562

Avoid null deref when parsing flow.bytes:toserver;
1 week ago
Philippe Antoine 8ae5665767 detect/krb5: avoid integer underflow with krb5.ticket_encryption
Ticket: 7560

When passing INT32_MIN aka 0x80000000, we cannot compute -vali
as it does not fit into a i32
1 week ago
Jason Ish 10ede91536 rust: add bindings to SCPlugin.* to sys crate
Also disable bindgen's generated layout tests.  They are valid for the
platform generating the tests, but may not be valid for other
platforms. For example, if the tests are generated on a 64 bit
platform the tests will not be valid when run on a 32 bit platform as
pointers are a different size.

However, the generating bindings are valid for both platform.

Ticket: #7341
2 weeks ago
Jason Ish 9b73de6f6d rust: add auto-generated header to sys.rs
We don't keep bindgen's autogenerated do not edit line as it contains
the bindgen version which could break the CI check for out of date
bindings. So add our own do not edit line.

Ticket: #7341
2 weeks ago
Jason Ish 4554c4778d rust: use AppProto from generated bindings instead of duplicating
Have bindgen generate bindings for app-layer-protos.h, then use the
generated definitions of AppProto/AppProtoEnum instead if defining
them ourselves.

This header was chosen as its used by Rust, and its a simple header
with no circular dependencies.

Ticket: #7341
2 weeks ago
Jason Ish 21ccc4f307 rust: integrate bindgen to generate Rust bindings to C
Bindgen works by processing a header file which includes all other
header files it should generate bindings for. For this I've created
bindgen.h which just includes app-layer-protos.h for now as an
example.

These bindings are then generated and saved in the "suricata-sys"
crate and become availale as "suricata_sys::sys".

Ticket: #7341
2 weeks ago
Jason Ish 8f22e55678 rust/sys: stub in suricata-sys crate for Rust bindings to C
Follow Rust convention of using a "sys" crate for bindings to C
functions. The bindings don't exist yet, but will be generated by
bindgen and put into this crate.

Ticket: #7341
2 weeks ago
Shivani Bhardwaj bc79300dfa datasets: move initial file reading to rust
In a recent warning reported by scan-build, datasets were found to be
using a blocking call in a critical section.

datasets.c:187:12: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
  187 |     while (fgets(line, (int)sizeof(line), fp) != NULL) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
datasets.c:292:12: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
  292 |     while (fgets(line, (int)sizeof(line), fp) != NULL) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
datasets.c:368:12: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
  368 |     while (fgets(line, (int)sizeof(line), fp) != NULL) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
datasets.c:442:12: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
  442 |     while (fgets(line, (int)sizeof(line), fp) != NULL) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
datasets.c:512:12: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
  512 |     while (fgets(line, (int)sizeof(line), fp) != NULL) {
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 warnings generated.

These calls are blocking in the multi tenant mode where several tenants
may be trying to load the same dataset in parallel.
In a single tenant mode, this operation is performed as a part of a
single thread before the engine startup.

In order to evade the warning and simplify the code, the initial file
reading is moved to Rust with this commit with a much simpler handling
of dataset and datarep.

Bug 7398
2 weeks ago
Shivani Bhardwaj 015da2c7ed rust: add C callback for FatalErrorOnInit 2 weeks ago
Shivani Bhardwaj 0ce8b15ca8 rust: add macro to return val if unwrap fails 2 weeks ago
Jason Ish 7a936cb486 base64: expose no padding and padding optional variants
A no padding option is provided as a mode, as its a variant suitable
for encoding and decoding.

A padding optional function is added that is indifferent to padding
when decoding. This can be useful when you're not sure if padding
exists, and don't really care.
2 weeks ago
Jason Ish ad6d9e0d93 base64: prefix base64 C API with "SC" 2 weeks ago
Jason Ish fd488170c4 lua: update lua to 5.4.7
This version of out Lua crate also supports cross compiling.
2 weeks ago
Alice Akaki 73455179d7 detect/integers: add support for negated strings when enum is used
function detect_parse_uint_enum can parse strings like !bind_request

Ticket: #7513
2 weeks ago
Philippe Antoine ef044b208c dcerpc: prevent integer underflow
in case a fragment has a length lesser than DCERPC_HDR_LEN

Fixes: 9daf8528b7 ("dcerpc: tidy up code")

Ticket: 7548
3 weeks ago
Ilya Bakhtin 27f0db7526 protodetect/dcerpc: improve DCERPC UDP probing parser
Several additional checks are added to the probing parser to avoid false
detection of DNS as DCERPC

Ticket - 7111
4 weeks ago
Shivani Bhardwaj c73299a298 dcerpc/tcp: add frames support
Frames of the following types have been added for toserver direction:
1. Pdu: The entire Protocol Data Unit
2. Hdr: Header of the request
3. Data: PDU data

Feature 4904
4 weeks ago
Shivani Bhardwaj 9daf8528b7 dcerpc: tidy up code
- remove unneeded variables
- remove unnecessary tracking of bytes in state
- modify calculations as indicated by failing tests
4 weeks ago
Shivani Bhardwaj 4790da1825 dcerpc: remove fragmented data tests
With the introduction of AppLayerResult::incomplete API, fragmented data
is no longer handled fully in the dcerpc code. Given that these code
paths are already covered by the following s-v tests, these tests can now be
safely removed.
- dce-gap-handling
- dcerpc-dce-iface-*

Ticket 5699
4 weeks ago
Shivani Bhardwaj 74de1042a9 dcerpc: use AppLayerResult::incomplete API
Instead of own internal mechanism of buffering in case of fragmented
data, use AppLayerResult::incomplete API to let the AppLayer Parser take
care of it. This makes the memory use more efficient.
Remove any unneeded variables and code with the introduction of this
API.

Ticket 5699
4 weeks ago
Shivani Bhardwaj fc88e61c7f dcerpc: save version info in tx
to make it available for logging.
4 weeks ago
Shivani Bhardwaj 0d6017d174 dcerpc: do not assume an upper bound on data
TCP data can be presented to the protocol parser in any way e.g. one
byte at a time, single complete PDU, fragmented PDU, multiple PDUs at
once. A limit of 1MB can be easily reached in some of such scenarios.
Remove the check that rejects data that is more than 1MB.
4 weeks ago