Skip to content

feat(recommendations): add a Wazuh-derived Linux pattern catalogue and a sources and licensing table - #498

Merged
TheWitness merged 7 commits into
developfrom
feat/linux-wazuh-catalogue
Dec 3, 2026
Merged

TheWitness merged 7 commits into
developfrom
feat/linux-wazuh-catalogue

Conversation

@TheWitness

@TheWitness TheWitness commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Stacked on #497, which is stacked on #496. This PR targets feat/recommendation-patterns. Retarget it after those merge.

Summary

This finishes phase 2 of the Linux recommendations work:

  1. docs/linux-wazuh.json.gz: 411 manually importable pattern recommendations (feat(recommendations): match recommendations by regular expression and program #497) converted from 315 rules of the Wazuh 4.14.11 ruleset (GPL-2.0). They cover the four groups agreed for phase 2:

    Group Records Rule files
    Core Linux 133 syslog (kernel, su, sudo, cron, user management), PAM, sshd, systemd, firewalld, Dropbear, AppArmor, auditd, USB, Docker
    Network services 160 telnetd, arpwatch, ftpd, ProFTPD, Pure-FTPd, vsftpd, BIND, Samba, racoon, Apache, nginx, Squid, Unbound, OpenVPN
    Mail 71 Sendmail, Postfix, spamd, imapd, MailScanner, Courier, Dovecot, vm-pop3d, vpopmail, OpenSMTPD, Exim
    Databases and applications 47 MySQL, PostgreSQL, ClamAV, Puppet, Redis, FreeIPA, MongoDB, MariaDB

    No forwarder change is needed, because records match on message text and program.

  2. README "Recommendation sources and licensing" table: for every bundled .json.gz, it lists the vendor, file, source, copyright holder and license (with links to the governing terms), and a short sentence on how it was obtained. A paragraph explains that only the systemd, Wazuh and FRRouting-derived data is openly licensed. The remaining catalogues are short factual summaries of proprietary vendor documentation, with references back to it, and are not relicensed under the plugin's GPL.

Behaviour change: no catalogue is seeded on install

This PR removes syslog_recommendations_seed() and its call in setup.php. A new install now starts with no recommendations, and every bundled catalogue, including Cisco's, is imported manually from the Recommendations page. Existing installs keep what they already have. The CHANGELOG records this as well.

Conversion (contrib/recommendations/extract_wazuh_rules.py)

  • A rule's own <match>/<regex> conditions are combined with those inherited through if_sid and decoded_as, including the decoder's prematch and named child decoders, into one PCRE pattern. Multiple conditions become lookaheads (^(?=.*?A)(?=.*?B)), and negated ones become (?!…).
  • OS_Match and OS_Regex are compiled case-insensitive by Wazuh (verified in src/analysisd/rules.c), so their conversions start with (?i). OS_Regex classes are expanded and $VARIABLEs substituted. PCRE2 expressions are kept as written.
  • program_name becomes a program glob: ^sshd gives sshd* (which matches sshd-session) and ^postfix gives postfix* (which matches postfix/smtpd). This uses the * wildcards added to feat(recommendations): match recommendations by regular expression and program #497 in 71130e3.
  • Skipped rules:
    • level-0 rules (203);
    • correlation rules or rules on decoder-extracted fields (195);
    • rules with no message condition (2);
    • rule 1002, a catch-all that matches "error", "failed" and similar words.
  • Each rule gets one record per program: same-program variants are joined into one (?:A)|(?:B) pattern, and the plugin skips a pattern record that repeats the vendor, message and explanation of an earlier match, so a rule is never listed twice. A rule's <description> elements are joined as Wazuh does.
  • Records are ordered program-bound first, then most severe first, because the plugin tries patterns in import order and shows at most three recommendations.
  • Fields:
    • Severity is mapped from the Wazuh level.
    • The explanation is the rule description plus its ID, level, groups and MITRE ATT&CK techniques.
    • The reference links to the rule's line at the tag.
    • Wazuh provides no recommended actions.
  • build_catalogues.py now keeps regex and program, and the build is byte-reproducible. Rebuilding the existing systemd catalogue leaves it unchanged.

Testing

  • The catalogue-load test now covers linux-wazuh.json.gz. All 411 records import through the plugin's own validation: every pattern compiles under PHP PCRE and none matches an empty message.

  • New end-to-end cases run real syslog lines through the plugin matcher with the full catalogue:

    • a kernel OOM kill matches rule 5108;
    • sshd-session "Invalid user" matches rule 5710;
    • a postfix/smtpd hostname-resolution warning matches rule 3398;
    • the same sshd text from cron, and an ordinary NetworkManager carrier message, match nothing;
    • sshd "Failed password for root" and an Apache segfault each list their Wazuh rule once.
  • Full Pest suite against Cacti 1.2.x: 929 passed. The one warning (ProcessHelperCompatTest /proc probe) is also present on develop.

  • CI memory fix (789947a): the existing test "enforces the expanded import limit and accepts content exactly at that limit" set memory_limit to a fixed 256M before inflating a 64 MB file, so memory the suite already held counted against it. Under Xdebug coverage on PHP 8.3 and 8.5, that overflowed in syslog_recommendations_read_file(). The test now sets the limit to current usage plus 256M.

Licensing sources

The terms linked in the README table were checked against each vendor's published terms-of-use or license pages. Juniper, Dell, HPE and Nokia could only be read through search-result text, and Arista through an archived copy. I found no documentation terms for MikroTik. The table records what the sources say; it is not legal advice.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The extractor emits overlapping same-rule recommendations that consume multiple slots and truncates multi-element descriptions, requiring fixes and catalogue regeneration.

2 open issues
What changed in this PR

Extends Linux recommendations with a Wazuh-derived pattern catalogue, documents catalogue licensing, and makes all catalogue imports manual.

Changes:

  • Adds conversion tooling and coverage for 434 Wazuh-derived recommendations.
  • Adds licensing metadata, SPDX sidecars, and a packaged NOTICE.
  • Removes automatic Cisco catalogue seeding while preserving existing records.
File Description
tests/​Unit/​RecommendationsTest.php Tests Wazuh matching and licensing metadata; removes seed tests.
setup.php Removes automatic recommendation seeding.
README.md Documents Wazuh coverage, manual imports, and licensing.
NOTICE Explains code and catalogue licensing.
manifest.json Includes NOTICE in distribution.
includes/​recommendations.php Removes the seed function and constants.
docs/​RECOMMENDATION_SOURCES.md Documents Wazuh conversion and metadata builds.
docs/​paloalto.json.gz.license Adds Palo Alto licensing tags.
docs/​nvidia.json.gz.license Records NVIDIA’s mixed licensing.
docs/​nokia.json.gz.license Adds Nokia licensing tags.
docs/​mikrotik.json.gz.license Adds MikroTik licensing tags.
docs/​linux.json.gz.license Records systemd catalogue licensing.
docs/​linux-wazuh.json.gz.license Records Wazuh catalogue licensing.
docs/​juniper.json.gz.license Adds Juniper licensing tags.
docs/​huawei.json.gz.license Adds Huawei licensing tags.
docs/​hpe.json.gz.license Adds HPE licensing tags.
docs/​fortinet.json.gz.license Adds Fortinet licensing tags.
docs/​dell.json.gz.license Adds Dell licensing tags.
docs/​cisco.json.gz.license Adds Cisco licensing tags.
docs/​arista.json.gz.license Adds Arista licensing tags.
contrib/​recommendations/​extract_wazuh_rules.py Converts Wazuh rules into pattern recommendations.
contrib/​recommendations/​build_catalogues.py Preserves patterns and writes licensing metadata.
CHANGELOG.md Records catalogue, licensing, and import changes.

Review effort: Balanced

@TheWitness

TheWitness commented Dec 3, 2026 •

Copy link
Copy Markdown
Member Author

Review follow-up, CI now green:

  • 1a52b47 confines extract_wazuh_rules.read_xml() to .xml files directly inside rules/ or decoders/ (Sonar S8707). It also groups the component-name regex alternation (S5850).

  • 5231223 adds the new top-level NOTICE to manifest.json expected, which the manifest drift check needs.

  • a2d460c adds syslog_db_index_exists() to tests/regression/support/database_shim.php. The regex index check in schema.php comes from feat(recommendations): match recommendations by regular expression and program #497, and without the helper review_fixes_database_test.php failed fatally. feat(recommendations): match recommendations by regular expression and program #497 likely needs the same shim fix.

  • 42d09f7 addresses the Copilot review:

    • full multi-element descriptions;
    • one record per rule and program;
    • the matcher skips pattern records that repeat an earlier match's vendor, message and explanation.

    The catalogue is regenerated: 411 records from the same 315 rules. Docs and counts are updated to match.

  • 362a67f uses SHA-256 for that dedup key (Sonar S4790).

One PHP 8.3 run ran out of memory in the existing Cisco catalogue decode under coverage (256 MB limit). It passed on rerun, and the other versions were unaffected.

Comment thread includes/recommendations.php Fixed
xmacan
xmacan previously approved these changes Dec 3, 2026
@TheWitness
TheWitness force-pushed the feat/linux-wazuh-catalogue branch 3 times, most recently from 899e392 to 10db933 Compare December 3, 2026 19:54

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker: "PHP 8.3 Integration Test" fails on the last two heads (10db933, 10518ac) with the same fatal: Allowed memory size of 268435456 bytes exhausted (tried to allocate 67112960 bytes) at includes/recommendations.php:608. The limit in the message is still 256M after 10518ac set 512M in phpunit.xml, because the test "enforces the expanded import limit and accepts content exactly at that limit" calls ini_set('memory_limit', '256M') itself (tests/Unit/RecommendationsTest.php:418). That test builds a 64 MiB string by appending, so the allocation that fails is the string growing. Raise or drop the limit inside the test, or have it free the earlier payload first. #499 and #500 carry the same commit.

Suggestion: this PR removes syslog_recommendations_seed() and its call in setup.php, so a new install starts with no recommendations. Only the CHANGELOG says so. Put it in the description, since the title reads as an addition.

Suggestion: only level 0 Wazuh rules are skipped, so routine successes get a lightbulb: wazuh-5715 (sshd authentication success) and wazuh-5402 (successful sudo to root) match ordinary log lines. 327 of the 411 records are severity 5 or 6. Consider a severity floor or leaving the informational ones out.

Nit: wazuh-80003 and wazuh-80051 (two leading lookaheads with .*?) reach the backtrack limit on long puppet lines. The limit turns that into no match, so it is cost only.

Not verified here: I did not run the Pest suite or rebuild the catalogue from the Wazuh tag.

@TheWitness
TheWitness force-pushed the feat/linux-wazuh-catalogue branch from 10518ac to 789947a Compare December 3, 2026 20:16
Base automatically changed from feat/recommendation-patterns to develop December 3, 2026 20:27
@bmfmancini
bmfmancini force-pushed the feat/linux-wazuh-catalogue branch from 789947a to d179c6e Compare December 3, 2026 20:27
@TheWitness

Copy link
Copy Markdown
Member Author

@somethingwithproof thanks, addressed:

  • Blocker (PHP 8.3 memory): fixed in "test: give the expanded import limit test headroom above current usage". The test now sets memory_limit to current usage plus 256M instead of a fixed 256M, as you suggested. I reproduced the exact CI fatal locally by pinning 120 MB first: the old test fails, the new one passes. The earlier phpunit.xml 512M attempt is gone.
  • Suggestion (seeding removed): the description now has a "Behaviour change: no catalogue is seeded on install" section.
  • Not changed: the Wazuh severity floor (wazuh-5715, wazuh-5402 and other informational rules) is a catalogue design call left to the author. The wazuh-80003/80051 backtracking costs CPU but never produces a wrong match, as you noted.

#499 and #500 are rebased on this. Please re-review.

TheWitness and others added 7 commits December 3, 2026 15:34
…d a sources and licensing table

Add docs/linux-wazuh.json.gz, a manually importable catalogue of 434
pattern recommendations converted from 315 rules of the Wazuh 4.14.11
ruleset (GPL-2.0): core Linux (syslog, kernel, sshd, PAM, su, sudo,
systemd, auditd, AppArmor, firewalld, Docker, USB), mail, network services
and databases and applications.

contrib/recommendations/extract_wazuh_rules.py reads the release's rule and
decoder XML. It combines a rule's own and inherited (if_sid, decoded_as,
decoder prematch) OS_Match, OS_Regex and PCRE2 conditions into one PCRE
pattern and its program_name into a program glob. Level 0, correlation and
decoded-field rules, and the generic rule 1002, are skipped. Records are
ordered program-bound and most severe first. build_catalogues.py now keeps
the regex and program fields.

The README gains a Recommendation sources and licensing table naming, for
every bundled catalogue, its vendor, source, copyright holder and license,
and how it was obtained. RECOMMENDATION_SOURCES.md documents the Wazuh
conversion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… the Cisco catalogue

Add a NOTICE file, a SPDX .license file next to every docs/*.json.gz, and
copyright, license, license_url and source fields in each catalogue's JSON,
from a LICENSING table in build_catalogues.py. Vendor-derived catalogues are
marked as separate works aggregated with the plugin, not licensed under the
GPL, with LicenseRef- identifiers pointing at each vendor's terms. The
Wazuh-derived catalogue is GPL-2.0-only and the systemd one
LGPL-2.1-or-later. The NVIDIA catalogue's Cumulus Linux switchd and FRRouting
records are identified as CC BY-NC-SA 4.0 (NVIDIA networking documentation
license) and its Xid and SXid records as NVIDIA Terms of Service; the README
no longer presents its FRRouting records as GPL-licensed.

build_catalogues.py --metadata-only <vendor> refreshes only these fields and
keeps the shipped records exactly; every catalogue's records are unchanged.

The Cisco catalogue is no longer loaded on install or upgrade:
syslog_recommendations_seed() and its tests are removed, and every catalogue
is imported only on request. Records loaded by an earlier upgrade are kept.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
read_xml() now takes the rules/ or decoders/ directory and a file name,
and refuses any resolved path that is not an .xml file directly inside
that directory (SonarCloud pythonsecurity:S8707). Also group the
component-name regex alternation explicitly (python:S5850).

Regenerating linux-wazuh.json.gz from Wazuh v4.14.11 is byte-identical.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The licensing NOTICE added with the catalogue sources table is a
top-level file, so validate-manifest.php fails until it is listed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tions

Review follow-up for the Wazuh catalogue:

- Join all of a rule's <description> elements, as Wazuh does, so rules
  such as 3102 and 3191 no longer lose the second half of their text.
- Emit one record per rule and program: same-program variants become one
  (?:A)|(?:B) pattern (kept split only beyond the 1,024-character import
  limit), and a program-bound variant implied by an any-program variant
  is dropped. wazuh-5760 is now one record instead of two.
- Skip a matched pattern record whose vendor, message and explanation
  repeat an earlier match. A rule can still need an any-program record
  next to its program-bound ones (Apache 30104 for apache2 and for logs
  decoded without a program), and they no longer take two of the three
  recommendation slots.

The catalogue is regenerated (411 records from the same 315 rules), and
the README, CHANGELOG and RECOMMENDATION_SOURCES.md counts follow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The key only identifies repeated recommendation text, but SHA-256 avoids
the weak-hash finding (SonarCloud php:S4790).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The test set memory_limit to a fixed 256M before inflating a 64 MB
catalogue, so whatever the suite already held counted against it. Under
Xdebug coverage in CI that left too little room once more catalogue tests
ran first (Allowed memory size of 268435456 bytes exhausted in
syslog_recommendations_read_file()). Set the limit to current usage plus
256M instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness
TheWitness force-pushed the feat/linux-wazuh-catalogue branch from d179c6e to e30fb5e Compare December 3, 2026 20:34
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blockers found at e30fb5e. The import-limit test now sizes memory_limit from current usage, and PHP 8.2 to 8.6 pass on this head. The description now covers the removal of the install-time seed.

The severity floor for routine Wazuh successes (wazuh-5715, wazuh-5402) is still open as a suggestion. It is not a blocker.

@TheWitness
TheWitness merged commit 04b8bd7 into develop Dec 3, 2026
11 checks passed
@TheWitness
TheWitness deleted the feat/linux-wazuh-catalogue branch December 3, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants