Commit Graph

741 Commits (809aebfee183c680ae14e4d58316e477fad0dca0)

Author SHA1 Message Date
Victor Julien 20b379d92a smb: fix read queue exceeded event and rules 4 years ago
Victor Julien 788d8abea3 smb: log max read/write sizes
(cherry picked from commit 90d4b8e438)
4 years ago
Victor Julien 65f24b2e84 smb2: validate negotiate read/write max sizes
Raise event if they exceed the configured limit.

(cherry picked from commit fc9b65d8d3)
4 years ago
Victor Julien 8510031e6c smb2: allow limiting in-flight data size/cnt
Allow limiting in-flight out or order data chunks per size or count.

Implemented for read and writes separately:

app-layer.protocols.smb.max-write-queue-size
app-layer.protocols.smb.max-write-queue-cnt
app-layer.protocols.smb.max-read-queue-size
app-layer.protocols.smb.max-read-queue-cnt

(cherry picked from commit 4be8334c9e)
4 years ago
Victor Julien 5b38b97181 filetracker: track total queued data (in_flight)
As well as expose number of chunks.

(cherry picked from commit 2c5ad8858e)
4 years ago
Victor Julien 502db40240 smb2: add options for max read/write size
Add options for the max read/write size accepted by the parser.

(cherry picked from commit 5bcc4162f7)
4 years ago
Victor Julien 9f969e2545 smb2: track max read/write size and enforce its values
(cherry picked from commit f28888513a)
4 years ago
Victor Julien 2ba9ad53eb smb: minor function cleanup
Remove used argument from `filetracker_newchunk()`. We're not
using fill_bytes with smb.

(cherry picked from commit 594acec5dc)
4 years ago
Victor Julien 02c3bd00fa filetracker: make FileChunk private
(cherry picked from commit c7a474c725)
4 years ago
Philippe Antoine f3a6d15034 mqtt: fix consumed bytes computation for truncated msg
Ticket: 5268
(cherry picked from commit 3b13008c1b)
4 years ago
Sascha Steinbiss 084b16a63b mqtt: raise event on parse error 4 years ago
Jason Ish 4c2d543022 mqtt: ensure we do not request extra data after buffering
This is a minimal backport of 5618273ef4
to address ticket 5018.

Uses the "complete" version of take instead of the macro which is thre
streaming variant.

Ticket #5018
4 years ago
Jason Ish e55fef32d9 smb: handle records in the wrong direction
If an SMB record is seen in the wrong direction, set an event on the PDU
frame and don't process the record in the state.

No error is returned, so the next record will be processed.

(cherry picked from commit 2341f47755)
4 years ago
Jason Ish e63795543f smb: expose smb1 request/reply flags with a method
Adds `.is_request()` and `.is_reply()` to check if a SMB record flags
say the message is a request or a reply.

(cherry picked from commit 09e2d3b216)
4 years ago
Jason Ish 12a8415326 smb: fix smb2 header flag parsing
The bits were being parsed in the order they're displayed in Wireshark,
rather than the order they were being seen on the wire, resulting in
direction and async being 0 more often than they should be.

Instead of bits, take the 4 bytes as an le_u32 and just use bit masks to
extract what we need into a struct, I think its easier to reason about
this way when comparing to the Microsoft documentation.

(cherry picked from commit 7b659489c8)
4 years ago
Victor Julien ce69f79f6a smb1: apply close to direction
Instead of closing files in both direction when receiving a close request,
close only toserver files for the request and close toclient on receiving
a response.

(cherry picked from commit b336882008)
5 years ago
Victor Julien 2075038390 nfs: clean up partial record handling
There should be no remaining data after parsing the partial
RPC record, so don't handle it but instead add a debug validation
bug on.

Successful processing for NFSv3 read/write records returns
AppLayerResult::ok() directly as all data is consumed.

(cherry picked from commit 07b1100713)
5 years ago
Victor Julien fb8f4ef849 nfs3: improve read validation; fix partial handling
(cherry picked from commit d85b77cad0)
5 years ago
Victor Julien 29468e60f5 nfs3: fix partial write record handling
Comment from Jason Ish: This was a bit more than a cherry pick as some
of the modifications weren't directly portable to the nom macros. So
instead bring in some of the nom function based parsers as they work
fine with nom 5.

(cherry picked from commit 4418fc1b02)
5 years ago
Victor Julien 8c09ba0508 nfs3: enforce more values
Enforce values of a number of u32's that are used as bools or for
really low values.

(cherry picked from commit 5baf94e40d)
5 years ago
Victor Julien 5bb752e65a rpc: enforce various field values
Minimal frag_len. Correct msgtype and others.

(cherry picked from commit 1c57e3c18d)
5 years ago
Victor Julien 98773d0985 nfs/rpc: update full record parsers to be more exact
Instead of 'take'ing all data for the RPC prog_data and then
letting the higher level parsers figure out which part to use
take the exact amount.

Comments from Shivani Bhardwaj: This is was more than a cherry pick and
some of the modifications were not directly portable to the nom macros.
So, parsers were changed to make sure the functionality remained same while
making the transition to nom5 while keeping the diff minimal.

(cherry picked from commit 64d8a1e16e)
5 years ago
Victor Julien 12beed09ae nfs: break out partial record handling
(cherry picked from commit bfb5ae867e)
5 years ago
Victor Julien 353bfd6d0a nfs/rpc: enforce length field limits
Limits based on the Linux kernel limits. Then multiplied a few times
to allow for other implementations to have higher limits.

(cherry picked from commit fe76ab1803)
5 years ago
Victor Julien 1fba08a27d nfs4: verify bool fields
(cherry picked from commit 5ecb626e50)
5 years ago
Philippe Antoine 18bf8c89d9 mqtt: parse properties with the right buffer's length
(cherry picked from commit f0e869b26b)
5 years ago
Eloy Pérez González 1556ea0ceb dcerpc: remove prev_tx_call_id and clear_bind_cache from DCERPCState
remove those fields since are not used because of the removal of
handle_bind_cache.

(cherry picked from commit 15f493f516)
5 years ago
Eloy Pérez González 0c400b2ddb dcerpc: avoid delete the rpc state interface context
The bug:
The dcerpc dce_iface keyword just match the packet following the bind. Only the
next request after the rpc is sent will match. However the expected behaviour it
that all the rpc requests/responses sent under the context of the given
interface would match.

In the Open Group c706 the following is indicated:

In 2.2.1 Binding-related Operations, indicates that one category of binding
operations are those that "operations that establish internal call routing
information for the server." (The other are to establish the protocol which is
not relevant here). And the following statement can be found:

Operations in the second category establish a set of mappings that the server
can use to route calls internally to the appropriate manager routine. This
routing is based on the interface and version, operation and any object
requested by the call.

It indicates that server routes (to call methods) are based on the operation,
interface and object.

- Operation: To indicate the method to call, and operation number is
             specified as indicated in the second step of 2.3.3.2 (Client
             Binding Steps).
- Interface: An interface is a set of remotely callable operations offered by a
             server and invokable by clients. (2.1.1.1)
- Object: Is the manager that implements the interface, as stated in section
          Interface and Manager Selection of 2.3.3.3. It is not mandatory, can
          be nil.

To call a method, a client must send a request message as defined in 2.6.4.9,
that contains these identifiers:

- opnum: The opnum field identifies the operation being invoked within the
         interface.
- p_cont_id (Context ID in Wireshark): The p_cont_id field holds a presentation
                                       context identifier that identifies the
                                       data representation and interface, as
                                       defined in 12.6.3.4 (Context Identifiers).
- object: The object field is contained if the PFC_OBJECT_UUID is set. (Could be
          interesting to create a keyword dce_object for matching this UUID)

Therefore, to get the correct method to invoke, the server must map the context
to the correct interface. This is negotiated by the bind request

Interfaces are first negotiated using the bind message (12.6.4.3), contained in
the p_context_elem array. Then they are accepted or rejected using the bind_ack
message (12.6.4.4).

Once these contexts are established, both client and server can use the context
id, which is the index of the p_context_elem array, to refer the interface they
are using.

Moreover, in the middle of the connection, the context can be changed with the
alter_context message.

This is way suricata shouldn't delete the bindack attribute, that contains
the contexts, used by match_backuuid. This is the only way to know the interface
a request message is referring to.

ticket: 4769
https://redmine.openinfosecfoundation.org/issues/4769

(cherry picked from commit 1aca2676a6)
5 years ago
Eloy Pérez González 3028bdadc5 smb/dce_iface: avoid deleting current ifaces from state
The smb dce_iface keyword must match for all those dcerpc requests
and responses sent in the context of the given interface. They are
not matching as the current bind interfaces are deleted by any
non bind message.

Ticket: 4767
(cherry picked from commit bff0774767)
5 years ago
Eloy Pérez González 9bc31affa4 smb/dce_iface: use DCERPC_TYPE_REQUEST
The smb dce_iface keyword must match for all those dcerpc requests and
responses sent in the context of the given interface. They are not
matching because in rs_smb_tx_get_dce_iface, x.req_cmd is erroneously
compared with 1. Fix this by comparing with DCERPC_TYPE_REQUEST instead.

Ticket: 4767
(cherry picked from commit 1ae22fd5de)
5 years ago
Eloy Pérez González 09c8b17bf7 smb/dce_opnum: move range if to outer context
The smb dce_opnum matches all the opnums that are higher that the
indicated opnum. This is due the range comparison if was put in the
exact comparison context, and in case the opnum doesn't match exactly,
then the range comparison is triggered (the upper limit is always true).

Move the erroneus if to the outer context, as else option of the block
checks if comparison should be exact or range.

Ticket: 4767
(cherry picked from commit 333db3b385)
5 years ago
Eloy Pérez González 97d90ea62c smb/dce_opnum: use DCERPC_TYPE_REQUEST
The smb dce_opnum keyword doesn't match the dcerpc requests/responses.
This occurs because in the rs_smb_tx_match_dce_opnum function, the
x.req_cmd is matched against the erroneous code 1. Fix this by using
DCERPC_TYPE_REQUEST for the comparison instead.

Ticket: 4767
(cherry picked from commit 8dca3d0416)
5 years ago
Jason Ish a3b803d150 dns: add dns flag to dns request logging
Ticket #4515

(cherry picked from commit 0861b66e15)
5 years ago
Odin Jenseg 4318e9726f dns: Logging of Z-bit
[Edit by Jason Ish: fix flag bit value]

Ticket #4515

(cherry picked from commit dfb6f105e8)
5 years ago
Jason Ish 6a55c14c77 dns: create transaction even if z-bit was set
It appears that DNS servers will still process a DNS request even if the
z-bit is set, our parser will fail the transaction. So create the
transaction, but still set the event.

Ticket #4924

(cherry picked from commit fcbdc30426)
5 years ago
Philippe Antoine 9d7630d142 mqtt: fix transaction completion
Ticket: 4862

A transaction to client is always considered
complete in the direction to server and vice versa.
Otherwise, transactions are never complete for
AppLayerParserTransactionsCleanup

(cherry picked from commit 1b10848d84)
5 years ago
Jason Ish 19d9a05549 dhcp: fix url in comment
rustdoc was complaining about the format of the URL in a comment
while trying to generate documentation. Convert the comment to a
non-rustdoc comment for now to satisfy rustdoc.

(cherry picked from commit eb6cc62937)
5 years ago
Philippe Antoine f5049041be ntp: fixes leak of de_state
Bug: #4752.
(cherry picked from commit 3212fa7d2b)
5 years ago
Philippe Antoine 7e8247164c snmp: fixes leak of de_state
Bug: #4752.
(cherry picked from commit 28a3181a2d)
5 years ago
Philippe Antoine 5c95c28387 smb: midstream probing checks for netbios message type
If it is available

Bug: #4620.
(cherry picked from commit f37240a3e2)
5 years ago
Philippe Antoine 8b54e8fdf0 rust: right condition for both uint to be zero
Theay can overflow leading to their addition to be zero

If a NFS read reply indicates a count of 0xFFFFFFFF

Bug: #4680.
(cherry picked from commit 8f8823b6f2)
5 years ago
Philippe Antoine f992e2adb1 style: remove latest warnings
about unused variables

(cherry picked from commit cb30772372)
5 years ago
Shivani Bhardwaj 2616afa625 ssh: fix match on ssh banner
Default detection handling of SSH should not be to pass in case the
direction was not a match but to treat it like it was meant to server.
5 years ago
Philippe Antoine e5ca0f7abb http2: better rust lifetimes
so that borrow check gets happy

(cherry picked from commit 56fae072b2)
5 years ago
Philippe Antoine 2b4be3187e http2: better rust style
(cherry picked from commit 596a4a9d6e)
5 years ago
Philippe Antoine 4f15d53f1f http2: concatenate one headers multiple values
For detection, as is done with HTTP1

(cherry picked from commit 48ed874dda)
5 years ago
Philippe Antoine ff698f522f http2: generic http2_header_blocks
so as not to forget continuation and push promise
when iterating over headers

(cherry picked from commit e3ff0e7731)
5 years ago
Philippe Antoine 9556b376f9 http2: http.header keyword now works for HTTP2
As well as http.header.raw

(cherry picked from commit 0b0649d98e)
5 years ago
Philippe Antoine 240f779b99 http2: http.header_names keyword now works for HTTP2
(cherry picked from commit 9b9f909d7d)
5 years ago
Philippe Antoine 629a8226a0 http2: http.host normalized keyword now works for HTTP2
(cherry picked from commit 547e9f4ab4)
5 years ago
Philippe Antoine 59a109c049 http2: turn Host header into authority during upgrade
HTTP1 uses Host, but HTTP2 uses rather :authority cf HPACK

(cherry picked from commit 75f75e1eb0)
5 years ago
Philippe Antoine cf04608992 dns: improve probing parser
Checks opcode is valid
Checks additional_rr do not exceed message length
Better logic for incomplete cases

(cherry picked from commit 9e7ea631b2)
5 years ago
Philippe Antoine c42b81b769 nfs: improve probing parser
Checks credentials flavor is known

(cherry picked from commit b3c1f2ab48)
5 years ago
Philippe Antoine 8704057df0 http2: better file tracking
If an HTTP2 file was within only ont DATA frame, the filetracker
would open it and close it in the same call, preventing the
firther call to incr_files_opened

Also includes rustfmt again for all HTTP2 files

(cherry picked from commit bb98a18b3d)
5 years ago
Victor Julien 12e71ed090 smb: add debug validation on file counts
(cherry picked from commit c9cee7af49)
5 years ago
Victor Julien c7da7215db smb: count files in tx
(cherry picked from commit 114d3ba730)
5 years ago
Victor Julien f8a50a66ca http2: support per-tx file accounting
(cherry picked from commit c1dfb619c4)
5 years ago
Victor Julien bed74c7fbc nfs: add debug validation on file counts
(cherry picked from commit 1b3c3225cd)
5 years ago
Victor Julien e9ff5e2c6e nfs: support per-tx file accounting
(cherry picked from commit 1d48601c25)
5 years ago
Victor Julien 8f2f2b55ee nfs: don't reuse file transactions
After a file has been closed (CLOSE, COMMIT command or EOF/SYNC part of
READ/WRITE data block) mark it as such so that new file commands on that
file do not reuse the transaction.

When a file transfer is completed it will be flagged as such and not be
found anymore by the NFSState::get_file_tx_by_handle() method. This forces
a new transaction to be created.

(cherry picked from commit 67759795c6)
5 years ago
Victor Julien 717c6b021e filestore: track files getting stored per tx
Avoid evicting a tx before the filedata logger has decided it is
done.

(cherry picked from commit 56d3e28a3a)
5 years ago
Victor Julien 4151173e1a app-layer/transactions: track files opens and logs
To make sure a transaction is not evicted before all file logging is complete.

(cherry picked from commit c78f5ac316)
5 years ago
Philippe Antoine a900dea72e http2: support deflate decompression
cf #4556

(cherry picked from commit 1378b2f451)
5 years ago
Victor Julien b46b2936f2 http2: set Debug on structs
(cherry picked from commit 20e8f90981)
5 years ago
Philippe Antoine 9d9209b65f rust: bump bitflags dependency version
So that lexical-core, needed by nom, and using bitflags
is used with version 0.7.5 instead of version 0.7.0
which fixed the fact that BITS is now a reserved keyword
in nightly version

(cherry picked from commit 0105d4f017)
5 years ago
Jason Ish c37f4b7e54 rust/ike: suppress some compile warnings when not debug
Due to ef5755338f, the variables
that are only used for debug output now emit unused variable
warnings when Suricata is not built with debug. Prefix these
variables with _ to suppress these warnings.
5 years ago
Shivani Bhardwaj 6a53185797 ikev2: remove transforms fields 5 years ago
Philippe Antoine d70bbb24f4 rust: SCLogDebug is real nop when built as release
Before, even if there were no outputs, all the arguments
were evaluated, which could turn expensive

All variables which are used only in certain build configurations
are now prefixed by underscore to avoid warnings

(cherry picked from commit ef5755338f)
5 years ago
Philippe Antoine 234cafdcfe detect: use u32 for InspectionBufferMultipleForList
So that we do not have an endless loop casting index to
u16 and having more than 65536 buffers in one transaction

Changes for all protocols, even ones where it is impossible
to have such a pattern, so as to avoid bad pattern copy/paste
in the future

(cherry picked from commit 7d0a39412b)
5 years ago
Philippe Antoine 80c3bc4827 dcerpc: handles bigger inputs than 2^16
By comparing integers with the largest size

(cherry picked from commit 6f03ee2e47)
5 years ago
Jason Ish 0e8a248b99 rust/template: suppress unread variable warning
Suppress the warning about an unused variable in the template
parser. As this is just a template I think this is OK, however
master should make sure this variable is used, if only to be
more self documenting.
5 years ago
Sascha Steinbiss b6fd5e0c2d rust: fix warnings with nightly 5 years ago
Philippe Antoine 41054a68ef http2: http.cookie keyword now works for HTTP2
(cherry picked from commit 999327ba1f)
5 years ago
Philippe Antoine 7d5dd8b5b2 http2: makes all HTTP1 header keywords work
(cherry picked from commit 017e39d8fd)
5 years ago
Philippe Antoine f81985596b http2: http.host.raw keyword now works for HTTP2
(cherry picked from commit df039555bc)
5 years ago
Philippe Antoine 9c1349ac18 http2: http.method keyword now works for HTTP2
(cherry picked from commit 1e82d0b3c8)
5 years ago
Philippe Antoine a79b784edd http2: http.user_agent keyword now works for HTTP2
(cherry picked from commit 47928babfc)
5 years ago
Philippe Antoine 00eadac277 http2: http.uri keyword now works for HTTP2
cf #4067

(cherry picked from commit a98d0fe6ed)
5 years ago
Philippe Antoine 9aa5c6aff0 rust: fix app-layer parser flags
This especially allows for SSH bypass to work

(cherry picked from commit fdab22d924)
5 years ago
Philippe Antoine 437b7d3348 ftp: completely parses pasv and epsv responses
(cherry picked from commit ca6e434e0b)
5 years ago
Philippe Antoine e0764e1e12 http2: make decompression a configure-time option 5 years ago
Philippe Antoine 56bda0f9cb http2: have filecontainer for both directions
(cherry picked from commit 6fe8bce3b0)
5 years ago
Philippe Antoine 2504b96c48 http2: adds check about dynamic headers table size
(cherry picked from commit 3de0123ffb)
5 years ago
Victor Julien a3f94435d3 http2: remove dead code
(cherry picked from commit de280c47d9)
5 years ago
Philippe Antoine eb250e5512 http2: remove assertion which can be wrong
Brotli decoder stops consuming input it it reaches the
end of its input

(cherry picked from commit b3c502d572)
5 years ago
Philippe Antoine 6109855bca http2: pass data through when decompression fails
as is done for HTTP1

(cherry picked from commit 1ca4f041bb)
5 years ago
Philippe Antoine 899a9b8e17 http2: decompression for files
gzip and brotli decompression for files

(cherry picked from commit d861228214)
5 years ago
Philippe Antoine 0e6ffb966f rust: BIT_U16 macro utility
(cherry picked from commit 2e46b5d100)
5 years ago
Philippe Antoine 9287f6ae7f rust: better panic message for missing file config
(cherry picked from commit aee8e60149)
5 years ago
Jason Ish a8e1172e7f rust: pin memchr to ~2.3
2.4+ requires a newer version of Rust.
5 years ago
Philippe Antoine 76a981f7a2 rdp: correctly returns incomplete in parse_tc
Adding the already consumed bytes
In case an incomplete tls handshake is handled with/after
a refular rdp t123_tpkt

(cherry picked from commit 6da9a37285)
5 years ago
Philippe Antoine effa7ac54f kerberos: fix probing parser tag condition
according to the comment

(cherry picked from commit cb150e97d0)
5 years ago
Philippe Antoine 90fdb53439 smb: relax probing parser to handle first NBSS message
cf dcerpc-udp S-V test :
First message is Message Type: Session request (0x81)
Second message is SMB

(cherry picked from commit 8307010255)
6 years ago
Philippe Antoine bfa66c6d6c smb: probing parser for start and midstream
The probing parser is more strict at the start of the stream

(cherry picked from commit 1b6e81cd72)
6 years ago
Philippe Antoine fe50461346 smb: split probing function for code style
Introduces rs_smb_probe_tcp_midstream

(cherry picked from commit 9dc5258a21)
6 years ago
Philippe Antoine 2c9a2cc895 protodetect: rename direction to flags
And use whole flags in AppLayerProtoDetectPPGetProto

(cherry picked from commit c6aadf0dfa)
6 years ago
Shivani Bhardwaj dd2285724e dcerpc: trigger raw assembly on record completion
(cherry picked from commit 0ac5c5376a)
6 years ago
Shivani Bhardwaj 772b8f61e7 rust/context: add AppLayerParserTriggerRawStreamReassembly
(cherry picked from commit c77c8e7005)
6 years ago
Shivani Bhardwaj a0fce7bb4e dcerpc/udp: improve detection
Lately, Wireguard proto starting w pattern |04 00| is misdetected as
DCERPC/UDP which also starts with the same pattern, add more checks
to make sure that it is the best guess for packet to be dcerpc/udp.

(cherry picked from commit f967a49104)
6 years ago
Shivani Bhardwaj d7a633a684 dcerpc: add probe function
(cherry picked from commit 3641f1b522)
6 years ago