Commit Graph

19464 Commits (928ac012156fb8d393ce5ac4a496fde3c2e87b00)
 

Author SHA1 Message Date
Victor Julien cedb836d01 output/dns: update for DOH2 change 2 months ago
Victor Julien 5735b87c3a detect: change how DOH2 inspection works
DNS/HTTP2 no longer automatically registers all keywords also for DOH2.

Instead, the DNS keywords and HTTP/2 stream keywords are registered for
DOH2 explicitly as well.

- flow alproto DOH2 + engine DOH2  -> inspect inner DNS
- flow alproto DOH2 + engine HTTP2 -> inspect outer HTTP/2
- flow alproto DOH2 + engine UNKNOWN -> inspect outer HTTP/2
2 months ago
Victor Julien 17953d2355 detect/http: register keywords for HTTP/2
Now that HTTP keywords are no longer automatically registered for
HTTP/2, register them manually.
2 months ago
Victor Julien b36ec146aa detect/dns: register keywords for DOH2 as well
Now that DNS keywords are no longer registered for DOH2, the keywords
need to manually registered for DOH2.
2 months ago
Victor Julien 1bb843d83f detect/http2: don't double register engines
Each keyword supporting DOH2 must register explicitly
2 months ago
Victor Julien 416b9c12ae detect/file: register http/2 with sub-state 2 months ago
Victor Julien c943de4fac detect/parse: initial http2 substate support
Hard coded for now.
2 months ago
Victor Julien 7ebc699df0 http2: split transaction state machines
Split into 2 sub-states:
- stream, which has the "HTTP" requests and responses, including DOH2
- global, which has the settings and other global or control handling

Introduce a simpler progress tracking for the global sub state:
- HTTP2ProgGlobalStart and HTTP2ProgGlobalComplete.

The stream sub state uses the same state machine as before.

Ticket: #8386.
2 months ago
Victor Julien 2f41e0ef2d output/tx: support substate completion flags 2 months ago
Victor Julien 67e2cb538a detect/app-layer-event: support sub-state progress handling 2 months ago
Victor Julien 59e2c5a40c detect/parse: initial substate support 2 months ago
Victor Julien 95365ce05b detect: support per tx sub states
Support for per transaction sub states: different state machines per
transaction type.

Skip engines not belonging to our substate.

Store tx_type in DetectTransaction.

Each protocol supporting sub states will register states from 1 and up.

To support:

Ticket: #8386.
2 months ago
Victor Julien b6bc025789 app-layer: start of substate API support
Allow registration of per substate progress name mappings.

Implement logic for getting sub-state names, id's.

Add transaction type and end of progress values to AppLayerTxData.

Introduce helpers to keep logic clean.
2 months ago
Shivani Bhardwaj 06db2e2698 detect/flowbits: add max usage per signature limit
Add a limit on the maximum number of times flowbits keyword that can be used in a
signature.

Task 8596
2 months ago
Shivani Bhardwaj 3462b126a3 detect: add max_flowbits option
Also move field around to pack holes and align the struct better.

Task 8596
2 months ago
Jason Ish 842b14ee1f smtp: don't create transaction for trailing quit
Also ensures that a quit or rset without a helo still creates a tx.

Ticket: #8728
2 months ago
Jason Ish e2a62dd1c0 smtp: handle pipelined replies on owning tx
Track the transaction id for each queued SMTP command so replies can update the
transaction that created the command instead of always using the current
transaction.

Ticket: #8393
2 months ago
Jason Ish 7b31f41878 smtp: complete transactions by progress state
Add directionality to completion states, and replace tx->done by checking for
both directions being complete.

This means that the transaction is now not complete until the server responds
to the clients of data marker, previously the tx was completed when the client
send end of data without waiting for the server response.

This keeps smtp:response_complete from being exposed before the server response
is parsed.

Ticket: #8393
2 months ago
Jason Ish c2728eee01 smtp: add firewall progress states
Add minimal SMTP progress states to support envelope validation before
moving to data.

Update SMTP, file and email keywords to hook into the appropriate
states.

Purposefully kept minimal for now as to not break the current idea of an
SMTP transaction, which is probably not ideal for firewall mode.

Ticket: #8393
2 months ago
Philippe Antoine 9c244c978a snmp/detect: add snmp.trap_address keyword
Ticket: 8486
2 months ago
Philippe Antoine 08b0adf09d snmp/detect: add snmp.trap_oid keyword
Ticket: 8485
2 months ago
Philippe Antoine 752dae89ea detect: add progress argument to SCDetectRegisterMpmGeneric
Will be needed by snmp
2 months ago
Philippe Antoine 7d024a840c rust: bindgen detect ThreadCtx keyword functions 2 months ago
Philippe Antoine 5fe920ec42 detect: make Http2ThreadBuf a generic DetectThreadBuf
to be used by snmp and other
2 months ago
Philippe Antoine b84f26ef0a jsonschema: add existing snmp keywords 2 months ago
Jason Ish 4e642b9f06 rust/ffi: specify sys crate dependency version
This is required for crates.io publishing, and we also use this for
other internal crate dependencies, for example suricata depending on
derive, etc.
2 months ago
Yash Datre 43bc2db41e detect: extend app-layer-protocol to accept a pipe-separated value list
Extend the app-layer-protocol keyword to accept a pipe-separated list of
protocol values, so a single rule can match any of several protocols:

    app-layer-protocol:[!]<proto1>|<proto2>[|...][,<qualifier>]...;

A non-negated list matches when the flow's protocol equals any listed value
(OR); a negated list matches when it equals none of them (NOR). The
single-value form and the trailing mode qualifier are unchanged.

Matching keeps the historical AppProtoEquals() equivalences by default
(dns/doh2, http/http1/http2, dcerpc/smb, ...). An `exact` qualifier selects
strict identity matching with no equivalences and no http umbrella; it
combines with a direction mode in any order. Because a flow is never the
generic ALPROTO_HTTP, `http,exact` is rejected at load.

Values are expanded once at rule load into an effective match-set bitmask, so
the per-packet match is a single bitmask test. Single-value rules remain
prefilterable; multi-value rules are excluded from prefiltering and an
explicit prefilter on them is rejected. Conflicting keyword combinations
(duplicate or overlapping negations, mixed positive/negated) are rejected at
load. Engine-analysis reports the effective match set.

Ticket: 7705
2 months ago
Philippe Antoine 1731805967 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
2 months ago
Philippe Antoine 7ec9d72d28 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.
2 months ago
Jeff Lucovsky c8f68b0e4f 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
2 months ago
Philippe Antoine 392b6aee29 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.
2 months ago
Philippe Antoine bc41dcc854 flow: check ip family when comparing
Ticket: 8558

Do not accept an IPv6 as an IPv4 (even if the hash is likely
different in the first place)

Do the check also for ESP, and ebpf
2 months ago
Philippe Antoine 03ba8a71d8 mqtt: bounds number of messages per tx
Ticket: 8525
2 months ago
Philippe Antoine 4985eb9dae 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...
2 months ago
Philippe Antoine 82c4190558 ftp: do not create more than max-tx transactions
Ticket: 8592

Fixes: 5ddd808e9b ("ftp: don't halt the flow when raising
too_many_transactions")

In the case we receive a big chunk of TCP data, we end up
creating much more than max-tx transactions, and have
quadratic complexity on this packet, even if all
these transactions get cleaned up at the end of the processing
of this packet.
2 months ago
Philippe Antoine 4a728464e6 ippair: check ip family when comparing
Ticket: 8559

Do not accept an IPv6 as an IPv4 (even if the hash is likely
different in the first place)
2 months ago
Jason Ish 40503f6602 github-ci: fix new authors check
Shortly after minimizing the new authors check to one workflow, github
released an action update that required more permissions due to an
attack scenario, which didn't really apply to us as we didn't run code
from the remotes fork.

However, to avoid extending permissions, rework the authors check to
pull the OISF repo, checkout the PR fork as history, then do the new
authors check. This safely allows the check to run in the context of our
repo without the fork being able to inject code execution.
2 months ago
Amir Boussejra f917926165 ebpf: raise RLIMIT_MEMLOCK only on kernel >= 5.11
EBPFLoadFile() unconditionally raised RLIMIT_MEMLOCK to infinity and
aborted the eBPF/XDP load if the call failed.

Since Linux 5.11 BPF map memory is memcg-accounted and is no longer
charged against RLIMIT_MEMLOCK (https://lwn.net/Articles/829307/), so
raising the limit is unnecessary on those kernels.

Ticket: 8719
2 months ago
Giuseppe Longo 499995bf0e 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
2 months ago
Philippe Antoine d62acf5d75 detect: use only one non-prefilter frame for prefilter
Ticket: 8590
2 months ago
Shivani Bhardwaj 0f56783ec1 dcerpc: make tx id handling consistent
dcerpc parser creates a new tx with id 0 and compensates for the 1 based
index handling throughout the code by overriding that value in a trait
implementation. Make this consistent with other applayer parsers.

Task 8720
2 months ago
Adam Kiripolsky b8d7f894be flow/manager: no flow timeout when hash-size < 10
Fix Flow Manager error when flows were not being timed out
in case flow.hash-size < 10.
This happened because calculation of variable rows_per_sec in
flow-manager.c rounded the value to zero.

This commit ensures that variable rows_per_sec is at least 1.

Ticket: 8710
2 months ago
Victor Julien 9555e3add6 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.
2 months ago
Victor Julien 9e31a21aba detect/firewall: apply accept if last tx was skipped
In firewall mode, a accept:hook or accept:tx needs to lead to a accept
packet when the action is applied to the last TX. For this the code
relied of the `DetectTransaction::is_last` field, where the assumption
was that there would always be an inspection on the last transaction.
This assumption was wrong however, as transactions can be skipped for a
few reasons: not updated, fully inspected, unidirectional for the other
direction. This would cause the accept not be applied to the packet,
leading to a default drop.

The reason this wasn't noticed before is that until now the work had
focused on protocols that used sequential transactions (http/tls),
and/or short lived sequential unidir transactions (dns)

This patch addresses the issue by making a simple assumption: if the
last available transaction in the main detection loop is skipped, it
means it has been accepted before. Therefore we can apply the "accept
packet" logic in this case.

Bug: #8698.
2 months ago
Victor Julien ee1b9b9212 detect: use next tx info from iterator
In non-sequential transaction handling, the is_last set could be
incorrect.
2 months ago
Victor Julien b065a4bf98 http1: fix transaction iterator
The has_next field was not correctly set.
2 months ago
Victor Julien 3b351e2574 detect: move packet alert logic into helper 2 months ago
Victor Julien 695c9d8d20 detect/alert: split append func per packet/tx 2 months ago
Adam Kiripolsky 74bc0feb1a af-packet: invert ebpf g_flowv4_ok log flag
Fix how error messages are printed in a case error occurs in the ebpf
flow table code. The log flag g_flowv4_ok was inverted,
so the error messages were never printed.

The fix follows g_flowv6_ok flag code structure.

Ticket: 8704
2 months ago
dependabot[bot] 6cbf511f65 github-actions: bump github/codeql-action/upload-sarif
Bumps [github/codeql-action/upload-sarif](https://github.com/github/codeql-action) from eda5730a8bfb740e03a28087a958444c646e5842 to 1f34ec16430d82636d18716acc7aaa6d843b35a9.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](eda5730a8b...1f34ec1643)

---
updated-dependencies:
- dependency-name: github/codeql-action/upload-sarif
  dependency-version: 1f34ec16430d82636d18716acc7aaa6d843b35a9
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2 months ago