Commit Graph

18356 Commits (b800ace56fb08c29aadb0f68a3bad1fe3e4a0d67)
 

Author SHA1 Message Date
Jason Ish 1281bc0309 ftp: mark ftp.reply_received as firewall supported
Ticket: #8392
(cherry picked from commit 974241aa50)
2 months ago
Jason Ish 0e650766b5 ftp: support STOU data transfers
Support STOU on the FTP data channel.

With STOU a filename is optional. If no filname is provided, use
"<stou>". The server does respond with the filename to use, but there
can be a race condition in getting this filename and setting up file
storage before data starts flowing.

Ticket: #8664
(cherry picked from commit f59960d42b)
2 months ago
Jason Ish c729bddc1e ftp: support APPE data transfers
Support the APPE (append) command on the ftp data channel. Like STOR,
APPE uploads file content on the data channel.

Ticket: #8664
(cherry picked from commit e65bf4c905)
2 months ago
Jason Ish c95c99b83b ftp: support LIST and MLSD data channels
Support LIST and MLSD on the ftp data channel.

Ticket: #8664
(cherry picked from commit 5856ced29c)
2 months ago
Jason Ish 0dc49ab65e ftp: register ftp.mode at response_complete
Also mark as supported by the firewall.

Ticket: #8392
(cherry picked from commit be94ab952a)
2 months ago
Jason Ish d1da9701a2 ftp: register ftp.completion_code at response_complete
Ticket: #8392
(cherry picked from commit fc1546e25e)
2 months ago
Jason Ish 032a81c5fb ftp: support nlst on the data channel
Ticket: #8664
(cherry picked from commit 1b289daea3)
2 months ago
Jason Ish 9893bf5374 ftp: mark ftpdata_command as firewall supported
(cherry picked from commit 6bc2969b8d)
2 months ago
Jason Ish 9146d472a9 ftp: mark ftp.dynamic_port as firewall supported
Ticket: #8392
(cherry picked from commit f93268e531)
2 months ago
Jason Ish 9ad221d25a ftp: register ftp.dynamic_port at response completion
Register ftp.dynamic_port at the FTP transaction completion progress
instead of progress 0. This allows ftp.dynamic_port to be used in
ftp:response_complete.

Ticket: #8392
(cherry picked from commit 41cad78506)
2 months ago
Jason Ish e9e491dc7b ftp: mark ftp.command as firewall supported
Ticket: #8392
(cherry picked from commit 0d566f90ce)
2 months ago
Jason Ish f1845f015f ftp: register ftp.command_data at request completion
Register ftp.command_data with the FTP request completion progress so it
can be used by firewall rules on the ftp:request_complete hook.

Ticket: #8392
(cherry picked from commit a6ce31d50d)
2 months ago
Jason Ish 90aef2d689 ftp: register ftp.command buffer at request completion
Register ftp.command with the FTP request completion progress so it can
be used by firewall rules on the ftp:request_complete hook.

Ticket: #8392
(cherry picked from commit bf63c574d3)
2 months ago
Jason Ish 8cdff89fe3 psl: update to latest version
Ticket: #8535
2 months ago
Philippe Antoine feb0ff9115 ftp: do not error the flow on file before port
Ticket: 8659

If a client sends a SOTR/RETR command before doing a PASV/PORT
command, ther server may reply
425 Use PORT or PASV first.\r\n
and allow the client to continue sendinf other commands

So, Suricata should not put the whole flow into error, it just
sets an event, and continues to parse further

(cherry picked from commit 52490b8c26)
2 months ago
Philippe Antoine b63224871b swf: prevents overflow with bad config value
Ticket: 8642

Do not allocate too much by using the config value, when the flash
file does not require that much data anyways

(cherry picked from commit d9fae18432)
2 months ago
Jeff Lucovsky ef035c7603 rdp: mark transactions single-directional
Mark the direction into RDP transactions at creation time,
so the tx carries SKIP_INSPECT for the direction it is
never seen in, matching DHCP and the other single-direction
parsers. This lets cleanup free completed transactions and
stops a tx from being inspected (and alerting) twice, once per
direction.

RDP bounds its transactions to connection setup and stops
parsing once bypass_parsing is set.

Issue: 8621
(cherry picked from commit 5af13e3eb0)
3 months ago
Jeff Lucovsky bac8a69ca4 dhcp: mark transactions single-directional to fix tx leak
DHCP is a stateless parser where each datagram is its own standalone,
single-direction transaction. It was creating transactions with
AppLayerTxData::new(), which leaves both SKIP_INSPECT bits clear, so the
engine treats every tx as still needing inspection in both directions.

For a flow that only ever carries one direction (broadcast DHCP, or a
relay seeing one side), the never-observed direction's inspect bit can
never be set, so AppLayerParserTransactionsCleanup() never frees the tx.
The per-flow transaction Vec then grows without bound and every packet
re-scans the whole list, giving O(n^2) CPU and unbounded memory on a
busy DHCP aggregation point.

Use AppLayerTxData::for_direction() like every other stateless parser
(DNS, SNMP, NTP, IKE, KRB5, MQTT, QUIC, SIP, WebSocket, bittorrent-dht)
so the tx carries SKIP_INSPECT for the direction it will never be seen
in. This lets cleanup free completed transactions and also stops the tx
from being inspected (and alerting) twice, once per direction.

Issue: 8621
(cherry picked from commit 3f86c56c80)
3 months ago
Jeff Lucovsky f234d155bc detect: revert 3adadde
Revert issue 8619 fix in favor of a more general change that
sets INSPECTED_T{S,C} correctly on passed flows. This makes clean no
longer need the FLOW_ACTION_PASS special case to free those
transactions.

Issue: 8621
(cherry picked from commit 30d4edf9eb)
3 months ago
Jeff Lucovsky 60a83c62a1 app-layer: fix inverted tx inspected flag check
Issue: 8628

AppLayerParserSetTransactionInspectId() had an inverted guard when
tagging completed transactions as inspected: it set the INSPECTED flag
only on txs that already had it, so a finished tx was never newly
marked.

On a normal flow DetectRunTx() sets the same flag and masks the
mistake. On a passed flow -- a `pass` rule or a pass-the-flow exception
policy -- detection is skipped and this function is the only thing that
marks txs inspected. With the inverted guard the transactions are never
flagged, AppLayerParserTransactionsCleanup() never frees them, and the
per-flow transaction list grows without bound while each packet
re-scans it, giving O(n^2) cleanup cost.

This is an unintended regression from 834378ff88.

(cherry picked from commit 006e21c1cc)
3 months ago
Jason Ish f2ef8e0805 ftpdata: ignore direction in ftpdata_command
The ftpdata_command would never match a RETR in the to_server direction,
or a STOR in the to_client direction, this effectively makes the
ftpdata_command applicable to passive mode only.

Instead, remove the directionality on the ftpdata_command. Its "meta"
information passed from the control channel and isn't really
directional. I think the idea was to abstract away active/passive from
the rule writer, but unfortunately doesn't allow the ftpdata_command
keyword to work in the more strict firewll mode.

Ticket: #8663
(cherry picked from commit 2fe4bb2872)
3 months ago
Jason Ish dace9ecc45 ftp: skip ts inspection on tc only transactions
In FTP, the first transaction is a banner from the server. Skip TS
inspection on this transaction.

Allows firewall mode to get past this transaction and onto the next.

Ticket: #8662
(cherry picked from commit d346e469c5)
3 months ago
Philippe Antoine bd3293aca7 detect/datajson: check json objects are string as expected
Ticket: 8624
(cherry picked from commit 3ca2ed25a3)
3 months ago
Samaresh Kumar Singh 6bcf958e20 pcap-file: skip setvbuf on non-seekable streams
Reading a pcap from /dev/stdin or a named pipe currently fails with "failed to get first packet timestamp. pcap_next_ex(): -1" because InitPcapFile calls setvbuf on the FILE* underlying the pcap handle after libpcap has already consumed the pcap header. On a non-seekable fd glibc cannot recover from that and the next read returns -1.

Detect non-regular files via fstat and skip setvbuf in that case so the read keeps working on pipes, fifos and stdin.

Accept pcap-file.buffer-size values of 0, which disables setvbuf buffering as an explicit opt-out, or PCAP_FILE_BUFFER_SIZE_MIN (4 KiB) to PCAP_FILE_BUFFER_SIZE_MAX (64 MiB). Treat any non-zero setvbuf return value as an error, not just negative values.

When pcap-file.buffer-size fails to parse, retain the default buffer size instead of falling through and setting it to 0. The branches are now mutually exclusive so only one of the parse-error, accepted, or out-of-range messages is logged.

Update the user guide: --pcap-file-buffer-size now documents valid values of 0 (disables setvbuf buffering) or 4 KiB to 64 MiB, and pcap-file.rst notes that 0 is the opt-out for non-seekable sources such as stdin and named pipes.
Bug: #8464.

(cherry picked from commit 565e138754)
3 months ago
Philippe Antoine f45b8f7748 fuzz: forbid usage of pcre with \X
Ticket: 8634
(cherry picked from commit 097975e289)
3 months ago
Philippe Antoine 2b924d47cc windows: always quote path for windows functions needing it
Ticket: 8600

CreateServiceA doc states for example :

> If the path contains a space, it must be quoted so that it is
  correctly interpreted.

Also fixes strlcat usage and check return value to error out on
truncated path

(cherry picked from commit ac1b3cc1ef)
3 months ago
Victor Julien 5560c7efc4 Revert "af-packet: speed up thread sync during startup"
This reverts commit 923ad6af77.

Several issues have been reported:

1. non-deterministic thread to queue mapping (privately reported)

2. race condition causing IPS mode to loose packets, or get stuck
   completely, ticket 8667.

Ticket: #8667.
(cherry picked from commit 2b19f86ee6)
3 months ago
Shivani Bhardwaj 36fb9ae59a flowbits: add deprecation notice for toggle command
Task 8638
3 months ago
Philippe Antoine 078ab2ff70 conf: uses SCConfGetNonNull
Ticke: 8651

Uses it in place when we dereferenced the value straight away
after checking SCConfGet result but not its value

(cherry picked from commit 6bb271cee9)
3 months ago
Philippe Antoine 819299852c conf: introduce SCConfGetNonNull
Ticket: 8651

Behaves like SCConfGet but returns 0 on null value

(cherry picked from commit a9e1dff4a6)
3 months ago
Andreas Dolp 3e4bc398ae doc: improve manpage of suricatasc
- describe all options
- describe optional socket path

Redmine ticket: #8563

(cherry picked from commit 2f972b6759)
3 months ago
Victor Julien 2d17c31e48 decode/vlan: implement max layers for IEEE8021ah
Ticket: #8615.
(cherry picked from commit b11aa94d42)
3 months ago
Victor Julien 94a82f83ff defrag: decrement memuse on alloc failure
Ticket: #8613.
(cherry picked from commit 377462ea63)
3 months ago
Shivani Bhardwaj 69c777d617 rust: exclude DETECT_BYTEMATH_ENDIAN_DEFAULT from bindings
to deal with the failure due to cbindgen updates and mismatches in
generated bindings.

detect-bytemath.c:61: error: "DETECT_BYTEMATH_ENDIAN_DEFAULT" redefined [-Werror]
   61 | #define DETECT_BYTEMATH_ENDIAN_DEFAULT (uint8_t) BigEndian
      |
In file included from rust.h:34,
                 from detect-bytemath.c:32:
./../rust/gen/rust-bindings.h:5071: note: this is the location of the previous definition
 5071 | #define DETECT_BYTEMATH_ENDIAN_DEFAULT BigEndian
      |

(cherry picked from commit 0345b91ddd)
3 months ago
dependabot[bot] aedc0edec0 github-actions: bump codecov/codecov-action from 6.0.1 to 7.0.0
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 6.0.1 to 7.0.0.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](e79a6962e0...fb8b3582c8)

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

Signed-off-by: dependabot[bot] <support@github.com>
(cherry picked from commit 39688a6252)

Cherry-pick note:
- old version wasn't actually 6.0.1
3 months ago
Victor Julien 46b98c97d2 detect/firewall: support hook LTE mode for built-in hooks
LTE support depended on registered hook names, but did not support the
built-in names. This commit adds the support.

Ticket: #8645.
(cherry picked from commit d154484cc6)
3 months ago
Victor Julien fd51eb2b83 detect: add helper for getting hook name
To fetch hook name from app-layer, or use built-ins.

(cherry picked from commit b02fa53134)
3 months ago
Victor Julien 0ea62b4943 detect: propagate inspect engine setup failures
(cherry picked from commit 569d27e153)
3 months ago
Victor Julien fe14bc8d37 detect: don't register unrelated inspect engines
For rules that specify an explicit app-layer hook,
e.g. http1:request_headers, don't register inspect engines for
other protocols like HTTP/2. These have their own progress tracking,
so should be excluded from these rules.

(cherry picked from commit d64954a873)
3 months ago
Victor Julien 892360565b github-ci: add --enable-qa-simulation to debug validation job 3 months ago
Juliana Fajardini a90ef60210 qa/live: update tests for fw stats counters
Part of
Ticket #7699

(cherry picked from commit 040369ed1a)
3 months ago
Victor Julien 1c4a1a2413 qa: add rule reload step to firewall test
Additionally, use bsize, pcre and urilen.

Ticket: #8204.
Ticket: #8397.
(cherry picked from commit 7ac32910c9)
3 months ago
Victor Julien ae3655f87d mpm/hs: fix compile warnings
CC       util-mpm-hs-cache.o
util-mpm-hs-cache.c:301:59: error: implicit conversion loses integer precision: '__size_t' (aka 'unsigned long') to 'uint32_t'
      (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
  301 |         SCSha256Update(hasher, (const uint8_t *)ref_info, strlen(ref_info));
      |         ~~~~~~~~~~~~~~                                    ^~~~~~~~~~~~~~~~
util-mpm-hs-cache.c:310:46: error: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'uint32_t'
      (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
  310 |     if (!SCSha256FinalizeToHex(hasher, hash, hash_len)) {
      |          ~~~~~~~~~~~~~~~~~~~~~               ^~~~~~~~
2 errors generated.

(cherry picked from commit 736f50600f)
3 months ago
Victor Julien 497a69c5a8 clang-format: support clang 17
Update Github CI runner to use it.

Bump to Ubuntu 24.04 as well.

(cherry picked from commit 781bd5184e)
3 months ago
Victor Julien c1dbdaddf2 detect: cleanup last tx logic
Move into DetectTransaction.

(cherry picked from commit e0b501a4b7)
3 months ago
Victor Julien eddff49ebc detect: make progress values uint8_t
Also reflect that it can be >= 48, like in prefilter.

(cherry picked from commit 3d00e73d91)
3 months ago
Victor Julien 28f1b6b15f detect/firewall: minor code cleanup
(cherry picked from commit a9b3ad49ea)
3 months ago
Victor Julien 4a75eb9d4d detect/firewall: clean up apply accept logic
Use end state from tx.

Handle flow control from inside the function consistently.

(cherry picked from commit 4db84cfa28)
3 months ago
Victor Julien af8e861a2a detect/firewall: refactor per tx rule result handling
Break out the 3 options: match, partial match, no match for firewall
into separate functions.

Additionally, handle the re-match case for matches on a hook where the
progress value didn't yet progress further. In this case the continue
inspection logic revisits the rule and the accept needs to be
re-applied.

(cherry picked from commit 68885e75e1)
3 months ago
Victor Julien d095860fa1 detect/firewall: further simplify flow control
For the last for progress case we can just break on a firewall drop.

For the accept:flow and accept:tx cases the next sig (if any) will check
the flow/tx flag and manage flow control from there.

(cherry picked from commit 9c76480ac3)
3 months ago