Commit Graph

174 Commits (e250ef6402998eac36dfb46b6d91aca0e4d184b2)

Author SHA1 Message Date
Victor Julien e250ef6402 debug: remove empty header 3 years ago
Philippe Antoine 11f849c3ee protocol-change: sets event in case of failure
Protocol change can fail if one protocol change is already
occuring.

Ticket: #5509
3 years ago
Eric Leblond 954e3e1f3f smtp/mime: fix url extraction when no config is set 3 years ago
Philippe Antoine 02f2602dde src: rework includes as per cppclean 3 years ago
Victor Julien 6e2c066ce1 smtp: fix passing a wrong delim len around 3 years ago
Victor Julien a38f2f2a52 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.
3 years ago
Victor Julien 84448d3bae tests: remove unnecessary flow locks
Added once to satisfy debug validation, but we don't mix unittests
and debug validation anymore.

    sed -i -E '/.*FLOWLOCK_.*LOCK/d' *.c
3 years ago
Victor Julien 579547c849 smtp: minor line loop cleanup 3 years ago
Victor Julien 96bb67f474 smtp: remove defunct check for line with single LF
Don't fix it as DATA processing needs all the bytes.
3 years ago
Victor Julien a2924b7141 smtp: constify line arguments where possible 3 years ago
Victor Julien e0d5878e49 smtp: move current line out of state 3 years ago
Victor Julien 1451bd62a6 smtp: move input out of state 3 years ago
Victor Julien 77fae275ef smtp: turn assertions in to debug asserts 3 years ago
Victor Julien 3a631085bb smtp: simplify preprocess loop 3 years ago
Shivani Bhardwaj 1e3282f363 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
3 years ago
Victor Julien f9a5ceb0d8 smtp: minor code cleanup 3 years ago
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.
3 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.
3 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
3 years ago
Shivani Bhardwaj 57a7cf7a0b smtp: add truncated line event 3 years ago
Philippe Antoine 99b3443369 smtp: check if there is a transaction to close
Ticket: 4948

When parsing the response for starttls
4 years ago
Philippe Antoine ae6c416972 util/mime: fix integer warnings
Ticket: 4516
4 years ago
Philippe Antoine 4247605d87 smtp: check if we have a current transaction
Ticket: 4948

This is not the perfect solution, but it prevents to trigger
the assert, and keep the assert.
A better solution would need to create transaction from
the reponse parsing, in case a later command was buffered and
not answered. But this would not be enough as NoNewTx prevents
the creation of a new transaction for RSET...
4 years ago
Aaron Bungay a5d3a1f92c src: use bool instead of int 4 years ago
Aaron Bungay 272786908c smtp/mime: configurable url scheme extraction
Parse extract-url-schemes from the mime config.
e.g. 'extract-urls-schemes: [http, https, ftp, mailto]'
Update MimeDecConfig struct to new url extraction fields.
Change app-layer-smtp.c & util-decode-mime.c to initialize new struct
fields for MimeDecConfig.
Sets the default value for extract-url-schemes if not found in the
config to 'extract-urls-schemes: [http]' for backwards compatibility.

Uses the schemes defined in the mime config value for
extract-urls-schemes to search for URLS starting with those scheme
names followed by "://".
Logs the URLS with the scheme + '://' at the start if the
log-url-scheme is set in the mime config, otherwise the old behaviour
is reverted to and the urls are logged with the schemes stripped.

Removed unused constant URL_STR now that URLS are being searched for
using extract-urls-schemes mime config values instead of just URL's
starting with 'http://'.

Added commented out new options for extract-urls-schemes and
log-url-scheme to suricata.yaml.in.

Update FindUrlStrings comments.
Remove old outdated comments/commented code from FindUrlStrings.
Update test case for mime which now needs schemes list to be set.
Add Test Cases for FindUrlStrings() method.

Feature: #2054
4 years ago
Shivani Bhardwaj 8918f53f6b smtp: use AppLayerResult instead of buffering
Also, remove tests that check for the removed buffers and any middle
states while parsing and buffering.

Ticket 4907
4 years ago
Philippe Antoine 86ea7f2474 file: define own variable instead of PATH_MAX
to be used for maximum size of file names,
and not depend on the OS
4 years ago
Philippe Antoine 078e1cdacc smtp: fix int warnings
and explicitly truncating filename's length
4 years ago
Victor Julien c073d5cfbf app-layer: use StreamSlice as input to parsers
Remove input, input_len and flags in favor of stream slice.
4 years ago
Victor Julien 6466296b32 app-layer: add StreamSlice to pass data to parsers
Since object to contain relevant pointer, length, offset, flags to make
it easy to pass these to the parsers.
4 years ago
Jason Ish 7732efbec2 app-layer: include decoder events in app-layer tx data
As most parsers use an events structure we can include it in the
tx_data structure to reduce some boilerplate/housekeeping code
in app-layer parsers.
4 years ago
Jason Ish 9c67c634c1 app-layer: include DetectEngineState in AppLayerTxData
Every transaction has an existing mandatory field, tx_data. As
DetectEngineState is also mandatory, include it in tx_data.

This allows us to remove the boilerplate every app-layer has
for managing detect engine state.
4 years ago
Philippe Antoine f44bbbb9ad smtp: completes RSET transaction on last multiline
Bug: #4561.
4 years ago
Victor Julien 0867b0dbcd smtp: support per-tx file accounting 4 years ago
Shivani Bhardwaj 8fd47cb84c smtp: fix clang fmt 4 years ago
Philippe Antoine 33fa7ab596 smtp: null terminate before calling strtoul
by copying in a temporary buffer
as is done in ByteExtractString
4 years ago
Jeff Lucovsky 1eeb96696b general: Cleanup bool usage 4 years ago
Victor Julien efc9a7a398 app-layer: remove callback for completion status
Since the completion status was a constant for all parsers, remove the
callback logic and instead register the values themselves. This should
avoid a lot of unnecessary callback calls.

Update all parsers to take advantage of this.
5 years ago
Philippe Antoine 547d6c2d78 applayer: pass parameter to StateAlloc
This parameter is NULL or the pointer to the previous state
for the previous protocol in the case of a protocol change,
for instance from HTTP1 to HTTP2

This way, the new protocol can use the old protocol context.
For instance, HTTP2 mimicks the HTTP1 request, to have a HTTP2
transaction with both request and response
5 years ago
Victor Julien 4f73943df9 app-layer: split EOF flag per direction 5 years ago
Victor Julien bc11a1c23e smtp: support AppLayerTxData 5 years ago
Jeff Lucovsky beb45c564e detect/smtp: Refactor command check
This commit refactors the code that matches reply with command.

Bug: #3677
5 years ago
Jeff Lucovsky dc7a991bfb app-layer/smtp: Improve RSET handling
This commit improves how the parser handles the `RSET` command.
Termination of the transaction occurs when the `RSET` ack is seen (reply
code 250).

Bug: #3677
5 years ago
Victor Julien 44d3f264bf app-layer: update API to return more details
Add AppLayerResult struct as the Parser return type in
preparation of allowing returning 'Incomplete(size)' similar
to what nom in Rust allows.
6 years ago
Victor Julien 3bcf948a75 app-layer: change return codes
This patch simplifies the return codes app-layer parsers use,
in preparation of a patch set for overhauling the return type.

Introduce two macros:

APP_LAYER_OK (value 0)
APP_LAYER_ERROR (value -1)

Update all parsers to use this.
6 years ago
Jeff Lucovsky 9a33b5d5de smtp/mime: Fix typos 6 years ago
Jeff Lucovsky 130b8d26e7 smtp/mime: Set event when name exceeds limit 6 years ago
Victor Julien f302f3543f files: add call for setting inspect sizes
The inspect sizes are currently only used during file prune
house keeping for SMTP.
6 years ago
Victor Julien f9f958d66e smtp: fix and clean up new file handling
Set tx id on files that were just opened.

Move logic to a small util func.
6 years ago
Victor Julien 683b22d114 smtp: use FILE_USE_DETECT for raw-extract 6 years ago