]> git.ipfire.org Git - people/ms/suricata.git/commit - src/app-layer-dnp3.c
proto-detect: improve midstream support
authorVictor Julien <victor@inliniac.net>
Thu, 21 Mar 2019 12:57:50 +0000 (13:57 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 27 Mar 2019 10:12:13 +0000 (11:12 +0100)
commit422e4892cc724e2ec064a5672030220cbdcd5406
treef2d7e20670bf0ad8cdca2edfe3b60706a9ed4623
parentc0ab45aa6fbe1a299facf45e34ba2bcb3d76ce75
proto-detect: improve midstream support

When Suricata picks up a flow it assumes the first packet is
toserver. In a perfect world without packet loss and where all
sessions neatly start after Suricata itself started, this would be
true. However, in reality we have to account for packet loss and
Suricata starting to get packets for flows already active be for
Suricata is (re)started.

The protocol records on the wire would often be able to tell us more
though. For example in SMB1 and SMB2 records there is a flag that
indicates whether the record is a request or a response. This patch
is enabling the procotol detection engine to utilize this information
to 'reverse' the flow.

There are three ways in which this is supported in this patch:

1. patterns for detection are registered per direction. If the proto
   was not recognized in the traffic direction, and midstream is
   enabled, the pattern set for the opposing direction is also
   evaluated. If that matches, the flow is considered to be in the
   wrong direction and is reversed.

2. probing parsers now have a way to feed back their understanding
   of the flow direction. They are now passed the direction as
   Suricata sees the traffic when calling the probing parsers. The
   parser can then see if its own observation matches that, and
   pass back it's own view to the caller.

3. a new pattern + probing parser set up: probing parsers can now
   be registered with a pattern, so that when the pattern matches
   the probing parser is called as well. The probing parser can
   then provide the protocol detection engine with the direction
   of the traffic.

The process of reversing takes a multi step approach as well:

a. reverse the current packets direction
b. reverse most of the flows direction sensitive flags
c. tag the flow as 'reversed'. This is because the 5 tuple is
   *not* reversed, since it is immutable after the flows creation.

Most of the currently registered parsers benefit already:

- HTTP/SMTP/FTP/TLS patterns are registered per direction already
  so they will benefit from the pattern midstream logic in (1)
  above.

- the Rust based SMB parser uses a mix of pattern + probing parser
  as described in (3) above.

- the NFS detection is purely done by probing parser and is updated
  to consider the direction in that parser.

Other protocols, such as DNS, are still to do.

Ticket: #2572
27 files changed:
rust/src/applayertemplate/template.rs
rust/src/dhcp/dhcp.rs
rust/src/ikev2/ikev2.rs
rust/src/krb/krb5.rs
rust/src/nfs/nfs.rs
rust/src/ntp/ntp.rs
rust/src/parser.rs
rust/src/smb/smb.rs
rust/src/smb/smb2_records.rs
src/app-layer-detect-proto.c
src/app-layer-detect-proto.h
src/app-layer-dnp3.c
src/app-layer-dns-tcp-rust.c
src/app-layer-dns-tcp.c
src/app-layer-dns-udp-rust.c
src/app-layer-dns-udp.c
src/app-layer-enip.c
src/app-layer-modbus.c
src/app-layer-nfs-tcp.c
src/app-layer-nfs-udp.c
src/app-layer-protos.h
src/app-layer-smb-tcp-rust.c
src/app-layer-smb.c
src/app-layer-ssl.c
src/app-layer-template.c
src/app-layer-tftp.c
src/app-layer.c