Commit Graph

741 Commits (809aebfee183c680ae14e4d58316e477fad0dca0)

Author SHA1 Message Date
tianjinshan 708bdf79fa smb/ntlmssp: fix parsing of negotiate flags
Ticket: #5783
(cherry picked from commit 2c0c6cb0a5)
3 years ago
Jason Ish 248176caba rust: update nom to 5.1.3
Update nom to 5.1.3 which fixes some future breaking changes in the Rust
compiler.

See https://github.com/rust-bakery/nom/pull/1657 for more info.
3 years ago
Philippe Antoine 42786aef59 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 9adb59bcdb)
3 years ago
Eric Leblond 9dfb3baf19 sip: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago
Eric Leblond 0a78edc20f ntp: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago
Eric Leblond 94a7072384 krb: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago
Eric Leblond 7137c877e8 mqtt: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago
Eric Leblond 6cb79d0721 ike: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago
Eric Leblond b1af87709f dns: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago
Eric Leblond 84cbdbf21f snmp: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
3 years ago
Eric Leblond 4a3fdedc1f 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
Jason Ish 2b02abfa75 rfb: remove duplicate logging of depth
The "depth" field in the "pixel_format" object was being logged twice.

Issue: 5813

(cherry picked from commit f15f092a69)
4 years ago
Jason Ish 0e0ce39190 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 67baab573b)
4 years ago
Philippe Antoine 70a4587a9b dns: remove unused events field from state
found overflowing by oss-fuzz

(cherry picked from commit 26dc70648c)
4 years ago
Philippe Antoine 95009e4411 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 233ab11148)
4 years ago
Philippe Antoine 0bf3ab9e6d 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 c1b7befb18)
4 years ago
Victor Julien 6c7bdd7aca smb: set defaults for file transfer limits
Ticket: #5782.
(cherry picked from commit 37f13a4fc7)
4 years ago
Philippe Antoine fa4dedc1d4 nfs2: improve READ parsing
Inspired by commit ddf14e51dc

But keeping old nom version
4 years ago
Philippe Antoine ffb2e38ae0 smb/ntlmssp: parse fields independently of order
Instead of relying on the usual ordering...

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

Manual conflict fixes to use nom instead of nom7
4 years ago
Victor Julien ba4a533797 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 a24d7dc45c)
4 years ago
Philippe Antoine b5131da355 dcerpc: store consumed_bytes as i32
As it can grow bigger than u16

(cherry picked from commit 704bc878ea)
4 years ago
Jason Ish 6b6709c9d9 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.
4 years ago
Philippe Antoine 938597691c nfs4: fix write record handling
Ticket: #5280
(cherry picked from commit 95f0424423)
4 years ago
Victor Julien d607c9295b smb: fix file reopening issue
Fuzzing highlighted an issue where a command sequence on the same file
id triggered a logging issue:

file data for id N
close id N
file data for id N

If this happened in a single blob of data passed to the parser, the
existing file tx would be reused, the file "reopened", confusing the
file logging logic. This would trigger a debug assert.

This patch makes sure a new file tx is created for the file data
coming in after the first file tx is closed.

Bug: #5567.
(cherry picked from commit 45eb038e63)
4 years ago
Philippe Antoine a567305240 dcerpc: fix integer underflow
as input.len() can be 65536, it cannot be directly cast to u16

Ticket: #5557
Ticket: #5602
4 years ago
Philippe Antoine 05509b52f6 smb: do not use tree id to match request and response
Completes commit e94920b49f

This must be true for access to state ssn2vecoffset_map

Ticket: #5161
4 years ago
Philippe Antoine d84eee39a8 smb: do not use tree id to match create request and response
As an SMB2 async response does not have a tree id, even if
the request has it.

Per spec, MessageId should be enough to identifiy a message request
and response uniquely across all messages that are sent on the same
SMB2 Protocol transport connection.
So, the tree id is redundant anyways.

Ticket: #5508
(cherry picked from commit e94920b49f)
4 years ago
Victor Julien acec24a816 rust/files: open file without trackid as pointer
(cherry picked from commit cade6046c5)
4 years ago
Victor Julien 304fd1796f rust/filecontainer: remove unused declaration
(cherry picked from commit ad869e1c52)
4 years ago
Philippe Antoine 0324a9b20b http2: fix decompression buffering
It was not enough to set Cursor position to 0,
also its inner Vec should be cleared.

This way, a new input gets written at the beginning of the
Cursor and its inner Vec...

Ticket: #5691
(cherry picked from commit 086b28da3d)
4 years ago
Philippe Antoine 9cc92b8dd5 http2: support padded data frames
Ticket: #5691
(cherry picked from commit c6349d3cfc)
4 years ago
Philippe Antoine 0ca12493e3 mime: handles multiple sections for a parameter
Ticket: 4386

as per RFC2231.
For instance filename can be split between filename*0,
filename*1, etc...

(cherry picked from commit 784558df2e)
4 years ago
Philippe Antoine 55781229d7 mime: move FindMimeHeaderTokenRestrict to rust
Also fixes the case where the token name is present
in a value

(cherry picked from commit 8feb9c35ae)
4 years ago
Philippe Antoine 40d1bb3422 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 a8079dc978

Ticket: #5399
(cherry picked from commit e160917bcf)
4 years ago
Jeff Lucovsky ba37574ca5 mqtt: convert transaction list to vecdeque
Ticket: 5430
4 years ago
Philippe Antoine 18c616394e 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 e42094f238)
4 years ago
Philippe Antoine e029f80af2 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 a8079dc978)
4 years ago
Philippe Antoine 16da02cfbd http2: remove to_vec for comparisons
Ticket: #5454
(cherry picked from commit 9b4a133777)

Conflict fixed by Philippe Antoine
4 years ago
Philippe Antoine eae0aadab8 http2: fix clippy warning about &Vec<u8>
Using &[u8] instead in function prototype

(cherry picked from commit d011b468da)

Conflict fixed by Philippe Antoine
4 years ago
Philippe Antoine ed15b0d6ab http2: check overflow before it happens
instead of checking afterwards if value got smaller

(cherry picked from commit b86beb9b68)

Manually adapted to make it work with MSRV
4 years ago
Jason Ish b8875d4a22 rust/nfs: add a maximum number of operations per compound
This is a backport of ea1d03f8e3 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
4 years ago
Jeff Lucovsky aa396f4f5e rust: Unused doc comment warning fixup
Since rustdoc does not generate documentation for extern blocks, Fedora
35 builds flagged 2 occurrences where doc comments existed on extern C
blocks.
4 years ago
Philippe Antoine 9bc690897a smb: ntlmssp domain_blob_offset underflow check
Ticket: 5246
(cherry picked from commit e72036f12f)
4 years ago
Philippe Antoine d80fbfd4c6 smb: check on param parsing
Ticket: 5246

so as not to overflow u16

(cherry picked from commit 817a5001a5)
4 years ago
Philippe Antoine dfe3da7765 rust: RustParser same fields as AppLayerParser
So that there is no problem when crossing FFI

(cherry picked from commit c78722a671)
4 years ago
Philippe Antoine 5924869f5d dcerpc: use wrappingadd for padding parsing
As we compute a modulo, we can safely wrap around even if there
is an overflow

Ticket: #5301
(cherry picked from commit d2f00ac824)
4 years ago
Jason Ish eeb8c17e0f dns: don't parse a full request during probe if not enough data
If there is more data than a header, but not enough for a complete DNS
message, the hostname parser could return an error causing the probe to
fail on valid DNS messages.

So only parse the complete message if we have enough input data. This is
reliable for TCP as DNS messages are prefixed, but for UDP its just
going to be the size of the input buffer presented to the parser, so
incomplete could still happen.

Ticket #5034

(cherry picked from commit 27679a12aa)
4 years ago
Jason Ish fa04c1bc57 dns: better error handling when parsing names
The DNS name parser will error out with an error even if the
error is incomplete. Instead of manually generating errors,
use '?' to let the nom error ripple up the error handling chain.

The reason this wasn't done in the first place is this code
predates the ? operator, or we were not aware of it at the time.

This prevents the case where probing fails when there is enough data to
parse the header, but not enough to complete name parser. In such a case
a parse error is returned (instead of incomplete) resulting in the
payload not being detected as DNS.

Ticket #5034

(cherry picked from commit 0623ada24d)
4 years ago
Jason Ish 947cb09e5b smb: protocol detection on pattern without midstream
To recognize a protocol, Suricata first looks for
patterns, which can be confirmed by a probing parser.
If this does not work, Suricata can try to run
some probing parsers on some ports.

This is the case for SMB.

This commit makes handling the confirming and the probing
paser differently even if they share much code.

The confirmation parser knows that a pattern has been found.
So, it must not do the midstream case of looking for this
pattern in the whole buffer, but only check it at the beginning.
But it must reverse direction if needed.

Ticket #4849

Backported manually by jason.ish@oisf.net.

(cherry picked from commit 464ff80c6a)
4 years ago
Philippe Antoine 8498999c6a tftp: use destate
And avoids memory leaks on it

Ticket #4848
4 years ago