Commit Graph

1048 Commits (6ae294c7706d2a82712b57edebde87517b2ad5b6)

Author SHA1 Message Date
Philippe Antoine 6ae294c770 detect: run frames on pseudo flush packets
for SSH packets that mark the end of plaintext
2 years ago
Philippe Antoine 0ccad8fd88 doh: make dns and http keywords for doh2
Ticket: 5773
2 years ago
Victor Julien ce727cf4b1 detect: remove unnecessary detect thread flags stores 2 years ago
Victor Julien 956c8bebd1 detect/prefilter: use sig mask to exclude pkt engines
Add an argument to the packet prefilter registration function to include
`SignatureMask` flags. This will be used at runtime to only call these
prefilter engines when the mask check passes.
2 years ago
Victor Julien 683363b42d detect/frames: avoid IPS rescanning
Make sure to only scan the data when the app layer has been updated
as well.

Ticket: #6718.
2 years ago
Philippe Antoine 20423fdd38 style: remove some useless return
and remove empty line before end of function
2 years ago
Philippe Antoine 9e01956e77 detect: log relevant frames app-layer metadata
Ticket: 6973

Completes commit 2b4e10224e
2 years ago
Victor Julien 68804b8c4b decode/tcp: move tcph into L4 packet data
To reduce Packet size.

Ticket: #6938.
2 years ago
Victor Julien 1002068e39 decode/icmpv4: add and use PacketIsICMPv4 inline func
For better readability and type checking.

Ticket: #5517.
2 years ago
Victor Julien cca912e9b3 decode/tcp: add and use PacketIsTCP inline func
To prepare future changes to the Packet header pointers.

Ticket: #5517.
2 years ago
Victor Julien 2001ddc583 decode: use macro's instead of direct ptr checks
To prepare future changes to the Packet header pointers.

Ticket: #5517.
2 years ago
Victor Julien eb3ca643c1 decode: reduce PKT_IS_IPV4/PKT_IS_IPV6 use
Replace it with inline functions. Adds inline functions to
wrap PKT_IS_IPV4/PKT_IS_IPV6.

This is in preparation of removing the macro's, and cleaning up the
header pointers.

Ticket: #5517.
2 years ago
Victor Julien 813147755d decode: rename IP_GET_IPPROTO to PacketGetIPProto
To match function naming style.

Ticket: #5517.
2 years ago
Philippe Antoine 7274ad58aa detect: use direction-based tx for app-layer logging
When we only have stream matches.

Ticket: 6846

This solves the case where another transaction was created
by parsing data in the other direction, before running the
detection.

Like
1. get data in direction 1
2. acked data: parse it, but do not run detection in dir 1
3. other data in direction 2
4. other data acked : parse it and create new tx,
then run detection for direction 1 with data from first packet
2 years ago
Philippe Antoine 910f6af54f output: do not use tx id 0 when there is no tx
Ticket: 6846

This led to packet rules logging irrelevant app-layer data
2 years ago
Victor Julien 4fd0745b78 detect: minor cleanup 2 years ago
Philippe Antoine 497394eec6 detect: do not run tx detection on non established packets
Follows commit 2fb5059

Ticket: 6775
2 years ago
Philippe Antoine 2fb50598f2 detect: do not store state without flags
If flags are zero, there is nothing to store and remember.

Stored signatures will be reused on a later packet, and
qsorted (which may be expensive), with newer matches candidates.

Avoiding to store, leads to avoid the call to qsort.
3 years ago
Philippe Antoine 5bb8800588 detect: merge sorted lists instead of qsort
Ticket: #6299

Simply because it is faster (just linear).

This is for merging match_array into tx_candidates
3 years ago
Philippe Antoine 9240ae250c detect: avoids case of useless detection on txs
When a TCP flow packet has not led to app-layer updates,
it is useless to run DetectRunTx, as there cannot be new
matches.

This happens for instance, when one side sends in a row multiple
packets which are not acked (and thus not parsed in IDS mode).

Doing so requires to move up the call to
AppLayerParserSetTransactionInspectId
so that it is run the same times DetectRunTx is run, and not in the
case where the transaction was not updated.

Ticket: 6299
3 years ago
Victor Julien 44a8bf463e detect/rule-header: use bool type
Update frame prototype as well, to match already returned true/false values.
3 years ago
Victor Julien 72841be050 detect/rule-header: minor code cleanups 3 years ago
Victor Julien 91f153fb1d detect: constify flow flags in tx rule inspect 3 years ago
Victor Julien e4550bee0a detect: minor cleanup for rule group get function 3 years ago
Victor Julien 2b3ec34de8 detect: use do { } while loop for app engine loop 3 years ago
Victor Julien bcb2b50cfc detect/profiling: improve pcap reading performance
When reading a pcap, packet time can move much faster than wall
clock time. This would trigger many more profile syncs than before.

As the sync is using a lock to synchronize with other threads, this
is an expensive operation.

Bug: #6619.

Fixes: b591813b86 ("profiling/rules: reduce sync logic scope")
3 years ago
Victor Julien 95bf7248e8 detect: add check to validate drops 3 years ago
Victor Julien 85ddba63f6 detect: update/document drop flow logic
Now that flow drop is applied to packets before other processing,
no drop has to be issued on a packet.
3 years ago
Victor Julien b591813b86 profiling/rules: reduce sync logic scope
Use a simple once a second scheme.
3 years ago
Eric Leblond 020cfbcd61 profiling: introduce rules profiling
Performance measurement of rules is important on live Suricata
as bad rules can cause severe performance regression. This patch
introduces the --enable-profiling-rules that activate profiling
for the rules. This reduces the performance impact of full
profiling  and provide visiblity on the rules performance at
the same time.
3 years ago
Victor Julien 549f7873df detect: spelling 3 years ago
Victor Julien 5914e0518c detect: fix potential null pointer deref
Could only happen if htp user data alloc would fail, but handle
it anyway.

Bug: #4952.
3 years ago
Justin Azoff aacb7dc291 detect/iponly: remove DetectEngineIPOnlyThreadCtx
This is unused.

Issue: 4578
3 years ago
Eric Leblond 5aaf50760f app-layer: add flag to skip detection on TX
Stamus team did discover a problem were a signature can shadow
other signatures.

For example, on a PCAP only containing Kerberos protocol and where the
following signature is matching:

alert krb5 $HOME_NET any -> any any (msg:"krb match"; krb5_cname; content:"marlo"; sid:3; rev:1;)

If we add the following signature to the list of signature

alert ssh $HOME_NET any -> any any (msg:"rr"; content:"rr"; flow:established,to_server; sid:4; rev:2;)

Then the Kerberos signature is not matching anymore.

To understand this case, we need some information:

- The krb5_cname is a to_client keyword
- The signal on ssh is to_server
- Kerberos has unidirectional transaction
- kerberos application state progress is a function always returning 1

As the two signatures are in opposite side, they end up in separate
sig group head.

Another fact is that, in the PCAP, the to_server side of the session
is sent first to the detection. It thus hit the sig group head of
the SSH signature. When Suricata runs detection in this direction
the Kerberos application layer send the transaction as it is existing
and because the alstate progress function just return 1 if the transaction
exists. So Suricata runs DetectRunTx() and stops when it sees that
sgh->tx_engines is NULL.

But the transaction is consumed by the engine as it has been evaluated
in one direction and the kerberos transaction are unidirectional so
there is no need to continue looking at it.

This results in no matching of the kerberos signature as the match
should occur in the evaluation of the other side but the transaction
with the data is already seen has been handled.

This problem was discovered on this Kerberos signature but all
the application layer with unidirectional transaction are impacted.

This patch introduces a flag that can be used by application layer
to signal that the TX should not be inspected. By using this flag
on the directional detect_flags_[ts|tc] the application layer can
prevent the TX to be consumed in the wrong direction.

Application layers with unidirectional TX will be updated
in separate commits to set the flag on the direction opposite
to the one they are.

Ticket: #5799
3 years ago
Eric Leblond 236869bc58 detect: remove STREAM_FLUSH
It is unused in the code so can be removed.

Ticket: #5799
3 years ago
Victor Julien 9e41075d5d detect/frames: improve IPS and GAP handling
Inspect individual chunks in lossy traffic.

Don't use the frame idx as the inspection buffer idx. Engines are running
per frame, so multi inspection can be used for stream chunks instead.

Ticket: #4977.
4 years ago
Victor Julien 6fcf48d09a detect/frames: handle duplicate sigs in candidates
Prefilter engines run on each stream chunk in a lossy stream, so
we can get the same sid in the list multiple times.
4 years ago
Victor Julien aa376a3b21 detect/frame: improve frame detection
Add a per frame progress tracker.
4 years ago
Victor Julien af211cbfad debug: add pkt_src to detect/stream entry log 4 years ago
Victor Julien b31ffde6f4 output: remove error codes from output 4 years ago
Victor Julien e042cd785e error: use SC_ENOMEM for alloc errors 4 years ago
Philippe Antoine 62352ad030 src: fix remaining cppclean warnings 4 years ago
Victor Julien cd2a5ec84f packet: move action functions to packet files 4 years ago
Victor Julien 6c200c7793 detect: issue drop to root packet in all cases
Update DROP action handling in tunnel packets. DROP/REJECT action is set
to outer (root) and inner packet.

Check action flags both against outer (root) and inner packet.

Remove PACKET_SET_ACTION macro. Replace with RESET for the one reset usecase.
The reason to remove is to make the logic easier to understand.

Reduce scope of RESET macros.

Rename PacketTestAction to PacketCheckAction except in unittests. Keep
PacketTestAction as a wrapper around PacketCheckAction. This makes it
easier to trace the action handling in the real code.

Fix rate_filter setting actions directly.

General code cleanups.

Bug: #5571.
4 years ago
Victor Julien ad0a29cabc detect: remove wrapper func 4 years ago
Victor Julien 1bff888947 detect: fix duplicate detect state issue
For protocols with multi buffer inspection there could be multiple times
the same sid would be queued into the candidates queue. This triggered
a debug validation check.

W/o debug validation this would lead to duplicate work and possibly multiple
alerts where a single one would be appropriate.

Bug: 5419.
4 years ago
Juliana Fajardini 1774ff18a6 decode: make PacketDrop use action as parameter
A Packet may be dropped due to several different reasons. This change
adds action as a parameter, so we can update the packet action when we
drop it, instead of setting it to drop.

Related to
Bug #5458
4 years ago
Philippe Antoine 02f2602dde src: rework includes as per cppclean 4 years ago
Victor Julien a83f02d4cd detect/dcerpc: apply dcerpc to smb as well
So 'alert dcerpc' also matches if the DCERPC is over SMB.

Explicitly refuse smb keywords for the 'dcerpc' app proto setting:
`alert dceprc ... smb.share; ...` is rejected.

Remove a now useless special case in the stateless rule processing
matching for dcerpc/smb.

Bug: #5208.
4 years ago
Philippe Antoine b8524e70d9 detect: change InspectEngineFuncPtr2 to return uint8_t 4 years ago