-
Notifications
You must be signed in to change notification settings - Fork 830
Add Tripwire integrity rules #15127
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
Open
israel-villar
wants to merge
7
commits into
ComplianceAsCode:master
Choose a base branch
from
israel-villar:feat/tripwire-integrity-rules
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Tripwire integrity rules #15127
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8ac8a86
Add Tripwire integrity rules
israel-villar bc27929
Add Automatus test scenarios for tripwire_build_database and tripwire…
israel-villar 916c2fa
Make tripwire_periodic_cron_checking scenarios self-contained
israel-villar 4b5c825
Simplify tripwire_periodic_cron_checking to the real Debian behavior
israel-villar 59cd6fa
Drop /etc/cron.hourly from tripwire_periodic_cron_checking
israel-villar 59ad6d6
Drop stray cron.hourly reference from no_schedule.fail.sh
israel-villar 2f8e515
Document expected results in tripwire test scenarios
israel-villar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| name: tripwire | ||
| groups: | ||
| - tripwire | ||
| packages: | ||
| - tripwire | ||
| rules: | ||
| - package_tripwire_installed | ||
| - tripwire_build_database | ||
| - tripwire_periodic_cron_checking | ||
12 changes: 12 additions & 0 deletions
12
linux_os/guide/system/software/integrity/software-integrity/tripwire/group.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Verify Integrity with Tripwire' | ||
|
|
||
| description: |- | ||
| Tripwire conducts integrity checks by comparing hashes and metadata of | ||
| files against a previously-generated, known-good database. It is a | ||
| common alternative to AIDE for this purpose. The database should be | ||
| created immediately after initial system configuration and regenerated | ||
| after any software update. | ||
|
|
||
| platform: system_with_kernel |
23 changes: 23 additions & 0 deletions
23
...system/software/integrity/software-integrity/tripwire/package_tripwire_installed/rule.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Install Tripwire' | ||
|
|
||
| description: |- | ||
| {{{ describe_package_install(package="tripwire") }}} | ||
|
|
||
| rationale: |- | ||
| The tripwire package provides the Tripwire file and directory integrity | ||
| checker, a common alternative to AIDE. It must be installed for any | ||
| integrity checking to be possible. | ||
|
|
||
| severity: medium | ||
|
|
||
| references: | ||
| nist: CM-6(a) | ||
|
|
||
| {{{ complete_ocil_entry_package_installed("tripwire") }}} | ||
|
|
||
| template: | ||
| name: package_installed | ||
| vars: | ||
| pkgname: tripwire |
20 changes: 20 additions & 0 deletions
20
...em/software/integrity/software-integrity/tripwire/tripwire_build_database/oval/shared.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <def-group> | ||
| <definition class="compliance" id="{{{ rule_id }}}" version="1"> | ||
| {{{ oval_metadata("The Tripwire database must be initialized to provide a known-good baseline for integrity checks.", rule_title=rule_title) }}} | ||
| <criteria operator="AND"> | ||
| <extend_definition comment="tripwire is installed" definition_ref="package_tripwire_installed" /> | ||
| <criterion test_ref="test_tripwire_database_initialized" comment="Tripwire operational database file exists" /> | ||
| </criteria> | ||
| </definition> | ||
|
|
||
| <unix:file_test id="test_tripwire_database_initialized" check="all" | ||
| check_existence="at_least_one_exists" version="1" | ||
| comment="Testing existence of the Tripwire operational database file"> | ||
| <unix:object object_ref="object_tripwire_database_file" /> | ||
| </unix:file_test> | ||
|
|
||
| <unix:file_object id="object_tripwire_database_file" version="1"> | ||
| <unix:path>/var/lib/tripwire</unix:path> | ||
| <unix:filename operation="pattern match">^.*\.twd$</unix:filename> | ||
| </unix:file_object> | ||
| </def-group> |
37 changes: 37 additions & 0 deletions
37
...de/system/software/integrity/software-integrity/tripwire/tripwire_build_database/rule.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Build and Initialize Tripwire Database' | ||
|
|
||
| description: |- | ||
| Run the following command to generate the initial known-good database, | ||
| supplying the local passphrase when prompted: | ||
| <pre>$ sudo tripwire --init</pre> | ||
| By default the database is written to | ||
| <tt>/var/lib/tripwire/$(HOSTNAME).twd</tt>, as configured by the | ||
| <tt>DBFILE</tt> directive in <tt>/etc/tripwire/twcfg.txt</tt>. | ||
| To run a manual integrity check afterwards: | ||
| <pre>$ sudo tripwire --check</pre> | ||
| If the check produces unexpected output, investigate. | ||
|
|
||
| rationale: |- | ||
| For Tripwire to be effective, an initial database of "known-good" | ||
| information about files must be captured so that installed files can be | ||
| verified against it. | ||
|
|
||
| severity: medium | ||
|
|
||
| references: | ||
| nist: CM-6(a) | ||
|
|
||
| warnings: | ||
| - general: |- | ||
| This rule doesn't come with a remediation; <tt>tripwire --init</tt> | ||
| requires the site and local passphrases to be entered interactively | ||
| and must be run by the administrator. | ||
|
|
||
| ocil_clause: 'the Tripwire database file has not been created' | ||
|
|
||
| ocil: |- | ||
| To verify the Tripwire database has been initialized, run: | ||
| <pre>$ sudo ls -l /var/lib/tripwire/*.twd</pre> | ||
| A <tt>.twd</tt> database file should be present. |
9 changes: 9 additions & 0 deletions
9
...egrity/software-integrity/tripwire/tripwire_build_database/tests/database_missing.fail.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/bin/bash | ||
| # packages = tripwire,linux-base | ||
| # platform = multi_platform_debian | ||
| # remediation = none | ||
|
|
||
| # No .twd database file exists yet, so the Tripwire database hasn't been | ||
| # initialized. Expected result: FAIL. | ||
| mkdir -p /var/lib/tripwire | ||
| rm -f /var/lib/tripwire/*.twd |
8 changes: 8 additions & 0 deletions
8
...egrity/software-integrity/tripwire/tripwire_build_database/tests/database_present.pass.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/bin/bash | ||
| # packages = tripwire,linux-base | ||
| # platform = multi_platform_debian | ||
|
|
||
| # A .twd database file is present, matching the DBFILE default documented | ||
| # in twconfig(4) (/var/lib/tripwire/$(HOSTNAME).twd). Expected result: PASS. | ||
| mkdir -p /var/lib/tripwire | ||
| touch "/var/lib/tripwire/$(hostname).twd" |
21 changes: 21 additions & 0 deletions
21
...are/integrity/software-integrity/tripwire/tripwire_periodic_cron_checking/oval/shared.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <def-group> | ||
| <definition class="compliance" id="{{{ rule_id }}}" version="1"> | ||
| {{{ oval_metadata("Tripwire must run on a schedule so unexpected file changes are revealed promptly.", rule_title=rule_title) }}} | ||
| <criteria operator="AND"> | ||
| <extend_definition comment="tripwire is installed" definition_ref="package_tripwire_installed" /> | ||
| <criterion test_ref="test_tripwire_cron_periodic" comment="tripwire check scheduled in /etc/cron.{daily,weekly}" /> | ||
| </criteria> | ||
| </definition> | ||
|
|
||
| <ind:textfilecontent54_test check="all" check_existence="at_least_one_exists" | ||
| id="test_tripwire_cron_periodic" version="1" | ||
| comment="tripwire check scheduled via /etc/cron.{daily,weekly}"> | ||
| <ind:object object_ref="object_tripwire_cron_periodic" /> | ||
| </ind:textfilecontent54_test> | ||
| <ind:textfilecontent54_object id="object_tripwire_cron_periodic" version="1"> | ||
| <ind:path operation="pattern match">^/etc/cron\.(daily|weekly)$</ind:path> | ||
| <ind:filename operation="pattern match">^.*$</ind:filename> | ||
| <ind:pattern operation="pattern match">tripwire[^\n]*(?:--check|-m\s+c)</ind:pattern> | ||
| <ind:instance datatype="int">1</ind:instance> | ||
| </ind:textfilecontent54_object> | ||
| </def-group> |
27 changes: 27 additions & 0 deletions
27
...m/software/integrity/software-integrity/tripwire/tripwire_periodic_cron_checking/rule.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| documentation_complete: true | ||
|
|
||
| title: 'Configure Periodic Execution of Tripwire' | ||
|
|
||
| description: |- | ||
| Tripwire should run at least weekly. The Debian <tt>tripwire</tt> package | ||
| installs <tt>/etc/cron.daily/tripwire</tt> by default, which runs | ||
| <tt>tripwire --check</tt> once a day and mails the report to root. The | ||
| script can instead be moved to <tt>/etc/cron.weekly</tt> if weekly checks | ||
| are preferred. | ||
|
|
||
| rationale: |- | ||
| By default, integrity checking tools do not run themselves periodically. | ||
| Running Tripwire on a schedule is necessary to reveal unexpected changes | ||
| to installed files in a timely manner. | ||
|
|
||
| severity: medium | ||
|
|
||
| references: | ||
| nist: SI-7,SI-7(1),CM-6(a) | ||
|
|
||
| ocil_clause: 'Tripwire is not configured to run periodically' | ||
|
|
||
| ocil: |- | ||
| Run the following command to check for a scheduled Tripwire run: | ||
| <pre>$ ls -l /etc/cron.daily/tripwire /etc/cron.weekly/tripwire 2>/dev/null</pre> | ||
| A script invoking <tt>tripwire --check</tt> should be present. |
17 changes: 17 additions & 0 deletions
17
...ity/software-integrity/tripwire/tripwire_periodic_cron_checking/tests/cron_weekly.pass.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
| # packages = tripwire,linux-base | ||
| # platform = multi_platform_debian | ||
|
|
||
| # The Debian package's default script may be relocated to a less | ||
| # frequent cron directory if daily checks are too frequent. | ||
| # Expected result: PASS. | ||
| rm -f /etc/cron.daily/tripwire | ||
| mkdir -p /etc/cron.weekly | ||
| cat > /etc/cron.weekly/tripwire <<EOF | ||
| #!/bin/sh -e | ||
| tripwire=/usr/sbin/tripwire | ||
| [ -x \$tripwire ] || exit 0 | ||
| umask 027 | ||
| \$tripwire --check --quiet --email-report | ||
| EOF | ||
| chmod +x /etc/cron.weekly/tripwire |
8 changes: 8 additions & 0 deletions
8
...ity/software-integrity/tripwire/tripwire_periodic_cron_checking/tests/no_schedule.fail.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/bin/bash | ||
| # packages = tripwire,linux-base | ||
| # platform = multi_platform_debian | ||
| # remediation = none | ||
|
|
||
| # Neither /etc/cron.daily/tripwire nor /etc/cron.weekly/tripwire exists, | ||
| # so no periodic check is scheduled. Expected result: FAIL. | ||
| rm -f /etc/cron.daily/tripwire /etc/cron.weekly/tripwire |
17 changes: 17 additions & 0 deletions
17
...oftware-integrity/tripwire/tripwire_periodic_cron_checking/tests/packaged_default.pass.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
| # packages = tripwire,linux-base | ||
| # platform = multi_platform_debian | ||
|
|
||
| # Matches the /etc/cron.daily/tripwire script shipped by the Debian | ||
| # tripwire package, written explicitly instead of relying on the | ||
| # package's post-install state so this scenario stays deterministic | ||
| # across package versions. Expected result: PASS. | ||
| mkdir -p /etc/cron.daily | ||
| cat > /etc/cron.daily/tripwire <<EOF | ||
| #!/bin/sh -e | ||
| tripwire=/usr/sbin/tripwire | ||
| [ -x \$tripwire ] || exit 0 | ||
| umask 027 | ||
| \$tripwire --check --quiet --email-report | ||
| EOF | ||
| chmod +x /etc/cron.daily/tripwire |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Refer to #15127 (comment), please
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.
Thanks for the review, @macko1. Here are the exact official Tripwire sources for the decisions in this PR:
tripwire --init / tripwire --check and the --quiet/--email-report flags — official tripwire(8) man page from the upstream Open Source Tripwire project: https://github.com/Tripwire/tripwire-open-source/blob/master/man/man8/tripwire.8 (see the mode selectors -m i/--init, -m c/--check, and the option table listing -s/--quiet and -M/--email-report.)
The DBFILE default of /var/lib/tripwire/$(HOSTNAME).twd — official twconfig(4) man page, same upstream project: https://github.com/Tripwire/tripwire-open-source/blob/master/man/man4/twconfig.4 ("Required Variables" section: DBFILE Default = /var/lib/tripwire/$(HOSTNAME).twd).
The /etc/cron.daily/tripwire script and its exact contents shipped by the Debian tripwire package (source of the tripwire_periodic_cron_checking check and test scenarios): https://sources.debian.org/src/tripwire/2.4.3.7-6/debian/cron.daily/ and the packaged twcfg.txt confirming Debian keeps the upstream DBFILE default: https://sources.debian.org/src/tripwire/2.4.3.7-6/debian/twcfg.txt/
I've also pushed a commit adding/extending expected-result comments on each test scenario per your second request