]> git.ipfire.org Git - thirdparty/suricata.git/log
thirdparty/suricata.git
2 years agodoc/byte_math: Add divide by 0 discussion. 8724/head
Jeff Lucovsky [Thu, 30 Mar 2023 13:48:47 +0000 (09:48 -0400)] 
doc/byte_math: Add divide by 0 discussion.

Issue: 5945
(cherry picked from commit fd46c93a8f0f35375d349cf9402c2614dedff72b)

2 years agodetect/byte_math: fix bug in byte_math detection
Jeff Lucovsky [Tue, 28 Mar 2023 14:24:57 +0000 (10:24 -0400)] 
detect/byte_math: fix bug in byte_math detection

Issue: 5945

Avoid division by zero when the byte_math operation is division and the
rvalue is 0.

(cherry picked from commit 38c5e89e2959fcb22994ac4b232c7c298dd7d699)

2 years agosmtp: enforce line limit even when LF is found 8721/head
Shivani Bhardwaj [Tue, 4 Apr 2023 06:28:42 +0000 (11:58 +0530)] 
smtp: enforce line limit even when LF is found

Before:
If LF character was found, so far, we won't enforce the line limit on
the line. We only enforced limits in case of LF character missing in a
long line.

After this patch:
Line limit is enforced on the line if it is bigger than 4096 Bytes
irrespective of whether LF was found or not.

Redmine Bug: 5819

(cherry picked from commit 5f52b199ff0a49628fa00103d86bd72c5792a6b0)

2 years agosmtp: reset current line len at start
Shivani Bhardwaj [Wed, 12 Apr 2023 07:12:53 +0000 (12:42 +0530)] 
smtp: reset current line len at start

2 years agoutil/mime: allow delim len 0 when line limit is hit
Shivani Bhardwaj [Tue, 4 Apr 2023 06:13:21 +0000 (11:43 +0530)] 
util/mime: allow delim len 0 when line limit is hit

(cherry picked from commit fd4e0fbafedd23bc4a0f6ab874e20f73cb40d1e0)

2 years agosmtp: move constant declaration to header
Shivani Bhardwaj [Thu, 6 Apr 2023 12:14:49 +0000 (17:44 +0530)] 
smtp: move constant declaration to header

(cherry picked from commit c0bff5f9214f65296442ae3aa2ee9b6bde3ab3a6)

2 years agopcap: improve pcap_breakloop support
Victor Julien [Tue, 11 Apr 2023 09:40:35 +0000 (11:40 +0200)] 
pcap: improve pcap_breakloop support

When pcap_breakloop has been issued on a handle, the current pcap_dispatch
call may return -2 (PCAP_ERROR_BREAK), but it can also return the number
of processed packets if lower than the desired number. So add this condition
as a check.

(cherry picked from commit 9fe08f2374f690a901205f0df073b702f92b6345)
(cherry picked from commit 2ddd26446e3a568074650cf16ec4ad8402acdcd4)

2 years agodetect: only breakloop threads that are lagging
Victor Julien [Thu, 6 Apr 2023 14:06:34 +0000 (16:06 +0200)] 
detect: only breakloop threads that are lagging

Sleep after all threads have been checked.

Bug: #5969.
(cherry picked from commit 8a968faa04443d31fed473cc4e358609fb925f25)

2 years agoflow/worker: refresh detect thread during housekeeping
Victor Julien [Thu, 6 Apr 2023 13:43:41 +0000 (15:43 +0200)] 
flow/worker: refresh detect thread during housekeeping

During housekeeping multiple flows are processed. If a rule reload happens
at that time, we need to use the new detect thread as soon as possible.

Bug: #5969.
(cherry picked from commit 5e4cf182abf72ab33e56d4e17c261c025b4ce766)

2 years agohttp2: faster when reducing dynamic headers size 8705/head
Philippe Antoine [Thu, 16 Mar 2023 08:20:40 +0000 (09:20 +0100)] 
http2: faster when reducing dynamic headers size

avoid quadratic complexity from removing the first element
and copying all the contents a big number fo times.

Ticket: #5909
(cherry picked from commit 9adb59bcdb61a06792bec1bee468a900ad5118f5)

2 years agohttp: complete multipart until request.body-limit 8690/head
Philippe Antoine [Thu, 26 Jan 2023 08:28:46 +0000 (09:28 +0100)] 
http: complete multipart until request.body-limit

In the case we are truncating a multipart file because of reaching
request.body-limit, we used to not consume the whole buffer, but
keep expected_boundary_len bytes in case a new boundary begins
in these bytes.
Even if we cannot check the complete boundary, we can still check
the first bytes, as will be done in the rust version.

Ticket: #5952
(cherry picked from commit 578f328e06b3e03f3bdbbf852b5d121e20849b8b)
(cherry picked from commit caf9940fd10f474bcbc7bf983e3849a83a8c7562)

2 years agostream: improve FIN checking 8678/head
Victor Julien [Mon, 3 Apr 2023 09:50:09 +0000 (11:50 +0200)] 
stream: improve FIN checking

After recent next_seq changes, the FIN checks could be too strict
leading to stalling sessions in IPS mode.

This patch requires a FIN to be >= last ack and <= next_win to be
accepted.

(cherry picked from commit 39a6f411e9748e76211b76b1f45b6c1863012972)

2 years agoutil/base64: don't reset decoded bytes in RFC4648 8665/head
Shivani Bhardwaj [Thu, 9 Mar 2023 07:13:41 +0000 (12:43 +0530)] 
util/base64: don't reset decoded bytes in RFC4648

Old behavior:
With RFC4648, the decoded bytes were reset to 0 in case an unusual
character was encountered in the encoded string. This worked out fine
for small test cases where there weren't many bytes to be decoded.

Problem:
If a big encoded string had a character outside of the base alphabet,
the processing would stop and the number of decoded bytes were set to 0.
However, even though the processing should stop at the invalid
character, the number of decoded bytes should correctly store the bytes
decoded up until the point an invalid characted was encountered.

New behavor:
For any base64 encoded string given to the base64 decoder in RFC4648
mode, we make sure that the number of decoded bytes correctly reflect
the number of bytes processed up until the string was valid. This makes
sure any further calculations/use of the decoded data is done correctly.

Redmine ticket: 5885

(cherry picked from commit 418ddba38e008f0a57c07e7a872d0771d36a9bbd)

2 years agoenip: optimized tx iterator 8664/head
Philippe Antoine [Thu, 23 Mar 2023 08:00:42 +0000 (09:00 +0100)] 
enip: optimized tx iterator

As for SMTP, having a linked list.

Ticket: #5927
(cherry picked from commit 4f7426fdcf3ec4cab1e1a9da862f3de342b0d85c)

2 years agodnp3: optimized tx iterator
Philippe Antoine [Thu, 23 Mar 2023 07:57:53 +0000 (08:57 +0100)] 
dnp3: optimized tx iterator

As for SMTP, having a linked list.

Ticket: #5927
(cherry picked from commit e15daf6a4ba00baa09c97ab61ca0b4909708d637)

2 years agosmtp: optimized tx iterator
Philippe Antoine [Wed, 22 Mar 2023 16:24:40 +0000 (17:24 +0100)] 
smtp: optimized tx iterator

To be more efficient with larger number of transactions.
As was done for FTP.

Ticket: #5927
(cherry picked from commit f5f215dae7032d55fea7876a1716d30f0c68c4b7)

2 years agosip: add TX orientation
Eric Leblond [Mon, 23 Jan 2023 21:01:18 +0000 (22:01 +0100)] 
sip: add TX orientation

Set no inspection in the opposite side of the transaction.

Ticket: #5799

2 years agoenip: add TX orientation
Eric Leblond [Mon, 23 Jan 2023 19:08:57 +0000 (20:08 +0100)] 
enip: add TX orientation

Set no inspection in the opposite side of the transaction.

Ticket: #5799

2 years agontp: add TX orientation
Eric Leblond [Mon, 23 Jan 2023 19:05:08 +0000 (20:05 +0100)] 
ntp: add TX orientation

Set no inspection in the opposite side of the transaction.

Ticket: #5799

2 years agokrb: add TX orientation
Eric Leblond [Mon, 23 Jan 2023 19:04:26 +0000 (20:04 +0100)] 
krb: add TX orientation

Set no inspection in the opposite side of the transaction.

Ticket: #5799

2 years agomqtt: add TX orientation
Eric Leblond [Mon, 23 Jan 2023 19:04:00 +0000 (20:04 +0100)] 
mqtt: add TX orientation

Set no inspection in the opposite side of the transaction.

Ticket: #5799

2 years agoike: add TX orientation
Eric Leblond [Mon, 23 Jan 2023 19:03:35 +0000 (20:03 +0100)] 
ike: add TX orientation

Set no inspection in the opposite side of the transaction.

Ticket: #5799

2 years agodns: add TX orientation
Eric Leblond [Mon, 23 Jan 2023 19:03:12 +0000 (20:03 +0100)] 
dns: add TX orientation

Set no inspection in the opposite side of the transaction.

Ticket: #5799

2 years agosnmp: add TX orientation
Eric Leblond [Mon, 23 Jan 2023 19:02:00 +0000 (20:02 +0100)] 
snmp: add TX orientation

Set no inspection in the opposite side of the transaction.

Ticket: #5799

2 years agoapp-layer: add flag to skip detection on TX
Eric Leblond [Mon, 23 Jan 2023 19:01:05 +0000 (20:01 +0100)] 
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

2 years agodetect: remove STREAM_FLUSH
Eric Leblond [Fri, 20 Jan 2023 10:08:11 +0000 (11:08 +0100)] 
detect: remove STREAM_FLUSH

It is unused in the code so can be removed.

Ticket: #5799

2 years agoapp-layer-parser: give direction to progress func
Eric Leblond [Fri, 20 Jan 2023 09:35:59 +0000 (10:35 +0100)] 
app-layer-parser: give direction to progress func

The tx progress functions are expecting a direction and were given
a flow flags. As a result, they were not reporting correctly the
status if a DetectRunScratchPad flow_flags was containing some other
bits in the flag.

One case was when a signature was alterating the stream analysis
and triggering the addition of the STREAM_FLUSH flags.

The consequences are quite severe as the transactions are pilling
up waiting to be inspected causing sometimes a 10x performance hit
on pcap parsing. Also as the inspection was not done, Suricata is
missing a part of the alerts.

This was discovered when working on the following set of signatures:

alert ssh $HOME_NET any -> any any (msg:"pcre without content"; pcre:"/rabbit/"; sid:1; rev:1;)
alert smb $HOME_NET any -> any any (msg:"smb share content"; smb.share; content:"C"; sid:2; rev:1;)

When the first one is present the second is not triggering even
though the pcap file had no ssh inside. This is due to the fact
that the ssh signature was triggering the STREAM_FLUSH flag to
be set on the flowflags of the packet. But the application
layer will ask the smb state progress via

r = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
        StateGetProgress(alstate, flags);

passing it the flow flags but the smb function is expecting
a direction so we end up in a unplanned case

pub unsafe extern "C" fn rs_smb_tx_get_alstate_progress(tx: *mut ffi::c_void,
                                                  direction: u8)
...
if direction == Direction::ToServer as u8 && tx.request_done {

This leads the signature to not be evaluated correctly.

Ticket: #5799

2 years agodocs: clarify exception policy's supported values 8646/head
Juliana Fajardini [Wed, 22 Mar 2023 19:05:40 +0000 (16:05 -0300)] 
docs: clarify exception policy's supported values

As flow.memcap-policy and defrag.memcap-policy do not support flow
actions, clarify that in the documentation. Also fix some typos, and
add missing values in some places where the exception policies were
explained.

Related to
Bug #5940

(cherry picked from commit 31066c7c3b54e5a7144b68ef10b3352929a29166)

2 years agoexception/policy: use pkt action if no flow support
Juliana Fajardini [Fri, 24 Mar 2023 14:15:14 +0000 (11:15 -0300)] 
exception/policy: use pkt action if no flow support

Defrag memcap and flow memcap do not support flow action for the
exception policies, as there is no flow when the exception condition is
hit. In such cases, the exception policy must be considered for the
packet only, when that makes sense, or should be ignored, in case of
`bypass`.

Bug #5940

(cherry picked from commit d4333fb959bf7e12651971d542dc36e77cc2d2ad)

2 years agodetect: bump detect engine version for tenant reload 8642/head
Philippe Antoine [Fri, 10 Mar 2023 10:28:26 +0000 (11:28 +0100)] 
detect: bump detect engine version for tenant reload

Because the engine version is used to free the old
variables and not the new ones.
As is done in DetectEngineReload.

Ticket: #5866
(cherry picked from commit d313b5d60598e143e6e97eca8ac35d6a01ec6014)

2 years agodetect: bytemath do not left shift more than 64
Philippe Antoine [Tue, 14 Mar 2023 11:17:05 +0000 (12:17 +0100)] 
detect: bytemath do not left shift more than 64

As it is undefined behavior by C standard.
In this case, zeroes the value.

Ticket: #5900
(cherry picked from commit 473ca6dcf4789259ec4543d7d648bd1bd19986fc)

2 years agostream: accept and flag ack of ZWP data
Victor Julien [Fri, 3 Mar 2023 07:02:35 +0000 (08:02 +0100)] 
stream: accept and flag ack of ZWP data

Tcp Zero Window Probes try to send a single byte payload to "probe" if
the window has reopened. This single byte is, if accepted, not retransmitted.

(cherry picked from commit 30a716a4ab102a3b39cca8c8dab84be88c092687)

2 years agostream: harden tcp reuse check against RST/FIN
Victor Julien [Fri, 3 Mar 2023 12:30:55 +0000 (13:30 +0100)] 
stream: harden tcp reuse check against RST/FIN

(cherry picked from commit 64fb4066cfafbaf7157ad9bfca1e541d1a8ff76c)

2 years agostream: improve SYN and SYN/ACK handling with ECN/CWR flags
Victor Julien [Fri, 3 Mar 2023 12:30:14 +0000 (13:30 +0100)] 
stream: improve SYN and SYN/ACK handling with ECN/CWR flags

(cherry picked from commit 0d1d28854462c2a9442e42268bf32fd71ae50e5f)

2 years agostream: fix TFO overlap detection with ECN/CWR flags
Victor Julien [Fri, 3 Mar 2023 12:02:48 +0000 (13:02 +0100)] 
stream: fix TFO overlap detection with ECN/CWR flags

(cherry picked from commit 5fe2fba1849afa3cd30a44dbf328a3dc256e4d08)

2 years agostream: turn session flags into u32
Victor Julien [Sat, 11 Feb 2023 18:16:28 +0000 (19:16 +0100)] 
stream: turn session flags into u32

Due to gaps/padding the size of the struct won't change.

(cherry picked from commit aa7d58b0c756d758508937bfd643fcccef6918a7)

2 years agoflow/manager: apply clang formatting changes 8637/head
Juliana Fajardini [Tue, 28 Mar 2023 13:45:19 +0000 (10:45 -0300)] 
flow/manager: apply clang formatting changes

2 years agoflow/manager: fix coverity divide_by_zero warning
Juliana Fajardini [Fri, 24 Mar 2023 20:04:57 +0000 (17:04 -0300)] 
flow/manager: fix coverity divide_by_zero warning

Updated all cases where flow_config.prealloc was used in a division.

*** CID 1524506:  Integer handling issues  (DIVIDE_BY_ZERO)
/src/flow-manager.c: 858 in FlowManager()
852                                "flow_spare_q status: %" PRIu32 "%% flows at the queue",
853                             spare_pool_len, flow_config.prealloc,
854                             spare_pool_len * 100 / flow_config.prealloc);
855
856                     /* only if we have pruned this "emergency_recovery" percentage
857                      * of flows, we will unset the emergency bit */
>>>     CID 1524506:  Integer handling issues  (DIVIDE_BY_ZERO)
>>>     In expression "spare_pool_len * 100U / flow_config.prealloc", division by expression "flow_config.prealloc" which may be zero has undefined behavior.
858                     if (spare_pool_len * 100 / flow_config.prealloc > flow_config.emergency_recovery) {
859                         emerg_over_cnt++;
860                     } else {
861                         emerg_over_cnt = 0;
862                     }

Related to
Bug #5919

(cherry picked from commit 754d2803dd5f5956b7f2ae947f933ef03cf1d15b)

2 years agoflow/manager: fix prealloc unhandled division by 0
Juliana Fajardini [Mon, 20 Mar 2023 14:56:58 +0000 (11:56 -0300)] 
flow/manager: fix prealloc unhandled division by 0

If flow.prealloc was set to zero in our yaml config, this led to
a floating point exception in the flow manager.

Bug: #5919.
(cherry picked from commit 5baa6c0024c7e49eb28e84546c286a5fd50fe303)

2 years agorfb: remove duplicate logging of depth 8636/head
Jason Ish [Wed, 25 Jan 2023 17:07:19 +0000 (11:07 -0600)] 
rfb: remove duplicate logging of depth

The "depth" field in the "pixel_format" object was being logged twice.

Issue: 5813

(cherry picked from commit f15f092a696ebcafb3f402c511ba24be98557e7f)

2 years agosmb: remove duplicate tree_id logging
Jason Ish [Wed, 25 Jan 2023 18:02:27 +0000 (12:02 -0600)] 
smb: remove duplicate tree_id logging

Remove the second occurrence of tree_id logging which appears to
always be a duplicate of the first tree_id logged, even though they
come from different data structures.

Issue: 5811

(cherry picked from commit 67baab573b8046ace275e6c0f671f62af22a49a6)

2 years agodns: remove unused events field from state
Philippe Antoine [Wed, 8 Jun 2022 12:31:24 +0000 (14:31 +0200)] 
dns: remove unused events field from state

found overflowing by oss-fuzz

(cherry picked from commit 26dc70648c2b840ae7b56c88162f129c06ef03fd)

2 years agoutil/mime: use uint8_t for cnt
Shivani Bhardwaj [Wed, 15 Mar 2023 06:26:18 +0000 (11:56 +0530)] 
util/mime: use uint8_t for cnt

cnt should not exceed B64_BLOCK which is 4, so, it is unnecessary to use
uint32_t for the variable.

2 years agoutil/mime: use uint32_t for consumed bytes
Shivani Bhardwaj [Wed, 8 Mar 2023 15:46:03 +0000 (21:16 +0530)] 
util/mime: use uint32_t for consumed bytes

In a case of the line buffer being over 255 bytes, the consumed bytes
would reset to 0 as it was uint8_t. Fix this integer overflow by setting
the type to uint32_t.

Redmine ticket: 5883

(cherry picked from commit c089bbb7d7a6250fc4fdcffca1923a29916c1e1e)

2 years agosmb: handles records with trailing nbss data
Philippe Antoine [Wed, 18 Jan 2023 15:47:56 +0000 (16:47 +0100)] 
smb: handles records with trailing nbss data

If a file (read/write) SMB record has padding/trailing data
after the buffer being read or written, and that Suricata falls
in one case where it skips the data, it should skip until
the very end of the NBSS record, meaning it should also skip the
padding/trailing data.

Otherwise, an attacker may smuggle some NBSS/SMB record in this
trailing data, that will be interpreted by Suricata, but not
by the SMB client/server, leading to evasions.

Ticket: #5786
(cherry picked from commit 233ab1114873e632014b58d91c351505417fe8ed)

2 years agosmb: checks against nbss records length
Philippe Antoine [Tue, 27 Dec 2022 16:34:47 +0000 (17:34 +0100)] 
smb: checks against nbss records length

When Suricata handles files over SMB, it does not wait for the
NBSS record to be complete, and can stream the payload to the
file... But it did not check the consistency of the SMB record
length being read or written against the NBSS record length.

This could lead to an evasion where an attacker crafts a SMB
write with a too big Length field, and then sends its evil
payload, even if the server returned an error for the write request.

Ticket: #5770
(cherry picked from commit c1b7befb18a974eae05b25fad91d9ba84a65ab50)

2 years agonetmap/config: New API display during debug
Jeff Lucovsky [Fri, 24 Feb 2023 15:04:51 +0000 (10:04 -0500)] 
netmap/config: New API display during debug

This PR changes the log level associated with the message indicating
if the new Netmap API (v14+) is in use during module registration.

Issue: 5879

2 years agonetmap: packet stall
Bill Meeks [Thu, 23 Feb 2023 16:12:56 +0000 (11:12 -0500)] 
netmap: packet stall

- Fix packet processing stall under high load when using netmap in IPS mode.
- Detect and generate Fatal Error exit for rare case when hardware NIC exposes
unmatched RX/TX queue counts. This is rare, but would result in some traffic
bypassing Suricata since it assumes NIC queue counts are symmetrical.
- Fix instance of missing unlock call for netmap device list when exiting due
to an error condition.
- Clean up existing code comments and add additional ones to better document
the new netmap v14 API code.

2 years agoconfig: put version in configuration as a proper value
Jason Ish [Mon, 30 Jan 2023 23:13:04 +0000 (17:13 -0600)] 
config: put version in configuration as a proper value

Adds a new field, "suricata-version" to the configuration file with
the major and minor version of the Suricata that generated the
configuration file.

This may be useful in the future for presenting warnings about
important changes, or even providing different defaults based on what
the user might expect.

Ticket: 5822

(cherry picked from commit c6c781ef677132d579b82e7860c83f9dbb2c7301)

2 years agoeve/drop: don't log drops unless packet is dropped
Victor Julien [Tue, 21 Mar 2023 19:20:48 +0000 (20:20 +0100)] 
eve/drop: don't log drops unless packet is dropped

In pass/drop combinations where the pass rule took precendence over
the drop, a "drop" false positive could still be logged due to the
storing of the drop record in the packet drop alert store.

Bug: #5867.
(cherry picked from commit 09348564f032ad61811d2a77aecc1d0472f4a656)

2 years agodetect/urilen: fix applying urilen as depth
Victor Julien [Thu, 23 Mar 2023 14:42:18 +0000 (15:42 +0100)] 
detect/urilen: fix applying urilen as depth

If urilen induced depth was set, later DetectContentPropagateLimits()
would apply a wrong depth setting, leading to a false negative in
some cases.

Bug: #5929.
(cherry picked from commit ba7db2583b0d96627d3088dd3d89b69ad21ff757)

2 years agostream: SYN queue support 8569/head
Victor Julien [Thu, 9 Feb 2023 16:11:21 +0000 (17:11 +0100)] 
stream: SYN queue support

Support case where there are multiple SYN retransmits, where
each has a new timestamp.

Before this patch, Suricata would only accept a SYN/ACK that
matches the last timestamp. However, observed behavior is that
the server may choose to only respond to the first. In IPS mode
this could lead to a connection timing out as Suricata drops
the SYN/ACK it considers wrong, and the server continues to
retransmit it.

This patch reuses the SYN/ACK queuing logic to keep a list
of SYN packets and their window, timestamp, wscale and sackok
settings. Then when the SYN/ACK arrives, it is first evaluated
against the normal session state. But if it fails due to a
timestamp mismatch, it will look for queued SYN's and see if
any of them match the timestamp. If one does, the ssn is updated
to use that SYN and the SYN/ACK is accepted.

Bug: #5856.
(cherry picked from commit 7bfee147ef6caefe0dd4444a088f451188108e0a)

2 years agostream: move state queue code into util func
Victor Julien [Thu, 9 Feb 2023 15:35:53 +0000 (16:35 +0100)] 
stream: move state queue code into util func

(cherry picked from commit 288086af3feb40318784b5fa1e92d73c11081481)

2 years agodebug: add bool string print helper macro
Victor Julien [Wed, 7 Sep 2022 06:38:07 +0000 (08:38 +0200)] 
debug: add bool string print helper macro

(cherry picked from commit 0ec136621d7c5e24b38e706856c461fd5a96ef2d)

2 years agostream: support SYN/ACK with TFO only ack'ing ISN 8568/head
Victor Julien [Sat, 25 Feb 2023 09:10:29 +0000 (10:10 +0100)] 
stream: support SYN/ACK with TFO only ack'ing ISN

Not ack'ing the data.

(cherry picked from commit 7ef57cc7cbbfe6ca0aff3c3526614c7ab6d14d40)

2 years agostream: add liberal timetamps option
Victor Julien [Wed, 22 Feb 2023 14:17:53 +0000 (15:17 +0100)] 
stream: add liberal timetamps option

Linux is slightly more permissive wrt timestamps than many
other OS'. To avoid many events/issues with linux hosts, add an
option to allow for this slightly more permissive behavior.

Ideally the host-os config would be used, but in practice this
setting is rarely set up correctly, if at all.

This option is enabled by default.

(cherry picked from commit 01b7ccc224f573ca2106731b07ea845b27f89661)

2 years agostream: D-SACK detection and logging
Victor Julien [Tue, 21 Feb 2023 09:47:13 +0000 (10:47 +0100)] 
stream: D-SACK detection and logging

RFC 2883 specifies a special use of SACKs to indicate a host has
received a segment it considers a spurious retransmission.

(cherry picked from commit d79a926085ce66e0be4bb22ede1671928b6995fb)

2 years agostream: fix next_seq updates after temporary gap
Victor Julien [Sat, 18 Feb 2023 14:36:55 +0000 (15:36 +0100)] 
stream: fix next_seq updates after temporary gap

On every accepted packet in established state, update next_seq if
packet seq+len is larger than existing next_seq. This allows it to
catch up after large gaps that are filled again a bit later.

Bug: #5877.
(cherry picked from commit 76225bf9ac87ed4312d44b83d9499794cc760207)

2 years agostream: improve first FIN next_seq update
Victor Julien [Tue, 14 Feb 2023 14:36:56 +0000 (15:36 +0100)] 
stream: improve first FIN next_seq update

For accepted FIN packets, always update next_seq. This helps track the
FIN sequence.

Bug: #5877.
(cherry picked from commit 551fb80150c6b07183771e455a30f38953298fff)

2 years agostream: improve FIN next_seq handling
Victor Julien [Wed, 15 Feb 2023 10:56:47 +0000 (11:56 +0100)] 
stream: improve FIN next_seq handling

Update next_seq to SEQ + payload_len + 1, so retransmission checks
work better.

Bug: #5877.
(cherry picked from commit 80a012a7877cad8b9f8d12ba4bab63971ac7bb78)

2 years agostream: set next_seq before last_ack
Victor Julien [Wed, 15 Feb 2023 10:56:01 +0000 (11:56 +0100)] 
stream: set next_seq before last_ack

next_seq sometimes depends on last_ack in cases of packet loss
catch up, so first update it.

Bug: #5877.
(cherry picked from commit 20df715e64ccab00c6f6778e1453b051aee7be17)

2 years agostream/tcp: update ack handling logic
Eric Leblond [Fri, 28 May 2021 10:19:19 +0000 (12:19 +0200)] 
stream/tcp: update ack handling logic

Only update the ack value of a session for regular packets when
the ACK bit is set.

(cherry picked from commit 0d81173d6e912f4be9e3e8f7593d779d8ffed52f)

2 years agostream/tcp: fix wrong ACK trigger FIN1 to FIN2
Victor Julien [Sat, 11 Feb 2023 12:14:53 +0000 (13:14 +0100)] 
stream/tcp: fix wrong ACK trigger FIN1 to FIN2

An ACK that ACK'd older data while still being in-window could
lead to FIN_WAIT1 to FIN_WAIT2 state transition. Detect this
case and generally harden the check.

Bug: #5877.
(cherry picked from commit 67af94f2e07352807cfedb722ea8c79e156da5fc)

2 years agostream: fix overlap detection
Victor Julien [Tue, 28 Feb 2023 10:41:59 +0000 (11:41 +0100)] 
stream: fix overlap detection

If a in-tree segment was partly before base_seq the overlap detection
miscalculated the data offset. This lead to memcmp comparing the wrong
data.

Bug: #5881.

(cherry picked from commit cbcd70537a2af1d15474d08412d3a7134163ee6b)

2 years agostream: set event on bad timestamp on syn_sent state 8531/head 8634/head
Victor Julien [Thu, 9 Feb 2023 08:36:56 +0000 (09:36 +0100)] 
stream: set event on bad timestamp on syn_sent state

(cherry picked from commit fc376f81455ebfd487a0de2f8a14884be073b8ac)

2 years agostream/tcp: allow tcp session reuse on null sessions 8525/head
Victor Julien [Thu, 2 Feb 2023 13:45:30 +0000 (14:45 +0100)] 
stream/tcp: allow tcp session reuse on null sessions

When a "stream starter" packet finds an existing TCP flow, the flow will be
evaluated for reuse.

The following scenario wasn't handled well:

1. Suricata starts after a tool has just stopped using lots of connections
   (e.g. ab stress testing a webserver)
2. even though the client is closed already, the server is still doing
   connection cleanup sending many FINs and later RSTs
3. Suricata creates flows for these packets, but no TCP sessions
4. client resumes testing, creating flows that have the same 5 tuple as the
   flows created for the FIN/RST packets
5. Suricata refuses to "reuse" the flows as the condition "tcp flow w/o session"
   is not considered valid for session reuse
6. new TCP connection is not properly tracked and evaluated in parsing and
   detection

There may be other vectors into this, like a flow w/o session because of
memcap issues.

Bug: #5843.
(cherry picked from commit 93c9594dd8158a9d8fa76fdbc7c02e82da2b0ed2)

2 years agoflowworker: don't keep unnecessary flow reference
Victor Julien [Fri, 27 Jan 2023 19:30:20 +0000 (20:30 +0100)] 
flowworker: don't keep unnecessary flow reference

Flow stream/detect/log flush packets, don't hold on to the flow
beyond the flow worker module.

(cherry picked from commit a2dc9a40e76ded08e084f1c11eff2140380e73ec)

2 years agoversion: start development towards 6.0.11
Victor Julien [Tue, 31 Jan 2023 18:43:17 +0000 (19:43 +0100)] 
version: start development towards 6.0.11

2 years agorelease: 6.0.10; update changelog suricata-6.0.10
Shivani Bhardwaj [Tue, 31 Jan 2023 06:18:36 +0000 (11:48 +0530)] 
release: 6.0.10; update changelog

2 years agorequirements: suricata-update 1.2.7 8500/head
Jason Ish [Mon, 30 Jan 2023 18:02:47 +0000 (12:02 -0600)] 
requirements: suricata-update 1.2.7

2 years agothreshold: suppress debug notice message 8499/head
Victor Julien [Mon, 30 Jan 2023 15:08:24 +0000 (16:08 +0100)] 
threshold: suppress debug notice message

2 years agodecode/events: add strict mode for udp.hlen_invalid; remove rule
Victor Julien [Mon, 30 Jan 2023 12:55:52 +0000 (13:55 +0100)] 
decode/events: add strict mode for udp.hlen_invalid; remove rule

2 years agorules/decoder: add udp.len_invalid rule
Shivani Bhardwaj [Wed, 18 Jan 2023 01:35:08 +0000 (07:05 +0530)] 
rules/decoder: add udp.len_invalid rule

(cherry picked from commit b5b05b8fce68ac18e7ea6330508afc3ad0c35866)

2 years agodecode/udp: fix payload_len calculation
Shivani Bhardwaj [Wed, 4 Jan 2023 06:30:13 +0000 (12:00 +0530)] 
decode/udp: fix payload_len calculation

Fix payload_len calculation post removal of the condition that returned
error code if the length to the decode fn did not match the length of
header from the UDP packet.

Bug 5379

(cherry picked from commit f941ceae2be883596a3571ec9046ea884d3f3f85)

2 years agodecode/events: add event type UDP_LEN_INVALID
Shivani Bhardwaj [Wed, 18 Jan 2023 00:53:13 +0000 (06:23 +0530)] 
decode/events: add event type UDP_LEN_INVALID

(cherry picked from commit eebdfe9a3e46be0508ff636db0fc514a4f922656)

2 years agodecode-udp: Allow shorter UDP packets than the remaining payload length
Lukas Sismis [Fri, 27 Jan 2023 11:34:37 +0000 (12:34 +0100)] 
decode-udp: Allow shorter UDP packets than the remaining payload length

If the packet is shorter than IP payload length we no longer flag it as an
invalid UDP packet. UDP packet can be therefore shorter than IP payload.
Keyword "udp.hlen_invalid" became outdated as we no longer flag short UDP
packets as invalid. The keyword's evaluation remains the same.

Inspired by commit: d18e52ed93e996bc0335d4a100b2ac7f12b3848d

Redmine ticket: #5793

2 years agofuzz: checks pcap timestamp consistency
Philippe Antoine [Mon, 30 Jan 2023 09:49:29 +0000 (10:49 +0100)] 
fuzz: checks pcap timestamp consistency

Inspired by commit e22b59b8c17c2fb8ae30b2612086a7975cd94a6c

Master7 is now diverging with use of SCTime_t

2 years agoapp-layer: explicitly enable sip, rdp and mqtt
Victor Julien [Mon, 30 Jan 2023 12:42:31 +0000 (13:42 +0100)] 
app-layer: explicitly enable sip, rdp and mqtt

In the default config these were enabled implicitly, as their `enabled`
field was commented out. This lead to warnings in the default config.

Ticket: #5299.

2 years agodetect: config keyword transaction logic fix 8458/head
Philippe Antoine [Mon, 25 Jul 2022 08:33:42 +0000 (10:33 +0200)] 
detect: config keyword transaction logic fix

When the keyword config:logging disable,type tx is used,
OutputTxLog checks a flag to skip the transaction without logging
it, but AppLayerParserTransactionsCleanup waits for the
transaction to be marked as logged to clean it.

So, OutputTxLog now marks the tx as logged, so that it can
get cleaned away.

Ticket: #5456
(cherry picked from commit 0c0fcc94111b183ae2953f659d14ab2f671fc019)

2 years agosmb: set defaults for file transfer limits
Victor Julien [Tue, 24 Jan 2023 11:38:21 +0000 (12:38 +0100)] 
smb: set defaults for file transfer limits

Ticket: #5782.
(cherry picked from commit 37f13a4fc7356432cfec80852eb1f58da7cc8850)

2 years agostream/tcp: fix typos, update copyright year 8454/head
Juliana Fajardini [Thu, 19 Jan 2023 14:21:10 +0000 (11:21 -0300)] 
stream/tcp: fix typos, update copyright year

Bug #5765

2 years agoexceptions: ignore policy if stream.midstream=true
Juliana Fajardini [Thu, 19 Jan 2023 14:18:16 +0000 (11:18 -0300)] 
exceptions: ignore policy if stream.midstream=true

Set the engine to ignore the stream.midstream-policy if stream.midstream
is enabled.

If we had both stream.midstream AND stream.midstream_policy enabled,
this could lead to midstream flows being dropped (or bypassed, or...)
instead of being accepted by the engine, as it was probably meant when
the user enabled midstream flows.

Bug #5765

(cherry picked from commit 8e9905e0d833858a5053285c8ffe6ed4ed30fc12)

2 years agonfs2: improve READ parsing
Philippe Antoine [Wed, 25 Jan 2023 15:20:00 +0000 (16:20 +0100)] 
nfs2: improve READ parsing

Inspired by commit ddf14e51dcf5dabdb4bc07414a118530e2a1b819

But keeping old nom version

2 years agofuzz: specify protocol with fuzz target name
Philippe Antoine [Mon, 29 Mar 2021 18:27:34 +0000 (20:27 +0200)] 
fuzz: specify protocol with fuzz target name

cf https://redmine.openinfosecfoundation.org/issues/4125

This allows fuzz_applayerparser_parse to fuzz one specific
app-layer protocol based on the binary name, as is done
with the environment variable FUZZ_APPLAYER
That is if we rename/copy to fuzz_applayerparser_parse_smb,
it will fuzz only SMB protocol
This way, we can easily produce different fuzz targets for
each protocol in oss-fuzz

(cherry picked from commit e9b76a0e663ce5c2f8900f90a4f4fd7ed3436335)

2 years agonetmap: Fixup issues with v14+ backport
Jeff Lucovsky [Fri, 20 Jan 2023 14:16:05 +0000 (09:16 -0500)] 
netmap: Fixup issues with v14+ backport

This commit reduces the changes associated with adding the v14 api to
6.0.x

During the preparation of this commit, issues in the original backport
were corrected
- Failure to release a lock under error conditions
- Typo in an CPP ifdef
- Incorrect target for goto statement in an error handling case.

Issue: 5744

2 years agotest: do not output non ascii character
Philippe Antoine [Thu, 15 Sep 2022 13:26:46 +0000 (15:26 +0200)] 
test: do not output non ascii character

The unit test for content |aa bz| transforms in place the string
str to replace the 2 characters aa by one character 0xaa
Then, when z is not recognized as a valid hexadeicmal character,
the whole modified string is printed out, inclusing the non-ascii
0xaa

Ticket: #5558
(cherry picked from commit b281199e9aa1d2d66ac35d1f53358afca8c44a13)

2 years agosmb/ntlmssp: parse fields independently of order
Philippe Antoine [Tue, 6 Dec 2022 13:34:37 +0000 (14:34 +0100)] 
smb/ntlmssp: parse fields independently of order

Instead of relying on the usual ordering...

Ticket: #5258
(cherry picked from commit 1db86858482ddfed446f2f124c546a133e01b17c)

Manual conflict fixes to use nom instead of nom7

2 years agodoc/userguide: ubuntu: install software-properties-common 8428/head
Jason Ish [Tue, 29 Nov 2022 20:32:03 +0000 (14:32 -0600)] 
doc/userguide: ubuntu: install software-properties-common

This package likely needs to be installed when starting with an Ubuntu
container or other minimal Ubuntu install.

Ticket: #5616
(cherry picked from commit 0a4e3d0f82a5bf9d6090b3663b143a689bd52d9e)

2 years agosmb: fix post-trunc chunk behavior
Victor Julien [Wed, 11 Jan 2023 20:07:16 +0000 (21:07 +0100)] 
smb: fix post-trunc chunk behavior

After a gap in a file transaction, the file tracker is truncated. However
this did not clear any stored out of order chunks from memory or stop more
chunks to be stored, leading to accumulation of a large number of chunks.

This patches fixes this be clearing the stored chunks on trunc. It also
makes sure no more chunks are stored in the tracker after the trunc.

Bug: #5781.
(cherry picked from commit a24d7dc45c818054f97448ce42ca9ba270b3b8e4)

2 years agostreaming/sbb: fix debug message
Victor Julien [Thu, 5 Jan 2023 06:25:26 +0000 (07:25 +0100)] 
streaming/sbb: fix debug message

(cherry picked from commit 989e5c7ba23534a488794592193deea8c3a293e8)

2 years agostream: remove bug on from packet path
Victor Julien [Wed, 4 Jan 2023 19:39:24 +0000 (20:39 +0100)] 
stream: remove bug on from packet path

(cherry picked from commit a00db15bd41ad08bec19ad3c252d1aab92c5c525)

2 years agosrc: fix deprecated-non-prototype compile warnings
Victor Julien [Tue, 17 Jan 2023 10:10:54 +0000 (11:10 +0100)] 
src: fix deprecated-non-prototype compile warnings

Tested on Fedora 37 with clang 15.

util-strlcatu.c:45:8: error: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Werror,-Wdeprecated-non-prototype]
size_t strlcat(dst, src, siz)
           ^
1 error generated.

(cherry picked from commit 41ca206fdfa1a071d5bf18ae2a18e1e4cea583bd)

2 years agosrc: fix unused-but-set-variable compile warnings
Victor Julien [Mon, 16 Jan 2023 21:09:02 +0000 (22:09 +0100)] 
src: fix unused-but-set-variable compile warnings

Tested on Fedora 37 with clang 15.

datasets.c:852:9: error: variable 'n' set but not used [-Werror,-Wunused-but-set-variable]
    int n = 0;
        ^
1 error generated.

(cherry picked from commit 1bc6976a061a78f953f6b9c796cd4135c1494beb)

2 years agosrc: fix strict-prototype warnings
Victor Julien [Mon, 16 Jan 2023 18:14:28 +0000 (19:14 +0100)] 
src: fix strict-prototype warnings

Tested on Fedora 37 with clang 15.

app-layer.c:1055:27: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void AppLayerSetupCounters()
                          ^
                           void
app-layer.c:1176:29: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
void AppLayerDeSetupCounters()
                            ^
                             void
2 errors generated.

(cherry picked from commit ebd87282196e4757db44e9d40823477b34484238)

2 years agouserguide: update http2 config header syntax
jason taylor [Wed, 11 Jan 2023 18:38:53 +0000 (18:38 +0000)] 
userguide: update http2 config header syntax

Signed-off-by: jason taylor <jtfas90@gmail.com>
2 years agoftp: completely resets port_line
Philippe Antoine [Wed, 28 Dec 2022 14:57:12 +0000 (15:57 +0100)] 
ftp: completely resets port_line

In the case port_line is first allocated and port_line_len is set,
Then a second request reaches memcap and frees port_line,
port_line_len should also be reset, because both will get used
by the response parsing.

Ticket: #5701
(cherry picked from commit 1660172a8b5af48b156096c4ad8bebcd9dbfafd9)

2 years agodcerpc: store consumed_bytes as i32 8419/head
Philippe Antoine [Sat, 2 Apr 2022 19:16:53 +0000 (21:16 +0200)] 
dcerpc: store consumed_bytes as i32

As it can grow bigger than u16

(cherry picked from commit 704bc878ea3f2fcb911d38b6a21aa5a7ee4d2a79)

2 years agorust: fix for loop over option 8376/head
Jason Ish [Fri, 13 Jan 2023 20:04:52 +0000 (14:04 -0600)] 
rust: fix for loop over option

As of Rust 1.66 with strict mode enabled, a for loop over an option is
now an error. Replace the last occurrence of this pattern with an "if
let" statement.

2 years agotls: fix off by one in supported versions extension 8374/head
Philippe Antoine [Fri, 11 Nov 2022 10:52:27 +0000 (11:52 +0100)] 
tls: fix off by one in supported versions extension

Ticket: #5663
(cherry picked from commit b5147189aecd1d49520e6dc9b40b1baca5a4f503)

2 years agossl: add debug validation checks for recent changes
Victor Julien [Tue, 1 Nov 2022 15:48:13 +0000 (16:48 +0100)] 
ssl: add debug validation checks for recent changes

Make sure the assumptions are correct.

(cherry picked from commit 8f0d820218585ea450fd87b86e8754f03805cb38)