Commit Graph

2051 Commits (4c28cc1b4ac64f48efdca6ce3e09748227a04a7e)

Author SHA1 Message Date
Shivani Bhardwaj 4c28cc1b4a release: 8.0.6; update changelog 4 months ago
Philippe Antoine e369bf29ee http1: limit the number of compression bombs per flow
Ticket: 8694

Otherwise, a flow full of small compression bombs is too slow
to process.

When the threshold is reached, decompression is skipped for the
rest of the flow.

(cherry picked from commit 392b6aee29)
4 months ago
Philippe Antoine 26c26dea84 doh2: clear the buffer after processing it
Ticket: 8725

So that multiple HTTP2 DATA frames with EndOfStream flag set,
do not make the buffer grow, while processing it each time,
resulting in quadratic complexity

(cherry picked from commit 1731805967)
4 months ago
Philippe Antoine 9a54a04351 stream: disrupt never seen direction with async-oneside
Ticket: 8629

When we are in async-oneside mode, we see only one direction
of the traffic, and should not wait for the other direction
before cleaning up a transaction.

(cherry picked from commit 7ec9d72d28)
4 months ago
Jeff Lucovsky 755d6c3061 smb: fail transaction creation once the limit is reached
new_tx() now refuses to create a transaction when the list is already at
SMB_MAX_TX, returning None instead of a transaction. Every creation path --
the new_*_tx helpers and their callers across smb1/smb2/dcerpc/session/
files/ioctl -- propagates that, so no single input can create more than the
limit, including a compound SMB2 request that chains many PDUs in one
record. When the list is full the parser puts the flow into an error state
and stops processing it.

This replaces the previous force-completion of old transactions, which did
not reliably bound the list and could leave transactions unreclaimable on
asymmetric flows. The now-unused tx_index_completed bookkeeping is removed.

Issue: 8629
(cherry picked from commit c8f68b0e4f)
4 months ago
Philippe Antoine c03666d261 mqtt: bounds number of messages per tx
Ticket: 8525
(cherry picked from commit 03ba8a71d8)
4 months ago
Philippe Antoine c0215c7e17 smtp/mime: consolidate a MimeStateSMTP restart function
Ticket: 8649

Fully resets all the fields before tackling an ecapsulated message
to avoid evasion, due to the encoding of the upper file
leaking into the next one...

(cherry picked from commit 4985eb9dae)
4 months ago
Giuseppe Longo 6f87930aff sip: store frame lens as u32 to avoid body truncation
Body lengths were stored as u16, so a SIP body of 65536 bytes truncated
body_len to 0 and the RequestBody/ResponseBody frame was never created,
letting body content evade inspection. Widen the framing fields to u32.

Ticket #8582

(cherry picked from commit 499995bf0e)
4 months ago
Victor Julien 6be7484054 rdp: fix tx id handling
Tx ID handling did not take the required + 1 into account.

From a report:

        RDP can skip cleanup because its id convention does not match the
        generic Rust iterator. The generic iterator in applayer.rs returns
        tx.id() - 1, and cleanup trusts that id when calling StateTransactionFree
        in app-layer-parser.c. RDP registers that iterator in rdp.rs, but
        RdpTransaction::id() returns the stored id unchanged in rdp.rs, while
        free_tx also compares against the raw stored id in rdp.rs. For a single
        freeable RDP tx with stored id 1, the iterator returns C id 0; cleanup
        calls free_tx(0), nothing is removed, then has_next == false allows
        min_id to advance to total_txs in app-layer-parser.c. That leaves the
        tx live but now below min_id, so later cleanup will not revisit it.

This patch brings the handling in line with the other parsers.

Bug: #8717.
(cherry picked from commit 9555e3add6)
4 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)
4 months ago
Jason Ish 8cdff89fe3 psl: update to latest version
Ticket: #8535
4 months ago
Philippe Antoine feb0ff9115 ftp: do not error the flow on file before port
Ticket: 8659

If a client sends a SOTR/RETR command before doing a PASV/PORT
command, ther server may reply
425 Use PORT or PASV first.\r\n
and allow the client to continue sendinf other commands

So, Suricata should not put the whole flow into error, it just
sets an event, and continues to parse further

(cherry picked from commit 52490b8c26)
4 months ago
Jeff Lucovsky ef035c7603 rdp: mark transactions single-directional
Mark the direction into RDP transactions at creation time,
so the tx carries SKIP_INSPECT for the direction it is
never seen in, matching DHCP and the other single-direction
parsers. This lets cleanup free completed transactions and
stops a tx from being inspected (and alerting) twice, once per
direction.

RDP bounds its transactions to connection setup and stops
parsing once bypass_parsing is set.

Issue: 8621
(cherry picked from commit 5af13e3eb0)
4 months ago
Jeff Lucovsky bac8a69ca4 dhcp: mark transactions single-directional to fix tx leak
DHCP is a stateless parser where each datagram is its own standalone,
single-direction transaction. It was creating transactions with
AppLayerTxData::new(), which leaves both SKIP_INSPECT bits clear, so the
engine treats every tx as still needing inspection in both directions.

For a flow that only ever carries one direction (broadcast DHCP, or a
relay seeing one side), the never-observed direction's inspect bit can
never be set, so AppLayerParserTransactionsCleanup() never frees the tx.
The per-flow transaction Vec then grows without bound and every packet
re-scans the whole list, giving O(n^2) CPU and unbounded memory on a
busy DHCP aggregation point.

Use AppLayerTxData::for_direction() like every other stateless parser
(DNS, SNMP, NTP, IKE, KRB5, MQTT, QUIC, SIP, WebSocket, bittorrent-dht)
so the tx carries SKIP_INSPECT for the direction it will never be seen
in. This lets cleanup free completed transactions and also stops the tx
from being inspected (and alerting) twice, once per direction.

Issue: 8621
(cherry picked from commit 3f86c56c80)
4 months ago
Philippe Antoine 819299852c conf: introduce SCConfGetNonNull
Ticket: 8651

Behaves like SCConfGet but returns 0 on null value

(cherry picked from commit a9e1dff4a6)
4 months ago
Shivani Bhardwaj 69c777d617 rust: exclude DETECT_BYTEMATH_ENDIAN_DEFAULT from bindings
to deal with the failure due to cbindgen updates and mismatches in
generated bindings.

detect-bytemath.c:61: error: "DETECT_BYTEMATH_ENDIAN_DEFAULT" redefined [-Werror]
   61 | #define DETECT_BYTEMATH_ENDIAN_DEFAULT (uint8_t) BigEndian
      |
In file included from rust.h:34,
                 from detect-bytemath.c:32:
./../rust/gen/rust-bindings.h:5071: note: this is the location of the previous definition
 5071 | #define DETECT_BYTEMATH_ENDIAN_DEFAULT BigEndian
      |

(cherry picked from commit 0345b91ddd)
5 months ago
Shivani Bhardwaj dd5888ce8a version: start development towards 8.0.6 5 months ago
Shivani Bhardwaj 5611b60c61 release: 8.0.5; update changelog 5 months ago
Philippe Antoine 3d371fff99 detect/transforms: dotprefix can be chained
Ticket: 8537

Otherwise, it may cause a use-after-free, in case of reallocated
buffer and we used the buffer inspect which was freed.

(cherry picked from commit 6d437956e2)
5 months ago
Philippe Antoine 11d1fe1ca8 detect/transforms: decompress checks earlier if it is in-place
Ticket: 8536

Otherwise, it may cause a use-after-free.

So, need to allocate the temporary vector, before calling
SCInspectionBufferCheckAndExpand

(cherry picked from commit 2b20a436e7)
5 months ago
Philippe Antoine 4253b82db7 detect/engine: helper to know if a transform happens in-place
(cherry picked from commit 4c42998feb)
5 months ago
Philippe Antoine 9c24b5bf1c http2: better compression against decompression bombs
Ticket: 8513

Suricata decides at 2 levels if a http2 flow is doing a compression
bomb.

There is a direct computation when one chunk of TCP data
is being parsed.
In this case, do not take the ratio into account, just use the size
of the decompressed data, so that if we get a big chunk of TCP data
like 1 MiB, and a not so high ratio of 200, we do not trigger
the debug assertion in util-file.c about 64MiB

The other case stays unchanged : when accumulating over the lifetile of
a flow with multiple txs, take into account the compression ratio,
so that a flow of many txs, having a super high (brotli) compression
ratio, ends up classified as a compression bomb.
(For example, having 100 txs each turning a 100 byte input into a 700 KiB
one)

(cherry picked from commit bf64b52b95)
5 months ago
Philippe Antoine 3a6414eb6a ikev2: remove unused field
Ticket: 8415
(cherry picked from commit 614c48d3c3)
5 months ago
Philippe Antoine 20104d0978 http2: protection against decompression bombs
Ticket: 8513

During decompression, fail early if we have a big decompression
ratio, and enough data.
Track this data also during a tx lifetime, and even a flow/state
lifetime, so that we set event and fail also if the compression
bomb is split over multiple packets

(cherry picked from commit 7bf48b02be)
5 months ago
Philippe Antoine 69107199d6 http2: code refactoring to split big function
(cherry picked from commit 29e4b08647)
5 months ago
Philippe Antoine 82cf3d67b1 ldap: bound the number of responses
Ticket: 8405
(cherry picked from commit e98d419d96)
5 months ago
Victor Julien 75a4641af6 http2: check for HTTP1 protocol during upgrade path
Ticket: 8492
(cherry picked from commit 6ebd0c3cc2)
5 months ago
Philippe Antoine c029c09585 nfs: bound file_additional_procs to 1
Ticket: 8418

As we only need to know we saw at least one NFSPROC3_COMMIT

(cherry picked from commit 10bde66586)
5 months ago
Philippe Antoine af37786ee4 nfs: bound namemap by using lru
Ticket: 8418
(cherry picked from commit aea7ee21b8)
5 months ago
Philippe Antoine f43d442251 nfs: bound requestmap and use lru
Ticket: 8418
(cherry picked from commit a50f494ef6)
5 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)
5 months ago
Jason Ish bc05d40d70 rust/lua: add method for pushing bytes
Much like pushstring, but accepts an &[u8] as an argument instead of an &str.

In support of ticket #8533.

(cherry picked from commit 81692dd2c1)
5 months ago
Jason Ish c8d95f20db ntp: enable keywords for firewall mode
Ticket: #8394

Backport note: main-8.0.x does not have the keyword information flag
constants from main, so keep SIGMATCH_SUPPORT_FIREWALL and omit the
informational SIGMATCH_INFO_* flags.

(cherry picked from commit fd31e50954)
5 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)
5 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)
5 months ago
Jason Ish 545070ad61 ntp: add ntp.stratum keyword
Ticket: #8431
(cherry picked from commit c10c482290)
5 months ago
Jason Ish 4f427c30be ntp: add ntp.version keyword
SNMP was used as a template.

Ticket: #8430
(cherry picked from commit ec344fe68d)
5 months ago
Jason Ish e2b2737e8e ntp: create tx for all modes; log version, mode and stratum
Add logging for version, mode and stratum as these will be the first
keywords we will add.

Ticket: #8425
(cherry picked from commit 74bb525401)
5 months ago
Jason Ish 21c7adf071 ntp: remove unused event types
NotRequest and NotResponse event type have never been used.

Unsolicited is also unused, however there is a rule for it so removing
support would be a breaking change at this time.

(cherry picked from commit 879846e153)
5 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)
5 months ago
Jeff Lucovsky 9162048a93 ftp: raise too_many_transactions event on overflow
Other parsers (SMB, POP3, ENIP) already raise a too_many_transactions
event when a flow exceeds its per-flow transaction limit. FTP had
the limit wired up through app-layer.protocols.ftp.max-tx but just
dropped the excess transaction on the floor with a "FTP does not set
events yet..." TODO, so no event was raised when the limit was
reached.

Add the FtpEventTooManyTransactions variant, a stock rule at
sid 2232002, and raise the event from FTPTransactionCreate when the
live-tx count goes past ftp_config_maxtx.

Issue: 8489
(cherry picked from commit 9ea2e29581)
6 months ago
Philippe Antoine ad9d979f92 detect/dcerpc: avoids FP on dcerpc.iface keyword
When we got a bind without the first fragment flag, and did not
set any_frag in the signature, the signature always matched,
whatever the uuid value

Ticket: 8457
(cherry picked from commit e38888810d)
6 months ago
Jason Ish 07555b97fc psl: update to 2.1.206
Update the public suffix list to the latest release.

Ticket: #8360
6 months ago
Victor Julien e55197d103 detect/snmp: let generic keyword share the same list
(cherry picked from commit 2cef1404bc)
6 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)
6 months ago
Philippe Antoine df625bd32f detect: enable snmp keywords for firewall mode
Ticket: #8395
(cherry picked from commit 8ac9a62ec4)
6 months ago
Philippe Antoine 80c6145478 detect/snmp: sticky buffers at progress 1
Since snmp txs are created at progress 1 which is the completion,
this does not change detection, except allowing firewall mode
to use these keywords with generic hook like
snmp:request_complete

Ticket: 8395
(cherry picked from commit 63603fe14a)
6 months ago
Philippe Antoine 7ce6fd6b21 detect: adds helper function SCDetectHelperBufferProgressMpmRegister
Taken from ea8ac2a0
6 months ago
Philippe Antoine efc5075a4f detect: new helper for buffer register with required progress
Ticket: 8395

Not a cherry-pick of 8f824458 which replaces, so as not to change
the current API, just extending it
6 months ago
Philippe Antoine f53a5d3b7a websocket: check pdu opcode for reassembly
Ticket: 8413

RFC 6455 Section 5.4 states

Control frames (see Section 5.5) MAY be injected in the middle of
a fragmented message.

Control frames are identified by opcodes where the most significant
bit of the opcode is 1.

(cherry picked from commit 2fa10052cf)
7 months ago