Commit Graph

784 Commits (56541c7c37d0de3f4c7eaafc19118ad837bbbc3d)

Author SHA1 Message Date
Philippe Antoine 62d5cac1b8 http2: do not expand duplicate headers
Ticket: 7104

As this can cause a big mamory allocation due to the quadratic
nature of the HPACK compression.

(cherry picked from commit 5bd17934df)
2 years ago
Philippe Antoine d519f74770 rust/probing: safety check for null input
Ticket: 7013

Done consistently for all protocols

This may change some protocols behaviors which failed early
if they found there was not enough data...

(cherry picked from commit 37a9003736)
2 years ago
Philippe Antoine 65733e2a93 rust: return empty slice without using from_raw_parts
As this triggers rustc 1.78
unsafe precondition(s) violated: slice::from_raw_parts requires
the pointer to be aligned and non-null,
and the total size of the slice not to exceed `isize::MAX`

Ticket: 7013
inspired from commit 5dc8dea869
2 years ago
Victor Julien 7e6dbcd851 rust: fix compilation error on MSRV
Caused by:
  failed to parse manifest at `/builds/inliniac/suricata-ci/suricata/rust/vendor/num-traits/Cargo.toml`

Caused by:
  failed to parse the `edition` key

Caused by:
  supported edition values are `2015` or `2018`, but `2021` is unknown

Lock to last working version 0.2.18.

Ticket: #7007.
2 years ago
Victor Julien cb823d4203 http2: fix for rustc 1.41.1
Co-authored-by: Philippe Antoine <pantoine@oisf.net>
2 years ago
Philippe Antoine d24b37a103 http2: do not log duplicate headers
Ticket: 6900

And thus avoid DOS by logging a request using a compressed
header block repeated many times and having a long value...

(cherry picked from commit 03442c9071)
2 years ago
Philippe Antoine 08d93f7c37 http2: use a reference counter for headers
Ticket: 6892

As HTTP hpack header compression allows one single byte to
express a previously seen arbitrary-size header block (name+value)
we should avoid to copy the vectors data, but just point
to the same data, while reamining memory safe, even in the case
of later headers eviction from the dybnamic table.

Rust std solution is Rc, and the use of clone, so long as the
data is accessed by only one thread.

(cherry picked from commit 390f09692e)
2 years ago
Philippe Antoine fa6c003f16 rust/mqtt: fix clippy 1.77 warning
error: creating a mutable reference to mutable static is discouraged
   --> src/mqtt/mqtt.rs:752:23
    |
752 |     let max_msg_len = &mut MAX_MSG_LEN;
    |                       ^^^^^^^^^^^^^^^^ mutable reference to mutable static
    |
    = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
    = note: this will be a hard error in the 2024 edition
    = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
2 years ago
Philippe Antoine 47781a7985 rust: fix clippy 1.77 warning
Ticket: 6883

error: field `0` is never read
  --> src/asn1/mod.rs:36:14
   |
36 |     BerError(Err<der_parser::error::BerError>),
   |     -------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |     |
   |     field in this variant
   |

(cherry picked from commit 02f2fb8833)
2 years ago
Philippe Antoine c2202b152e rust: fix build with MSRV
Ticket: 6876

Do not backport try_string_from_bytes as it uses try_reserve
And just use string_from_bytes instead

Fixes: b9963b3e29 ("ssh: limit length for banner logs")
3 years ago
Victor Julien a4d3e9b1a1 rust: add MSRV as rust-version
Update github-actions to use it for the MSRV check.
3 years ago
Philippe Antoine b9963b3e29 ssh: limit length for banner logs
Ticket: 6770
(cherry picked from commit c4b8fb7aca)
3 years ago
Philippe Antoine a947228259 ssh: avoid quadratic complexity from long banner
Ticket: 6799

When we find an overlong banner, we get into the state just
waiting for end of line, and we just want to skip the bytes
until then.
Returning AppLayerResult::incomplete made TCP engine retain
the bytes and grow the buffer that we parsed again and again...

(cherry picked from commit 271ed2008b)
3 years ago
Philippe Antoine b1549e930f http2: limit number of concurrent transactions
Ticket: 6481

Instead of just setting the old transactions to a drop state so
that they get later cleaned up by Suricata, fail creating new ones.

This is because one call to app-layer parsing can create many
transactions, and quadratic complexity could happen in one
single app-layer parsing because of find_or_create_tx

(cherry picked from commit 80abc22f64)
3 years ago
Philippe Antoine ffed4b35cb http2: handle reassembly for continuation frames
Ticket: 5926

HTTP2 continuation frames are defined in RFC 9113.
They allow header blocks to be split over multiple HTTP2 frames.
For Suricata to process correctly these header blocks, it
must do the reassembly of the payload of these HTTP2 frames.
Otherwise, we get incomplete decoding for headers names and/or
values while decoding a single frame.

Design is to add a field to the HTTP2 state, as the RFC states that
these continuation frames form a discrete unit :
> Field blocks MUST be transmitted as a contiguous sequence of frames,
> with no interleaved frames of any other type or from any other stream.
So, we do not have to duplicate this reassembly field per stream id.

Another design choice is to wait for the reassembly to be complete
before doing any decoding, to avoid quadratic complexity on partially
decoding of the data.

(cherry picked from commit aff54f29f8)
3 years ago
Philippe Antoine 24404135e9 http2: app-layer event for userinfo in uri
Ticket: #6426

as per RFC 9113
":authority" MUST NOT include the deprecated userinfo subcomponent
for "http" or "https" schemed URIs.

(cherry picked from commit e3cd0d073f)
3 years ago
Philippe Antoine 595149d1e8 http2: event on mismatch between authority and host
Ticket: #6425
(cherry picked from commit 46a46e5b1f)
3 years ago
Philippe Antoine 0f097acd35 rust: tilde version for byteorder
so that we get one compatible with MSRV
3 years ago
Haleema Khan 1b01e075c5 dns/eve: add 'HTTPS' type logging
Add a new DNS record type to represent HTTPS
Ticket: #4751

(cherry picked from commit 8d5c5f24a1)
3 years ago
Shivani Bhardwaj 9e2fb158ab dcerpc: accept ALTER_CONTEXT as a valid request
So far, if only the starting request was a DCERPC request, it would be
considered DCERPC traffic. Since ALTER_CONTEXT is a valid request type,
it should be accepted too.

Reported and patch proposed in the following Redmine ticket by
InterNALXz.

Bug 6191

(cherry picked from commit 8770431986)
3 years ago
Shivani Bhardwaj 71ebd0bd77 rust: fix compiler warnings 3 years ago
Victor Julien 79c9d3e1ca rust: lock proc-macro2 to maintain MSRV 3 years ago
Sascha Steinbiss 74cbbd7ef4 rfb: also set unimplemented auth types
(cherry picked from commit 1521b77edd)
3 years ago
Sascha Steinbiss b1d2d78622 rfb: ensure logging of incompletely parsed txs
(cherry picked from commit 1606aca881)
3 years ago
Sascha Steinbiss 8f1e08b28e rfb: never return error on unknown traffic
We only try to parse a small subset of what is possible in
RFB. Currently we only understand some standard auth schemes
and stop parsing when the server-client handshake is complete.
Since in IPS mode returning an error from the parser causes
drops that are likely uncalled for, we do not want to return
errors when we simply do not understand what happens in the
traffic. This addresses Redmine #5912.

Bug: #5915.
(cherry picked from commit 1f8a5874fb)
3 years ago
Sascha Steinbiss 7a52e39297 rfb: add myself as contributor
(cherry picked from commit 836fff3679)
3 years ago
Sascha Steinbiss 66d55a7f35 rfb: be more strict parsing the version
(cherry picked from commit bd1fbf392e)
3 years ago
Philippe Antoine afeb022164 tls: update x509 crate to v0.8
Ticket: #5439

Fixes cetificate parsing without issuer, and do not require an
update to MSRV.
3 years ago
Lancer Cheng d23540da9d smb: fix wrong data offset when wct = 12
Bug: #6008
(cherry picked from commit 000eb91078)
3 years ago
Philippe Antoine 4cd06d2247 dcerpc: maximum number of live transactions also for UDP
Ticket: #6129

Avoids that quadratic complexity gets too bad

(cherry picked from commit d40dca5e55)
3 years ago
Philippe Antoine a0ce78ca87 dcerpc: convert transaction list to vecdeque for UDP
As was done for TCP in dfe76bb90 and d745d28d4

Ticket: #5518
(cherry picked from commit bf43011a43)
3 years ago
Jason Ish ee77e2e60b dcerpc: convert transaction list to vecdeque
Allows for more efficient removal from front of the list.

Ticket: #5271
(cherry picked from commit dfe76bb905)
3 years ago
Jason Ish 5937a1cc86 template(rust): convert transaction list to vecdeque
Allows for more efficient removal from front of the list.

Ticket: #5298
(cherry picked from commit e319d31c14)
3 years ago
Jason Ish 20952ba8e0 http2: convert transaction list to vecdeque
Allows for more efficient removal from front of the list.

Ticket: #5296
(cherry picked from commit 2db84726ad)
3 years ago
Jason Ish 506c45f934 rdp: convert transaction list to vecdeque
Allows for more efficient removal from front of the list.

Ticket: #5295
(cherry picked from commit 4e0ad5e0bd)
3 years ago
Jason Ish 5f728464e4 dns: convert transaction list to vecdeque
Allows for more efficient removal from front of the list.

Ticket: #5277
(cherry picked from commit 3189414788)
3 years ago
Philippe Antoine d362e45d72 smb: convert transaction list to vecdeque
Allows for more efficient removal from front of the list.

Ticket: #5753
(cherry picked from commit 1d9183638f)
3 years ago
Philippe Antoine 401a1b36b1 http2: avoid quadratic complexity in headers
When adding an element to the dynamic headers table, the oldest
ones may get evicted. When multiple elements get evicted, they
should get evicted all at once with drain, instead of one by one
as there will be a massive move each time.

Ticket: #6103
(cherry picked from commit 6350736882)
3 years ago
Jason Ish 2e4aade51d 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.

(cherry picked from commit d720ead470)
3 years ago
Jason Ish 0b283ef4a6 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.

(cherry picked from commit 595700ab7e)
3 years ago
Jason Ish dbaf63df5a 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
(cherry picked from commit c98c49d4ba)
3 years ago
Jason Ish 66b36f4de1 dns: mark test buffers with rustfmt::skip
(cherry picked from commit 39d2524bf6)
3 years ago
Jason Ish f5f2dc996b rust/doc: wrap some code examples in backticks
(cherry picked from commit 13fe957b7e)
3 years ago
tianjinshan 708bdf79fa smb/ntlmssp: fix parsing of negotiate flags
Ticket: #5783
(cherry picked from commit 2c0c6cb0a5)
3 years ago
Jason Ish 248176caba rust: update nom to 5.1.3
Update nom to 5.1.3 which fixes some future breaking changes in the Rust
compiler.

See https://github.com/rust-bakery/nom/pull/1657 for more info.
3 years ago
Philippe Antoine 42786aef59 http2: faster when reducing dynamic headers size
avoid quadratic complexity from removing the first element
and copying all the contents a big number fo times.

Ticket: #5909
(cherry picked from commit 9adb59bcdb)
3 years ago
Eric Leblond 9dfb3baf19 sip: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago
Eric Leblond 0a78edc20f ntp: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago
Eric Leblond 94a7072384 krb: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago
Eric Leblond 7137c877e8 mqtt: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago