Commit Graph

272 Commits (main)

Author SHA1 Message Date
Victor Julien 6792375d62 ssh: expose the parse failure reason and state in the eve ssh log
A flow that hit an unrecoverable ssh parse error (invalid banner
or invalid record) was never visible in the eve ssh output: the
log condition only admitted a successful handshake (both
directions at kex or session), and the tx logger is one-shot, so
the successful-handshake log fired before a later failure could
be reported and the failure was then silent - the reason was
only visible through the app-layer events.

The log condition is now failure-only: the failure latches, so
the object is emitted exactly once - at the failure, carrying
the error field (invalid_banner / invalid_record) and the state
field (the state the failure occurred in - banner, kex, or
session if a later record fails after NewKeys) - and successful
flows are logged at the flow-end flush, where the engine logs
unconditionally. Logging on the success condition mid-flow would
consume the one-shot tx log and drop a later failure, so it is
not done. The state field is emitted only alongside the error.
The object may be error + state only, when no banner was
parsed. A unit test pins the condition for a failed, a
banner-only and a both-at-kex flow (the failure admits the log
on the failing delivery); the user guide and eve reference doc
commits that follow carry the field docs.

That flow-end flush is skipped for flows that end without a
further app-layer update, though: in IPS/firewall mode a drop
disables the app layer (StreamTcpCheckFlowDrops ->
StreamTcpDisableAppLayer), after which no app-layer update
reaches the tx loggers, and a bypassed flow gets no flow-end
packet either. A successful ssh record - e.g. one that only saw
the banners - was therefore never emitted for those flows. The
hook is the app-layer end: on the transition to app-layer EOF,
StreamTcpDisableAppLayer raises FLOW_APP_LAYER_FLUSH_PENDING,
and FlowUpdateState raises it on the transition to a bypassed
state; OutputTxLog runs the tx loggers once for the next packet,
also when that packet itself has no app-layer update and is not
marked established (the disabling packet returns from the
stream engine before that), and flow-worker clears the flag when
it frees the app layer of a bypassed flow. The flush is
deliberately not a flow-end flush: when the flush is the only
reason to run the loggers, eof is not forced, so each logger's
condition decides and no other parser starts logging records it
suppressed; a disabling packet that does carry an app-layer
update keeps the existing EOF behaviour. SSHTxLogCondition
admits an IPS drop or a bypass, so the pending record is emitted
there; an IDS drop does not end the app layer, so the condition
stays failure-only - a later failure still wins, and the success
record is emitted by the flow-end flush, which the flow timeout
path now also runs for IDS-dropped flows. The unrelated
schema-sort ordering of the new state keys is fixed up as well.

Ticket: #9046.
3 weeks ago
William Ling e7b22ba5fe detect/ldap: add BindRequest detection keywords
Added new keywords:
- ldap.bind_request.version
- ldap.bind_request.authentication:simple
- ldap.bind_request.authentication:sasl
- ldap.bind_request.sasl.mechanism
- ldap.bind_request.sasl.credentials

Ticket: #7536
3 weeks ago
Philippe Antoine 4fa2843344 jsonschema: sort pgsql properties
Fixes 8b5fb9b044
2 months ago
Juliana Fajardini fe939e8da7 pgsql: better boundaries to row_description/data_row
parse_row_description and parse_consolidated_data_row read a field_count
from the message body and use that to iterate a slice, without checking
whether the count actually fits the body.

A backend-controlled attack could lead to fewer fields logged, or
stalling of the parser to-client direction for the duration of the flow.

A malformed_response event is set for pgsql, if either of those
message's inner parsers has a field_count that can't be reconciled with
the body slice.

A new pgsql.response log field is added to indicate this, too:
pgsql.response.row_description_malformed, a boolean. This wasn't added
to the consolidated data row message, per its summarization nature.

The row_description unit test buffer declared a length one byte longer
than its three fields occupy. The old code silently discarded that
surplus byte; the new one reports it, so the buffer was corrected.

Ticket: #8885
2 months ago
Juliana Fajardini 816e23f374 schema: fix typos
s/massage/message
2 months ago
Victor Julien 0282a4fd81 detect/threshold: bound the per-thread decision cache
The per-thread threshold decision cache (limit/both thresholds tracked
by_src/by_dst, IPv4) grew without bound: every distinct tracked address
allocated an item plus a hash-table bucket, while housekeeping reclaims
at most two entries per whole second.

Address this by:

Cap the cache at detect.thresholds.cache.max-entries entries per
thread (default 256; valid range 256-1048576, out-of-range values
fail startup); on overflow evict the entry with the earliest expiry
before inserting

Account cache memory in the new detect.thresholds.cache.memuse
counter: each entry (item plus bucket node) is charged on insert and
released on eviction, expiry and on thread teardown, and the fixed
per-thread charge (thread context, hash table struct and the eagerly
allocated bucket pointer array) is charged at cache init and released
symmetrically on teardown, so the gauge reflects the cache memory in
use and does not accumulate stale charges when threads are recreated,
e.g. unix-socket PCAP file jobs

Size the cache hash table to the entry cap (next power of two, minimum 256)
at thread init so lookups stay O(1) up to the cap.

Fail startup when the threshold table cannot be initialized, instead
of continuing with a NULL table.

Ticket: #8956.
2 months ago
Shivani Bhardwaj e44de40ad7 etc/schema: explicitly add all MQTT properties
Add all the missing properties explicitly and disallow
additionalProperties so any failure is loud and clear.
2 months ago
Juliana Fajardini 41ebbdf499 pgsql: add missing ErrorResponse fields to schema
Due to a lack of tests with varied ErrorResponse messages, it wasn't
noticed before that these were missing.

Partially covers
Ticket: #8903

Related to
Bug: #8886
2 months ago
Juliana Fajardini 8b5fb9b044 pgsql: bound Copy responses to their length field
CopyIn and CopyOut message parsers read the length field, but did not
use that information to parse the rest of the message, instead, parsing
as many columns as indicated in the columns field, without ever
checking against the informed length. This opened the door for
attackers to fabricate messages that were never sent by the server,
as well as to obfuscate following valid backend messages, in case the
columns value was bigger than the actual message (up to ~128KiB).

Those parsers also had a message length parsing check off-by-one, fixed
in this patch.

When a malformed CopyIn or CopyOut response is seen, it is logged as
previously, with a new field added to indicate whether it is malformed
or not.

Ticket: #8863
2 months ago
Shivani Bhardwaj 2eb0b60b83 smb/log: map dcerpc uuid, opnum to service names
With this patch, the logged uuids will also have corresponding
stringified service names. The requests that will have an opnum will
have a corresponding stringified procedure name.

Feature 2727
Feature 8523
3 months ago
Shivani Bhardwaj d77f73d9a6 dcerpc/log: map uuid, opnum to service and procedure
Log the service and procedure names corresponding to a UUID and opnum
for each DCERPC event where it's available.

Feature 2727
Feature 8523
3 months ago
Philippe Antoine d0cc39c79a rfb/jsonschema: add missing field
Ticket: 6478
3 months ago
Victor Julien e1e24d6cb4 eve/alert: add sub state output 4 months ago
Philippe Antoine 9c244c978a snmp/detect: add snmp.trap_address keyword
Ticket: 8486
4 months ago
Philippe Antoine 08b0adf09d snmp/detect: add snmp.trap_oid keyword
Ticket: 8485
4 months ago
Philippe Antoine b84f26ef0a jsonschema: add existing snmp keywords 4 months ago
Giuseppe Longo ede1bce923 output/json: add sctp metadata to alerts
Log SCTP-specific fields in the EVE JSON "sctp" object for alert events.

Ticket #4251
5 months ago
Giuseppe Longo 21d35f6b37 decoder/sctp: extend decoder
Extend the SCTP decoder to parse chunk headers after the 12-byte common
header. Each chunk is validated for minimum header size and length
consistency per RFC 4960 sec 3.2.

Add SCTPChunkHdr and SCTPVars structs to track per-packet chunk metadata

Add five new decoder events for protocol violations:
- SCTP_CHUNK_TOO_SMALL: insufficient data for a chunk header
- SCTP_CHUNK_LEN_INVALID: chunk length < 4 or exceeds packet
- SCTP_INIT_CHUNK_NOT_ALONE: INIT/INIT_ACK bundled (RFC 4960 sec 6.10)
- SCTP_INIT_WITH_NON_ZERO_VTAG: INIT with vtag != 0 (RFC 4960 sec 8.5.1)
- SCTP_DATA_WITH_ZERO_VTAG: DATA chunk with vtag == 0

Ticket #4251
5 months ago
Giuseppe Longo 8f205bb34f llmnr: implement logger
This adds an LLMNR protocol logger that reuses existing DNS functions,
following the same approach as the mDNS logger:

- No grouped logging
- Rdata is logged in a field that is named after the rdata type
- Types are logged in lower case
- Flags are logged as an array

Ticket #8366
5 months ago
Victor Julien 90a837cef3 detect/firewall: update discarded logic
Only count alert queue overflow here, not alerts in the queue after a drop.
5 months ago
Victor Julien 8572088b0f eve/alert: firewall default policy logging improvements
Add firewall.hook to indicate the hook that the policy was set on.

Ticket: #8566.
5 months ago
Victor Julien 2d4f1968b8 detect/firewall: support alert in default app policy
Support `alert` as a secondary action in app-layer firewall policies.

To implement this a Signature object is created per policy that uses
alert, and this is stored in a hash table. When the policy is applied
the signature is looked up and used in the PacketAlert.

Ticket: #8566.
5 months ago
Juliana Fajardini 8a8574b149 exceptions: add dedicated flow drop reason
To better control stats counters.
5 months ago
Juliana Fajardini 312967f291 detect: add flow drop by firewall as drop reason
To track flow drops triggered by the firewall.
Add flow drop by firewall as drop reason.

As part of
Ticket #7699
5 months ago
Juliana Fajardini 0acb136b40 schema: expand stats.ips.replaced explanation
As this is a less obvious counter.
5 months ago
Juliana Fajardini 5b488feef5 detect/firewall: add dedicated stats counters
Add a `firewall` stats counter aggregator for all firewall-related
stats.
De-overload "detect.alert_queue_overflow", by adding
"firewall.discarded_alerts" to account for discarded drops in
Firewall mode.
Add Debug statements for tracking corner cases where it can be
difficult to know where a drop is coming from.

Added counters:
- stats.firewall.blocked
- stats.firewall.accepted
- stats.firewall.rejected
- stats.firewall.drop_reason.default_app_policy
- stats.firewall.drop_reason.default_packet_policy
- stats.firewall.drop_reason.flow_drop
- stats.firewall.drop_reason.pre_flow_hook
- stats.firewall.drop_reason.pre_stream_hook
- stats.firewall.drop_reason.rules
- stats.firewall.discarded_alerts

Ticket #7699
5 months ago
Jeff Lucovsky cc6fbcd5dd etc/schema: add missing ftp fields
Add ftp detect keywords to metadata

Issue: 7502, 7503, 7507, 7505, 7508, 7506
5 months ago
Jason Ish 029fd1be59 eve: add rule generation source to alert record
When an alert is generated from firewall context, add an engine value of
"fw", otherwise "td" (for threat detect).

The engine field is only added when firewall mode is enabled.

Ticket: #8456
6 months ago
Philippe Antoine 54c02e1301 stats: replace dashes by underscores in app-layer protocols
Ticket: 6502

Forbid dashes in json keys for better use by processing tools
6 months ago
Philippe Antoine d030ea7f29 output: rename reject-target to reject_target
Ticket: 6502

Forbid dashes in json keys for better use by processing tools
6 months ago
Jason Ish 18f742fdbd schema: map NTP fields to keywords 6 months ago
Jason Ish 713e4eb900 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
6 months ago
Jason Ish 74bb525401 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
6 months ago
Jason Ish 31b967b089 ntp: add transaction logging
Adds basic NTP transaction logging for the current supported message
types.

Includes small cleanups around reference ID.

Ticket: #8425
6 months ago
Victor Julien 670fdabd32 detect/snmp: add snmp.trap_type keyword
Implemented as a U8 integer keyword.

Ticket: #8482.
6 months ago
Victor Julien c94cb8e098 eve/schema: add snmp trap fields 6 months ago
Eric Leblond e4e5413478 etc/schema: add http_request_body
Ticket: 8161
7 months ago
Eric Leblond 97a0ad342b etc/schema: match on http response body
Matching on the HTTP response body is not really possible as it is
a transformed version that can not be accessed via the signature
language.
7 months ago
Jason Ish 3e9c726aa8 etc/schema: remove "optional" field
The optional field has not been valid JSON schema field since we started
using it, so remove it.

All fields are optional unless marked as required.
7 months ago
Victor Julien 94c16d8915 eve/igmp: add schema support for alert records 8 months ago
Victor Julien d652b7ef62 decoder/igmp: detect RGMP (RFC 3488)
RGMP is a dialect of IGMP that uses the same protocol structure,
but with some different values for the fields.

Detect this and log it differently.
8 months ago
Victor Julien 1b7cc2b323 decoder/igmp: initial decoder support for IGMP
Basic v1, v2 and v3 header validation.

Ticket: #8262.
8 months ago
Philippe Antoine 0d714b9624 doc/jsonschema: remove non-existing email fields 9 months ago
Philippe Antoine 81cc007a11 doc/jsonschema: remove non-existent ldap field
Probably a duplicate typo
9 months ago
Philippe Antoine 750ae52eac doc/jsonschema: remove obsolete insert_list_fail field
Ticket: 5267
9 months ago
Ofer Dagan 2371829bf1 schema: add threshold stats counters
Add schema definitions for new threshold-related statistics:
- bitmap_alloc_fail: Count of bitmap allocation failures
- bitmap_memuse: Memory usage by detection_filter bitmaps
- memcap: Memory cap for threshold hash table
- memuse: Memory usage by threshold hash table

Task #7928
9 months ago
Jeff Lucovsky 54bd8edf68 decode/ipv4: Create event on unknown protos
Issue: 7146

Create an event when the IPv4 header contains an unknown IP protocol.
9 months ago
Philippe Antoine dd6baccabd src: doc: remove more double-space typos
Found with git grep -E '[a-z]  [a-z]'
10 months ago
Shivani Bhardwaj 0f92583702 flow: split elephant flow detection per dir
The tracking for elephant flow is done per direction however, the flag
was set on the flow whenever either of the directions crossed the
rate-limit defined in the settings. Given that the tracking was already
split, it makes sense to split the detection tracking per direction as
well and allow user to have a better control via rule language.
10 months ago
Philippe Antoine 24405a7b76 doc: http fields in json schema
Ticket: 6075
11 months ago