Skip to content
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

Add Variable-based CPE and UFW rules for Ubuntu 20.04 STIG #7635

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
638e1be
Add macro for shared variable<->value checks
cipherboy May 11, 2021
d995d24
Add applicability checks against variables
cipherboy May 11, 2021
bfe6cac
Add removed form to complete_ocil_entry_package
cipherboy May 11, 2021
93007f4
Start tracking var_applicability separately
cipherboy May 11, 2021
9c8da6f
Update remediation to understand variable-based applicability
cipherboy May 11, 2021
6139f93
Prevent generation of var_ based CPEs
cipherboy May 12, 2021
1bb6428
Add variable-based CPEs into hand-written OVALs
cipherboy May 14, 2021
f091c67
Update templated OVALs to obey variable-based CPE checks
cipherboy May 14, 2021
f088275
Support variable-based CPE platforms
cipherboy May 20, 2021
7be752e
Add sub-namespaces to oval parsing
cipherboy May 21, 2021
f4934bc
Add pseudo variable-based CPEs land to templates
cipherboy Jul 16, 2021
1aeda0b
Correctly handle negation for pseudo-CPEs
cipherboy May 26, 2021
41da952
Fix variable population
cipherboy May 26, 2021
0635ed0
Add var_firewall_package for selecting which firewall to use
cipherboy May 20, 2021
10d57dc
Add firewall-based CPE variables
cipherboy May 20, 2021
dc2b376
Add OVAL checks for all variable CPEs
cipherboy May 20, 2021
b25f410
Add Uncomplicated Firewall (ufw) group
cipherboy Apr 27, 2021
8c76e05
Add package_ufw_installed for CIS 3.5.1.1
cipherboy Apr 27, 2021
6665385
Add platforms for package_ufw_installed
cipherboy May 20, 2021
3e88930
Add stigid, disa and srg references to package_ufw_installed
dodys Sep 23, 2021
d7c1e69
Add package_ufw_installed to Ubuntu 20.04 STIG profile
dodys Sep 23, 2021
d9545da
Add service_ufw_enabled for CIS 3.5.1.3
cipherboy Apr 27, 2021
8eb3392
Add platforms for service_ufw_enabled
cipherboy May 20, 2021
6f0a9c1
Add stigid, disa and srg to service_ufw_enabled
dodys Sep 23, 2021
a67154f
Add service_ufw_enabled to Ubuntu 20.04 STIG profile
dodys Sep 23, 2021
f95387d
Add rule ufw_rate_limit
dodys Jun 25, 2021
2b2a420
Add ufw_rate_limit to Ubuntu 20.04 STIG profile
dodys Sep 23, 2021
f7327c5
Add rule ufw_only_required_services
dodys Jun 24, 2021
33871dc
Add ufw_only_required_services to Ubuntu 20.04 STIG profile
dodys Sep 23, 2021
db29da6
Fix pep8 issue
dodys Sep 23, 2021
fa91678
Replace populate with bash-populate in build_remediations
dodys Sep 27, 2021
c5b263f
Define default firewall for Ubuntu 20.04 STIG profile
dodys Sep 28, 2021
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
4 changes: 4 additions & 0 deletions build-scripts/cpe_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def main():
for el in defs.findall(".//{%s}definition" % oval_ns):
if el.get("class") != "inventory":
continue
if el.get("id").startswith("var_"):
continue
inventory_defs.append(el)

# Keep the list of 'id' attributes from untranslated inventory def elements
Expand Down Expand Up @@ -145,6 +147,8 @@ def main():
product_cpes = ssg.build_cpe.ProductCPEs(product_yaml)
cpe_list = ssg.build_cpe.CPEList()
for cpe_name in benchmark_cpe_names:
if cpe_name.startswith("var_") or cpe_name.startswith("not_var_"):
continue
cpe_list.add(product_cpes.get_cpe(cpe_name))

cpedict_filename = "ssg-" + product + "-cpe-dictionary.xml"
Expand Down
26 changes: 26 additions & 0 deletions linux_os/guide/system/network/network-ufw/group.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
documentation_complete: true

title: Uncomplicated Firewall (ufw)

description: |-
The Linux kernel in Ubuntu provides a packet filtering system called
netfilter, and the traditional interface for manipulating netfilter are
the iptables suite of commands. iptables provide a complete firewall
solution that is both highly configurable and highly flexible.

Becoming proficient in iptables takes time, and getting started with
netfilter firewalling using only iptables can be a daunting task. As a
result, many frontends for iptables have been created over the years,
each trying to achieve a different result and targeting a different
audience.

The Uncomplicated Firewall (ufw) is a frontend for iptables and is
particularly well-suited for host-based firewalls. ufw provides a
framework for managing netfilter, as well as a command-line interface
for manipulating the firewall. ufw aims to provide an easy to use
interface for people unfamiliar with firewall concepts, while at the
same time simplifies complicated iptables commands to help an
administrator who knows what he or she is doing. ufw is an upstream
for other distributions and graphical frontends.

platform: machine
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
documentation_complete: true

prodtype: ubuntu2004

title: 'Install ufw Package'

description: |-
{{{ describe_package_install(package="ufw") }}}

rationale: |-
<tt>ufw</tt> controls the Linux kernel network packet filtering
code. <tt>ufw</tt> allows system operators to set up firewalls and IP
masquerading, etc.

platforms:
- var_ufw
- machine

severity: medium

references:
cis@ubuntu2004: 3.5.1.1
disa: CCI-002314
srg: SRG-OS-000297-GPOS-00115
stigid@ubuntu2004: UBTU-20-010433

ocil_clause: 'the package is not installed'

ocil: '{{{ ocil_package(package="ufw") }}}'

template:
name: package_installed
vars:
pkgname: ufw
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
documentation_complete: true

title: 'Verify ufw Enabled'

description: |-
{{{ describe_service_enable(service="ufw") }}}

rationale: |-
The ufw service must be enabled and running in order for ufw to protect the system

platforms:
- var_ufw
- machine

severity: medium

references:
cis@ubuntu2004: 3.5.1.3
disa: CCI-002314
srg: SRG-OS-000297-GPOS-00115
stigid@ubuntu2004: UBTU-20-010434

ocil: |-
{{{ ocil_service_enabled(service="ufw") }}}

template:
name: service_enabled
vars:
servicename: ufw

platform: machine
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
documentation_complete: true

prodtype: ubuntu2004

title: 'Only Allow Authorized Network Services in ufw'

description: |-
Check the firewall configuration for any unnecessary or prohibited
functions, ports, protocols, and/or services by running the following
command:
<pre>$ sudo ufw show raw
Chain OUTPUT (policy ACCEPT)
target prot opt sources destination
Chain INPUT (policy ACCEPT 1 packets, 40 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination</pre>

Ask the System Administrator for the site or program PPSM CLSA. Verify
the services allowed by the firewall match the PPSM CLSA.

rationale: |-
To prevent unauthorized connection of devices, unauthorized transfer of
information, or unauthorized tunneling (i.e., embedding of data types
within data types), organizations must disable or restrict unused or
unnecessary physical and logical ports/protocols on information systems.

Operating systems are capable of providing a wide variety of functions
and services. Some of the functions and services provided by default
may not be necessary to support essential organizational operations.
Additionally, it is sometimes convenient to provide multiple services
from a single component (e.g., VPN and IPS); however, doing so
increases risk over limiting the services provided by any one component.

To support the requirements and principles of least functionality, the
operating system must support the organizational requirements, providing
only essential capabilities and limiting the use of ports, protocols,
and/or services to only those required, authorized, and approved to
conduct official business or to address authorized quality of life
issues.

platforms:
- var_ufw
- machine

severity: medium

references:
disa: CCI-000382
srg: SRG-OS-000096-GPOS-00050
stigid@ubuntu2004: UBTU-20-010407

ocil_clause: 'unauthorized network services can be accessed from the network'

ocil: |-
Check the firewall configuration for any unnecessary or prohibited
functions, ports, protocols, and/or services by running the following
command:
<pre>$ sudo ufw show raw</pre>

Ask the System Administrator for the site or program PPSM CLSA. Verify
the services allowed by the firewall match the PPSM CLSA.

Add all ports, protocols, or services allowed by the PPSM CLSA by using
the following command:
<pre>$ sudo ufw allow "direction" "port/protocol/service"</pre>
where the direction is "in" or "out" and the port is the one
corresponding to the protocol or service allowed.

To deny access to ports, protocols, or services, use:
<pre>$ sudo ufw deny "direction" "port/protocol/service"</pre>
52 changes: 52 additions & 0 deletions linux_os/guide/system/network/network-ufw/ufw_rate_limit/rule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
documentation_complete: true

prodtype: ubuntu2004

title: 'ufw Must rate-limit network interfaces'

description: |-
The operating system must configure the uncomplicated firewall to
rate-limit impacted network interfaces.

rationale: |-
This requirement addresses the configuration of the operating system to
mitigate the impact of DoS attacks that have occurred or are ongoing on
system availability. For each system, known and potential DoS attacks
must be identified and solutions for each type implemented. A variety
of technologies exist to limit or, in some cases, eliminate the effects
of DoS attacks (e.g., limiting processes or establishing memory
partitions). Employing increased capacity and bandwidth, combined with
service redundancy, may reduce the susceptibility to some DoS attacks.

platforms:
- var_ufw
- machine

severity: medium

references:
disa: CCI-002385
srg: SRG-OS-000420-GPOS-00186
stigid@ubuntu2004: UBTU-20-010446

ocil_clause: 'network interface not rate-limit'

ocil: |-
Check all the services listening to the ports with the following
command:
<pre>$ sudo ss -l46ut
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 [::]:ssh [::]:*</pre>

For each entry, verify that the ufw is configured to rate limit the
service ports with the following command:
<pre>$ sudo ufw status</pre>

If any port with a state of "LISTEN" is not marked with the "LIMIT"
action, run the following command, replacing "service" with the
service that needs to be rate limited:
<pre>$ sudo ufw limit "service"</pre>

Rate-limiting can also be done on an interface. An example of adding
a rate-limit on the eth0 interface follows:
<pre>$ sudo ufw limit in on eth0</pre>
16 changes: 16 additions & 0 deletions linux_os/guide/system/network/var_firewall_package.var
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
documentation_complete: true

title: 'Selected firewall utility'

description: 'Which firewalling utility (iptables, nftables, ufw, or firewalld) should be used.'

type: string

interactive: true

options:
default: iptables
iptables: iptables
nftables: nftables
ufw: ufw
firewalld: firewalld
5 changes: 5 additions & 0 deletions products/ubuntu2004/profiles/stig.profile
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ selections:
- package_rsh-server_removed

# UBTU-20-010407 The Ubuntu operating system must be configured to prohibit or restrict the use of functions, ports, protocols, and/or services, as defined in the PPSM CAL and vulnerability assessments.
- ufw_only_required_services

# UBTU-20-010408 The Ubuntu operating system must prevent direct login into the root account.
- prevent_direct_root_logins
Expand Down Expand Up @@ -513,8 +514,11 @@ selections:
- service_rsyslog_enabled

# UBTU-20-010433 The Ubuntu operating system must have an application firewall installed in order to control remote access methods.
- var_firewall_package=ufw
- package_ufw_installed

# UBTU-20-010434 The Ubuntu operating system must enable and run the uncomplicated firewall(ufw).
- service_ufw_enabled

# UBTU-20-010435 The Ubuntu operating system must, for networked systems, compare internal information system clocks at least every 24 hours with a server which is synchronized to one of the redundant United States Naval Observatory (USNO) time servers, or a time server designated for the appropriate DoD network (NIPRNet/SIPRNet), and/or the Global Positioning System (GPS).
- var_time_service_set_maxpoll=36_hours
Expand Down Expand Up @@ -548,6 +552,7 @@ selections:
# UBTU-20-010445 Ubuntu operating system must implement cryptographic mechanisms to prevent unauthorized disclosure of all information at rest.

# UBTU-20-010446 The Ubuntu operating system must configure the uncomplicated firewall to rate-limit impacted network interfaces.
- ufw_rate_limit

# UBTU-20-010447 The Ubuntu operating system must implement non-executable data to protect its memory from unauthorized code execution.
- bios_enable_execution_restrictions
Expand Down
82 changes: 82 additions & 0 deletions shared/applicability/variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
cpes:
- var_chrony:
name: "cpe:/a:var_chrony"
title: "Chrony is selected"
check_id: var_time_synchronization_daemon_is_chrony
variable: var_time_synchronization_daemon
value: chrony
negated: false

- not_var_chrony:
name: "cpe:/a:not_var_chrony"
title: "Chrony is not selected"
check_id: var_time_synchronization_daemon_is_not_chrony
variable: var_time_synchronization_daemon
value: chrony
negated: true

- var_ntp:
name: "cpe:/a:var_ntp"
title: "ntp is selected"
check_id: var_time_synchronization_daemon_is_ntp
variable: var_time_synchronization_daemon
value: ntp
negated: false

- not_var_ntp:
name: "cpe:/a:not_var_ntp"
title: "ntp is not selected"
check_id: var_time_synchronization_daemon_is_not_ntp
variable: var_time_synchronization_daemon
value: ntp
negated: true

# The following variables are for var_firewall_package, choosing between
# iptables, nftables, and ufw.
- var_iptables:
name: "cpe:/a:var_iptables"
title: "iptables is selected"
check_id: var_firewall_package_is_iptables
variable: var_firewall_package
value: iptables
negated: false

- not_var_iptables:
name: "cpe:/a:not_var_iptables"
title: "iptables is not selected"
check_id: var_firewall_package_is_not_iptables
variable: var_firewall_package
value: iptables
negated: true

- var_nftables:
name: "cpe:/a:var_nftables"
title: "nftables is selected"
check_id: var_firewall_package_is_nftables
variable: var_firewall_package
value: nftables
negated: false

- not_var_nftables:
name: "cpe:/a:not_var_nftables"
title: "nftables is not selected"
check_id: var_firewall_package_is_not_nftables
variable: var_firewall_package
value: nftables
negated: true

- var_ufw:
name: "cpe:/a:var_ufw"
title: "ufw is selected"
check_id: var_firewall_package_is_ufw
variable: var_firewall_package
value: ufw
negated: false

- not_var_ufw:
name: "cpe:/a:not_var_ufw"
title: "ufw is not selected"
check_id: var_firewall_package_is_not_ufw
variable: var_firewall_package
value: ufw
negated: true
1 change: 1 addition & 0 deletions shared/checks/oval/var_firewall_package_is_iptables.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{{ oval_check_var_is_value("var_firewall_package", "iptables") }}}
1 change: 1 addition & 0 deletions shared/checks/oval/var_firewall_package_is_nftables.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{{ oval_check_var_is_value("var_firewall_package", "nftables") }}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{{ oval_check_var_is_value("var_firewall_package", "iptables", negate=true) }}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{{ oval_check_var_is_value("var_firewall_package", "nftables", negate=true) }}}
1 change: 1 addition & 0 deletions shared/checks/oval/var_firewall_package_is_not_ufw.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{{ oval_check_var_is_value("var_firewall_package", "ufw", negate=true) }}}
1 change: 1 addition & 0 deletions shared/checks/oval/var_firewall_package_is_ufw.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{{ oval_check_var_is_value("var_firewall_package", "ufw") }}}
8 changes: 5 additions & 3 deletions shared/macros-highlevel.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ substituting the correct package management software.

:param package: Name of package
:type package: str
:param removed: Boolean condition for ocil_clause
:type removed: bool

#}}
{{% macro complete_ocil_entry_package(package) -%}}
{{% macro complete_ocil_entry_package(package, removed=False) -%}}
{{% if pkg_system is defined %}}
{{%- if pkg_system == "rpm" %}}
{{{ rpm_complete_ocil_entry_package(package) }}}
{{{ rpm_complete_ocil_entry_package(package, removed=removed) }}}
{{%- elif pkg_system == "dpkg" %}}
{{{ dpkg_complete_ocil_entry_package(package) }}}
{{{ dpkg_complete_ocil_entry_package(package, removed=removed) }}}
{{%- else -%}}
ocil: |-
JINJA MACRO ERROR - Unknown package system '{{{ pkg_system }}}'.
Expand Down
Loading