Commit Graph

12326 Commits (9cc92b8dd59ea97e0a9051542d34680e53afc31b)
 

Author SHA1 Message Date
Victor Julien b4fd4c048b 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 a38f2f2a52)
4 years ago
Victor Julien bf5d9d542b 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 a89840929b)
4 years ago
Victor Julien a32b02fb65 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 e36b9b89a1)
4 years ago
Victor Julien 5fcbc8bb50 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 3874d08015)
4 years ago
Victor Julien 660484404f 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 8580499ded)
4 years ago
Victor Julien 3a55873eb8 eve/drop: log drop reason
Ticket: #5202.
(cherry picked from commit 0035673208)
4 years ago
Victor Julien aa66765253 flow: log action applied to all packets
Log if action applied to whole flow is drop or pass.

(cherry picked from commit 9a09fe454b)
4 years ago
Victor Julien 38744135ef 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 802c1ffee3)
4 years ago
Victor Julien d8b5d3d34a clang-format: disable for option table 4 years ago
Lukas Sismis 4c4b1de168 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 05797c45bb)
4 years ago
Lukas Sismis 8fa5f3bdd4 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 8845c07a90)
4 years ago
Victor Julien e9b084e8ca 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: 9fafc1031c ("time: Add TIMEVAL_EARLIER and TIMEVAL_DIFF_SEC macros.")
Fixes: 82dc61f4c3 ("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 df2e408d96)
4 years ago
Victor Julien 643d502d9e 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 fea374626a)
4 years ago
Victor Julien 1f31eb9e58 app-layer: don't switch dir if proto already known
(cherry picked from commit 86e8611f5e)
4 years ago
Victor Julien 91ea80291f 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 84e26d670e)
4 years ago
Victor Julien e65ab0fc90 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 7d38f5667d)
4 years ago
Victor Julien b588c8623f github/workflows: add cargo for all Ubuntu jobs
(cherry picked from commit 7ced8de6c4)
4 years ago
Victor Julien e9b88f67cc file: consistently track size of gaps
Until now only the size of gaps counted in the regular append, not
close and open.

Bug: #5392.
(cherry picked from commit 71ef62bfc5)
4 years ago
Michael Tremer aeee505ff2 stream: tcp: Handle retransmitted SYN with TSval
For connections that use TCP timestamps for which the first SYN packet
does not reach the server, any replies to retransmitted SYNs will be
tropped.

This is happening in StateSynSentValidateTimestamp, where the timestamp
value in a SYN-ACK packet must match the one from the SYN packet.
However, since the server never received the first SYN packet, it will
respond with an updated timestamp from any of the following SYN packets.

The timestamp value inside suricata is not being updated at any time
which should happen. This patch fixes that problem.

Bug: #4376.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
(cherry picked from commit f50af12068)
4 years ago
Victor Julien 9ab4c98430 detect/content: fix FNs due to bad depth calc
When trying to propegate the depth/offset, within/distance chains
a logic error would set too a restrictive depth on a pattern that
followed more than one "unchained" patterns.

Bug: #5162.
(cherry picked from commit 8d20b40cdd)
4 years ago
Victor Julien df0cca4537 detect/content: simplify int bounds checking
Use a macro to validate the ranges for overflows. This removes
the clutter of all the checks and warnings, and also no longer
puts the state machine in an undefined state when hitting such
a condition.

(cherry picked from commit 50d02ebc05)
4 years ago
Philippe Antoine 301af290ca detect: fix integer warnings for content
Ticket: #4516
(cherry picked from commit ac8fb553a1)
4 years ago
Philippe Antoine 249a3b5677 detect: parsing avoiding infinite loop
by comparing size_t to strlen result
Instead of uint16_t which would loop

Ticket: #5310
(cherry picked from commit ced96a8aad)
4 years ago
Jason Ish 6ba16e883e detect: introduce "like" ip-only signature type
Rules that look like they should be IP-only but contain a negated rule
address are now marked with an LIKE_IPONLY flag. This is so they are
treated like IPONLY rules with respect to flow action, but don't
interfere with other IPONLY processing like using the radix tree.

Ticket: #5361
(cherry picked from commit c8a5207083)
4 years ago
Victor Julien 5ed73e839f detect/iponly: remove unused code
(cherry picked from commit 51ef6f4e3a)
4 years ago
Victor Julien 0ffd310180 detect/iponly: include postmatch in determination
(cherry picked from commit beecc1890f)
4 years ago
Victor Julien ca3be76e23 smtp: remove defunct check for line with single LF
Don't fix it as DATA processing needs all the bytes.

(cherry picked from commit 96bb67f474)
4 years ago
Victor Julien 45083caf81 smtp: turn assertions in to debug asserts
(cherry picked from commit 77fae275ef)
4 years ago
Victor Julien 35145c1c6f smtp: simplify preprocess loop
(cherry picked from commit 3a631085bb)
4 years ago
Victor Julien 9e244a87ae mime/base64: decode cleanups and simplification
Addresses edge case: > 4 bytes at the end of the input with 2 or more
spaces.

Changes length type for remainder processing to allow for much longer
lines, which can happen in practice.

Adds a series of debug validation checks with real error handling
as well, to assist the fuzzer to find more edge cases.

(cherry picked from commit 30e47b2171)
4 years ago
Victor Julien e1a24c8ee7 base64: no special case for nul char
Let it be handled like other invalid input.

(cherry picked from commit 92cd95b416)
4 years ago
Shivani Bhardwaj 2eebad50cd base64: make decoder handle decoded data space constraints
So far, it was the job of caller to send the bae64 decoder a perfect
block of data and take care of the destination buffer (decoded data)
size. Now, make it the decoder's job to take care of any space
constraints that the destination buffer may have and return accordingly.

Also, handle space characters in base64 encoded data as per RFC 2045.

Update MIME parser accordingly to handle the base64 data.

Ticket: 5315
(cherry picked from commit 5b27619778)
4 years ago
Shivani Bhardwaj dec114d206 base64: add Base64Ecode enum
(cherry picked from commit cb01cc6929)
4 years ago
Shivani Bhardwaj 67220da86d base64: add Base64Mode enum
(cherry picked from commit 9131d1d857)
4 years ago
Shivani Bhardwaj 5390c61320 smtp: treat CR as a line terminator
The ideal line terminator for an SMTP line is <CRLF>. But, given that
bare LF is still allowed by many systems despite the prohibition by
standards, we have to consider that. In order to simplify things, we
consider bare CR as line terminators as well while updating the
delimiter parameter correctly if they were to be followed by a LF
immediately or as a part of next fragment.

This takes care of some edge cases that made base64 decoder error out
because unexpected data was sent to it at times.

Ticket: 5316
(cherry picked from commit 1e3282f363)
4 years ago
Victor Julien fef20c6426 runmodes: fix more warnings
(cherry picked from commit a535cc5a25)
4 years ago
Juliana Fajardini b3070b8ba9 detect/alert: directly increment alerts.discarded
In the unlikely case of AlertQueueExpand failure, we were incrementing
the discarded alerts stats in AlertQueueAppend via the Packet member in the
DetectEngineThreadCtx, which may not be initialized yet.

Bug #5353

(cherry picked from commit 28ac75b505)
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
Victor Julien afff6a3105 stream/unittests: fix failures after last_ack fix
Work around many tests not setting up stream completely or correctly.

(cherry picked from commit 3d6e733aa7)
4 years ago
Victor Julien 5be1c87a74 stream: improve last_ack validation check
If a packet after the initialization would come with ACK flag set
but a ACK value of 0, the last_ack tracking could get confused. Fix
this by not checking for 0 but instead checking if the ACK flag
has been seen.

Bug: #4549.
(cherry picked from commit 1f43e1477f)
4 years ago
Juliana Fajardini 47243c0839 userguide: dynamically determine copyright date
This uses the date of doc generation to determine the copyright date
for the trailing date. Based on Jeff Lucovsky solution.

(cherry picked from commit e0c8dba7ac)
4 years ago
Victor Julien cb51da6564 detect: optimize mpm-engine setup
Instead of a loop over the rules in a group *per engine* do a single
loop in which all the engines are prepared in parallel.

(cherry picked from commit 9e6370ae2e)
4 years ago
Philippe Antoine eccedfb225 ssh: install app-layer events rules
(cherry picked from commit acbe6a33a2)
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
Sascha Steinbiss 87bec36093 util: add unit tests for CIDRFromMask()
(cherry picked from commit 5ec6f3ba51)
4 years ago
Sascha Steinbiss a2c5b8fc42 detect: make int CIDRFromMask() work on big endian platforms
(cherry picked from commit 394356f73c)
4 years ago
Victor Julien b4ee40eb38 detect: initialization optimization
A lot of time was spent in `SigMatchListSMBelongsTo` for the `mpm_sm`.

Optimize this by keeping the value at hand during Signature parsing and
detection engine setup.

(cherry picked from commit 3352c0bee4)
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