Repository navigation
nfs: feature work, SMB parity (v26) - v26 #16626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b8b9d4a
a623098
9c32007
2f55ace
ddd9969
9f36638
c04edcf
ba03a65
298116f
812a69e
4b88981
bac51d0
1703735
5ec2d73
91b622e
aa78154
a2de53e
29518ff
3666f3e
04057a7
bce035c
0ed1d60
aeb3a76
55b7cd7
544e8a3
1bbefc0
5682b5d
94c8d35
d43a6f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| .. _NFS Rule Keywords: | ||
|
|
||
| NFS Keywords | ||
| ============ | ||
|
|
||
|
|
@@ -37,3 +39,66 @@ Unlike the other keywords, the usage of range is inclusive. | |
| Syntax:: | ||
|
|
||
| nfs_procedure:(mode) <number or string> | ||
|
|
||
| nfs.name | ||
| -------- | ||
|
|
||
| Match on the name the NFS transaction carries, when known. The name is | ||
| learned from LOOKUP and friends and associated with the file handle, so | ||
| READ and WRITE transactions on that handle carry it too. It is the | ||
| name the event reports as ``nfs.filename``: the buffer holds the raw bytes, | ||
| the event holds them lossily converted to UTF-8, so for a name that is not | ||
| valid UTF-8 they differ. It is a name component, not a path - NFS switches | ||
| to the handle once the directory walk is done. | ||
|
|
||
| Examples:: | ||
|
|
||
| nfs.name; content:"secret.txt"; endswith; | ||
| nfs.name; content:".crypter"; nocase; | ||
|
|
||
| ``nfs.name`` is a 'sticky buffer'. | ||
|
|
||
| ``nfs.name`` can be used as ``fast_pattern``. | ||
|
|
||
| For a READ or WRITE that opens a file, the generic :doc:`file-keywords` | ||
| keyword ``file.name`` matches the same bytes: it asks the file engine for | ||
| the name recorded at open. Prefer ``file.name`` there. ``nfs.name`` is the | ||
| wider of the two: it also covers the requests that name a file without | ||
| transferring it (LOOKUP, CREATE, REMOVE, RENAME, READDIR, READLINK, LINK, | ||
| SYMLINK, MKNOD, SETATTR), and the handle-only ones carry whatever the | ||
| handle map resolved for that handle. | ||
|
|
||
| Two limits to know about. A RENAME carries its source name in the | ||
| transaction and the target in ``rename.to`` of the event, so the buffer | ||
| holds the source only. And a COMMIT makes no transaction of its own - it | ||
| completes the WRITE it refers to - so there is nothing there for | ||
| ``nfs.name`` to match; match the WRITE instead. | ||
|
Comment on lines
+71
to
+75
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As these are limitations, I it's better to have something like a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't agree, these are not so important that they should draw your attention before anything else |
||
|
|
||
| Signature Example: | ||
|
|
||
| .. container:: example-rule | ||
|
|
||
| alert nfs any any -> any any (msg:"NFS nfs.name usage"; \ | ||
| :example-rule-options:`nfs.name; content:"secret.txt";` \ | ||
| classtype:bad-unknown; sid:1; rev:1;) | ||
|
|
||
| nfs.handle | ||
| ---------- | ||
|
|
||
| This keyword allows to match the file handle of the NFS transaction, | ||
| when known. File handles are binary and server-specific. | ||
|
|
||
| ``nfs.handle`` is a 'sticky buffer': use :ref:`content` with hex escapes | ||
| to match on it. | ||
|
|
||
| ``nfs.handle`` can be used as ``fast_pattern``. The handle is the raw | ||
| file handle; the NFS event logs a hash of it as ``nfs.hhash``, which is not | ||
| what this buffer matches. | ||
|
|
||
| Signature Example: | ||
|
|
||
| .. container:: example-rule | ||
|
|
||
| alert nfs any any -> any any (msg:"NFS nfs.handle usage"; \ | ||
| :example-rule-options:`nfs.handle; content:"|01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10|";` \ | ||
| classtype:bad-unknown; sid:1; rev:1;) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,3 +141,169 @@ Example - Client Proposal | |
| } | ||
| } | ||
| } | ||
|
|
||
| .. _9.0-nfs-logging-changes: | ||
|
|
||
| NFS | ||
| *** | ||
|
|
||
|
Comment on lines
+144
to
+149
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll come back to review this bit. It feels... quite verbose.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've worked with claude for an easier to read version of this (here 2275a94), but didn't take into account the reviews for that part on this PR. I'll go back to it and incorporate those.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These seem already up-to-date with the latest review iteration, in case you want to incorporate anything from it. |
||
| nfs.status is logged only when a reply carried one | ||
| ================================================== | ||
|
|
||
| In 8.x, ``nfs.status`` was always logged and read ``OK`` by default. In an | ||
| ``nfs`` record it is now left out when no reply status was seen; treat a | ||
| missing ``nfs.status`` there as "no reply status". The ``nfs`` block of an | ||
| alert and of a ``fileinfo`` record still carries ``status``, ``OK`` until a | ||
| reply status is seen. ``status_code`` follows the record rule everywhere: it | ||
| appears only once a reply status was seen. | ||
|
|
||
| This happens when: | ||
|
|
||
| * a WRITE whose last record is fully buffered is logged as the request is | ||
| parsed, before any reply; | ||
| * the reply never arrives; | ||
| * the reply is rejected at the RPC layer. | ||
|
|
||
| When a status is logged, it is: | ||
|
|
||
| * the first NFS error carried by any reply to the request, or else | ||
| * the status of the first reply that carried one. | ||
|
|
||
| A request split into several records can be answered more than once. If one | ||
| reply reports success and another an NFS error, the record reports the error, | ||
| whatever the order. A reply that fails at the RPC message level | ||
| (``GARBAGE_ARGS``, ``PROC_UNAVAIL`` and the like) carries no NFS status, so it | ||
| does not override one. ``rpc.status`` behaves the other way round: once a reply | ||
| to the request was denied, the record reports ``DENIED`` there, whatever order | ||
| the replies arrived in. | ||
|
|
||
| Special cases: | ||
|
|
||
| * A READ that stops before EOF is logged with the status of the replies that | ||
| did arrive. | ||
| * An UNSTABLE WRITE closed by a COMMIT reports its own reply status only if | ||
| that reply arrived before the COMMIT. The COMMIT closes the record, so a | ||
| later reply is not logged. | ||
|
|
||
| The ``fileinfo`` record for such a file is written when the file closes. It | ||
| describes the file, not an RPC reply: | ||
|
|
||
| * its ``status`` reads ``OK`` unless an error reply arrived before the file | ||
| closed; | ||
| * its ``status_code`` appears only once a reply status was seen. | ||
|
|
||
| More NFSv4 operations are logged | ||
| ================================ | ||
|
|
||
| A compound carrying any of the operations below now produces an ``nfs`` record: | ||
|
|
||
| - CLOSE, | ||
| - CREATE_SESSION, | ||
| - DELEGRETURN, | ||
| - DESTROY_CLIENTID, | ||
| - DESTROY_SESSION, | ||
| - EXCHANGE_ID, | ||
| - GETDEVINFO, | ||
| - LAYOUTGET, | ||
| - LAYOUTRETURN, | ||
| - RECLAIM_COMPLETE, | ||
| - SECINFO_NO_NAME | ||
|
|
||
| In 8.x it produced none. | ||
|
|
||
| Unchanged: | ||
|
|
||
| * Each compound still yields one transaction, for its main operation. READ | ||
| and WRITE also get a file transaction. | ||
| * A compound of only PUTFH and GETATTR yields no transaction. | ||
| * A GETATTR after another operation stays part of that operation. | ||
|
|
||
| Rules that use NFS transaction keywords (``nfs_version``, ``nfs_procedure``, | ||
| the file keywords) can now alert on these compounds too. They still alert | ||
| once per compound, not once per operation. To match a single operation, add | ||
| ``nfs_procedure``. | ||
|
|
||
| NFS over TCP is detected on any port | ||
| ==================================== | ||
|
|
||
| NFS is no longer detected only on the configured ports. Suricata now | ||
| recognizes NFS calls on the to-server stream by the ONC RPC call header and | ||
| program number. | ||
|
|
||
| NFS on an unusual port now: | ||
|
|
||
| * gets ``app_proto: nfs``; | ||
| * produces ``nfs`` records; | ||
| * can match ``alert nfs`` rules. | ||
|
|
||
| In 8.x such flows went undetected. Other ONC RPC services (mountd, rpcbind, | ||
| nlockmgr) use a different program number and are not claimed. | ||
|
|
||
| Size limits on logged records | ||
| ============================= | ||
|
|
||
| RFC 1813 (section 3.2) sets no length limit on NFSv3 names, so a name can be | ||
| as large as the reassembly buffer. The logger now caps what it writes: | ||
|
|
||
| * Each string field: 8 KiB of the value, before JSON escaping. A shortened | ||
| value ends with ``[truncated N additional bytes]``; a field of control bytes | ||
| can take up to 48 KiB once each is escaped. | ||
| * Each ``nfs`` record: 128 KiB. ``nfs.truncated`` (or ``rpc.truncated``) is | ||
| set when a value was shortened or the record limit was reached. Each field | ||
| left out at the limit gets a ``<field>_truncated`` key. | ||
|
|
||
| NFSv2 names are limited to 255 bytes (RFC 1094). Only these are checked when | ||
| parsing: a longer one raises ``malformed_data`` but is still available to | ||
| ``nfs.name`` and ``nfs.filename``. | ||
|
|
||
| New fields and events | ||
| ===================== | ||
|
|
||
| New fields in ``nfs`` records: | ||
|
|
||
| * ``nfs.minorversion`` and ``nfs.client_id``: NFSv4.1 session identity. | ||
| * ``nfs.status_code``: the numeric value of ``nfs.status``. Like | ||
| ``nfs.status``, it is logged only once a reply status was seen. A | ||
| transaction closed before its reply never shows ``0`` (OK). | ||
|
|
||
| NFSv4 status names now come from the v4 table instead of the v3 table. | ||
|
|
||
| New events, with default rules in ``rules/nfs-events.rules``: | ||
|
|
||
| * ``fsinfo_too_large`` | ||
| * ``record_overflow`` | ||
| * ``file_overlap`` | ||
| * ``internal_error`` | ||
| * the direction sanity events | ||
| * ``malformed_data``, for corrupted UDP records | ||
|
|
||
| The same file also adds default rules for eight events that 8.x raised | ||
| without one: ``non_existing_version``, ``read_queue_size_exceeded``, | ||
| ``read_queue_cnt_exceeded``, ``write_queue_size_exceeded``, | ||
| ``write_queue_cnt_exceeded``, ``write_request_too_large``, | ||
| ``read_response_too_large`` and ``truncated_file_data``. A configuration that | ||
| loads this file sees alerts for them after the upgrade. | ||
|
|
||
| Alerts for ``record_overflow`` and the direction events have no ``nfs`` or | ||
| ``rpc`` block. These transactions stand for an event, not a call, so there | ||
| is no procedure, status or valid transaction id to report. | ||
|
|
||
| Overlapping file data | ||
| ===================== | ||
|
|
||
| ``file_overlap`` flags a READ or WRITE chunk that starts before the end of | ||
| the data already tracked for the file. When a flow overlaps, the two sizes | ||
| differ: | ||
|
|
||
| * the ``nfs`` record's ``size`` counts the bytes the calls carried, so the | ||
| overlap is counted twice; | ||
| * ``fileinfo`` reports what the file tracker kept, which is the smaller | ||
| value. | ||
|
|
||
| Read both together. | ||
|
|
||
| New keywords | ||
| ============ | ||
|
|
||
| ``nfs.name`` and ``nfs.handle`` match the file name and file handle of NFS | ||
| records. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this was added, but the config option isn't present in the
nfssettings example.