]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
2 years agoeve: log mac addresses in packet direction 8047/head
Victor Julien [Wed, 19 Oct 2022 12:26:53 +0000 (12:26 +0000)] 
eve: log mac addresses in packet direction

(cherry picked from commit 90f3823cadf76378f292c03b389986e12acf1aad)

2 years agorelease: 6.0.8; update changelog suricata-6.0.8
Victor Julien [Tue, 27 Sep 2022 17:25:37 +0000 (19:25 +0200)] 
release: 6.0.8; update changelog

Re-releasing 6.0.7 with the correct libhtp and Suricata-Update versions.

2 years agorelease: 6.0.7; update changelog suricata-6.0.7
Shivani Bhardwaj [Tue, 27 Sep 2022 10:47:01 +0000 (16:17 +0530)] 
release: 6.0.7; update changelog

2 years agostream: fix reachable assertion 7936/head
Victor Julien [Mon, 26 Sep 2022 15:14:39 +0000 (17:14 +0200)] 
stream: fix reachable assertion

Fix `Flow::thread_id` not always getting properly set up, leading to
a reachable assertion.

Bug #4582.

(cherry picked from commit b06c0579f568226721f38f6a964bdffdfd1791fc)

2 years agouserguide: add section about exception policies
Juliana Fajardini [Thu, 15 Sep 2022 23:07:54 +0000 (20:07 -0300)] 
userguide: add section about exception policies

This describes briefly what the exception policies are, what is the
engine's behavior, what options are available and to which parts are
they implemented.

Task #5475
Task #5515

2 years agouserguide: minor rewording and typo fixes
Juliana Fajardini [Fri, 2 Sep 2022 17:27:15 +0000 (14:27 -0300)] 
userguide: minor rewording and typo fixes

Some of these were recently introduced, some were highlited after the
applayer sections got merged. Some paragraphs seem to have been changed
due to trying to respect character limits for lines. Also includes a
typo pointed out by one of our community members via Discord.

2 years agostream/tcp: typo fix
Juliana Fajardini [Fri, 16 Sep 2022 18:12:06 +0000 (15:12 -0300)] 
stream/tcp: typo fix

2 years agosource: pcap timestamp microsecond consistency
Philippe Antoine [Fri, 1 Apr 2022 15:55:33 +0000 (17:55 +0200)] 
source: pcap timestamp microsecond consistency

That is it should be less than 1 000 000.
Have the same for fuzz targets where the bug came from.

https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44177
(cherry picked from commit 8ecf7e403ec493118afaa0543166e0c11d907417)

2 years agoflow/icmpv4: fix vlan.use-for-tracking
Philippe Antoine [Thu, 5 May 2022 07:46:01 +0000 (09:46 +0200)] 
flow/icmpv4: fix vlan.use-for-tracking

For ICMPv4 error messages the vlan ids were always considered,
even if the 'vlan.use-for-tracking' option was disabled.

Ticket: #5330
(cherry picked from commit ce2775d331cecc072c99e1c0c3bced954de4900d)

2 years agorequirements: use suricata-update 1.2.5
Jason Ish [Thu, 22 Sep 2022 23:08:09 +0000 (17:08 -0600)] 
requirements: use suricata-update 1.2.5

2 years agodetect: fix user after free in debug log
Jason Ish [Mon, 19 Sep 2022 16:40:14 +0000 (10:40 -0600)] 
detect: fix user after free in debug log

Found by gcc 12.2.1.

2 years agomqtt: remove quadratic time complexity
Philippe Antoine [Thu, 16 Jun 2022 13:14:27 +0000 (15:14 +0200)] 
mqtt: remove quadratic time complexity

When having many transactions in a single parsing call...

Fix has overhead of having one more field in the mqtt state.

Completes commit a8079dc9787d77cf705aa47000b499a325be0716

Ticket: #5399
(cherry picked from commit e160917bcfb67b23535b4ce082f506a9e66b7778)

2 years agomqtt: convert transaction list to vecdeque
Jeff Lucovsky [Tue, 16 Aug 2022 12:59:46 +0000 (08:59 -0400)] 
mqtt: convert transaction list to vecdeque

Ticket: 5430

2 years agomqtt: make max transactions configurable
Philippe Antoine [Wed, 12 Jan 2022 20:58:47 +0000 (21:58 +0100)] 
mqtt: make max transactions configurable

Allows users to find balance between completeness of decoding
and increases resource consumption, which can DOS suricata.

(cherry picked from commit e42094f238aa388d05970993fd0de8194471fa60)

2 years agomqtt: limits the number of active transactions per flow
Philippe Antoine [Thu, 2 Dec 2021 09:03:05 +0000 (10:03 +0100)] 
mqtt: limits the number of active transactions per flow

Ticket: 4530

So, that we do not get DOS by quadratic complexity, while
looking for a new pkt_id over the ever growing list
of active transactions

(cherry picked from commit a8079dc9787d77cf705aa47000b499a325be0716)

2 years agodetect/flowbits: more permissive parsing by default
Victor Julien [Fri, 23 Sep 2022 15:13:55 +0000 (17:13 +0200)] 
detect/flowbits: more permissive parsing by default

To get strict parsing, `--strict-rule-keywords=flowbits` command line
option can be used.

Bug: #5547.

2 years agocontent: don't error out on incomplete hex 7887/head
Jason Ish [Mon, 19 Sep 2022 21:12:46 +0000 (15:12 -0600)] 
content: don't error out on incomplete hex

Before 6.0.6 if hex content was incomplete, Suricata didn't error out.
With 6.0.6 incomplete hex was detected and errored on which is a
breaking change in a release branch.  Instead, only emit a warning
unless strict content checking has been requested.

To enable strict behaviour on incomplete content hex in a rule,
"--strict-rule-keywords=content" can be used on the command line.

Issue: #5546

2 years agodetect: allow rule errors to display error, but not be fatal
Jason Ish [Tue, 20 Sep 2022 17:48:59 +0000 (11:48 -0600)] 
detect: allow rule errors to display error, but not be fatal

Add a new setup return code, -4 which will print the error, but not
error out in test mode. This is to support allowing incomplete hex, as
there is no context as to which rule had the issue.

For context:
- -3: error ok, no message
- -2: error not ok, no message
- -4: error ok, message

2 years agodetect: fix duplicate detect state issue 7878/head
Victor Julien [Sat, 27 Aug 2022 05:50:45 +0000 (07:50 +0200)] 
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.
(cherry picked from commit 1bff888947345505c773ab07337546aa72e95d16)

2 years agodetect: transforms check for 0-sized buffer
Philippe Antoine [Thu, 25 Aug 2022 15:05:41 +0000 (17:05 +0200)] 
detect: transforms check for 0-sized buffer

So as to avoid undefined behavior with a 0-sized variable length
array

Ticket: #5521
(cherry picked from commit 61b73416e27a07cab50743d69c1cf5cd7f07b45d)

2 years agoexceptions: add reject support to exception policy 7852/head
Juliana Fajardini [Tue, 6 Sep 2022 19:16:45 +0000 (16:16 -0300)] 
exceptions: add reject support to exception policy

This enables the usage of 'reject' as an exception policy. As for both
IPS and IDS modes the intended result of sending a reject packet is to
reject the related flow, this will effectively mean setting the reject
action to the packet that triggered the exception condition, and then
dropping the associated flow.

Task #5503

(cherry picked from commit bbd968c738230b4f77de3278994c4fd5aa859dcd)

2 years agostream/ids: make sure we don't slide past last_ack 7849/head
Victor Julien [Tue, 16 Aug 2022 09:35:01 +0000 (11:35 +0200)] 
stream/ids: make sure we don't slide past last_ack

Bug: #5401.
(cherry picked from commit f04b7a1827845d72b4d0c12f76eadfcc77d726cf)

2 years agodecode/tcp: allow 4 byte TFO with 2 byte cookie
Victor Julien [Mon, 5 Sep 2022 17:28:27 +0000 (19:28 +0200)] 
decode/tcp: allow 4 byte TFO with 2 byte cookie

(cherry picked from commit f5bd55dac863c4c54d6a21942a7ef821f2b4fa4f)

2 years agoipfw: use PF_DIVERT on modern FreeBSD
Gleb Smirnoff [Wed, 31 Aug 2022 03:15:31 +0000 (20:15 -0700)] 
ipfw: use PF_DIVERT on modern FreeBSD

(cherry picked from commit 5dbbc52b066b2047c4bc30be7fd29dbb3febaf96)

2 years agounittests: optimize RunmodeIsUnittests() 7834/head
Victor Julien [Wed, 9 Jun 2021 07:23:07 +0000 (09:23 +0200)] 
unittests: optimize RunmodeIsUnittests()

(cherry picked from commit 86e600dab8dd3e3787bab247f2884c839079743a)

2 years agohttp2: remove to_vec for comparisons
Philippe Antoine [Sun, 24 Jul 2022 19:54:24 +0000 (21:54 +0200)] 
http2: remove to_vec for comparisons

Ticket: #5454
(cherry picked from commit 9b4a133777e8d25eda0f9f44095bc4a10d8cce21)

Conflict fixed by Philippe Antoine

2 years agohttp2: fix clippy warning about &Vec<u8>
Philippe Antoine [Wed, 3 Aug 2022 06:29:40 +0000 (08:29 +0200)] 
http2: fix clippy warning about &Vec<u8>

Using &[u8] instead in function prototype

(cherry picked from commit d011b468da237c2d2e8b704dce9041ba40be5e01)

Conflict fixed by Philippe Antoine

2 years agogithub-ci: add cherry-pick line check 7828/head
Victor Julien [Mon, 5 Sep 2022 07:08:39 +0000 (09:08 +0200)] 
github-ci: add cherry-pick line check

2 years agoflow/recycler: bring back pthread_cond_t sleep
Victor Julien [Thu, 11 Nov 2021 07:34:43 +0000 (08:34 +0100)] 
flow/recycler: bring back pthread_cond_t sleep

Bug #4379.

(cherry picked from commit f271fb457522d77a1befeb1d097c125afcbdeeb9)

2 years agoflow/manager: sleep handled by pthread_cond_t again
Victor Julien [Tue, 9 Nov 2021 16:53:18 +0000 (17:53 +0100)] 
flow/manager: sleep handled by pthread_cond_t again

Use only in live mode to allow FM to respond quickly to time
increases in offline mode.

Bug #4379.

(cherry picked from commit e6ac2e4e8a697a4c98b637a0d6c58dce8fb918aa)

2 years agotime: add timeradd implementation
Victor Julien [Wed, 10 Nov 2021 14:40:26 +0000 (15:40 +0100)] 
time: add timeradd implementation

timeradd isn't available on MinGW.

(cherry picked from commit 39141a8836c99cf65e533e8c6dd312bfb579643b)

2 years agofuzz: restrict flags passed to AppLayerProtoDetectGetProto
Philippe Antoine [Thu, 1 Sep 2022 19:32:35 +0000 (21:32 +0200)] 
fuzz: restrict flags passed to AppLayerProtoDetectGetProto

Manual adaptation of 05f9b3f and f4449d3

2 years agohttp2: check overflow before it happens
Philippe Antoine [Sun, 23 Jan 2022 20:22:32 +0000 (21:22 +0100)] 
http2: check overflow before it happens

instead of checking afterwards if value got smaller

(cherry picked from commit b86beb9b68807e371f7af1ad6a1f789fdd5f7209)

Manually adapted to make it work with MSRV

2 years agouserguide: briefly introduce exception policy opts
Juliana Fajardini [Fri, 26 Aug 2022 16:13:09 +0000 (13:13 -0300)] 
userguide: briefly introduce exception policy opts

Added them in the configuration section so folks can be more aware of
them, while a more complete documentation isn't around.

Related to
Task #5475

(cherry picked from commit ef54f36e3480c8dfc5a160849e7b9d0fe1351ad6)

2 years agouserguide: update defrag settings options
Juliana Fajardini [Fri, 26 Aug 2022 20:52:46 +0000 (17:52 -0300)] 
userguide: update defrag settings options

We were still mentioning that there were only three options.

(cherry picked from commit 3c74e443bdd6e666692b1c1da1d0389268b0eec7)

2 years agouserguide: add section about HTTP2 settings
Juliana Fajardini [Thu, 1 Sep 2022 18:35:01 +0000 (15:35 -0300)] 
userguide: add section about HTTP2 settings

This was in master but not in 60x yet.

2 years agouserguide: merge sections about AppLayer Parsers
Juliana Fajardini [Fri, 26 Aug 2022 20:19:33 +0000 (17:19 -0300)] 
userguide: merge sections about AppLayer Parsers

We had two sections under the suricata.yaml configuration section
describing settings for application layer parsers. This merges them into
one and also fixes a few subsection title levels.

Task #5364

(cherry picked from commit 0cc040cf6128fadedf9ad9a6a23ecccdd4856878)

2 years agosuricata.yaml: add exception policy config options
Juliana Fajardini [Mon, 22 Aug 2022 23:05:50 +0000 (20:05 -0300)] 
suricata.yaml: add exception policy config options

Related to
Task #5468

(cherry picked from commit fc81c80c0412e11c382a122aa8fa6af441c24499)

2 years agostream: add exception policy for midstream flows
Juliana Fajardini [Wed, 17 Aug 2022 14:39:33 +0000 (11:39 -0300)] 
stream: add exception policy for midstream flows

This allows to set a midstream-policy that can:
- fail closed (stream.midstream-policy=drop-flow)
- fail open (stream.midstream-policy=pass-flow)
- bypass stream (stream.midstream-policy=bypass)
- do nothing (default behavior)

Usage and behavior:

If stream.midstream-policy is set then if Suricata identifies a midstream flow
it will apply the corresponding action associated with the policy.

No setting means Suricata will not apply such policies, either inspecting the
flow (if stream.midstream=true) or ignoring it stream.midstream=false.

Task #5468

(cherry picked from commit aa5bb2c329aff59b7811b43258ffd4d95fe7364f)

2 years agoexceptions: add callbacks for drop-flow policy
Juliana Fajardini [Mon, 29 Aug 2022 23:32:31 +0000 (20:32 -0300)] 
exceptions: add callbacks for drop-flow policy

Make sure that when the policy is to drop the flow, we set no inspection
for payload and packet and disable applayer inspection as well.

Task #5468

(cherry picked from commit 242b8f7d65498f7b7b33cf852a79206484c269b1)

2 years agogithub-ci: add AlmaLinux 9 build 7820/head
Jason Ish [Mon, 8 Aug 2022 19:17:01 +0000 (13:17 -0600)] 
github-ci: add AlmaLinux 9 build

(cherry picked from commit 2b83cc799d7574db5a2220c8b8cbdf1bd474a5f7)

2 years agogithub-ci: test execution of suricatasc and suricata-update
Jason Ish [Sun, 7 Aug 2022 16:24:56 +0000 (10:24 -0600)] 
github-ci: test execution of suricatasc and suricata-update

(cherry picked from commit d9b6e1d96748b6e49d0cccd0c45cc956ba1e2d74)

2 years agopython: install without distutils
Jason Ish [Tue, 3 May 2022 18:34:57 +0000 (12:34 -0600)] 
python: install without distutils

Instead of using distutils/setuptools for installing the Python code,
just install it into our own Python directory.

Distutils is being removed from Python, and setuptools doesn't work well
when trying to install into your own location. For our usage its just
simpler to install with make.

In addition to removing the configure check for distutils, also remove
the check for pyyaml. This lets the user install pyyaml after Suricata
is installed, and Suricata-Update does handle this case gracefully.

Issue: #5313

(cherry picked from commit 9a1d6af8582be4b817e9f0ffb9d5f591dfc31fb9)

2 years agodoc/conf: fix sphinx language setting 7806/head
Shivani Bhardwaj [Fri, 12 Aug 2022 09:46:14 +0000 (15:16 +0530)] 
doc/conf: fix sphinx language setting

sphinx-build 5.1.1 and above throws a warning which is treated as an
error while building.

Invalid configuration value found: 'language = None'. Update your configuration to a valid language code. Falling back to 'en' (English).

(cherry picked from commit 2c4d6b33aec856e7836136a0f97d05de794f0ec0)

2 years agoexceptions: error out when invalid policy is used
Juliana Fajardini [Wed, 24 Aug 2022 20:36:47 +0000 (17:36 -0300)] 
exceptions: error out when invalid policy is used

Before, if an invalid value was passed as exception policy, Suricata
would log a warning and set the exception policy to "ignore". This is a
very different result, than, say, dropping or bypassing a midstream flow.

Task #5504

(cherry picked from commit 58ef3cde7a01166a1ae56b814156e2cad02e1251)

2 years agogithub: bump ubuntu-18.04 runners to 22.04
Victor Julien [Thu, 18 Aug 2022 12:27:54 +0000 (14:27 +0200)] 
github: bump ubuntu-18.04 runners to 22.04

(cherry picked from commit 3dea69ec8303e8bc2b90ee154423c9bd7aef85e0)

2 years agodetect/parse: test sig parsing for more actions
Juliana Fajardini [Mon, 15 Aug 2022 18:57:58 +0000 (15:57 -0300)] 
detect/parse: test sig parsing for more actions

Our unittests were only covering sig parsing for alert actions. As in
environments without LibNet the reject action will not work, we must
ensure that our parser properly fails in such cases, instead of silently
accepting an unsupported action.

Added tests for the reject and drop action.

Task #5496

(cherry picked from commit c81b78fd1c9a6e86d6be14b7567c5b8d8c89d6af)

2 years agodetect/engine: fix typos in assorted files
Juliana Fajardini [Tue, 10 May 2022 20:01:20 +0000 (17:01 -0300)] 
detect/engine: fix typos in assorted files

(cherry picked from commit 5f4bcfe313c879fb411ef9a6e2c4561764e45c26)

2 years agocommandline: add alert-queue expand failure option
Juliana Fajardini [Mon, 9 May 2022 14:57:31 +0000 (11:57 -0300)] 
commandline: add alert-queue expand failure option

For testing purposes. Meant to simulate a reallocation failure when
dynamically growing the alert queue in DetectEngineThreadCtx, so we can
check that Suri's behavior doesn't break under such circumstances.

Task #5319

(cherry picked from commit 58928b249d3b5b9740bc7d35cd392c265097648c)

2 years agofuzz: disable enip detection based on source port
Philippe Antoine [Wed, 24 Aug 2022 07:51:52 +0000 (09:51 +0200)] 
fuzz: disable enip detection based on source port

So as to avoid fuzzing detecting protocol polyglots with enip

(cherry picked from commit d1ebf320f713af6ca102d71d9201a629334d162b)

2 years agodecode: remove unused macros 7803/head
Juliana Fajardini [Tue, 23 Aug 2022 13:35:18 +0000 (10:35 -0300)] 
decode: remove unused macros

With the recent changes, these macros weren't being used anymore.

Related to
Bug #5458

(cherry picked from commit e7727c3744bf1ec44d8cd74df6d8dd8bbd725ab8)

2 years agostream/tcp: remove repeated header declaration
Juliana Fajardini [Mon, 8 Aug 2022 14:12:33 +0000 (11:12 -0300)] 
stream/tcp: remove repeated header declaration

StreamTcpRegisterTests was being declared twice.

(cherry picked from commit d07a6c6174cadc2ea29070fc1963c74d20dc56c7)

2 years agodetect/alert: add unittests to check packet action
Juliana Fajardini [Mon, 1 Aug 2022 23:04:22 +0000 (20:04 -0300)] 
detect/alert: add unittests to check packet action

Add unittests to check that packet flags are correctly updated after
detection finds drop or reject rules that match.

Related to
Bug #5458

(cherry picked from commit f897761ecbc0e78d45110f35b53820d74fd2e1d3)

2 years agodecode: validate if dropped packet has drop reason
Juliana Fajardini [Mon, 8 Aug 2022 14:04:59 +0000 (11:04 -0300)] 
decode: validate if dropped packet has drop reason

Related to
Bug #5458

(cherry picked from commit abd595d695ce477cccd80ec22ebcc156a544f65e)

2 years agodetect/alert: ensure reject action is applied
Juliana Fajardini [Thu, 28 Jul 2022 23:05:47 +0000 (20:05 -0300)] 
detect/alert: ensure reject action is applied

Bug 5458 states that the reject action is no longer working. While SV
tests that use the reject action still pass, it indeed seems that a
regression has happened with commit aa93984, because while the
function that applies rule actions to the flow (RuleActionToFlow) does
check for the reject action, the newly added function PacketApply
SignatureActions only checks for ACTION_DROP or ACTION_PASS when
deciding to call RuleActionToFlow.

Bug #5458

(cherry picked from commit 1f54e8611ab39ce3509280574d137df23c325658)

2 years agodecode: make PacketDrop use action as parameter
Juliana Fajardini [Thu, 28 Jul 2022 15:04:45 +0000 (12:04 -0300)] 
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

(cherry picked from commit 1774ff18a6ab28233f7b31e0fb6b799d81abf34d)

3 years agosource/pcap: fix infinite loop if interface goes down 7672/head
Juliana Fajardini [Tue, 28 Jun 2022 20:06:50 +0000 (17:06 -0300)] 
source/pcap: fix infinite loop if interface goes down

When in live-pcap mode, if the sniffed interface went down and up again,
Suri would enter an infinite and keep running, while not registering new
events. This fixes that behavior by allowing Suri to retry to open the
pcap in case of a retry on an already activated capture
('PCAP_ERROR_ACTIVATED').

This change is based on Zhiyuan Liao's work.

Bug #3846

(cherry picked from commit 2544be4672215d8c86c68f0d03c8fd88f498f1d2)

3 years agodetect/engine: init alert queue counters on reload 7659/head
Jufajardini Reichow [Mon, 25 Jul 2022 23:47:23 +0000 (20:47 -0300)] 
detect/engine: init alert queue counters on reload

alert_queue_overflow and alerts_suppressed were not being
reinitialized when there was a reload of Suricata rules, leading to
non-valid stats counters if that happened.

Bug #5457

(cherry picked from commit 93c2c9743d4ebe35017317a2668c6f8a54498d34)

3 years agorust/nfs: add a maximum number of operations per compound
Jason Ish [Mon, 18 Jul 2022 21:52:40 +0000 (15:52 -0600)] 
rust/nfs: add a maximum number of operations per compound

This is a backport of ea1d03f8e38aca376adcb80b1851b97a0816a5e9 by Pierre
Chifflier adapted for 6.0.x.

> The `count` combinator preallocates a number of bytes. Since the value
> is untrusted, this can result in an Out Of Memory allocation.
> Use a maximum value, large enough to cover all current implementations.

Ticket: #5448

3 years agoreadthedocs: add configuration file 7634/head
Jason Ish [Wed, 20 Jul 2022 19:07:49 +0000 (13:07 -0600)] 
readthedocs: add configuration file

Readthedocs is attempting to use our /requirements.txt file as a Python
requirements file, which it is not. Add a Readthedocs configuration file
to tell it to not use any requirements file.

3 years ago.gitignore: don't ignore *.yaml, just suricata.yaml
Jason Ish [Wed, 20 Jul 2022 19:07:15 +0000 (13:07 -0600)] 
.gitignore: don't ignore *.yaml, just suricata.yaml

3 years agoversion: start development towards 6.0.7
Jason Ish [Wed, 20 Jul 2022 19:12:47 +0000 (13:12 -0600)] 
version: start development towards 6.0.7

3 years agorelease: 6.0.6; update changelog suricata-6.0.6
Jason Ish [Sat, 9 Jul 2022 22:51:17 +0000 (16:51 -0600)] 
release: 6.0.6; update changelog

3 years agooutput: fix integer warnings
Philippe Antoine [Tue, 18 Jan 2022 09:56:48 +0000 (10:56 +0100)] 
output: fix integer warnings

Ticket: 4516

(cherry picked from commit e3180e3248e38311ad56a080233ad1a8d31a623b)

3 years agoprotocol: forbids concurrent protocol upgrades
Philippe Antoine [Fri, 8 Apr 2022 12:40:02 +0000 (14:40 +0200)] 
protocol: forbids concurrent protocol upgrades

Ticket: 5243

When switching from SMTP to TLS, and getting HTTP1 instead of
expected TLS, and HTTP1 requesting upgrade to HTTP2, we do not
overwrite the alproto_orig value so as not to have type confusion
in AppLayerParserStateProtoCleanup

(cherry picked from commit cedffdf14cf1fdd4d551f16c331e5b3e7f0a6927)

3 years agooutput: skip files logging for ICMP packets 7617/head
Philippe Antoine [Mon, 4 Jul 2022 08:30:20 +0000 (10:30 +0200)] 
output: skip files logging for ICMP packets

Ticket: #5408
(cherry picked from commit f8bf5817752f19565f1b7449710d1e6a2a96d00a)

3 years agooutput: use flow's proto for file loggers 7616/head
Philippe Antoine [Fri, 1 Jul 2022 11:22:38 +0000 (13:22 +0200)] 
output: use flow's proto for file loggers

As there can be an ICMP packet which gets related to a TCP flow.

Ticket: #5408
(cherry picked from commit 5781631f858b078ad8e5d7982074f41a08699ee2)

3 years agooutput/alert: don't call basic logging twice 7605/head
Eric Leblond [Mon, 17 Jan 2022 08:31:06 +0000 (09:31 +0100)] 
output/alert: don't call basic logging twice

Issue: 4106
(cherry picked from commit 264eddb81f952c23b5dffc3d31eef87dceb8158f)

3 years agoftp: optimized tx iterator
Philippe Antoine [Fri, 29 Apr 2022 11:12:56 +0000 (13:12 +0200)] 
ftp: optimized tx iterator

To be more efficient with larger number of transactions.

Ticket: #5314
(cherry picked from commit 5a31b3508d6bec7df1a77e0422360c155a3de9f9)

3 years agoevent: only sets APPLAYER_UNEXPECTED_PROTOCOL once
Philippe Antoine [Wed, 1 Jun 2022 13:04:34 +0000 (15:04 +0200)] 
event: only sets APPLAYER_UNEXPECTED_PROTOCOL once

If f->alproto == ALPROTO_UNKNOWN, we do not know the new protocol
yet, so we do not set the event yet.

(cherry picked from commit e6925300212277a7300f4a3aa9b5c745ee10e0df)

3 years agoevents: reset logged event
Philippe Antoine [Tue, 31 May 2022 13:49:38 +0000 (15:49 +0200)] 
events: reset logged event

Otherwise, if we log a first app_layer_event, then reset
with AppLayerDecoderEventsResetEvents for a new packet,
then get another event, it does not get logged

Ticket: #5391
(cherry picked from commit b0298dd0468f150229f9021ebe9c438bc2b7cecf)

3 years agodetect: impose limits on pcrexform 7596/head
Victor Julien [Thu, 30 Jun 2022 14:52:44 +0000 (16:52 +0200)] 
detect: impose limits on pcrexform

Impose match and recursion limits on pcrexform keywords.

Based on: 585e5e0d3c4e ("detect: impose limits on pcrexform")

Bug: #5414.

3 years agofuzz/mime: fix call conditions and args 7587/head
Victor Julien [Tue, 28 Jun 2022 18:20:37 +0000 (20:20 +0200)] 
fuzz/mime: fix call conditions and args

The SMTP parser should not supply lines w/o EOL chars to the mime
parser unless its in the BODY parsing stage. Mimic this in the fuzz
target by testing the state for inputs that have no EOL.

Additionally, make sure the delim cnt reflects the missing EOL.

(cherry picked from commit 816bbeb7dc3684d47d47c35a2255db0671760baa)

3 years agomime: fix and cleanup tests
Victor Julien [Tue, 28 Jun 2022 05:46:54 +0000 (07:46 +0200)] 
mime: fix and cleanup tests

Line count check was failing after recent delim handling updates.

(cherry picked from commit 074cfb5c68e76642f35f78c10e56761eb8010f5f)

3 years agomime: fix corner case
Victor Julien [Tue, 28 Jun 2022 13:29:25 +0000 (15:29 +0200)] 
mime: fix corner case

Fix a corner case where a base64 sequence including a space was followed
by a newline in the input data.

(cherry picked from commit d81582c4a2b5b9cd6000c8637a7c6bc9b8f4dfd6)

3 years agomime: add base64 related debug messages
Victor Julien [Tue, 28 Jun 2022 13:29:11 +0000 (15:29 +0200)] 
mime: add base64 related debug messages

(cherry picked from commit 5805ed47f51edbb2319f687cfa4fe503d6f0f0e3)

3 years agomime: improved empty line handling
Victor Julien [Tue, 28 Jun 2022 11:07:37 +0000 (13:07 +0200)] 
mime: improved empty line handling

Make sure a new body is not set up on empty lines unless it is
a body that is not encoded as base64/quoted printable.

(cherry picked from commit 41c2c1ed5a8a1f71e4cab02bb28567da9171332d)

3 years agosmtp: fix passing a wrong delim len around
Victor Julien [Mon, 27 Jun 2022 18:51:53 +0000 (20:51 +0200)] 
smtp: fix passing a wrong delim len around

(cherry picked from commit 6e2c066ce1cf722e92f08574059b6138be4f0b1e)

3 years agomime: properly pass full lines to non-decoded body
Victor Julien [Mon, 27 Jun 2022 18:15:16 +0000 (20:15 +0200)] 
mime: properly pass full lines to non-decoded body

Use actual delim count and make sure we also pass on empty lines
(so delim(s) only).

(cherry picked from commit b82b8825e79bd43901720813b672a9ff5c7bf120)

3 years agomime/base64: fix final data not getting processed
Victor Julien [Mon, 27 Jun 2022 14:20:02 +0000 (16:20 +0200)] 
mime/base64: fix final data not getting processed

If the last data of the body was not a multple of 4 and not padded
to be a multiple of 4, it would not be processed.

(cherry picked from commit 0d6ab727c55cbda04404ec44c5aa6582f3922478)

3 years agostream: fix GAP check
Victor Julien [Mon, 27 Jun 2022 09:34:14 +0000 (11:34 +0200)] 
stream: fix GAP check

Gap check would consider a GAP when the current data was in fact
exactly not a gap, but next segment(s) were already available.

(cherry picked from commit 100d821a9fbe61709be275f77341438626a561e8)

3 years agomime: remove unused 'linerem' logic
Victor Julien [Sun, 26 Jun 2022 14:25:36 +0000 (16:25 +0200)] 
mime: remove unused 'linerem' logic

(cherry picked from commit 0871029d17d23a7875af074d76965675c31599f0)

3 years agosmtp/mime: fix parsing edge case
Victor Julien [Sun, 26 Jun 2022 00:29:34 +0000 (02:29 +0200)] 
smtp/mime: fix parsing edge case

Correctly track "remaining" bytes after partial base64 decoding.

Add comment clarifications and debug validation checks.

(cherry picked from commit 5953a7d2ebd20be2a9f578fae66face4e172b678)

3 years agosmtp: skip preprocessing for mime headers
Victor Julien [Sat, 25 Jun 2022 11:01:37 +0000 (13:01 +0200)] 
smtp: skip preprocessing for mime headers

Mime parser doesn't expect partial lines, which preprocessing can
provide. Add a check to let mime headers be handled by regular line
parsing.

(cherry picked from commit a38f2f2a52822f150fff0d5e17e9f62582d6558c)

3 years agodetect: set drop reason for rule based drops 7557/head
Victor Julien [Thu, 16 Jun 2022 15:27:35 +0000 (17:27 +0200)] 
detect: set drop reason for rule based drops

Call `PacketDrop` with drop reason for drops, keep old logic
in place for the rest.

(cherry picked from commit a89840929b46b765787bec3ae5cad529f558af0a)

3 years agodetect/tests: improve detection entry 7544/head
Victor Julien [Fri, 10 Sep 2021 11:42:15 +0000 (13:42 +0200)] 
detect/tests: improve detection entry

Lots of tests still use SigMatchSignatures as their main detection
entry function, which bypassed some logic. Make it match main logic
more closely.

(cherry picked from commit e36b9b89a1be5b45b6e071248a17208b617b0c71)

3 years agotests: fix drop test; cleanup
Victor Julien [Fri, 10 Sep 2021 11:43:26 +0000 (13:43 +0200)] 
tests: fix drop test; cleanup

SigTestDropFlow04 was incorrectly expecting an alert in the packet
following a "drop" packet. The first drop is applied to the flow, so
it should lead to the 2nd packet being dropped before inspection is
run.

Clean up the test as well.

(cherry picked from commit 3874d08015f36b79b32e25dbecc4b245d314f269)

3 years agoexceptions: initial exception-policy implementation
Victor Julien [Mon, 14 Mar 2022 06:20:11 +0000 (07:20 +0100)] 
exceptions: initial exception-policy implementation

Adds a framework for setting exception policies. These would be called
when the engine reaches some kind of exception condition, like hitting
a memcap or some traffic processing error.

The policy gives control over what should happen next: drop the packet,
drop the packet and flow, bypass, etc.

Implements the policy for:

    stream: If stream session or reassembly memcaps are hit call the
    memcap policy on the packet and flow.

    flow: Apply policy when memcap is reached and no flow could be
    freed up.

    defrag: Apply policy when no tracker could be picked up.

    app-layer: Apply ppolicy if a parser reaches an error state.

All options default to 'ignore', which means the default behavior
is unchanged.

Adds commandline options: add simulation options for exceptions. These
are only exposed if compiled with `--enable-debug`.

Ticket: #5214.
Ticket: #5215.
Ticket: #5216.
Ticket: #5218.
Ticket: #5194.
(cherry picked from commit 8580499deda6bae88034f1961c01179ded91246e)

3 years agoeve/drop: log drop reason
Victor Julien [Mon, 21 Mar 2022 20:57:04 +0000 (21:57 +0100)] 
eve/drop: log drop reason

Ticket: #5202.
(cherry picked from commit 0035673208e7d3a1d73bd2f18e03a69e78fbc4ba)

3 years agoflow: log action applied to all packets
Victor Julien [Fri, 10 Sep 2021 12:07:49 +0000 (14:07 +0200)] 
flow: log action applied to all packets

Log if action applied to whole flow is drop or pass.

(cherry picked from commit 9a09fe454b846dd2cd42adaa4b569314ad083bdb)

3 years agodetect: enforce flow drops earlier
Victor Julien [Fri, 10 Sep 2021 10:35:13 +0000 (12:35 +0200)] 
detect: enforce flow drops earlier

Enforcing flow drops is now done earlier in the detection engine and
moved out of the IP-only engine where it didn't belong.

(cherry picked from commit 802c1ffee35250d1ac753aec1343e481b83d854f)

3 years agoclang-format: disable for option table
Victor Julien [Tue, 14 Jun 2022 19:11:11 +0000 (21:11 +0200)] 
clang-format: disable for option table

3 years agobypass: fix memory leak - reassign of FlowBypassInfo 7535/head
Lukas Sismis [Fri, 20 May 2022 19:33:38 +0000 (21:33 +0200)] 
bypass: fix memory leak - reassign of FlowBypassInfo

In some situations bypass callback is called on already bypassed
flow. This allocates FlowBypassInfo structure for the flow but
does not check if the flow already has one.

Issue: #5368
(cherry picked from commit 05797c45bb5bb8b23a7af3dea2aa794c6f33e02d)

3 years agobypass: af-packet: fix memory leak - reassign of EBPFBypassData
Lukas Sismis [Sat, 21 May 2022 06:30:06 +0000 (08:30 +0200)] 
bypass: af-packet: fix memory leak - reassign of EBPFBypassData

AF-Packet bypass function in some situations allocates EBPF bypass data
for an already bypassed flow and assigns it to the flow without any checks

Issue: #5368
(cherry picked from commit 8845c07a90ff6ad8304c25f6ccdd495623d35d53)

3 years agodetect/threshold: fix offline time handling issue
Victor Julien [Tue, 7 Jun 2022 20:57:39 +0000 (22:57 +0200)] 
detect/threshold: fix offline time handling issue

Due to the TIMEVAL_DIFF_SEC calculating the delta into an unsigned
integer, it would underflow to a high positive value leading to
and incorrect result if the packet timestamp was below the timestamp
for the threshold entry. In normal conditions this shouldn't happen,
but in offline mode each thread has its own concept of time which
might differ significantly based on the pcap. In this case the
overflow would be very common.

Changing it to a signed value calculation triggered fuzz undefined
behavior if the packet timeval was very high, so this patch takes a
new approach where it no longer calculates a diff but sets up the
"seconds" value we compare against as a timeval itself, and uses
that to compare.

Fixes: 9fafc1031c0c ("time: Add TIMEVAL_EARLIER and TIMEVAL_DIFF_SEC macros.")
Fixes: 82dc61f4c3e3 ("detect/threshold: Refactor threshold calculation to handle by_rule and by_both.")
Uses add `timeradd` specific version where available.

Bug: #5386.
(cherry picked from commit df2e408d96d0e37a0599f885dc29fff4011f8899)

3 years agostream/midstream: fix double flow reverse case
Victor Julien [Wed, 8 Jun 2022 11:11:55 +0000 (13:11 +0200)] 
stream/midstream: fix double flow reverse case

In the case of midstream SYN/ACK pickup, we reverse the flow based on
the SYN/ACK. If we then later get traffic that appears to be in the
reverse direction based on the app-layer, we would reverse it again.
This isn't correct. When we have the SYN/ACK we know the flow's real
direction.

(cherry picked from commit fea374626ac9d0dfe69df24958596867f9e42734)

3 years agoapp-layer: don't switch dir if proto already known
Victor Julien [Sun, 10 Apr 2022 18:21:18 +0000 (20:21 +0200)] 
app-layer: don't switch dir if proto already known

(cherry picked from commit 86e8611f5edd461bc13aa5665a40f9d241c4f23d)

3 years agodetect/dcerpc: simplify keyword validation
Victor Julien [Fri, 10 Jun 2022 09:05:40 +0000 (11:05 +0200)] 
detect/dcerpc: simplify keyword validation

Now that the engine understands the relation between SMB and DCERPC better
we can get rid of some of the special case handling in keywords.

(cherry picked from commit 84e26d670e39e6ec40af9f3b0f2910d9accdf356)

3 years agodetect/dcerpc: apply dcerpc to smb as well
Victor Julien [Thu, 9 Jun 2022 11:53:20 +0000 (13:53 +0200)] 
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.
(cherry picked from commit 7d38f5667d1fe7dccd355f85434d2fb709578f57)

3 years agogithub/workflows: add cargo for all Ubuntu jobs
Victor Julien [Mon, 13 Jun 2022 15:21:51 +0000 (17:21 +0200)] 
github/workflows: add cargo for all Ubuntu jobs

(cherry picked from commit 7ced8de6c4659f21bb928d70a950f32016037da2)