Commit Graph

143 Commits (0a831b5ea2a311c5bdc688d43238a272170c9a29)

Author SHA1 Message Date
Jason Ish e7f5bd047d rust: fix needless borrows of references
Fixed automatically by cargo clippy --fix.
4 years ago
Jason Ish fab3f36b8c dns: never return error on UDP DNS
UDP parsers should never return error as it should indicate to Suricata
that an unrecoverable error has occurred.  UDP being record based for
the most part is almost always recoverable, at least for protocols like
DNS.
4 years ago
Jason Ish d720ead470 dns: split header and body parsing
As part of extra header validation, split out DNS body parsing to
avoid the overhead of parsing the header twice.
4 years ago
Jason Ish 595700ab7e dns: validate header on every incoming message
As UDP streams getting probed, a stream that does not appear to be DNS
at first, may have a single packet that does look close enough to DNS
to be picked up as DNS causing every subsequent packet to result in a
parser error.

To mitigate this, probe every incoming DNS message header for validity
before continuing onto the body.  If the header doesn't validate as
DNS, just ignore the packet so no parse error is registered.
4 years ago
Jason Ish c98c49d4ba dns: parse and alert on invalid opcodes
Accept DNS messages with an invalid opcode that are otherwise
valid. Such DNS message will create a parser event.

This is a change of behavior, previously an invalid opcode would cause
the DNS message to not be detected or parsed as DNS.

Issue: #5444
4 years ago
Jason Ish 7afc2e3aed dns: rustfmt 4 years ago
Jason Ish 39d2524bf6 dns: mark test buffers with rustfmt::skip 4 years ago
Jason Ish dfd7abe185 rust/clippy: fix lint: type_complexity
Convert a DNS sub-parser to use a return type rather than a large
tuple. For mqtt, allow the lint for now, but remove the global allow.
4 years ago
Jason Ish 4940dfb3bd rust/clippy: fix lint: len_without_is_empty 4 years ago
Jason Ish da12b77f18 rust/clippy: fix lint: new_without_default 4 years ago
Jason Ish 7c293ff68f rust/clippy: fix lint: never_loop 4 years ago
Jason Ish f250b92180 rust/clippy: fix lint: extra_unused_lifetimes 4 years ago
Jason Ish 359d5fcb7e rust/clippy: fix lint: needless_lifetimes 4 years ago
Philippe Antoine 286bd2a7ed rust: fix cargo clippy --all-features 4 years ago
Philippe Antoine bc287018e5 rust: cargo clippy --all-features --fix --allow-no-vcs 4 years ago
Haleema Khan 8d5c5f24a1 dns/eve: add 'HTTPS' type logging
Add a new DNS record type to represent HTTPS
Ticket: #4751
4 years ago
Jason Ish f0952aef0d rust: fix clippy lints for unneeded reference in debug code 4 years ago
Jason Ish 6a7439a26b rust: fix clippy lints for is_empty in debug code 4 years ago
Jason Ish 04f0ee0151 rust: fix clippy lints for clippy::unnecessary_cast 4 years ago
Jason Ish f342d4aacd rust: fix clippy lints for clippy::len_zero 4 years ago
Jason Ish 5e5401d3e9 rust: fix clippy lints for clippy::char_lit_as_u8 4 years ago
Jason Ish c4034dafa1 rust: fix clippy lints for clippy::derive_partial_eq_without_eq 4 years ago
Jason Ish c5b26e2043 rust: fix clippy ling for needless borrows
Cleanup needless borrows found by clippy. This fix done automatically by
`cargo clippy --fix`.
4 years ago
Victor Julien 79499e4769 app-layer: move files into transactions
Update APIs to store files in transactions instead of the per flow state.

Goal is to avoid the overhead of matching up files and transactions in
cases where there are many of both.

Update all protocol implementations to support this.

Update file logging logic to account for having files in transactions. Instead
of it acting separately on file containers, it is now tied into the
transaction logging.

Update the filestore keyword to consider a match if filestore output not
enabled.
4 years ago
Victor Julien c27df6304d app-layer: introduce common AppLayerStateData API
Add per state structure for storing flags and other variables.
4 years ago
Pierre Chifflier 16db04c1a7 rust: remove nom 5 dependency 4 years ago
Jason Ish f92708b8ca rust/frames: derive direction from StreamSlice
On the Rust side, a Frame requires a StreamSlice to be created. We can
derive the direction from the StreamSlice removing the need for callers
to provide the direction when operating on the frame.
4 years ago
Jason Ish b39d7f46e7 dns/tests: fix StreamSlice to satisfy debug validation 4 years ago
Philippe Antoine 26dc70648c dns: remove unused events field from state
found overflowing by oss-fuzz
4 years ago
Jason Ish b8b6a17a5b dns: add pdu frame
Adds a PDU frame to the DNS parser. For UDP this is the DNS payload
portion of the DNS packet, for TCP this is the payload minus the leading
legth field.

Ticket: 4984
4 years ago
Jason Ish d712a8b29d eve/dns: remove dns v1 logging
Removal of DNS v1 logging was scheduled to be removed in May 2022.

Ticket: #4157
4 years ago
Jason Ish 3189414788 dns: convert transaction list to vecdeque
Allows for more efficient removal from front of the list.

Ticket: #5277
4 years ago
Jason Ish 7b11b4d3a1 app-layer: more generic state trait
Instead of a method that is required to return a slice of transactions,
use 2 methods, one to return the number of transactions in the
collection, and another to get a transaction by its index in the
collection.

This allows for the transaction collection to not be a contiguous array
and instead can be a VecDeque, or possibly another collection type that
supports retrieval by index.

Ticket #5278
4 years ago
Jason Ish 0623ada24d dns: better error handling when parsing names
The DNS name parser will error out with an error even if the
error is incomplete. Instead of manually generating errors,
use '?' to let the nom error ripple up the error handling chain.

The reason this wasn't done in the first place is this code
predates the ? operator, or we were not aware of it at the time.

This prevents the case where probing fails when there is enough data to
parse the header, but not enough to complete name parser. In such a case
a parse error is returned (instead of incomplete) resulting in the
payload not being detected as DNS.

Ticket #5034
4 years ago
Jason Ish 27679a12aa dns: don't parse a full request during probe if not enough data
If there is more data than a header, but not enough for a complete DNS
message, the hostname parser could return an error causing the probe to
fail on valid DNS messages.

So only parse the complete message if we have enough input data. This is
reliable for TCP as DNS messages are prefixed, but for UDP its just
going to be the size of the input buffer presented to the parser, so
incomplete could still happen.

Ticket #5034
4 years ago
Victor Julien e6f49e5a05 app/frames: implement name to id API for frames 5 years ago
Victor Julien c073d5cfbf app-layer: use StreamSlice as input to parsers
Remove input, input_len and flags in favor of stream slice.
5 years ago
Victor Julien 6466296b32 app-layer: add StreamSlice to pass data to parsers
Since object to contain relevant pointer, length, offset, flags to make
it easy to pass these to the parsers.
5 years ago
Jason Ish 0861b66e15 dns: add dns flag to dns request logging
Ticket #4515
5 years ago
Odin Jenseg dfb6f105e8 dns: Logging of Z-bit
[Edit by Jason Ish: fix flag bit value]

Ticket #4515
5 years ago
Jason Ish fcbdc30426 dns: create transaction even if z-bit was set
It appears that DNS servers will still process a DNS request even if the
z-bit is set, our parser will fail the transaction. So create the
transaction, but still set the event.

Ticket #4924
5 years ago
Jason Ish 7732efbec2 app-layer: include decoder events in app-layer tx data
As most parsers use an events structure we can include it in the
tx_data structure to reduce some boilerplate/housekeeping code
in app-layer parsers.
5 years ago
Jason Ish 9c67c634c1 app-layer: include DetectEngineState in AppLayerTxData
Every transaction has an existing mandatory field, tx_data. As
DetectEngineState is also mandatory, include it in tx_data.

This allows us to remove the boilerplate every app-layer has
for managing detect engine state.
5 years ago
Jason Ish 049d43212e rust/app-layer: provide generic implementation of iterator
Create traits for app-layer State and Transaction that allow
a generic implementation of a transaction iterator that parser
can use when the follow the common pattern for iterating
transactions.

Also convert DNS to use the generic for testing purposes.
5 years ago
Shivani Bhardwaj a19d2b4e1e dns: use Direction enum 5 years ago
Pierre Chifflier c525a1337c rust/dns: convert parser to nom7 functions 5 years ago
Sam Muhammed 922a453da5 rust(lint): use is_null() instead of ptr::null_mut()
Bug: #4594
5 years ago
Jason Ish 6ed827a4ef dns: use derive macro for DNSEvent 5 years ago
Jason Ish b021726a0d rust(lint): map the error instead of using or_else
This is the preffered style and easier to understand the meaning
of the code.
5 years ago
Jason Ish d5c0962299 rust(lint): fix some usages of references
- ref is discouraged for top level variables
- the other borrow is not required
5 years ago