Commit Graph

10596 Commits (464ff80c6a8efd1212b617a80c726173573caf42)

Author SHA1 Message Date
Victor Julien e7417a8e96 smtp: don't pass partial boundary on to mime parser
If the start of a line looks like it might be a mime boundary we
yield to the get line logic if we don't have enough data to be
conclusive.
4 years ago
Victor Julien 6e800a8548 mime: allow partial lines as input
If we get a zero length delim we assume its a partial line and we
won't append CRLF just yet.
4 years ago
Shivani Bhardwaj cf749fd450 smtp: pre process DATA and BDAT commands
The input data received in DATA and BDAT command modes can be huge and
could have important data, like a legit huge email. Therefore, exempt
these from the line buffering limits which were introduced to regulate
the size of lines that we buffer at any point in time.

As a part of this patch, anything that comes under DATA or BDAT is
processed early without buffering as and when it arrives. The ways of
processing remain the same as before.
4 years ago
Shivani Bhardwaj 078c251dea smtp: fix indefinite buffering if no LF in line
Issue
-----
So far, with the SMTP parser, we would buffer data up until an LF char
was found indicating the end of one line. This would happen in case of
fragmented data where a line might come broken into multiple chunks.
This was problematic if there was a really long line without any LF
character. It would mean that we'd keep buffering data up until we
encounter one such LF char which may be many many bytes of data later.

Fix
---
Fix this issue by setting an upper limit of 4KB on the buffering of
lines. If the limit is reached then we save the data into current line
and process it as if it were a regular request/response up until 4KB
only. Any data after 4KB is discarded up until there is a new LF char in
the received input.

Cases
-----
1. Fragmentation
The limit is enforced for any cases where a line of >= 4KB comes as diff
fragments that are each/some < 4KB.
2. Single too long line
The limit is also enforced for any cases where a single line exceeds the
limit of buffer.

Reported by Victor Julien.
Ticket 5023
4 years ago
Shivani Bhardwaj 57a7cf7a0b smtp: add truncated line event 4 years ago
Jason Ish cf8ed576e0 ftp: truncate command data that is too long
FTP control commands will be buffered forever until a new line is seen,
this can lead to memory exhaustion in Suricata.

To fix, set an upper bound, 4096 bytes on the size of the command that
is saved in the transaction. The input continues to be parsed to find
the end of the command so the parser can continue to move onto the next
command.

The result is that the command data in the transaction is truncated,
which also shows up in the ftp transaction logs.

This value is configurable with the max-line-length field in the ftp
app-layer.protocols section.

As FTP doesn't have events at this time, add a new fields to eve-log
that specificy if the request, or the response has been truncated.

Ticket #5024
4 years ago
Philippe Antoine cedffdf14c 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
4 years ago
Victor Julien f5408ec2d7 detect/frame: fix frame detect registration
Rewrite keyword parser.

Duplicate short names could lead to buffer confusion and memory leaks.

Bug: #5238.
4 years ago
Victor Julien af90478167 detect/frames: reduce severity of validation check 4 years ago
Victor Julien 3a7d09edfc detect/frame: get data using stream callback
Inspect only data that has already been consumed by the
app-layer parser. This allows for simpler progress tracking.
4 years ago
Victor Julien ffe036e881 frame: introduce entry for getting stream data for frame 4 years ago
Victor Julien 96bc11d0d0 stream: make raw data handling more generally usable
Move raw detection logic out of main StreamReassembleRawDo() so that
it can be reused for other parts of the engine.

The caller now has to specify a right edge of the data.
4 years ago
Victor Julien afb97d1dee stream: add offset to raw stream callback
This gives the called function to understand where it is in the
stream.
4 years ago
Victor Julien 205bc1e288 app-layer: disable stream app tracking on no parser
If protocol has no parser enabled or implemented, disable the app
progress tracking in the stream engine to reduce the workload in
the stream engine.
4 years ago
Philippe Antoine 8ecf7e403e 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
4 years ago
Philippe Antoine dccf2e4c30 detect: config checks alstate before getting tx
Ticket: 4972

As is done in detect-lua-extensions.
We can have a flow with alproto unknown, no state, and therefore
cannot run AppLayerParserGetTx which could try to run a NULL
function
4 years ago
Philippe Antoine 45d1a9ae77 detect: faster linked list copy
In DetectAppLayerInspectEngineCopyListToDetectCtx
Avoid quadratic complexity by remembering last element
of the linked list we are inserting into
4 years ago
Philippe Antoine 2a22b4ca1f flow: fix integer warnings
Ticket: 4516
4 years ago
Philippe Antoine 1cc9762b6a host/ippair: fix integer warnings
Ticket: 4516
4 years ago
Philippe Antoine b1eaa1e8cd util: using size_t len for byte utils
Ticket: 4516

Like ByteExtractStringUint64, because most of their inputs come
from strlen which returns a size_t
4 years ago
Philippe Antoine f30975fb16 app-layer: fix integer warnings
Ticket: 4516
4 years ago
Victor Julien 1c8559b3ab debug: support %m output format again
Use thread local storage to avoid the previous dead lock issues.
4 years ago
Victor Julien ce4e543719 threading: simplify thread name logic 4 years ago
Victor Julien 013fb2dde3 frames: remove dead condition in eof check 4 years ago
Victor Julien 86e8611f5e app-layer: don't switch dir if proto already known 4 years ago
Victor Julien 7b55f8b2e3 fuzz/sigpcap_aware: set pkt_src to wire
Avoids an assert if DEBUG is compiled in:

fuzz_sigpcap_aware: source-pcap-file.c:420: TmEcode DecodePcapFile(ThreadVars *, Packet *, void *): Assertion `!(p->pkt_src != PKT_SRC_WIRE && p->pkt_src != PKT_SRC_FFR)' failed.
4 years ago
Victor Julien 61df4120da detect/frame: improve assert accuracy
Handle frames of unknown size correctly.

Bug: #5226.
4 years ago
Victor Julien c824804e2b eve: allow /dev/null in threaded mode
Avoids creation of actual files called /dev/null.N which take
up space in /dev/ which lives in memory.
4 years ago
Victor Julien 5deb479f4c flow: cleanup locking debug leftovers 4 years ago
Victor Julien 57533d3e47 flow: fix and simplify locking
Since:

9551cd0535 ("threading: don't pass locked flow between threads")

`MoveToWorkQueue()` unconditionally unlocks the flow. This allows simpler
locking handling, including of tcp reuse flows.

The simpler logic also fixes a scenario where TCP reuse flows got "unlocked"
twice, once in `FlowGetFlowFromHash()` and once in `MoveToWorkQueue()`.

Bug: #5248.
Coverity: 1494354.
4 years ago
Philippe Antoine e3180e3248 output: fix integer warnings
Ticket: 4516
4 years ago
Philippe Antoine 0cba561fec detect: not an iponly signature if it needs app-layer
Ticket: 4972

This may happen with `config` keyword which is postmatch,
but may require a transaction
4 years ago
Juliana Fajardini a6bda3596b unittests: alloc Packet with PacketGetFromAlloc
Some unittests used SCMalloc for allocating new Packet the unittests.
While this is valid, it leads to segmentation faults when we move to
dynamic allocation of the maximum alerts allowed to be triggered by a
single packet.

This massive patch uses PacketGetFromAlloc, which initializes a Packet
in such a way that any dynamic allocated structures within will also be
initialized.

Related to
Task #4207
4 years ago
Shivani Bhardwaj 6d2a2a0731 detect/dataset: fix space condition in rule lang
If there is a space following a keyword that does not expect a value,
the rule fails to load due to improper value evaluation.
e.g. Space after "set" command
alert http any any -> any any (http.user_agent; dataset:set  ,ua-seen,type string,save datasets.csv; sid:1;)

gives error
[ERRCODE: SC_ERR_UNKNOWN_VALUE(129)] - dataset action "" is not supported.

Fix this by handling values correctly for such cases.
4 years ago
Shivani Bhardwaj 7366396011 detect/dataset: cleanup dead code 4 years ago
Victor Julien 2b5eeab7d4 detect/urilen: don't pass null pointer to pcre2 free
Bug #5228.
4 years ago
Victor Julien 087151ddc3 detect/mpm: initialization micro optimization 4 years ago
Victor Julien 54a6dd09dd detect: pattern id assignment through hash table
Only consider active part of the pattern for mpm (so consider chop).

Move data structure to hash list table over the custom array logic.
4 years ago
Victor Julien a14854bce9 detect: keyword list to hash to improve perf
Since the switch to pcre2 this was much more heavily used, which
would lead to measurable time spent in list handling.
4 years ago
Victor Julien 9e6370ae2e 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.
4 years ago
Victor Julien 3352c0bee4 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.
4 years ago
Victor Julien b804a84c93 hash: constify data input 4 years ago
Victor Julien 4b0e3d79bb detect/analyzer: support frames in pattern dump 4 years ago
Victor Julien 47629b7aeb detect/filemagic: don't pass unused pointer 4 years ago
Arne Welzel 8ef066318d flow-manager: fix off-by-one in flow_hash row allocation
The current code doesn't cover all rows when more than one flow manager is
used. It leaves a single row between ftd->max and ftd->min of the next
manager orphaned. As an example:

    hash_size=1000
    flowmgr_number=3
    range=333

    instance  ftd->min  ftd->max
    0         0         333
    1         334       666
    2         667       1000

    Rows not covered: 333, 666
4 years ago
Victor Julien 9537d119b9 http: fix reassembled range file accounting 4 years ago
Victor Julien 6d30f4442c http2: fix file accounting for ranged files
Increment files_opened for tx that 'gets' reassembled ranged file
4 years ago
Victor Julien 54d34c96f5 files: open/log debug validation bugon
Meant to find more cases where there is a mismatch.
4 years ago
Philippe Antoine cfcade58ad http: move xff logging to alert object
Ticket: 4860

instead of root field
4 years ago
Philippe Antoine 862e84877f ssl: first pass limit when allocating buffer for certificates
With this check, on the first packet of a certificate presenting
a length of 16Mbytes, we only allocate up to 65Kb

When we get to the point where need more than 65Kb, we realloc
to the true size.

With this check, it makes it more expensive for an attacket to use
this allocation as a way to trigger ressource exhaustion...
4 years ago