Commit Graph

2373 Commits (main)

Author SHA1 Message Date
Victor Julien f545f06cf2 doh2: do not enable parser if http2 is disabled
DOH2 depends on HTTP/2, so it makes no sense to enable it separately.

It would also put the sub state handling in a weird state, as the DOH2
side reuses the registered HTTP/2 callbacks.
2 days ago
Victor Julien cf216b6309 http2: rename state *start to *started
This is to make the hook use names consistent with the default
hooks and other protocols.
2 days ago
Victor Julien bb41ef9caf http2: update push promise to account for stream id 0 filtering 2 days ago
Victor Julien c17ab6a65e http2: set event on frame types not allowed on stream id 2 days ago
Victor Julien 63b8143577 http2: register names for states per sub-state 2 days ago
Victor Julien 14100d795c http2: mark HTTP2TxProgress and HTTP2TxGlobalProgress as AppLayerState 2 days 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 days 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 days 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 days 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 days ago
Philippe Antoine 9c244c978a snmp/detect: add snmp.trap_address keyword
Ticket: 8486
3 days ago
Philippe Antoine 08b0adf09d snmp/detect: add snmp.trap_oid keyword
Ticket: 8485
3 days ago
Philippe Antoine 752dae89ea detect: add progress argument to SCDetectRegisterMpmGeneric
Will be needed by snmp
3 days ago
Philippe Antoine 7d024a840c rust: bindgen detect ThreadCtx keyword functions 3 days ago
Philippe Antoine 5fe920ec42 detect: make Http2ThreadBuf a generic DetectThreadBuf
to be used by snmp and other
3 days 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.
3 days 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
4 days 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.
4 days 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
4 days 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.
4 days ago
Philippe Antoine 03ba8a71d8 mqtt: bounds number of messages per tx
Ticket: 8525
4 days 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...
4 days 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
5 days 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
1 week 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.
1 week ago
Jason Ish e7e837c6af psl: update to latest version
Ticket: #8147
2 weeks ago
Philippe Antoine 3b994e807d detect/mqtt: bitflags do not support multi integer
Ticket: 7929

As both syntaxes share comma as delimiter
2 weeks ago
Philippe Antoine 06855cd832 detect/nfs: nfs_procedure does not support multi integer
Ticket: 7929
2 weeks ago
Philippe Antoine cb0ecb1722 detect/krb5: msg_type is not a multi integer
Ticket: 7929

There is only one msg_type by tx
2 weeks ago
Philippe Antoine be4c036071 detect/enip: status are not multi integers
Ticket: 7929
2 weeks ago
Philippe Antoine e08a19a88a detect/enip: cip_class and cip_instance are now a multi-integer
Ticket: 7929

One commit as they share the same code
2 weeks ago
Philippe Antoine 0bdfe3f571 detect/enip: cip_attribute keyword is now a multi-integer
Ticket: 7929
2 weeks ago
Jeff Lucovsky 5af13e3eb0 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
2 weeks ago
Jeff Lucovsky 3f86c56c80 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
2 weeks ago
Philippe Antoine a81031591e detect/krb5: move krb5.ticket_encryption to rust
Ticket: 8648
2 weeks ago
Philippe Antoine 8f0dbc0b63 detect/krb5: move krb5.cname and krb5.sname to rust
Ticket: 8648
2 weeks ago
Philippe Antoine 3327cf42f0 detect/krb5: move krb5_err_code to rust
Ticket: 8648

Make it a generic integer on the way
2 weeks ago
Jason Ish 5856ced29c ftp: support LIST and MLSD data channels
Support LIST and MLSD on the ftp data channel.

Ticket: #8664
2 weeks ago
Philippe Antoine 89dbce1b46 detect: convert tx_progress to uint8_t 2 weeks ago
Philippe Antoine 52490b8c26 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
3 weeks ago
Jeff Lucovsky 5d007ef25e detect/xor: add inline variable key syntax
Extend the xor transform to accept a variable-position key using
the 'extract <nbytes> <offset>' syntax. The engine reads <nbytes> bytes
at buffer position <offset> at transform time.

The optional 'offset' parameter specifies where XOR decoding
starts in the buffer; bytes before that position are left unchanged.

Syntax:
  xor:"<hex_key>"
  xor:extract <nbytes> <offset>
  xor:offset <N>,"<hex_key>"
  xor:offset <N>,extract <nbytes> <offset>

Variable-key helpers (VariableKeyLocation, variable_key_bytes,
parse_key_location, strip_keyword_prefix) are imported from the new
varkey module.

The variable key bytes are copied out of the inspection buffer before
decoding, so an in-place transform cannot corrupt the key when the key
region overlaps the decoded range.

Issue: 8671
3 weeks ago
Jeff Lucovsky 385bd4416b detect/transforms: add varkey module for variable-key helpers
Introduce rust/src/detect/transforms/varkey.rs to centralise helpers
used by transforms that read key material directly from the inspection
buffer at transform time.

Exported items:
  VariableKeyLocation  { offset: u16, nbytes: u8 }
  variable_key_bytes   bounds-checked slice into an inspection buffer
  strip_keyword_prefix strip 'keyword<ws>' from option strings
  parse_key_location   parse '<nbytes> <offset>' into VariableKeyLocation

All four items are pub so any transform can import them. Unit tests
are included in the module.

Issue: 8671
3 weeks ago
Philippe Antoine e6ee69c7da rust: format all files
except the ones with #[rustfmt::skip]

Ticket: 3836
3 weeks ago
Philippe Antoine ca34fba00c rust: format smb files
Ticket: 3836
3 weeks ago
Philippe Antoine f8ac56c591 dcerpc: remove obsolete comment 3 weeks ago
Philippe Antoine aea9fd73b7 rust: format dcerpc files
Ticket: 3836
4 weeks ago
Philippe Antoine c6014a77a2 websocket: accepts config value with units
Ticket: 8552

As was the commented out example
4 weeks ago
Philippe Antoine a9e1dff4a6 conf: introduce SCConfGetNonNull
Ticket: 8651

Behaves like SCConfGet but returns 0 on null value
4 weeks ago
Philippe Antoine e0152178da rust: format detect files
Ticket: 3836
4 weeks ago
Giuseppe Longo 695b4f4a3d sip: remove incomplete data event
It's no longer useful to set an event when the data is incomplete,
since an error is returned.

Ticket #8524
1 month ago