You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 71c178a
Browse filesBrowse the repository at this point in the historyBrowse files
fix(parser): warn on unread pfSense SSH switches; diff and score SSH on its switch (#1065)
## Summary
Follow-up to the pfSense SSH switch fix. The converter read two SSH
elements differently from pfSense without saying so, and the statistics,
the security score and `diff` each handled SSH on the wrong field or not
at all.
## Changes
- **Legacy switch on a newer config.** `<system><enablesshd>` alone
still reads SSH as on, and now draws a Low conversion warning when the
config version is 18.9 or later. pfSense moves the element to
`<ssh><enable>` in `upgrade_188_to_189` and reads only `<ssh><enable>`
from then on (`/etc/sshd`, `filter.inc` `filter_get_antilockout_ports`),
so such a config over-reports.
- **OPNsense spelling.** `<ssh><enabled>` with no `<ssh><enable>` and no
`<enablesshd>` leaves SSH off, and now draws a Medium warning, since the
config says enabled and pfSense ignores it. `pfsense.SSHConfig` gains
`Enabled *string` for this only; it never turns SSH on.
- **Statistics.** "SSH Daemon" is listed when `SSH.Enabled` is set, not
when `SSH.Group` is non-empty. Both vendors keep `<ssh><group>` with SSH
off, so `testdata/config.xml.sample` listed a daemon that does not run.
- **Security score.** The 10 SSH points go to SSH being off or limited
to a login group. They went to any config with a group set, whatever the
switch, and to no config without one.
- **Diff.** `CompareSystem` walks `common.SSH` as it does the web GUI
settings and reports `system.ssh.enabled`, `system.ssh.port` and
`system.ssh.group`. No SSH field was compared before, on either vendor.
- **Wording.** GOTCHAS 8.4 names both elements the converter reads, the
`system` row of the pfSense schema README reads "Partial (`BoolFlag`)"
like its siblings, and two comments name the element the upgrade moves
the switch to.
## Output changes
- A config with an SSH group and SSH off no longer lists "SSH Daemon" in
`statistics.enabledServices` and `serviceDetails`, and its service count
drops by one. A config with SSH on and no group gains the entry.
- `statistics.summary.securityScore` and
`securityAssessment.overallScore` rise by 10 for a config with SSH off
and no login group, an empty config included, and fall by 10 for none:
SSH on with a group scored before and still does. Four golden pairs move
for this reason only.
- `diff` reports SSH changes: the daemon turned on is rated MEDIUM and
turned off LOW, a port change LOW, a login group change MEDIUM. The
ratings table in the diff guide lists them.
- `pkg/schema/pfsense`: new field `SSHConfig.Enabled` (JSON and YAML
`enabled`); a stray `<enabled>` now survives a marshal round trip. API
snapshot regenerated.
## Testing
`just ci-check` passes.
- `TestConverter_SSHEnabled_VendorShapes` gains the warning expectation
on every row, plus rows for config versions 18.8 and 18.9 and for each
ignored element beside `<ssh><enable>`.
- `TestComputeStatistics_SSHGroupAloneIsNotAService` and three rows of
`TestComputeSecurityScore` pin the statistics and score changes.
- `common.SSH` joins the reflective diff guards
(`TestCompareSettings_EveryFieldIsReported` and the ratings-table
tests).
- `TestRedMode_AntiLockoutOnWAN_EndToEnd` also runs the pfSense fixture
with the legacy `<enablesshd>` switch.
## AI disclosure
Used Claude Code (`Claude Fable 5.2`) to draft the change and tests.
Reviewed and tested locally. See
[`AI_POLICY.md`](https://github.com/EvilBit-Labs/opnDossier/blob/main/AI_POLICY.md).
---------
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Copy file name to clipboardExpand all lines: GOTCHAS.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -261,7 +261,7 @@ OPNsense records a tunable left at its default in one of three ways, none of whi
261
261
262
262
Most `Compare*` methods in `internal/diff/analyzer.go` have early-return guards that emit a single `ChangeAdded` or `ChangeRemoved` when one side has data and the other does not. For pointer types (`*common.System`), this uses nil checks. For value types (`NATConfig`, slices), this uses `HasData()` or `len() == 0`. New `Compare*` methods must follow this pattern.
263
263
264
-
- **Exceptions:** `CompareFirewallRules`, `CompareUsers` and `CompareAliases` intentionally omit section-level guards because per-item granularity is more useful for security-sensitive resources (individual rule additions/removals are reported separately). `CompareDNS` and `compareServiceSettings` (SNMP and syslog, in the system section) omit them too: they walk the settings struct by reflection (`compareSettings` in `analyzer_settings.go`) and report one entry per field under its JSON name, so a field added to `SNMPConfig`, `SyslogConfig`, `UnboundConfig`, `DNSMasqConfig` or `WebGUI` is reported without a code change. A rating, a label, redaction (`snmp.roCommunity` shows only `[set]`) or a skip for a field another comparison already reports goes in `settingRatings`; `TestCompareSettings_EveryFieldIsReported` fails on a field no comparison reports. The comparer prints the old and new value of every field, so a field that holds a credential must set `redact`, and one inside a list element cannot be redacted by path at all; `TestSettingRatings_SecretFieldsAreRedacted` fails on a field named like one. `TestSettingRatings_EveryKeyNamesAField` fails on a table entry whose path no field has, as a renamed JSON tag leaves behind.
264
+
- **Exceptions:** `CompareFirewallRules`, `CompareUsers` and `CompareAliases` intentionally omit section-level guards because per-item granularity is more useful for security-sensitive resources (individual rule additions/removals are reported separately). `CompareDNS` and `compareServiceSettings` (SNMP and syslog, in the system section) omit them too: they walk the settings struct by reflection (`compareSettings` in `analyzer_settings.go`) and report one entry per field under its JSON name, so a field added to `SNMPConfig`, `SyslogConfig`, `UnboundConfig`, `DNSMasqConfig`, `WebGUI` or `SSH` is reported without a code change. A rating, a label, redaction (`snmp.roCommunity` shows only `[set]`) or a skip for a field another comparison already reports goes in `settingRatings`; `TestCompareSettings_EveryFieldIsReported` fails on a field no comparison reports. The comparer prints the old and new value of every field, so a field that holds a credential must set `redact`, and one inside a list element cannot be redacted by path at all; `TestSettingRatings_SecretFieldsAreRedacted` fails on a field named like one. `TestSettingRatings_EveryKeyNamesAField` fails on a table entry whose path no field has, as a renamed JSON tag leaves behind.
265
265
266
266
### 4.2 Rule and User Equality Helpers Must Cover Every Model Field
267
267
@@ -394,7 +394,7 @@ Only `blue` mode runs `RunComplianceChecks`. Red mode ignores `SelectedPlugins`
394
394
- **A port forward can keep a loopback SNMP agent's verdict:** the bullet above holds for `wanRulePermitsPort`, but one step outside it reads `device.NAT.InboundRules` too. An os-net-snmp agent bound only to loopback is set Local after every other step (`applySNMPListen`), unless an enabled forward that can redirect UDP port 161 targets a loopback address or a network or range spanning one, `(self)` (This Firewall, which pf reads as every address of every interface, those of `lo0` included), an alias that may hold one, the net or address of an interface whose own address is a loopback address, such as `lo0`, or a name no alias or interface defines that has the shape of an alias name (`forwardsToLoopback`). pf rewrites a forward's destination before the packet is delivered, so such a forward can reach an agent bound to loopback. An alias that may hold one includes a URL alias, a URL table, a URL table in JSON format and an external alias, whose addresses OPNsense gets at runtime, a host alias holding a hostname, which OPNsense resolves through DNS when it loads the alias (`resolvedThroughDNS`), and an alias naming one at any depth (`aliasNamesRuntimeTable`). A disabled alias is not followed and its members are not read, since OPNsense loads it with no members, except an external or internal one, whose table survives disabling. That holds for this step only, where `loadedAliases` leaves those members out. `forwardsToAlias` has no disabled check and reads a disabled alias's members like any other's, so a member that is an address of the firewall keeps the rule. The read above treats such an alias the other way, as holding no address of the firewall, and `aliasHoldsFirewallAddress` keeps that reading for it. The net or address of any other interface, such as `lan` or `lanip`, does not count: pf redirects such a forward to that interface's network or address, where the agent does not listen. That reading of a target is the one `ForwardRule.php` applies from 26.1.2. Through 26.1.1 it maps a target only when an alias of that name exists, of any type, and disables a forward to any other name that is no address or network as an invalid target, `(self)` and interface names among them, so on those releases a forward to `(self)`, or to `lo0` when no alias has that name, keeps the verdict although it redirects nothing, which over-reports. The forward never makes the agent reachable by itself: it only keeps the agent from being set Local, and the agent keeps the reachability the earlier steps gave it. Neither the forward's interface, nor `<system><disablefilter>`, nor whether the target's address family is one the agent listens on is read there, so a LAN forward (`TestSNMPAgent_ForwardInterfaceIsNotRead`), a forward on a firewall with packet filtering off, or a forward to `::1` for an agent bound to `127.0.0.1` keeps the verdict too, which over-reports. The key and `ip` form is matched for every interface, although OPNsense maps it only for wan, lan and optN and disables a forward to any other such name no alias defines as an invalid target, so a forward to `lo0ip` keeps the verdict too, which also over-reports. Do not remove `forwardsToLoopback` as a regression of the bullet above: without it, a WAN forward of UDP 161 to loopback with the rule that passes it reports no exposure, and `TestSNMPAgent_PortForwardToLoopbackKeepsWANExposure` fails.
395
395
-**Web GUI port comes from the unified model, not a hardcode:**`common.WebGUI.Port` carries the configured web-configurator port. Both the OPNsense and pfSense parsers populate it from `<system><webgui><port>` when the element is present in `config.xml`; the 443/80 protocol default applies only when the configured port is absent (either vendor). Red analysis reads `device.System.WebGUI.Port` via `parsePort` rather than assuming 443/80, so a box on a custom GUI port is analyzed correctly regardless of vendor. New device parsers should populate this field when the platform exposes a GUI port.
396
396
- **Rules describe nothing when packet filtering is disabled:** this and the anti-lockout rule below are the two exceptions to the correlation rule above: either one makes a management service WAN-reachable with no pass rule in `FirewallRules`. `<system><disablefilter>` makes both vendors run `pfctl -d` and return before any ruleset loads (`filter.inc`, tested with `isset()`, so an empty element counts), so no rule, block option, NAT or anti-lockout rule applies and every service is reachable from every interface. A check that reads `FirewallRules` alone passes such a box. `System.PacketFilterDisabled` carries the setting: the shared engine raises a critical WAN-reachable finding, red mode marks every management service WAN-reachable (`markImplicitWANExposure`), and each compliance plugin fails the controls listed in its `packetFilterControls` through `compliance.FailWhenPacketFilterDisabled`. A new control whose pass verdict means the firewall restricts, inspects, logs or translates traffic belongs in that list, and in the list `TestPacketFilterControls_List` pins in the plugin's package: an end-to-end run cannot pin it, because the fixtures fail several of these controls on their own checks. Only SANS-FW-016 is held back: it joins the list only when the config holds an FTP port forward, and otherwise stays Unknown. Every other listed control fails even where its own check would report Unknown, so on a config without the inputs those checks need, SANS-FW-007, -017, -021 and -024 go from Unknown to Fail. Port forwards are still reported by `addWeakNATRules` although pf performs none, which over-reports.
397
-
- **The anti-lockout rule is a WAN pass rule on a firewall with no LAN or OPT interface:** unless `<system><webgui><noantilockout>` is set (tested with `isset()`), both vendors add a quick pass rule to the web GUI port and, with SSH enabled, the SSH port, ahead of every user rule and absent from `FirewallRules`. OPNsense 22.7.5 and later put it on the first of the `lan`, `optN` and `wan` keys, enabled or not, so the WAN gets it when no `lan` or `optN` key exists, which is what the console's WAN-only assignment writes. OPNsense up to 22.7.4 took `lan` or `opt1` when it had a device, and otherwise `wan` when it was the only enabled interface. Both read the interfaces with virtual entries left out, so loopback and the VPN groups count for neither rule. pfSense takes `wan` only when it is the only interface. `antiLockoutOnWAN` reads the rule as on the WAN when any of these would put it there, the safe direction, except that the 22.7.4 rule is not applied to pfSense, and not when the `wan` interface is disabled or has no device. Only the `wan` key counts as the WAN here, so a rule the firewall places on an `optN` that is itself an uplink is not reported. pfSense adds the SSH port on the test sshd uses, `<ssh><enable>` present with any body (`filter.inc` `filter_get_antilockout_ports`), and `System.SSH.Enabled` reads the same element.
397
+
- **The anti-lockout rule is a WAN pass rule on a firewall with no LAN or OPT interface:** unless `<system><webgui><noantilockout>` is set (tested with `isset()`), both vendors add a quick pass rule to the web GUI port and, with SSH enabled, the SSH port, ahead of every user rule and absent from `FirewallRules`. OPNsense 22.7.5 and later put it on the first of the `lan`, `optN` and `wan` keys, enabled or not, so the WAN gets it when no `lan` or `optN` key exists, which is what the console's WAN-only assignment writes. OPNsense up to 22.7.4 took `lan` or `opt1` when it had a device, and otherwise `wan` when it was the only enabled interface. Both read the interfaces with virtual entries left out, so loopback and the VPN groups count for neither rule. pfSense takes `wan` only when it is the only interface. `antiLockoutOnWAN` reads the rule as on the WAN when any of these would put it there, the safe direction, except that the 22.7.4 rule is not applied to pfSense, and not when the `wan` interface is disabled or has no device. Only the `wan` key counts as the WAN here, so a rule the firewall places on an `optN` that is itself an uplink is not reported. pfSense adds the SSH port on the test sshd uses, `<ssh><enable>` present with any body (`filter.inc` `filter_get_antilockout_ports`), and `System.SSH.Enabled` reads the same element, or `<system><enablesshd>`, where configs older than version 18.9 keep the switch. The converter warns when it reads `<enablesshd>` on a config at 18.9 or later, which pfSense no longer reads, and when it leaves SSH off beside an `<ssh><enabled>`, the OPNsense spelling pfSense never reads.
398
398
-**ExploitNotes safety:** red `ExploitNotes` carry impact/context only (never weaponized/step-by-step guidance). Enforced by `FindInstructionalContent` (`exploit_notes_safety.go`) run over the actual generated notes plus a golden-file gate — not authoring discipline. `--audit-blackhat` selects the sharper-tone variant (red mode only; rejected in `PreRunE` for blue mode) and adjusts tone only — the denylist safety invariant holds for both tone variants.
399
399
-**NAT correlation is an intentional over-report:** an inbound NAT rule is treated as WAN-reachable when any enabled WAN pass rule exists (not one correlated by port to that specific forward). This is a deliberate safe-direction choice — precise per-rule correlation would risk under-reporting a real exposure, the wrong failure mode for a security audit.
The score in the `convert` and `audit` exports, `statistics.summary.securityScore` and `securityAssessment.overallScore`, is computed differently. It starts at 0 and adds points: 10 for each detected security feature (Block Private Networks, Block Bogon Networks, HTTPS Web GUI, NAT Reflection Disabled), 20 when any firewall rule exists, 15 for an HTTPS web GUI, 10 when an SSH group is set, 15 when IDS is enabled and 10 more in IPS mode, capped at 100. Block Private Networks and Block Bogon Networks count only when every WAN interface blocks them, including a second uplink (see [How WAN Interfaces Are Identified](../firewall-security-controls-reference.md#how-wan-interfaces-are-identified)).
74
+
The score in the `convert` and `audit` exports, `statistics.summary.securityScore` and `securityAssessment.overallScore`, is computed differently. It starts at 0 and adds points: 10 for each detected security feature (Block Private Networks, Block Bogon Networks, HTTPS Web GUI, NAT Reflection Disabled), 20 when any firewall rule exists, 15 for an HTTPS web GUI, 10 when SSH is off or limited to a login group, 15 when IDS is enabled and 10 more in IPS mode, capped at 100. Block Private Networks and Block Bogon Networks count only when every WAN interface blocks them, including a second uplink (see [How WAN Interfaces Are Identified](../firewall-security-controls-reference.md#how-wan-interfaces-are-identified)).
0 commit comments