Commit Graph

14412 Commits (76c71a9120a3f1f66b2fd38e21a84b3c9283133a)
 

Author SHA1 Message Date
Juliana Fajardini d314b57e6b userguide/muti-tenant: fix typo 2 years ago
jason taylor 5abcd50142 doc: add tenant id value requirement
Signed-off-by: jason taylor <jtfas90@gmail.com>
2 years ago
Maxim Korotkov 1c055dc370 output: fix logic error
The logical error may have been made here. Comparison with the upper
bound of the variable type does not make sense. It may be worth adding
the cast of one of the multiplication operands to the 64-bit type for
avoiding overflow.

Found by Security Code with Svace static analyzer
Bug: #5789

Signed-off-by: Maxim Korotkov <m.korotkov@securitycode.ru>
2 years ago
Victor Julien 39a6f411e9 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.
2 years ago
Shivani Bhardwaj 418ddba38e 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
2 years ago
Jason Ish 8ef410e284 app-layer: add direction to transaction creation where needed
Build on Eric's but set the direction on transaction creation when
needed. I think this makes it a little more clear, and easier to
document when creating single direction transactions.

This also somewhat abstracts the inner-workings of a directional
transaction from the implementation.

Ticket: #4759
2 years ago
Eric Leblond 9f4ca26962 sip: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
2 years ago
Eric Leblond 301237f82e enip: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
2 years ago
Eric Leblond 1decdbe409 dnp3: activate unidirectional TX flag
By implementing the no inspection flag we can now set
the unidirectional TX flag. Which means that the alstate
progress function can now be simplified to always return
1 f the transaction is complete.

Ticket: #5799
2 years ago
Eric Leblond 8b0d56c414 nfs: TX are not unidirectional
NFS transactions are not unidirectional so we should not declare
them as such.
2 years ago
Eric Leblond 19174de4f3 quic: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
2 years ago
Eric Leblond 44482a68b0 ntp: add TX orientation
Set no inspection in the opposite side of the transaction.

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

Ticket: #5799
2 years ago
Eric Leblond 322f3896ba mqtt: add TX orientation
Set no inspection in the opposite side of the transaction.

Ticket: #5799
2 years ago
Eric Leblond 7ce557a44c ike: add TX orientation
Set no inspection in the opposite side of the transaction.

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

Ticket: #5799
2 years ago
Eric Leblond 744fccee17 bittorrent_dht: add TX orientation
Set no inspection in the opposite side of the transaction.

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

Ticket: #5799
2 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
2 years ago
Eric Leblond 236869bc58 detect: remove STREAM_FLUSH
It is unused in the code so can be removed.

Ticket: #5799
2 years ago
Eric Leblond 29e70277d1 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 ago
Philippe Antoine 578f328e06 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
2 years ago
Victor Julien d9008614a2 stream: handle zero window probe acks
These can be skipped for the most part.
2 years ago
Victor Julien 7bc16af939 eve/stream: add output warning about experimental state 2 years ago
Victor Julien 30a716a4ab 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.
2 years ago
Victor Julien 64fb4066cf stream: harden tcp reuse check against RST/FIN 2 years ago
Victor Julien 0d1d288544 stream: improve SYN and SYN/ACK handling with ECN/CWR flags 2 years ago
Victor Julien 5fe2fba184 stream: fix TFO overlap detection with ECN/CWR flags 2 years ago
Victor Julien 277751051b stream: flag zero window probe packets 2 years ago
Jason Ish 6ebb643b83 conf: deprecate multiple "include" statements at same level
The YAML spec considers duplicate keys to be an error, as do some YAML
implementations, most notably Rust's serde_yaml which would be nice to
use in the future.

Multiple include lines at the same level will still work, but a warning
will be emitted.

These can be fixed by moving to an "include" array:

include:
  - file1.yaml
  - file2.yaml

Ticket: #5939
2 years ago
Jason Ish 6e1cd7bbea conf: fatal error if "include" is a mapping
If a field named "include" is mapping it is not processed correctly.
Instead return a fatal error.

In our YAML, "include" has always been a reserved word, so this should
not break any known configuration.

Ticket: #5939
2 years ago
Jason Ish 67ce33a97e conf: allow "include" to be a list of files
In preparation for deprecating multiple "include" fields at the same
level, allow "include" to be a list of filenames.

Ticket: #5939
2 years ago
Juliana Fajardini 31066c7c3b 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
2 years ago
Juliana Fajardini d4333fb959 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
2 years ago
Philippe Antoine d313b5d605 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
2 years ago
Philippe Antoine 473ca6dcf4 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
2 years ago
Jason Ish 60e67db452 rust: don't suppress vendor output
There appears to be some errors happening in CI and this may be hiding
the source of the error.
2 years ago
Jason Ish 6f14aed0e6 rust: bundle Cargo.lock
Cargo.lock has to be provided as template, Cargo.lock.in so it can
live beside Cargo.lock in out of tree automake builds, like distcheck.

This will pin Rust dependencies even for git builds, updating
Cargo.lock will now be a manual process that we'll have to take care
of periodically.
2 years ago
Juliana Fajardini 754d2803dd 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
2 years ago
Jeff Lucovsky f57c11df3f content: Constrain distance/within values
Ticket: 5740

This commit constrains the values for distance and limit to 1MB. The
constraint is enforced while parsing the keyword values.
2 years ago
Jeff Lucovsky 35bbdf4124 doc/content: Add limits for distance/within
Ticket: 5740
2 years ago
jason taylor 46d09a6ba6 profiling: updated switch block to fix gcc warning
This fixes a warning emitted by Fedora 37 when compiling
with gcc 12.2.1

Signed-off-by: jason taylor <jtfas90@gmail.com>
2 years ago
Victor Julien 94bb6dded6 profiling: minor reformatting 2 years ago
Juliana Fajardini 5baa6c0024 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.
2 years ago
Philippe Antoine 4f7426fdcf enip: optimized tx iterator
As for SMTP, having a linked list.

Ticket: #5927
2 years ago
Philippe Antoine e15daf6a4b dnp3: optimized tx iterator
As for SMTP, having a linked list.

Ticket: #5927
2 years ago
Philippe Antoine f5f215dae7 smtp: optimized tx iterator
To be more efficient with larger number of transactions.
As was done for FTP.

Ticket: #5927
2 years ago
Jason Ish 744759b0c9 source-xf-xdp: update for deprecated function in libbpf
libbpf 0.8 deprecates bpf_get_link_xpd_id, and 1.0 removes it. Add
./configure check to see if this method is available and use it if so,
otherwise use the deprecated method which is not available on older
but still supported Linux distributions.

Ticket: #5924
2 years ago
Jason Ish d4418034d1 rust: update aes and aes-gcm crates
Addresses RUSTSEC-2021-0059, RUSTSEC-2021-0060.
2 years ago
Victor Julien ba7db2583b 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.
2 years ago