Skip to content

Verify Permissions on /etc/hosts.deny

An XCCDF Rule

Description

To properly set the permissions of /etc/hosts.deny, run the command:
$ sudo chmod 0644 /etc/hosts.deny

Rationale

The /etc/hosts.deny file is used to control access of clients to daemons in the server. Insecure groupownership of this file could allow users to grant clients unrestricted access or no access at all to services in the server.

ID
xccdf_org.ssgproject.content_rule_file_permissions_etc_hosts_deny
Severity
Medium
References
Updated

Remediation Templates

A Shell Script

# Remediation is applicable only in certain platforms
if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then
chmod u-xs,g-xws,o-xwt /etc/hosts.deny

else
    >&2 echo 'Remediation is not applicable, nothing was done'
fi

An Ansible Snippet

- name: Test for existence /etc/hosts.deny
  stat:
    path: /etc/hosts.deny
  register: file_exists
  when: ansible_virtualization_type not in ["docker", "lxc", "openvz", "podman", "container"]
  tags: