Към съдържанието

File system and permissions

ANSSI-BP-028 v2.0 reference: R50 to R57 (M/I levels, R for some points).

This section covers the review of file system permissions and the protection of configuration files and sensitive directories.

R11. Control of permissions and sensitive files

Applies to: Mediation Controller · Edge Gateway

Files or directories with overly permissive permissions can allow a local user, or an attacker who has obtained limited access, to elevate their privileges, to modify sensitive files or to drop malicious code.

Warning!

This recommendation must be applied after installing CyberElements Bastion and after validating that the solution works correctly.

Files and directories with 777-type permissions:

1
2
find / -xdev -type f -perm 0777 2>/dev/null
find / -xdev -type d -perm 0777 2>/dev/null

Files and directories that all users can modify:

1
2
find / -xdev -type f -perm -0002 2>/dev/null
find / -xdev -type d -perm -0002 2>/dev/null

Some directories (/tmp, /var/tmp) can legitimately be writable by several users:

1
find / -xdev -type d -perm -0002 ! -perm -1000 2>/dev/null

Files with no known owner or group, which may reveal account deletions or configuration anomalies:

1
find / -xdev \( -nouser -o -nogroup \) 2>/dev/null

Files carrying the SUID or SGID bits must be given particular review, since they allow a program to be run with the privileges of the owner or of the group of the file:

1
find / -xdev -type f \( -perm -4000 -o -perm -2000 \) -ls 2>/dev/null

Any unexpected SUID or SGID file found must be analysed. Legitimate system binaries must not be modified without prior validation: an incorrect fix can make the system unstable or prevent some administration functions. The results should be compared with a known baseline validated for the role of the server concerned.

R12. Hardening of configuration files and sensitive directories

Applies to: Mediation Controller · Edge Gateway

Some files and directories of the system contain sensitive information or make it possible to change the behaviour of the server. Access to them must be limited to the users and groups with a legitimate need. The values below are the target permissions recommended in the context of CyberElements Bastion.

Path Owner:Group Octal mode Recommendation
/etc/passwd root:root 0644 Readable by everyone; modification reserved for root.
/etc/shadow root:shadow 0640 Access limited to root and to the shadow group.
/etc/group root:root 0644 Readable by everyone; modification reserved for root.
/etc/gshadow root:shadow 0640 Access limited to root and to the shadow group.
/etc/sudoers root:root 0440 Editing only through visudo.
/etc/sudoers.d/* root:root 0440 Each file must be protected and checked individually.
/etc/ssh/sshd_config root:root 0600 SSH configuration modifiable only by root.
/etc/ssh/ssh_host_*_key root:root 0600 SSH private keys accessible only to root.
/root root:root 0700 Directory accessible only to root.
/root/.ssh root:root 0700 SSH directory accessible only to root.
/etc/crontab root:root 0644 Modification reserved for root.
/boot/System.map* root:root 0600 Not readable by unprivileged accounts.
/boot Depending on the system To be validated Keep rights compatible with Debian and with the boot mechanism.
/var/log Depending on the service To be validated Do not impose a global mode; the rights depend on the services and on monitoring.

Information

The modes are shown with four digits (for example 0644, 0600 or 0700) so as to make the absence of special bits explicit. For the common permissions shown here, chmod also accepts the form without a leading zero (644, 600, 700).

The effective permissions can be checked with the stat command, which directly displays the octal mode, the symbolic permissions, the owner and the group:

1
2
3
4
stat -c '%a %A %U:%G %n' \
/etc/passwd /etc/shadow /etc/group /etc/gshadow \
/etc/sudoers /etc/ssh/sshd_config \
/root /root/.ssh /etc/crontab /boot/System.map*

For information, the following commands restore the target permissions of the files explicitly identified above:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Account management files
chown root:root /etc/passwd /etc/group
chmod 0644 /etc/passwd /etc/group
chown root:shadow /etc/shadow /etc/gshadow
chmod 0640 /etc/shadow /etc/gshadow
# sudo configuration
chown root:root /etc/sudoers
chmod 0440 /etc/sudoers
find /etc/sudoers.d/ -maxdepth 1 -type f -exec chown root:root {} \; -exec chmod 0440 {} \;
# SSH configuration
chown root:root /etc/ssh/sshd_config
chmod 0600 /etc/ssh/sshd_config
chown root:root /etc/ssh/ssh_host_*_key
chmod 0600 /etc/ssh/ssh_host_*_key
# root account
chown root:root /root /root/.ssh
chmod 0700 /root /root/.ssh
# Scheduled tasks and kernel symbols
chown root:root /etc/crontab
chmod 0644 /etc/crontab
chown root:root /boot/System.map*
chmod 0600 /boot/System.map*

Information

The restriction on /boot/System.map* answers the control on the protection of kernel symbols: that file exposes the mapping between kernel symbols and addresses. Its being read by an unprivileged account can provide information useful in exploiting kernel vulnerabilities; this measure is consistent with kernel.kptr_restrict, configured in recommendation R13.

Log directories and cron directories must not be given a generic recursive chmod. Their permissions may depend on the services, on the Debian packages installed and on monitoring needs. For scheduled tasks, it is preferable to look for the files abnormally modifiable by the group or by other users:

1
2
3
find /etc/cron.d /etc/cron.daily /etc/cron.hourly \
/etc/cron.weekly /etc/cron.monthly \
-type f -perm /022 -ls 2>/dev/null

Warning!

The values shown are the target permissions recommended for the files explicitly identified. The rights of directories or files managed by Debian services and packages must not be modified globally or recursively. Before any correction, check the owner, the group, any ACLs and the Debian package the file comes from (dpkg -S <file_path>). An incorrect change can disrupt a service or prevent it from starting.

The permissions of sensitive files should be checked regularly, notably after an initial installation, a major update, a backup restore, a maintenance operation or a security incident.