Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/ufw.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
groups:
- network-ufw

Check failure on line 2 in components/ufw.yml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

2:1 [indentation] wrong indentation: expected at least 1
name: ufw
packages:
- ufw

Check failure on line 5 in components/ufw.yml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

5:1 [indentation] wrong indentation: expected at least 1
rules:
- check_ufw_active

Check failure on line 7 in components/ufw.yml

View workflow job for this annotation

GitHub Actions / Yaml Lint on Changed yaml files

7:1 [indentation] wrong indentation: expected at least 1
- package_ufw_installed
- package_ufw_removed
- service_ufw_enabled
- set_ufw_default_rule
- set_ufw_loopback_traffic
- ufw_default_incoming_rule
- ufw_default_outgoing_rule
- ufw_disabled_routed
- ufw_only_required_services
- ufw_rate_limit
- ufw_rules_for_open_ports
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# platform = multi_platform_ubuntu,multi_platform_debian

ufw default deny incoming
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("Ensure ufw default incoming policy is deny or reject", rule_title=rule_title) }}}
<criteria>
<criterion comment="DEFAULT_INPUT_POLICY is DROP or REJECT in /etc/default/ufw"
test_ref="{{{ rule_id }}}_test_default_input_policy" />
</criteria>
</definition>

<ind:textfilecontent54_test check="all" check_existence="at_least_one_exists"
id="{{{ rule_id }}}_test_default_input_policy" version="1"
comment="Check DEFAULT_INPUT_POLICY is DROP or REJECT in /etc/default/ufw">
<ind:object object_ref="{{{ rule_id }}}_obj_default_input_policy"/>
</ind:textfilecontent54_test>

<ind:textfilecontent54_object id="{{{ rule_id }}}_obj_default_input_policy" version="1">
<ind:filepath>/etc/default/ufw</ind:filepath>
<ind:pattern operation="pattern match">^DEFAULT_INPUT_POLICY="(DROP|REJECT)"$</ind:pattern>
<ind:instance datatype="int">1</ind:instance>
</ind:textfilecontent54_object>
</def-group>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
documentation_complete: true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add test scenarios for both rules.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added deny.pass.sh, reject.pass.sh, and allow.fail.sh for both rules.


title: 'Ensure ufw Default Deny Policy for Incoming Connections'

description: |-
A default deny policy on incoming connections ensures that any unconfigured
inbound network traffic will be rejected.
Set <tt>DEFAULT_INPUT_POLICY</tt> to <tt>DROP</tt> or <tt>REJECT</tt>
in <tt>/etc/default/ufw</tt>.

Note: Any port or protocol without an explicit allow before the default
deny will be blocked.

rationale: |-
With a default accept policy the firewall will accept any incoming packet
that is not configured to be denied. It is easier to allow acceptable
usage than to block unacceptable usage.

severity: medium

platform: package[ufw]

ocil_clause: 'the default policy for incoming connections is not set to deny or reject'

ocil: |-
Run the following command and verify that the default policy for incoming
connections is deny or reject:
<pre># ufw status verbose | grep Default:</pre>
Example output:
<pre>Default: deny (incoming), ...</pre>

warnings:
- general: |-
Changing firewall settings while connected over network can
result in being locked out of the system.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# packages = ufw

ufw allow ssh
ufw default allow incoming
ufw -f enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# packages = ufw

ufw allow ssh
ufw default deny incoming
ufw -f enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# packages = ufw

ufw allow ssh
ufw default reject incoming
ufw -f enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# platform = multi_platform_ubuntu,multi_platform_debian

ufw default deny outgoing
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("Ensure ufw default outgoing policy is deny or reject", rule_title=rule_title) }}}
<criteria>
<criterion comment="DEFAULT_OUTPUT_POLICY is DROP or REJECT in /etc/default/ufw"
test_ref="{{{ rule_id }}}_test_default_output_policy" />
</criteria>
</definition>

<ind:textfilecontent54_test check="all" check_existence="at_least_one_exists"
id="{{{ rule_id }}}_test_default_output_policy" version="1"
comment="Check DEFAULT_OUTPUT_POLICY is DROP or REJECT in /etc/default/ufw">
<ind:object object_ref="{{{ rule_id }}}_obj_default_output_policy"/>
</ind:textfilecontent54_test>

<ind:textfilecontent54_object id="{{{ rule_id }}}_obj_default_output_policy" version="1">
<ind:filepath>/etc/default/ufw</ind:filepath>
<ind:pattern operation="pattern match">^DEFAULT_OUTPUT_POLICY="(DROP|REJECT)"$</ind:pattern>
<ind:instance datatype="int">1</ind:instance>
</ind:textfilecontent54_object>
</def-group>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
documentation_complete: true

title: 'Ensure ufw Default Deny Policy for Outgoing Connections'

description: |-
A default deny policy on outgoing connections ensures that only explicitly
allowed outbound network traffic will be permitted.
Set <tt>DEFAULT_OUTPUT_POLICY</tt> to <tt>DROP</tt> or <tt>REJECT</tt>
in <tt>/etc/default/ufw</tt>.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be great to describe here the exact setting that is supposed to be configured, ie. explain in the text that we want DEFAULT_OUTPUT_POLICY in /etc/default/ufw to be set to DROP or REJECT.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. Updated both ufw_default_incoming_rule and ufw_default_outgoing_rule to explicitly state that DEFAULT_INPUT_POLICY / DEFAULT_OUTPUT_POLICY in /etc/default/ufw must be set to DROP or REJECT

Note: Any port or protocol without an explicit allow before the default
deny will be blocked.

rationale: |-
With a default accept policy the firewall will allow any outgoing packet
that is not configured to be denied. Restricting outgoing traffic reduces
the risk of data exfiltration and limits the impact of a compromised host.

severity: medium

platform: package[ufw]

ocil_clause: 'the default policy for outgoing connections is not set to deny or reject'

ocil: |-
Run the following command and verify that the default policy for outgoing
connections is deny or reject:
<pre># ufw status verbose | grep Default:</pre>
Example output:
<pre>Default: ..., deny (outgoing), ...</pre>

warnings:
- general: |-
Changing firewall settings while connected over network can
result in being locked out of the system.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# packages = ufw

ufw allow ssh
ufw default allow outgoing
ufw -f enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# packages = ufw

ufw allow ssh
ufw default deny outgoing
ufw -f enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# packages = ufw

ufw allow ssh
ufw default reject outgoing
ufw -f enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# platform = multi_platform_ubuntu,multi_platform_debian

ufw default deny routed
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("Ensure ufw default routed policy is disabled or deny", rule_title=rule_title) }}}
<criteria>
<criterion comment="DEFAULT_FORWARD_POLICY is DROP or REJECT in /etc/default/ufw"
test_ref="{{{ rule_id }}}_test_default_forward_policy" />
</criteria>
</definition>

<ind:textfilecontent54_test check="all" check_existence="at_least_one_exists"
id="{{{ rule_id }}}_test_default_forward_policy" version="1"
comment="Check DEFAULT_FORWARD_POLICY is DROP or REJECT in /etc/default/ufw">
<ind:object object_ref="{{{ rule_id }}}_obj_default_forward_policy"/>
</ind:textfilecontent54_test>

<ind:textfilecontent54_object id="{{{ rule_id }}}_obj_default_forward_policy" version="1">
<ind:filepath>/etc/default/ufw</ind:filepath>
<ind:pattern operation="pattern match">^DEFAULT_FORWARD_POLICY="(DROP|REJECT)"$</ind:pattern>
<ind:instance datatype="int">1</ind:instance>
</ind:textfilecontent54_object>
</def-group>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
documentation_complete: true

title: 'Ensure ufw Default Policy for Routed (Forwarded) Traffic is Disabled'

description: |-
The default policy for routed (forwarded) traffic in ufw should be set to
disabled or deny, ensuring that the system does not forward packets between
interfaces unless explicitly configured to do so.

rationale: |-
Unless the system is intended to act as a router, forwarding traffic between
network interfaces should be disabled. Disabling the routed default policy
prevents the system from accidentally or maliciously forwarding traffic.

severity: medium

platform: package[ufw]

ocil_clause: 'the default policy for routed traffic is not set to disabled or deny'

ocil: |-
Run the following command and verify that the default policy for routed
traffic is disabled or deny:
<pre># ufw status verbose | grep Default:</pre>
Example output:
<pre>Default: ..., disabled (routed)</pre>

warnings:
- general: |-
Changing firewall settings while connected over network can
result in being locked out of the system.
Loading