Commit Graph

16556 Commits (9e9333b7d0ececa6d9d242ae51faaa9a5da7a5a2)
 

Author SHA1 Message Date
Philippe Antoine 9e9333b7d0 protodetect: use dynamic number of app-layer protos
for alproto_names

Ticket: 5053
2 months ago
Philippe Antoine 61657c8ec6 protodetect: use dynamic number of app-layer protos
for expectation_proto

Ticket: 5053
2 months ago
Philippe Antoine 6b7349dbc1 protodetect: make expectation_proto part of AppLayerProtoDetectCtx
instead of a global variable.

For easier initialization with dynamic number of protocols
2 months ago
Philippe Antoine 7750226e43 fuzz: use lower pcre limits
to avoid timeouts

instead of forbidding pcre signatures on stream

Ticket: 4858
2 months ago
Philippe Antoine 5cec270598 detect: move fields around to fill memory holes
to make scan-build happy avoiding its warning :

Excessive padding in 'struct DetectEngineThreadCtx_'
(33 padding bytes, where 1 is optimal)
2 months ago
Philippe Antoine b967fcaf8f stats: remove unused pseudo_failed stat 2 months ago
Philippe Antoine 954553f1ae src: remove unused struct fields
Even if they get defined
2 months ago
Victor Julien c56b741088 github-ci: update Fedora 39 jobs to 41 2 months ago
Philippe Antoine bdcb593738 detect: improve tx_id guessing for unidirectional protocols
So we get:
1. request arrives - buffered due to not ackd
2. response arrives, acks request - request is now parsed, response isn't
3. ack for response, response parsed. Then detect runs for request,
generates alert. We now have 2 txs. txid will be 0 from AppLayerParserGetTransactionInspectId

But txid 1 is unidirectional in the other way, so we can use txid 0
metadata for logging

Ticket: 7449
2 months ago
Philippe Antoine a499529477 doc: improve documentation about guess-applayer-tx
Ticket: 7199
2 months ago
Jeff Lucovsky 2d9df5a1ae flow/var: Release key storage
Issue: 7466

This commit releases the memory for the flow variable "key" when
the flow variable is of type string. The key is allocated in the Lua
extension logic.
2 months ago
dependabot[bot] def22fab6c github-actions: bump actions/upload-artifact from 4.4.3 to 4.5.0
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.4.3 to 4.5.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](b4b15b8c7c...6f51ac03b9)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2 months ago
dependabot[bot] e16f29e459 github-actions: bump github/codeql-action from 3.27.5 to 3.28.0
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.5 to 3.28.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Commits](https://github.com/github/codeql-action/compare/v3.27.5...v3.28.0)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2 months ago
dependabot[bot] 8e4b18f4e4 github-actions: bump codecov/codecov-action from 5.0.7 to 5.1.2
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.0.7 to 5.1.2.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](015f24e681...1e68e06f1d)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2 months ago
Jeff Lucovsky d853972c74 output/log: Remove extraneous error message
Issue: 7447

When the output file can't be opened, 2 error messages are displayed
for the same problem. The second message doesn't add value and lacks
context (error reason, e.g., "Permission denied").

Retaining the second message as a debug message.

Without this commit:

Error: logopenfile: Error opening file: "/home/jlucovsky/src/jal/suricata-verify/tests/bug-5198/output/noperms/eve.1.json": Permission denied [SCLogOpenFileFp:util-logopenfile.c:428]
Error: logopenfile: Unable to open slot 1 for file /home/jlucovsky/src/jal/suricata-verify/tests/bug-5198/output/noperms/eve.json [LogFileEnsureExists:util-logopenfile.c:737]
Error: runmodes: unable to initialize sub-module eve-log.stats [RunModeInitializeEveOutput:runmodes.c:692]

With commit:

Error: logopenfile: Error opening file: "/home/jlucovsky/src/jal/suricata-verify/tests/bug-5198/output/noperms/eve.1.json": Permission denied [SCLogOpenFileFp:util-logopenfile.c:428]
Error: runmodes: unable to initialize sub-module eve-log.stats [RunModeInitializeEveOutput:runmodes.c:692]
2 months ago
Jeff Lucovsky e72fc39f83 output/log: Improve error handling
This commit improves error handling for cases when file(s) cannot be
opened.
- Return NULL if file object can't be opened
- checks whether the file object has been opened before
  dereferencing the per-file context.

Issue: 7447
2 months ago
Shivani Bhardwaj 6f937c7545 doc: add guide for ticket title
Explain with examples what a good ticket title looks like and
why is it important to have ticket titles convey the correct issues.
2 months ago
Philippe Antoine b0282f49af http2: complete json schema
git grep js.set_string rust/src/http2/logger.rs | grep '"' |
cut -d'"' -f2 | sort | uniq | while read i;
do echo -n $i; git grep $i etc/schema.json | wc -l; done

shows only has_multiple was missing
2 months ago
Philippe Antoine fd7e2e5e9a doh2: really enforce 65K dns message limit
Ticket: #7464
2 months ago
Jason Ish 604e3c7422 rust/jsonbuilder: make set_uint generic over Into<u64>
Allow `set_uint` to accept any number value that can be converted to a
u64. Prevents callers from having to do `as u64`.

This required fixing up any callers that used `.into()` to just pass in
their value without the into conversion.

Most calls using `as u64` can have that cast removed, with the exception
of `usize` values which must still be cast is conversion can't be
guaranteed to be non-fallible.
2 months ago
Philippe Antoine 146314b0c5 ci: run CodeQL only on python changes
Ticket: 7358
2 months ago
Jeff Lucovsky 91d5b77316 doc/commit
Describe how to use the git commit template. The template helps ensure
that the information needed for evaluation and context is included in
the commit message.

Ticket: <Redmine ticket number>
2 months ago
Jeff Lucovsky 1b88f2189e git: Add commit template
Issue: none

This commit adds a template that identifies commit message elements that
we find important. The Suricata development team requests that
contributions use the template to help improve commit messages. We
reserve the right to strictly enforce adherence to the template in the
future.

Configure git to use this template with:
    git config commit.template ..github/commit-template.txt
2 months ago
Philippe Antoine 5da2b5d7a4 dns/probe: check that a request has at least one query
Ticket: 7279
2 months ago
Philippe Antoine 9b40446bea dns/probe: adds check for 0 records and big size
Ticket: 7279

Make dns probing function stricter to avoid matching on non-DNS
on port 53 and later returning a app-layer error.
2 months ago
Shivani Bhardwaj 2c0d3b83c4 dns: fix clippy lint warnings
Fix vector lint issues:
- same_item_push
- vec_init_then_push
3 months ago
Jeff Lucovsky 89c9cec0bb general/typo: Fix typo in stacksize msg 3 months ago
Victor Julien d11e8a8ee7 doc/userguide: document TCP urgent policy 3 months ago
Victor Julien 779f9d8ba3 eve/flow: add per flow TCP oob urg data counter
If TCP urgent handling is set to the OOB processing, the number of OOB
bytes is tracked for SEQ offset calculations. If this offset is
non-zero, add the field to the flow record.

Ticket: #7411.
3 months ago
Victor Julien 6882bcb3e5 stream: add TCP urgent handling options
TCP urgent handling is a complex topic due to conflicting RFCs and
implementations.

Until now the URG flag and urgent pointer values were simply ignored,
leading to an effective "inline" processing of urgent data. Many
implementations however, do not default to this behavior.

Many actual implementations use the urgent mechanism to send 1 byte of
data out of band to the application.

Complicating the matter is that the way the urgent logic is handled is
generally configurable both of the OS and the app level. So from the
network it is impossible to know with confidence what the settings are.

This patch adds the following policies:

`stream.reassembly.urgent.policy`:

- drop: drop URG packets before they affect the stream engine

- inline: ignore the urgent pointer and process all data inline

- oob (out of band): treat the last byte as out of band

- gap: skip the last byte, but do no adjust sequence offsets, leading to
       gaps in the data

For the `oob` option, tracking of a sequence number offset is required,
as the OOB data does "consume" sequence number space. This is limited to
64k. For this reason, there is a second policy:

`stream.reassembly.urgent.oob-limit-policy`:

- drop: drop URG packets before they affect the stream engine

- inline: ignore the urgent pointer and process all data inline

- gap: skip the last byte, but do no adjust sequence offsets, leading to
       gaps in the data

Bug: #7411.
3 months ago
Victor Julien 4c1554f4f6 stream: remove unused function argument
Sequence number is taken from seg, not the func arg.
3 months ago
Victor Julien ac02a71479 decode/tcp: count urg flag 3 months ago
Victor Julien d1b0d00478 flow/timeout: add frame awareness
If there are still frames in the flow, the detection and logging logic
needs to be able to evaluate them. To do this, make the flow timeout
logic aware of the frames. If frames still exist in a direction, trigger
a FFR packet to be created.

Ticket: #7440.
3 months ago
Victor Julien 0de9eee04d eve/frame: require frame length to be known
Or reach logging threshold.

Avoids logging too early.

Ticket: #7440.
3 months ago
Victor Julien 95ac92f9aa eve/frame: run logging for flow end packets
If there are frames in the flow the flow manager will create flow
timeout packets to log the remaining frames. This requires the logger to
run for those flow timeout packets.

Ticket: #7440.
3 months ago
Victor Julien db589765e4 eve/frame: remove unreachable if branch 3 months ago
Jason Ish 19cf0f8133 dns: provide events for recoverable parse errors
Add events for the following resource name parsing issues:

- name truncated as its too long
- maximum number of labels reached
- infinite loop

Currently these events are only registered when encountered, but
recoverable. That is where we are able to return some of the name,
usually in a truncated state.

As name parsing has many code paths, we pass in a pointer to a flag
field that can be updated by the name parser, this is done in
addition to the flags being set on a specific name as when logging we
want to designate which fields are truncated, etc. But for alerts, we
just care that something happened during the parse. It also reduces
errors as it won't be forgotten to check for the flags and set the
event if some new parser is written that also parses names.

Ticket: #7280
3 months ago
Jason Ish 37f4c52b22 eve/dns: add truncation flags for fields that are truncated
If rrname, rdata or mname are truncated, set a flag field like
'rrname_truncated: true' to indicate that the name is truncated.

Ticket: #7280
3 months ago
Jason Ish 3a5671739f dns: truncate names larger than 1025 characters
Once a name has gone over 1025 chars it will be truncated to 1025
chars and no more labels will be added to it, however the name will
continue to be parsed up to the label limit in attempt to find the end
so parsing can continue.

This introduces a new struct, DNSName which contains the name and any
flags which indicate any name parsing errors which should not error
out parsing the complete message, for example, infinite recursion
after some labels are parsed can continue, or truncation of name where
compression was used so we know the start of the next data to be
parsed.

This limits the logged DNS messages from being over our maximum size
of 10Mb in the case of really long names.

Ticket: #7280
3 months ago
Philippe Antoine 9a53ec43b1 util/streaming-buffer: add extra safety check
Ticket: 7393

Check if GrowRegionToSize is called with an argument
trying to shrink the region size, and if so do nothing,
ie do not try to shrink, and just return ok.

This way, we avoid a buffer overflow from memeset using an
unsigned having underflowed.
3 months ago
Philippe Antoine 8900041405 util/streaming-buffer: check need to grow region
Ticket: 7393

As it was possible before earlier patches to get here
with mem_size lesser than start->buf_size,
which caused then an unsigned underflow and a buffer overflow.
3 months ago
Philippe Antoine 282509f70c util/streaming-buffer: fix regions intersection
This was not a problem for current callers in Suricata,
as RegionsIntersect is only called through StreamingBufferInsertAt
which is only used by TCP...

And TCP uses default region gap = 256kb, and only calls
StreamingBufferInsertAt with a u16, so TCP never inserts a new
data that will strictly contain an existing region augmented
with region gap, which was the only case where RegionsIntersect
returned the wrong result, which could later lead to a
buffer overflow.

Ticket: 7393
3 months ago
Victor Julien 0e4faba79a detect: don't run pkt sigs on ffr pkts
Last packet from the TLS TCP session moves TCP state to CLOSED.

This flags the app-layer with APP_LAYER_PARSER_EOF_TS or
APP_LAYER_PARSER_EOF_TC depending on the direction of the final packet.
This flag will just have been set in a single direction.

This leads to the last packet updating the inspect id in that packets
direction.

At the end of the TLS session a pseudo packet is created, because:
 - flow has ended
 - inspected tx id == 0, for at least one direction
 - total txs is 1

Then a packet rule matches:

```
alert tcp any any -> any 443 (flow: to_server;                  \
        flowbits:isset,tls_error;                               \
        sid:09901033; rev:1;                                    \
        msg:"Allow TLS error handling (outgoing packet)"; )
```

The `SIG_MASK_REQUIRE_REAL_PKT` is not preventing the match, as the
`flowbits` keyword doesn't set it.

To avoid this match. This patch skips signatures of the `SIG_TYPE_PKT`
for flow end packets.

Ticket: #7318.
3 months ago
Philippe Antoine f426ee3ee2 detect: rename stream_log variables
to better reflect their true meaning
3 months ago
Philippe Antoine f2c3776314 detect: log app-layer metadata in alert with single tx
Ticket: 7199

Uses a config parameter detect.guess-applayer-tx to enable
this behavior (off by default)

This feature is requested for use cases with signatures not
using app-layer keywords but still targetting application
layer transactions, such as pass/drop rule combination,
or lua usage.

This overrides the previous behavior of checking if the signature
has a content match, by checking if there is only one live
transaction, in addition to the config parameter being set.
3 months ago
Lukas Sismis 18ab9a6ccd dpdk: set ice PMD RSS key length to 52 bytes for all DPDK versions
ICE driver (Intel E810 NIC) requires/supports 52-byte long RSS key.
The 52 byte key length was mandatory from DPDK 23.11 when Suricata
was starting with independently configured ice PMD.

However, Suricata failed to start when ice PMD was part of
net_bonding PMD, requiring 52 byte RSS key even in DPDK versions
lower than 23.11. Since the support for the longer key is present
since DPDK 19.11 the key is set to 52 bytes for all versions.

Ticket: 7444
3 months ago
Philippe Antoine b02557ac7d app-layer: track modified/processed txs
To optimize detection, and logging, to avoid going through
all the live transactions when only a few were modified.

Two boolean fields are added to the tx data: updated_tc and ts
The app-layer parsers are now responsible to set these when
needed, and the logging and detection uses them to skip
transactions that were not updated.

There may some more optimization remaining by when we set
both updated_tc and updated_ts in functions returning
a mutable transaction, by checking if all the callers
are called in one direction only (request or response)

Ticket: 7087
3 months ago
Philippe Antoine e62c7d733b rust/ftp: handle NULL inputs
Completes Ticket 7013
3 months ago
Philippe Antoine 38d7900fa9 sip: remove UPDATE method for detection
As it is also used for HTTP/1
Remove it only for TCP and keep it for UDP.

Ticket: 7436
3 months ago
Philippe Antoine e5b98be41f fuzz: simplify target for protocol detection
As too many cases are found when splitting tcp payload
3 months ago