Commit Graph

19692 Commits (31afa84f72116925d89e041fa116bde8630022f2)
 

Author SHA1 Message Date
Jeff Lucovsky 31afa84f72 transform/pcrexform: flag match failures
pcrexform gave no signal when the regex did not match, when the capture
could not be extracted, or when there was no room for the capture. A
capture of nothing also left the input in place when the buffer had no
room yet, since InspectionBufferCopy then copies nothing.

Mark the transform SIGMATCH_TRANSFORM_CAN_FAIL and flag those failures
with SCInspectionBufferSetError. Set an empty capture's length to 0
directly, and leave an empty input alone, as from_base64 does.

Issue: 7313
1 week ago
Jeff Lucovsky 9f8dad7245 transform/base64: flag from_base64 decode errors
from_base64 gave no signal when offset or bytes ran past the input or
nothing decoded, so a later keyword could not tell a failed decode from
a successful one.

It also skipped decoding when bytes equaled the input left after
offset, which the C transform before d8a99e1fdd decoded.

When an earlier transform had left the input in the buffer's own
memory, a strict decode that failed partway wrote decoded bytes over
it: after strip_whitespace, "/Zm9vYmFyYmF6cXV4!!" no longer matched.

Mark the transform SIGMATCH_TRANSFORM_CAN_FAIL and flag these failures,
and allocation failures, with SCInspectionBufferSetError. Decode when
bytes equals the remaining input. In place, decode into a separate
buffer and copy the result over only on success. Call base64_decode
instead of SCBase64Decode.

Issue: 7114
1 week ago
Jeff Lucovsky de7016b79b ffi/base64: add a safe decode function for Rust
SCBase64Decode builds its output slice with the input length, whatever
the caller allocated, and the from_base64 transform called it through
unsafe after asking for only the decoded length.

Move the decoding into base64_decode(), which takes the input and output
as slices, and keep SCBase64Decode as a wrapper for C callers. The
transform switches to base64_decode in the next commit.

Issue: 7114
1 week ago
Jeff Lucovsky a2ad1422f4 detect/inspect: add inspection buffer error function
Add SCInspectionBufferSetError(), which sets a new
DETECT_CI_FLAGS_ERROR flag and leaves the buffer's data unchanged, so a
keyword after a failed transform can tell the failure from a success.
Add SIGMATCH_TRANSFORM_CAN_FAIL to mark transforms that call it.

Clear the flags in each buffer setup function, so an error from one use
of a buffer does not carry over to the next.

Issue: 7313
1 week ago
Jeff Lucovsky 2a572b0c50 dcerpc: set endian flag after applying transforms
dcerpc_tx_get_stub_data set the DCE byte-order flag before
SCInspectionBufferSetupAndApplyTransforms. Once a later commit makes
buffer setup reset the flags, that order would clear the flag and
break byte_test's dce option (dcerpc/dcerpc-dcepayload-15).

Set the flag after the call.

Issue: 7313
1 week ago
Juliana Fajardini 4badfd13f4 docs: note about no support of config kw in fw mode
For Threat Detection rules.

Part of
Ticket: #9041
3 weeks ago
Juliana Fajardini cc84baf1dd detect/config: do not support keyword in TD rules
First part: rule keyword.

Ticket: #9041
3 weeks ago
Juliana Fajardini d4aa40df61 detect: allow banning kw from td in firewall mode
In case a keyword should work in firewall mode, with firewall rules
only. The engine errors out if threat detection rules use the given keyword.

Part of
Ticket #9041
3 weeks ago
Juliana Fajardini 3e3dcf4c9f firewall: don't use 'banned' when no fw support
Banned isn't the right messaging here, we decided.
Instead, go with "not supported".
3 weeks ago
Jason Ish f9f3c2082a pcap-file: clear directory current_file after cleanup
On PcapFileDispatch() failure, pv->current_file was left pointing at freed file
vars, which were then cleaned up again on thread teardown.

Generally unreachable, as no pcap-file pipeline slot fails on real input.

Ticket: #9162
3 weeks ago
Jason Ish cffd9cd62d app-layer: don't include decode.h from app-layer-frames.h
Including decode.h pulls inline functions that use SCLogDebug and SCLogError
into the bindgen input, but util-debug.h hides those macros from bindgen,
breaking "make update-bindings". Only forward declarations are needed.
3 weeks ago
Jason Ish 5f8d1beddf rust: fail check-bindgen-bindings if bindgen fails
Even on failure before, due to the ';', the make target was still
exiting success.
3 weeks ago
Lukas Sismis a329e0a3b9 firewall: reject flow scope for the pre-flow hook
Action scopes for packet hook default policies were validated per hook
class, so `flow` was accepted for every packet hook. The pre_flow hook is
a special case as it is evaluated before Suricata obtains a flow record.
Firewall rules on the pre_flow hook were not validated at all, so `flow`
and `tx` scopes were accepted there as well.

This commit adds extra validation to scope parsing for the pre_flow
hook default policy and validates pre_flow firewall rules against the
same scopes.

Ticket: 8967
3 weeks ago
Lukas Sismis 6fe3a3dfc3 firewall: apply flow scope to the default packet policy drop
The packet default policy runtime only applied the action scope for
`accept`. For `drop:flow` and `reject:flow` it dropped the packet and left
the flow untouched, so the flow scope had no effect.

Ticket: 8969
3 weeks ago
Lukas Sismis 3a6ecab098 github-ci: add OpenBSD 7.9 build
Ticket: 8975
3 weeks ago
Lukas Sismis 9d88976dfa ci: migrate to FreeBSD 15.1
As FreeBSD 15.0 hit EOL, Rust dependencies started to fail.
Upgrading to 15.1 to move from EOL release.

Ticket: 9172
3 weeks ago
Victor Julien 8998fbacc5 threads: add unit tests for TmThreadsWaitForUnpause
Covers the killed-during-initial-pause case (mgmt thread returns so the
main loop runs once; non-mgmt returns false and skips it, THV_PAUSED
cleared on both paths) and the unpause-while-spinning path, driven from
a helper thread.

Ticket: #9168.
3 weeks ago
Victor Julien 1ff8de029a threads: run the main loop once when a mgmt thread is killed during the initial pause
Every thread is created paused (THV_PAUSE) and the main thread unpauses
them all before the main loop. A thread that has not yet been scheduled
spins in TmThreadsWaitForUnpause() until it sees the unpause. Under
heavy thread oversubscription (many short offline runs in parallel) a
management thread can be descheduled across the whole run: by the time
it runs again the shutdown has set THV_KILL while it is still in the
initial pause. TmThreadsWaitForUnpause() then returned false, so the
thread skipped its main loop entirely and never did its final shutdown
work - for the stats thread that means the last stats event is never
written to eve.json. This intermittently fails suricata-verify tests
that assert on the final stats.

Mgmt threads (tv->type == TVT_MGMT) now return so the main loop still
runs once: it tests THV_KILL and exits after the pass, but the thread
gets the single pass it needs for final work (e.g. the last stats
output). THV_PAUSED is cleared on that path. RX, worker and other
non-mgmt threads keep the previous behaviour: their loops do not test
THV_KILL at the top - the RX loop exits only on the PktAcqLoop return
value and suricata_ctl_flags, and a pcap-file pass would dispatch
packets into a pipeline that is being torn down.

The log-maintenance thread breaks before its first sleep slice when it
is already being killed: on that pass no rotation or flush can happen
(their wait counts need a full second of slices), so the fixed 500 ms
sleep would be pure shutdown latency - the slice exists to react to
shutdown quickly, and a first wake into a KILL must not wait out a full
slice. A kill arriving after the first slice keeps the normal
behaviour, including the final rotation check.

Ticket: #9168.
3 weeks ago
Philippe Antoine b8275da9d0 dns/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine 895347aff2 kerberos/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine dfc42274ab ntp/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine 6abd9e9540 ldap/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine b39514269a rfb/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine fc36553629 mqtt/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine e6231074b2 enip/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine 72afcb301f websocket/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine 8a6359662c nfs/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine 5a5dcdab3e http2/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine c23ff8695b sctp/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine 49aefe7093 ci: check for enum integer keywords
And generic documentation about it

Ticket: 8675
3 weeks ago
Philippe Antoine b47bde6cda dnp3/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine f3d8af65cb snmp/doc: list possible values for enum keywords
Ticket: 8675
3 weeks ago
Philippe Antoine 5f068793d3 doc: string enum derive has a function listing the enum values
Ticket: 8675
3 weeks ago
Philippe Antoine 6f57427977 doc: keywords can register a callback for further info
Ticket: 8675

Will be used by enum uint keywords to print the list of possible
enum values
3 weeks ago
Philippe Antoine a269d8635f doc: list-keywords with json output
suricata --list-keywords=json outputs json for all the keywords

Ticket: 8675
3 weeks ago
Philippe Antoine 04c066977a smtp: apply max-tx to live txs
Instead of the cumulative tx count

Ticket: 9038
3 weeks ago
Philippe Antoine 8461e3f3e7 src: do not include "util-unittest.h" directly
It is included in suricata-common.h

Ticket: 945
3 weeks ago
Philippe Antoine 34841ab11b src: do not include "util-optimize.h" directly
It is included in suricata-common.h

Ticket: 945
3 weeks ago
Philippe Antoine 6b8aa7e7b6 src: do not have util-memcmp.h in suricata-common.h
Let every user include it directly

Ticket: 945
3 weeks ago
Philippe Antoine b1e7648077 src: do not include "util-atomic.h" directly
It is included in suricata-common.h

Ticket: 945
3 weeks ago
Philippe Antoine a2b0e7b0aa src: do not include "util-mem.h" directly
It is included in suricata-common.h

Ticket: 945
3 weeks ago
Philippe Antoine de335ba98a src: do not include "util-time.h" directly
It is included in suricata-common.h

Ticket: 945
3 weeks ago
Philippe Antoine 1f7f980ac4 src: do not have queue.h and tree.h in suricata-common.h
Let every user include it directly

Ticket: 945
3 weeks ago
Philippe Antoine 7610e36bb2 src: do not include "tm-threads-common.h" directly
It is included in suricata-common.h

Ticket: 945
3 weeks ago
Philippe Antoine d7dde0c743 src: move windows-specific includes out of suricata-common.h
Ticket: 945
3 weeks ago
Victor Julien e465600c9f stream/tcp: keep the ACK tracking alive past the reassembly depth
A direction that hit stream.reassembly.depth stops collecting data, so
StreamTcpPruneSession() stops sliding its reassembly buffer and base_seq
freezes where the data stopped while the sequence numbers keep moving. The
base_seq bound on last_ack updates compares an ACK against that anchor with
SEQ_GT(), which is only meaningful within half the sequence space: 2^31 bytes
past the depth it reads a regular ACK as being behind base_seq and last_ack
stops moving, next_win with it, and every packet from then on is flagged
out-of-window or with an invalid ack. 2^32 bytes later both comparisons line up
again at once, last_ack takes one step of 4 GB and the reassembly engine
reports a gap over data the peer already acked - for TLS a decoder error, and
in IPS mode the exception policy drops the flow without RST or FIN.

Take the bound only while the direction is still reassembling, as that is when
base_seq tracks the stream; nothing is inserted once it stopped, so there is
nothing left for the bound to protect. Where base_seq is ahead of the ACK it
still refuses the update, so the check Redmine #6865 added stays in place for
streams that are still collected.

Ticket: #9141.
3 weeks ago
Victor Julien 215961d672 http2: do not log an empty settings array
An empty SETTINGS frame (an ACK, or a SETTINGS without entries) opened
the settings array and closed it without items, producing a record the
eve schema rejects (settings has minItems 1). Skip the frame instead; a
tx whose only content is an empty SETTINGS frame is then not logged at
all, matching the empty headers handling.

Exposed by the flow-end flush of IDS-dropped flows: the dropped flow in
the drop-protocol-change test carries such a frame.
4 weeks ago
Victor Julien bf167418bf detect: reject the '<' hook form for non-firewall rules
The '<' lower bound hook form is a firewall policy construct: the rule
covers its own hook and every prior one. For a threat detection rule the
form has no such meaning, and the flag it sets leaked into the firewall
policy walk, where the rule could influence the per-state decisions.

Reject the form at load for rules without SIG_FLAG_FIREWALL.

Ticket: #8944.
4 weeks ago
Victor Julien ffd30f161a tls: fix SSLv2 hello tls.version matching
tls.version requires the connp's hello to have decoded (hello_decoded),
which only TLSDecodeHandshakeHello() set. The SSLv2 hello path sets the
client version without the flag, so an SSLv2-compatible ClientHello no
longer matched tls.version: on main it matched, so a firewall accept
rule using the keyword never accepted.

Set the flag in the SSLv2 client and server hello cases.

Ticket: #9047.
4 weeks ago
Victor Julien e6eac91974 detect: unify the transaction end state helper
AppLayerParserGetTxEndState() replaces the remaining copies of the
transaction end state computation in the firewall tx setup, the
app-layer-state and app-layer-event keywords and the completion check.
One tolerated a missing tx data pointer, the others asserted or
dereferenced it, so they could disagree.

Move DetectTxCompleted() above its first use while there, so it no
longer needs a forward declaration, and shorten its comment.

Ticket: #8944.
4 weeks ago