From 26c7be0d244f369db204bcc5ed367b6ffa3c7411 Mon Sep 17 00:00:00 2001 From: YuQing Date: Wed, 1 Jun 2022 16:05:35 +0800 Subject: [PATCH] benchmarks/access-and-control: add items from 1.1 to 1.40 Fixes: #I581GC Signed-off-by: YuQing --- .../1.1-ensure-cron-daemon-is-enabled.md | 38 ++++++ .../1.10-ensure-ssh-access-is-limited.md | 66 +++++++++++ ...h-private-host-key-files-are-configured.md | 62 ++++++++++ ...sh-public-host-key-files-are-configured.md | 50 ++++++++ ...1.13-ensure-ssh-loglevel-is-appropriate.md | 55 +++++++++ ...re-ssh-maxauthtries-is-set-to-4-or-less.md | 42 +++++++ ...1.15-ensure-ssh-ignorerhosts-is-enabled.md | 44 +++++++ ...ssh-hostbasedauthentication-is-disabled.md | 42 +++++++ .../1.17-ensure-ssh-root-login-is-disabled.md | 42 +++++++ ...re-ssh-permitemptypasswords-is-disabled.md | 40 +++++++ ...e-ssh-permituserenvironment-is-disabled.md | 39 +++++++ ...rmissions-on-etc-crontab-are-configured.md | 39 +++++++ ...ssh-idle-timeout-interval-is-configured.md | 72 ++++++++++++ ...ngracetime-is-set-to-one-minute-or-less.md | 42 +++++++ ...ensure-ssh-warning-banner-is-configured.md | 41 +++++++ .../1.23-ensure-ssh-pam-is-enabled.md | 45 +++++++ ...24-ensure-ssh-maxstartups-is-configured.md | 52 +++++++++ ...re-ssh-maxsessions-is-set-to-10-or-less.md | 42 +++++++ ...m-wide-crypto-policy-is-not-over-ridden.md | 44 +++++++ ...rd-creation-requirements-are-configured.md | 91 +++++++++++++++ ...-failed-password-attempts-is-configured.md | 56 +++++++++ .../1.29-ensure-password-reuse-is-limited.md | 50 ++++++++ ...sions-on-etc-cron.hourly-are-configured.md | 39 +++++++ ...e-password-hashing-algorithm-is-sha-512.md | 39 +++++++ ...password-expiration-is-365-days-or-less.md | 53 +++++++++ ...s-between-password-changes-is-7-or-more.md | 55 +++++++++ ...rd-expiration-warning-days-is-7-or-more.md | 55 +++++++++ ...active-password-lock-is-30-days-or-less.md | 53 +++++++++ ...ast-password-change-date-is-in-the-past.md | 41 +++++++ ...1.36-ensure-system-accounts-are-secured.md | 53 +++++++++ ...er-shell-timeout-is-900-seconds-or-less.md | 86 ++++++++++++++ ...ult-group-for-the-root-account-is-gid-0.md | 35 ++++++ ...t-user-umask-is-027-or-more-restrictive.md | 110 ++++++++++++++++++ ...ssions-on-etc-cron.daily-are-configured.md | 39 +++++++ ...-access-to-the-su-command-is-restricted.md | 53 +++++++++ ...sions-on-etc-cron.weekly-are-configured.md | 39 +++++++ ...ions-on-etc-cron.monthly-are-configured.md | 39 +++++++ ...ermissions-on-etc-cron.d-are-configured.md | 39 +++++++ ...-cron-is-restricted-to-authorized-users.md | 67 +++++++++++ ...s-on-etc-ssh-sshd_config-are-configured.md | 39 +++++++ 40 files changed, 2028 insertions(+) create mode 100644 benchmarks/access-and-control/1.1-ensure-cron-daemon-is-enabled.md create mode 100644 benchmarks/access-and-control/1.10-ensure-ssh-access-is-limited.md create mode 100644 benchmarks/access-and-control/1.11-ensure-permissions-on-ssh-private-host-key-files-are-configured.md create mode 100644 benchmarks/access-and-control/1.12-ensure-permissions-on-ssh-public-host-key-files-are-configured.md create mode 100644 benchmarks/access-and-control/1.13-ensure-ssh-loglevel-is-appropriate.md create mode 100644 benchmarks/access-and-control/1.14-ensure-ssh-maxauthtries-is-set-to-4-or-less.md create mode 100644 benchmarks/access-and-control/1.15-ensure-ssh-ignorerhosts-is-enabled.md create mode 100644 benchmarks/access-and-control/1.16-ensure-ssh-hostbasedauthentication-is-disabled.md create mode 100644 benchmarks/access-and-control/1.17-ensure-ssh-root-login-is-disabled.md create mode 100644 benchmarks/access-and-control/1.18-ensure-ssh-permitemptypasswords-is-disabled.md create mode 100644 benchmarks/access-and-control/1.19-ensure-ssh-permituserenvironment-is-disabled.md create mode 100644 benchmarks/access-and-control/1.2-ensure-permissions-on-etc-crontab-are-configured.md create mode 100644 benchmarks/access-and-control/1.20-ensure-ssh-idle-timeout-interval-is-configured.md create mode 100644 benchmarks/access-and-control/1.21-ensure-ssh-logingracetime-is-set-to-one-minute-or-less.md create mode 100644 benchmarks/access-and-control/1.22-ensure-ssh-warning-banner-is-configured.md create mode 100644 benchmarks/access-and-control/1.23-ensure-ssh-pam-is-enabled.md create mode 100644 benchmarks/access-and-control/1.24-ensure-ssh-maxstartups-is-configured.md create mode 100644 benchmarks/access-and-control/1.25-ensure-ssh-maxsessions-is-set-to-10-or-less.md create mode 100644 benchmarks/access-and-control/1.26-ensure-system-wide-crypto-policy-is-not-over-ridden.md create mode 100644 benchmarks/access-and-control/1.27-ensure-password-creation-requirements-are-configured.md create mode 100644 benchmarks/access-and-control/1.28-ensure-lockout-for-failed-password-attempts-is-configured.md create mode 100644 benchmarks/access-and-control/1.29-ensure-password-reuse-is-limited.md create mode 100644 benchmarks/access-and-control/1.3-ensure-permissions-on-etc-cron.hourly-are-configured.md create mode 100644 benchmarks/access-and-control/1.30-ensure-password-hashing-algorithm-is-sha-512.md create mode 100644 benchmarks/access-and-control/1.31-ensure-password-expiration-is-365-days-or-less.md create mode 100644 benchmarks/access-and-control/1.32-ensure-minimum-days-between-password-changes-is-7-or-more.md create mode 100644 benchmarks/access-and-control/1.33-ensure-password-expiration-warning-days-is-7-or-more.md create mode 100644 benchmarks/access-and-control/1.34-ensure-inactive-password-lock-is-30-days-or-less.md create mode 100644 benchmarks/access-and-control/1.35-ensure-all-users-last-password-change-date-is-in-the-past.md create mode 100644 benchmarks/access-and-control/1.36-ensure-system-accounts-are-secured.md create mode 100644 benchmarks/access-and-control/1.37-ensure-default-user-shell-timeout-is-900-seconds-or-less.md create mode 100644 benchmarks/access-and-control/1.38-ensure-default-group-for-the-root-account-is-gid-0.md create mode 100644 benchmarks/access-and-control/1.39-ensure-default-user-umask-is-027-or-more-restrictive.md create mode 100644 benchmarks/access-and-control/1.4-ensure-permissions-on-etc-cron.daily-are-configured.md create mode 100644 benchmarks/access-and-control/1.40-ensure-access-to-the-su-command-is-restricted.md create mode 100644 benchmarks/access-and-control/1.5-ensure-permissions-on-etc-cron.weekly-are-configured.md create mode 100644 benchmarks/access-and-control/1.6-ensure-permissions-on-etc-cron.monthly-are-configured.md create mode 100644 benchmarks/access-and-control/1.7-ensure-permissions-on-etc-cron.d-are-configured.md create mode 100644 benchmarks/access-and-control/1.8-ensure-at-cron-is-restricted-to-authorized-users.md create mode 100644 benchmarks/access-and-control/1.9-ensure-permissions-on-etc-ssh-sshd_config-are-configured.md diff --git a/benchmarks/access-and-control/1.1-ensure-cron-daemon-is-enabled.md b/benchmarks/access-and-control/1.1-ensure-cron-daemon-is-enabled.md new file mode 100644 index 0000000..756aab9 --- /dev/null +++ b/benchmarks/access-and-control/1.1-ensure-cron-daemon-is-enabled.md @@ -0,0 +1,38 @@ +# 1.1 确保 cron 守护进程正常启用 + +## 安全等级 + +Level 1 + +## 描述 + +cron 守护进程用于在系统上执行批处理作业。 + +即使操作系统目前可能没有需要运行的用户作业,也会有系统作业需要运行,其中就可能包括安全监控等重要作业,而 cron 守护进程就是用来执行这些作业的。 + +## 修复建议 + +目标:确保 cron 守护进程正常启用。 + +1. 执行以下命令来启用 cron 进程: + +```shell +# systemctl --now enable crond +``` + +## 扫描检测 + +确保 cron 守护进程正常启用。 + +1. 执行以下命令来确定 cron 守护进程是否正常启用: + +```shell +# systemctl is-enabled crond +enabled +``` + +如结果为`enabled`,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.10-ensure-ssh-access-is-limited.md b/benchmarks/access-and-control/1.10-ensure-ssh-access-is-limited.md new file mode 100644 index 0000000..427f990 --- /dev/null +++ b/benchmarks/access-and-control/1.10-ensure-ssh-access-is-limited.md @@ -0,0 +1,66 @@ +# 1.10 确保 SSH 远程访问权限受到管控 + +## 安全等级 + +Level 2 + +## 描述 + +通过对 SSH 远程访问的限制,可确保只有已授权的用户才可访问系统,对系统进行操作和管理。 + +对 SSH 远程访问的限制,可通过更新`/etc/ssh/sshd_config`配置文件,添加以下参数来实现: + +* AllowUsers: + * `AllowUsers`参数的作用是:允许特定用户通过`SSH`进行远程访问。该列表由空格分隔的用户名组成(不能识别UID)。可使用`user@host`的形式:仅允许某用户通过特定的主机登录,对权限进行更精细的限制。 + +* AllowGroups: + * `AllowGroups`参数的作用是:允许特定用户组通过`SSH`进行远程访问。该列表由空格分隔的组名组成(不能识别GID)。 + +* DenyUsers: + * `DenyUsers`参数的作用是:禁止特定用户通过`SSH`进行远程访问。该列表由空格分隔的用户名组成(不能识别UID)。可使用`user@host`的形式:仅禁止某用户通过特定的主机登录,对权限进行更精细的限制。 + +* DenyGroups: + * `DenyGroups`参数的作用是:禁止特定用户组通过`SSH`进行远程访问。该列表由空格分隔的组名组成(不能识别GID)。 + +至少利用以上一个参数,对 SSH 远程访问进行限制。 + +## 修复建议 + +目标:更新`/etc/ssh/sshd_config`配置文件,对 SSH 远程访问权限进行限制。 + +1. 更新`/etc/ssh/sshd_config`配置文件,至少添加以下4个权限控制参数中的1个或更多: + +```shell +AllowUsers +AllowGroups +DenyUsers +DenyGroups +``` + +``、``、``、``为使用空格分隔的自定义用户名列表或组列表。 + +## 扫描检测 + +确保`/etc/ssh/sshd_config`的权限配置正确 + +1. 执行以下命令,并查看输出结果: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi '^\h*(allow|deny)(users|groups)\h+\H+(\h+.*)?$' +# grep -Pi '^\h*(allow|deny)(users|groups)\h+\H+(\h+.*)?$' /etc/ssh/sshd_config +``` + +2.执行第`1`步的两条命令的输出结果至少匹配以下4条结果中的一条: + +```shell +allowusers +allowgroups +denyusers +denygroups +``` + +``、``、``、``为使用空格分隔的自定义用户名列表或组列表。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.11-ensure-permissions-on-ssh-private-host-key-files-are-configured.md b/benchmarks/access-and-control/1.11-ensure-permissions-on-ssh-private-host-key-files-are-configured.md new file mode 100644 index 0000000..0c32ce3 --- /dev/null +++ b/benchmarks/access-and-control/1.11-ensure-permissions-on-ssh-private-host-key-files-are-configured.md @@ -0,0 +1,62 @@ +# 1.11 确保 SSH 私钥文件的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 私钥是 SSH 公钥认证中使用的两个文件之一。在这种认证方式中,只有与公钥相对应匹配的私钥才能够认证成功,所以私钥是重要身份证明。如果一个未授权用户取得了某主机的 SSH 私钥,那么他就可以将身份伪装成该主机。综上,私钥的存储和处理是非常重要的,且不应当被复制为副本。 + +## 修复建议 + +目标:正确配置 SSH 私钥文件的权限。 + +1. 执行以下命令,配置 SSH 私钥文件的权限、所有者、所属组: + +```shell +# find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec chmod u-x,g-wx,o-rwx {} \; +# find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec chown root:ssh_keys {} \; +``` + +## 扫描检测 + +确保 SSH 私钥文件的权限配置正确 + +1. 执行以下命令,检查 SSH 私钥文件的权限、所有者、所属组的配置是否符合要求: + +```shell +# find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec stat {} \; +``` + +* 执行结果: + +```shell + File: /etc/ssh/ssh_host_ed25519_key + Size: 399 Blocks: 8 IO Block: 4096 regular file +Device: fd01h/64769d Inode: 787244 Links: 1 +Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root) +Access: 2022-05-26 23:37:16.614347951 +0800 +Modify: 2022-05-25 16:38:17.255207117 +0800 +Change: 2022-05-25 16:38:17.255207117 +0800 + Birth: 2022-05-25 16:38:17.255207117 +0800 + File: /etc/ssh/ssh_host_rsa_key + Size: 1679 Blocks: 8 IO Block: 4096 regular file +Device: ca01h/51713d Inode: 8628138 Links: 1 +Access: (0640/-rw-r-----) Uid: ( 0/ root) Gid: ( 993/ssh_keys) +Access: 2018-10-22 18:24:56.861750616 +0000 +Modify: 2018-10-22 18:24:56.861750616 +0000 +Change: 2018-10-22 18:24:56.873750616 +0000 + Birth: - +``` + +如果输出结果中: + +* 如果SSH 私钥文件的所属组(`Gid`)为`ssh_keys`,其权限(Access)应为`0640`或更小,`Uid`应为`0/root`。 +* 如果SSH 私钥文件的所属组(`Gid`)为`root`,其权限(Access)应为`0600`或更小,`Uid`应为`0/root`。 + +根据 SSH 私钥文件所属组(`Gid`)的不同,分别对其权限(Access)和`Uid`进行检查。如均满足条件,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.12-ensure-permissions-on-ssh-public-host-key-files-are-configured.md b/benchmarks/access-and-control/1.12-ensure-permissions-on-ssh-public-host-key-files-are-configured.md new file mode 100644 index 0000000..94750f1 --- /dev/null +++ b/benchmarks/access-and-control/1.12-ensure-permissions-on-ssh-public-host-key-files-are-configured.md @@ -0,0 +1,50 @@ +# 1.12 确保 SSH 公钥文件的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 公钥是 SSH 公钥认证中使用的两个文件之一。在这种认证方式中,公钥是用来验证对应私钥生成的数字签名的密钥,只有与私钥相对应的公钥才能够成功认证。如果公钥文件被一个未经授权的用户修改,SSH 服务很可能会受到影响。 + +## 修复建议 + +目标:正确配置 SSH 公钥文件的权限。 + +1. 执行以下命令,配置 SSH 公钥文件的权限、所有者、所属组: + +```shell +# find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec chmod u-x,go-wx {} \; +# find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec chown root:root {} \; +``` + +## 扫描检测 + +确保 SSH 公钥文件的权限配置正确 + +1. 执行以下命令,检查 SSH 公钥文件的权限、所有者、所属组的配置是否符合要求: + +```shell +# find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec stat {} \; +``` + +2. 执行结果: + +```shell + File: /etc/ssh/ssh_host_ed25519_key.pub + Size: 93 Blocks: 8 IO Block: 4096 regular file +Device: fd01h/64769d Inode: 787245 Links: 1 +Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) +Access: 2022-05-26 23:37:16.614347951 +0800 +Modify: 2022-05-25 16:38:17.255207117 +0800 +Change: 2022-05-25 16:38:17.255207117 +0800 + Birth: 2022-05-25 16:38:17.255207117 +0800 + +``` + +如果输出结果:`Access`中权限为`0644`或更低、`group`与`other`没有可执行(`x`)与可写(`w`)权限,且`Uid`与`Gid`均为`0/root`,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.13-ensure-ssh-loglevel-is-appropriate.md b/benchmarks/access-and-control/1.13-ensure-ssh-loglevel-is-appropriate.md new file mode 100644 index 0000000..619257d --- /dev/null +++ b/benchmarks/access-and-control/1.13-ensure-ssh-loglevel-is-appropriate.md @@ -0,0 +1,55 @@ +# 1.13 确保 SSH 的 LogLevel 配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的`LogLevel`参数,可定义 SSH 日志信息的冗余级别。 + +常用的级别有: + +* INFO --> INFO 级别是默认级别,只记录 SSH 的用户登录行为。如登录记录、注销记录等。 这些日志具有长期价值。 +* VERBOSE --> VERBOSE 级别除了记录 SSH 的用户登录行为之外,还对所有用户登录的 SSH 密钥的密钥指纹进行了记录。 +* DEBUG --> DEBUG 级别主要在开发过程中用于交互式调查的日志。 这些日志主要包含对调试有用的信息,且没有长期价值。除开发调试外,不推荐使用 DEBUG 级别,因为其提供的数据太多,会对重要的安全信息造成干扰。 + +推荐使用 INFO 或 VERBOSE 作为生产环境中的日志级别。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`LogLevel`参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`LogLevel`参数,或添加以下代码,对`LogLevel`参数进行配置: + +```shell +LogLevel VERBOSE +``` + +OR + +```shell +LogLevel INFO +``` + +* 以上代码为二选一,可根据使用环境自行选择。 +* 如`/etc/ssh/sshd_config`配置文件没有`LogLevel`参数或为:`#LogLevel INFO`(注释状态),可不进行操作,SSH 默认日志级别即为`INFO`级别。 + +## 扫描检测 + +确保`SSH`的`LogLevel`配置正确。 + +1. 执行以下命令,验证`SSH`的`LogLevel`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep loglevel +loglevel VERBOSE or loglevel INFO +# grep -i 'loglevel' /etc/ssh/sshd_config | grep -Evi '(VERBOSE|INFO)' +Nothing should be returned +``` + +如果第一条命令执行后返回`VERBOSE`或`INFO`中任意一个结果,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.14-ensure-ssh-maxauthtries-is-set-to-4-or-less.md b/benchmarks/access-and-control/1.14-ensure-ssh-maxauthtries-is-set-to-4-or-less.md new file mode 100644 index 0000000..a45505b --- /dev/null +++ b/benchmarks/access-and-control/1.14-ensure-ssh-maxauthtries-is-set-to-4-or-less.md @@ -0,0 +1,42 @@ +# 1.14 确保 SSH 的 MaxAuthTries 设置为 4 或更小 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的 MaxAuthTries 参数规定了每个会话连接所允许的最大认证尝试次数。当登录失败次数达到一半时,错误信息将被写入 syslog 文件,记录登录失败信息。 + +将 MaxAuthTries 参数设置为一个较低的数字,可最大限度地降低对 SSH 服务器暴力攻击的成功率。推荐设置为 4 或更小。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`MaxAuthTries `参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`MaxAuthTries`参数,或添加以下代码,对`MaxAuthTries `参数进行配置: + +```shell +MaxAuthTries 4 +``` + +* `MaxAuthTries`参数默认为`6`,建议配置为`4`或更小。 + +## 扫描检测 + +确保`SSH`的`MaxAuthTries`配置正确。 + +1. 执行以下命令,验证`SSH`的`MaxAuthTries`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep maxauthtries +maxauthtries 4 +# grep -Ei '^\s*maxauthtries\s+([5-9]|[1-9][0-9]+)' /etc/ssh/sshd_config +Nothing is returned +``` + +如果第一条命令执行后返回`4`或更小的值,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.15-ensure-ssh-ignorerhosts-is-enabled.md b/benchmarks/access-and-control/1.15-ensure-ssh-ignorerhosts-is-enabled.md new file mode 100644 index 0000000..01d6195 --- /dev/null +++ b/benchmarks/access-and-control/1.15-ensure-ssh-ignorerhosts-is-enabled.md @@ -0,0 +1,44 @@ +# 1.15 确保 SSH IgnoreRhosts 参数正确配置 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的 IgnoreRhosts 参数指定 .rhosts 和 .shosts 文件不被用于 RhostsRSAAuthentication 或 Host-basedAuthentication。 + +* `.rhosts`、`.shosts`文件是一种控制系统间信任的关系的方法,如果一个系统信任另一个系统,则这个系统不需要密码就允许来自受信认系统的登录。这是一个老旧的配置,应当在SSH配置中明确禁用。 + +IgnoreRhosts 参数的正确设定,可强制要求 SSH 在登录时必须使用密码进行验证,提高 SSH 登录验证的安全性。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`IgnoreRhosts `参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`IgnoreRhosts`参数,或添加以下代码,对`IgnoreRhosts `参数进行配置: + +```shell +IgnoreRhosts yes +``` + +* `IgnoreRhosts`参数默认即为`yes`,如已正确配置,可不用修改。 + +## 扫描检测 + +确保 SSH IgnoreRhosts 参数正确配置。 + +1. 执行以下命令,验证`SSH`的`IgnoreRhosts`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep ignorerhosts +ignorerhosts yes +# grep -Ei '^\s*ignorerhosts\s+no\b' /etc/ssh/sshd_config +Nothing is returned +``` + +如果第一条命令执行后返回`yes`,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.16-ensure-ssh-hostbasedauthentication-is-disabled.md b/benchmarks/access-and-control/1.16-ensure-ssh-hostbasedauthentication-is-disabled.md new file mode 100644 index 0000000..ed552fd --- /dev/null +++ b/benchmarks/access-and-control/1.16-ensure-ssh-hostbasedauthentication-is-disabled.md @@ -0,0 +1,42 @@ +# 1.16 确保 SSH HostbasedAuthentication 参数正确配置 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的`HostbasedAuthentication`参数指定了是否允许通过受信任的主机、`.rhosts`文件内的用户、或`/etc/hosts.equiv`进行身份认证。这个选项只适用于 SSH-2 版本。 + +即使在`/etc/pam.conf`配置文件中禁用了对`.rhosts`文件的支持,`.rhosts`文件也是无效的,也仍然需要在 SSH 中禁用`.rhosts`文件,以提供额外的保护能力。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`HostbasedAuthentication`参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`HostbasedAuthentication`参数,或添加以下代码,对`HostbasedAuthentication`参数进行配置: + +```shell +HostbasedAuthentication no +``` + +* `HostbasedAuthentication`参数默认即为`no`,如已正确配置,可不用修改。 + +## 扫描检测 + +确保 SSH HostbasedAuthentication 参数正确配置。 + +1. 执行以下命令,验证`SSH`的`HostbasedAuthentication`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep hostbasedauthentication +hostbasedauthentication no +# grep -Ei '^\s*HostbasedAuthentication\s+yes' /etc/ssh/sshd_config +Nothing is returned +``` + +如果第一条命令执行后返回`no`,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.17-ensure-ssh-root-login-is-disabled.md b/benchmarks/access-and-control/1.17-ensure-ssh-root-login-is-disabled.md new file mode 100644 index 0000000..c78f15d --- /dev/null +++ b/benchmarks/access-and-control/1.17-ensure-ssh-root-login-is-disabled.md @@ -0,0 +1,42 @@ +# 1.17 确保禁用 root 用户通过 SSH 登录 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的`PermitRootLogin`参数指定`root`用户是否可以使用 ssh 登录。 + +不允许`root`用户通过 SSH 登录:要求系统管理员使用自己的个人账户进行 SSH 登录,然后通过`sudo`或`su`提升权限到`root`。这样可在发生安全事件时提供清晰的审计线索。 + +在对此项安全建议进行配置前,应确认还有其他可用的系统管理员用户账号,否则在配置生效后,将可能导致无法进行 SSH 远程管理。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`PermitRootLogin`参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`PermitRootLogin`参数,或添加以下代码,对`PermitRootLogin`参数进行配置: + +```shell +PermitRootLogin no +``` + +## 扫描检测 + +确保 SSH PermitRootLogin 参数正确配置。 + +1. 执行以下命令,验证`SSH`的`PermitRootLogin`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep permitrootlogin +permitrootlogin no +# grep -Ei '^\s*PermitRootLogin\s+yes' /etc/ssh/sshd_config +Nothing is returned +``` + +如果第一条命令执行后返回`no`,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.18-ensure-ssh-permitemptypasswords-is-disabled.md b/benchmarks/access-and-control/1.18-ensure-ssh-permitemptypasswords-is-disabled.md new file mode 100644 index 0000000..4672597 --- /dev/null +++ b/benchmarks/access-and-control/1.18-ensure-ssh-permitemptypasswords-is-disabled.md @@ -0,0 +1,40 @@ +# 1.18 确保 SSH PermitEmptyPasswords 参数正确配置 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的`PermitEmptyPasswords`参数指定用户是否可以使用空字符串密码进行 SSH 登录。 + +禁止密码为空的帐户进行远程 SSH 登录,可有效减少未授权用户登录的可能性。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`PermitEmptyPasswords`参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`PermitEmptyPasswords`参数,或添加以下代码,对`PermitEmptyPasswords`参数进行配置: + +```shell +PermitEmptyPasswords no +``` + +## 扫描检测 + +确保 SSH PermitEmptyPasswords 参数正确配置。 + +1. 执行以下命令,验证`SSH`的`PermitEmptyPasswords`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep permitemptypasswords +permitemptypasswords no +# grep -Ei '^\s*PermitEmptyPasswords\s+yes' /etc/ssh/sshd_config +Nothing is returned +``` + +如果第一条命令执行后返回`no`,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.19-ensure-ssh-permituserenvironment-is-disabled.md b/benchmarks/access-and-control/1.19-ensure-ssh-permituserenvironment-is-disabled.md new file mode 100644 index 0000000..6667b9b --- /dev/null +++ b/benchmarks/access-and-control/1.19-ensure-ssh-permituserenvironment-is-disabled.md @@ -0,0 +1,39 @@ +# 1.19 确保 SSH PermitUserEnvironment 参数正确配置 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的`PermitUserEnvironment`参数控制是否允许用户向 SSH 守护进程设置环境变量选项。 +允许用户通过 SSH 守护进程设置环境变量,有可能使其绕过安全控制执行未授权的程序或脚本(例如,设置一个执行路径,让 ssh 执行木马程序)。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`PermitUserEnvironment`参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`PermitUserEnvironment`参数,或添加以下代码,对`PermitUserEnvironment`参数进行配置: + +```shell +PermitUserEnvironment no +``` + +## 扫描检测 + +确保 SSH PermitUserEnvironment 参数正确配置。 + +1. 执行以下命令,验证`SSH`的`PermitUserEnvironment`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep permituserenvironment +permituserenvironment no +# grep -Ei '^\s*PermitUserEnvironment\s+yes' /etc/ssh/sshd_config +Nothing is returned +``` + +如果第一条命令执行后返回`no`,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.2-ensure-permissions-on-etc-crontab-are-configured.md b/benchmarks/access-and-control/1.2-ensure-permissions-on-etc-crontab-are-configured.md new file mode 100644 index 0000000..e4151fb --- /dev/null +++ b/benchmarks/access-and-control/1.2-ensure-permissions-on-etc-crontab-are-configured.md @@ -0,0 +1,39 @@ +# 1.2 确保 /etc/crontab 的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/crontab` 文件中包含了批处理作业的信息。其读写权限需严格控制,否则可能导致:系统作业信息泄露、未授权用户篡改或删除作业信息、普通用户运行特权命令、普通用户获得 root 权限等多种风险。 + +应对`/etc/crontab` 文件的读写权限进行严格限制,并确保`/etc/crontab`文件的所有者与所属组为`root`,且只有所有者可以访问该文件。 + +## 修复建议 + +目标:正确配置`/etc/crontab`文件的权限和所有者。 + +1. 使用以下代码,配置`/etc/crontab`的文件权限和所有者: + +```shell +# chown root:root /etc/crontab +# chmod og-rwx /etc/crontab +``` + +## 扫描检测 + +确保`/etc/crontab`文件的权限配置正确。 + +1. 执行以下命令,检查`/etc/crontab`文件的权限属性: + +```shell +# stat /etc/crontab +Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如果输出结果中:`Uid`与`Gid`均为`0/root`,且`Access`中`group`与`other`没有任何权限,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.20-ensure-ssh-idle-timeout-interval-is-configured.md b/benchmarks/access-and-control/1.20-ensure-ssh-idle-timeout-interval-is-configured.md new file mode 100644 index 0000000..8febc7d --- /dev/null +++ b/benchmarks/access-and-control/1.20-ensure-ssh-idle-timeout-interval-is-configured.md @@ -0,0 +1,72 @@ +# 1.20 确保 SSH 配置了空闲超时时间 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的`ClientAliveInterval`和`ClientAliveCountMax`两个参数控制ssh会话超时时间。 + +* `ClientAliveInterval`参数设置了一个超时时间(以秒为单位),如果超时后没有收到来自客户端的数据,`sshd`将通过加密通道发送一个心跳消息,要求客户端作出响应。此参数默认值为0,表示不会向客户端发送心跳消息。 + +* `ClientAliveCountMax`参数设置了在`sshd`没有收到客户端任何响应的情况下,重复发送心跳消息的次数。如发送次数达到阈值,sshd将断开客户端的连接,终止会话。 此参数默认值为3。 +* 客户端心跳消息是通过加密通道发送的。 + +* 将`ClientAliveCountMax`设置为0,表示 SSH 客户端会话在到达配置的超时时间且没有对心跳消息做出响应后,不再重复发送心跳消息进行确认,直接断开其链接。 + +例:如`ClientAliveInterval`设置为15,`ClientAliveCountMax`设置为默认值(3),无响应的 SSH 客户端将在大约45秒(15*3)后被断开连接。 + +如果没有配置超时时间,可能会使未经授权的用户通过 ssh 会话访问到操作系统(例如,已登录的用户离开计算机,但没有及时锁定屏幕)。正确配置超时时间,可降低出现这种风险的几率。 + +* 建议`ClientAliveInterval`参数的值,设置不大于`900`秒(15分钟)。 +* 建议`ClientAliveCountMax`参数的值,设置为0。 +* 通过以上设置,可实现自动断开不活跃时间超过 15 分钟的的`ssh`会话。 + +在某些情况下,这个设置可能会导致通过 SSH 或依赖 SSH 的长期运行的远程自动化工具或脚本意外终止。 在配置这些参数时,应充分考虑到这些脚本的需求,并计算适当的`ServerAliveInterval`和`ClientAliveInterval`参数值,以确保操作的连续性。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`ClientAliveInterval`和`ClientAliveCountMax`参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`ClientAliveInterval`和`ClientAliveCountMax`参数,或添加以下代码,对`ClientAliveInterval`和`ClientAliveCountMax`参数进行配置: + +```shell +ClientAliveInterval 900 +ClientAliveCountMax 0 +``` + +默认配置为`clientaliveinterval 0`、`clientalivecountmax 3`,需修改为建议值。 + +## 扫描检测 + +确保 SSH 配置了空闲超时时间。 + +1. 执行如下命令,验证`ClientAliveInterval`的值小于等于`900`: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep clientaliveinterval +clientaliveinterval 900 +``` + +2. 执行如下命令,验证`clientalivecountmax`的值为`0`: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep clientalivecountmax +clientalivecountmax 0 +``` + +3. 执行如下命令,检查是否没有返回任何结果: + +```shell +# grep -Ei '^\s*ClientAliveInterval\s+(0|9[0-9][1-9]|[1-9][0-9][0-9][0-9]+|1[6-9]m|[2-9][0-9]m|[1-9][0-9][0-9]+m)\b' /etc/ssh/sshd_config +Nothing is returned +# grep -Ei '^\s*ClientAliveCountMax\s+([1-9]|[1-9][0-9]+)\b' /etc/ssh/sshd_config +Nothing is returned +``` + +如满足以上`3`条检查项目,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.21-ensure-ssh-logingracetime-is-set-to-one-minute-or-less.md b/benchmarks/access-and-control/1.21-ensure-ssh-logingracetime-is-set-to-one-minute-or-less.md new file mode 100644 index 0000000..704a230 --- /dev/null +++ b/benchmarks/access-and-control/1.21-ensure-ssh-logingracetime-is-set-to-one-minute-or-less.md @@ -0,0 +1,42 @@ +# 1.21 确保 SSH LoginGraceTime 被设置为 60 秒或更短 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的`LoginGraceTime`参数规定了 SSH 服务认证的等待时间。等待时间越长,未经认证的会话连接就积压越多。 等待时间应被限制在一个适当的范围内,确保 SSH 服务的会话资源不被未授权用户占用。 + +将`LoginGraceTime`参数设置为较低的值,可以降低 SSH 服务器被暴力攻击成功的风险。建议设置为`60`秒(1分钟)。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`LoginGraceTime`参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`LoginGraceTime`参数,或添加以下代码,对`LoginGraceTime`参数进行配置: + +```shell +LoginGraceTime 60 +``` + +默认值为`120`秒,需修改为建议值。 + +## 扫描检测 + +确保 SSH LoginGraceTime 被设置为 60 秒或更短。 + +1. 执行以下命令,验证`SSH`的`LoginGraceTime`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep logingracetime +logingracetime 60 +# grep -Ei '^\s*LoginGraceTime\s+(0|6[1-9]|[7-9][0-9]|[1-9][0-9][0-9]+|[^1]m)' /etc/ssh/sshd_config +Nothing is returned +``` + +如果第一条命令执行后返回值`<=60`,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.22-ensure-ssh-warning-banner-is-configured.md b/benchmarks/access-and-control/1.22-ensure-ssh-warning-banner-is-configured.md new file mode 100644 index 0000000..6ed416a --- /dev/null +++ b/benchmarks/access-and-control/1.22-ensure-ssh-warning-banner-is-configured.md @@ -0,0 +1,41 @@ +# 1.22 确保 SSH 已配置警告横幅 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的`Banner`参数指定了一个文件。当用户连接到服务器,在其输入用户名之后,`Banner`参数指定的文件中的内容将会被展示在其终端上。 + +横幅是用来告知或警告连接用户当前所登录设备的用途、使用政策及法律风险等,此信息会在用户正常登录之前展示。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`Banner`参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`Banner`参数,或添加以下代码,对`Banner`参数进行配置: + +```shell +Banner /etc/issue.net +``` + +* 默认没有横幅文件,`Banner`参数值为`none`,需改为建议值。 + +* `/etc/issue.net`为自定义文本文件,其内容将会作为 login banner 展示: + * 例:`Authorized uses only. All activity may be monitored and reported.` + +## 扫描检测 + +确保 SSH 已配置警告横幅。 + +1. 执行以下命令,验证`SSH`的`Banner`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep banner +banner /etc/issue.net +``` + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.23-ensure-ssh-pam-is-enabled.md b/benchmarks/access-and-control/1.23-ensure-ssh-pam-is-enabled.md new file mode 100644 index 0000000..87e7814 --- /dev/null +++ b/benchmarks/access-and-control/1.23-ensure-ssh-pam-is-enabled.md @@ -0,0 +1,45 @@ +# 1.23 确保 SSH PAM 已启用 + +## 安全等级 + +Level 1 + +## 描述 + +PAM(Pluggable Authentication Modules)是由 Sun 提出的一种认证机制。 + +它通过提供一些动态链接库和一套统一的API,将系统提供的认证服务与该服务的认证方式分开,使得系统管理员可以灵活的根据需要给不同的服务配置不同的认证方式而无需更改服务程序,同时也便于向系统中添加新的认证手段。 +`UsePAM` 参数如果设置为 "yes",将启用PAM认证。 + +注意:如果启用`UsePAM`,将不能以非`root`用户的身份运行`sshd(8)`。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`UsePAM`参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`UsePAM`参数,或添加以下代码,对`UsePAM`参数进行配置: + +```shell +UsePAM yes +``` + +默认值为`yes`。 + +## 扫描检测 + +确保 SSH PAM 已启用。 + +1. 执行以下命令,验证`SSH`的`UsePAM`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -i usepam +usepam yes +# grep -Ei '^\s*UsePAM\s+no' /etc/ssh/sshd_config +Nothing is returned +``` + +如果第一条命令执行后返回`yes`,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.24-ensure-ssh-maxstartups-is-configured.md b/benchmarks/access-and-control/1.24-ensure-ssh-maxstartups-is-configured.md new file mode 100644 index 0000000..82454cd --- /dev/null +++ b/benchmarks/access-and-control/1.24-ensure-ssh-maxstartups-is-configured.md @@ -0,0 +1,52 @@ +# 1.24 确保 SSH MaxStartups 参数正确配置 + +## 安全等级 + +Level 1 + +## 描述 + +SSH 配置文件:`/etc/ssh/sshd_config`中的`MaxStartups`参数指定了 SSH 守护进程的未认证连接的最大并发数量。 + +为了保护系统免受因大量未完成的认证连接尝试(DoS攻击)而导致的拒绝服务或服务崩溃,需正确配置`MaxStartups`参数,对验证速率进行限制,防止 SSH 守护程序无法响应正常用户的访问请求。 + +`MaxStartups`参数控制 SSH 等待认证的连接并发数(注意:已经成功通过认证并建立起会话的连接数,不在该参数的控制范围之内)。 + +该参数可以是冒号分隔的三个参数值(如:`10:30:100`),它们的含义分别如下: + +* 10:等待认证阶段的最大并发连接数。若超过此数量,后面的认证请求连接将被拒绝。即:最多有10个人可以同时向 sshd 发起登录请求。 +* 30:该参数是一个概率值(百分比的形式)。若设置了该参数,超过了上限(10)的连接,将会被随机拒绝,拒绝的比率是30%。即:超过了10个连接以后,后续的认证请求连接中,每3个中会有一个被随机拒绝。 +* 60:随着并发连接数的增加,这个拒绝连接的概率(30)也会逐步线性增加,当并发连接数达到最大值(60)后,后续的连接都将会被直接拒绝。 + +已通过认证、认证失败、或连接超时等,都会减少等待认证的并发连接数。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`maxstartups`参数进行配置。 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`maxstartups`参数,或添加以下代码,对`maxstartups`参数进行配置: + +```shell +maxstartups 10:30:60 +``` + +默认值为`10:30:100`,需修改为建议值。 + +## 扫描检测 + +确保 SSH MaxStartups 参数正确配置。 + +1. 执行以下命令,验证`SSH`的`MaxStartups`参数配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -i maxstartups +maxstartups 10:30:60 +# grep -Ei '^\s*maxstartups\s+(((1[1-9]|[1-9][0-9][0-9]+):([0-9]+):([0-9]+))|(([0-9]+):(3[1-9]|[4-9][0-9]|[1-9][0-9][0-9]+):([0-9]+))|(([0-9]+):([0-9]+):(6[1-9]|[7-9][0-9]|[1-9][0-9][0-9]+)))' /etc/ssh/sshd_config +Nothing is returned +``` + +如果第一条命令执行后返回`10:30:60`或更加严格的规则,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.25-ensure-ssh-maxsessions-is-set-to-10-or-less.md b/benchmarks/access-and-control/1.25-ensure-ssh-maxsessions-is-set-to-10-or-less.md new file mode 100644 index 0000000..38a64f4 --- /dev/null +++ b/benchmarks/access-and-control/1.25-ensure-ssh-maxsessions-is-set-to-10-or-less.md @@ -0,0 +1,42 @@ +# 1.25 确保 SSH MaxSessions 参数设置为 10 或以下 + +## 安全等级 + +Level 1 + +## 描述 + +`MaxSessions`参数指定 SSH 允许打开的最大会话数。 + +为了保护系统免受因大量未完成的认证连接尝试(DoS攻击)而导致的拒绝服务或服务崩溃,需正确配置`MaxSessions`参数对最大会话数进行限制,防止 SSH 守护程序崩溃无法响应正常用户的访问请求。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`MaxSessions`参数进行配置 + +1. 编辑`/etc/ssh/sshd_config`配置文件,修改`MaxSessions`参数,或添加以下代码,对`MaxSessions`参数进行配置: + +```shell +MaxSessions 10 +``` + +`MaxSessions`参数默认值即为`10`。 + +## 扫描检测 + +确保 SSH MaxSessions 参数设置为 10 或以下 + +1. 执行以下命令,验证`SSH`的`MaxSessions`配置是否正确: + +```shell +# sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -i maxsessions +maxsessions 10 +# grep -Ei '^\s*MaxSessions\s+(1[1-9]|[2-9][0-9]|[1-9][0-9][0-9]+)' /etc/ssh/sshd_config +Nothing is returned +``` + +如果第一条命令执行后返回值小于`10`,且第二条命令执行后,没有返回任何结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.26-ensure-system-wide-crypto-policy-is-not-over-ridden.md b/benchmarks/access-and-control/1.26-ensure-system-wide-crypto-policy-is-not-over-ridden.md new file mode 100644 index 0000000..4a883be --- /dev/null +++ b/benchmarks/access-and-control/1.26-ensure-system-wide-crypto-policy-is-not-over-ridden.md @@ -0,0 +1,44 @@ +# 1.26 确保全局加密策略不被覆盖 + +## 安全等级 + +Level 1 + +## 描述 + +对于 openSSH 来说,可选择是否覆盖全局加密策略。 + +覆盖全局加密策略可能会导致系统使用不安全的密码策略,如:MAC、KexAlgoritms 和 GSSAPIKexAlgorithsm 等。 + +## 修复建议 + +对`/etc/ssh/sshd_config`配置文件的`CRYPTO_POLICY`参数进行配置 + +1. 编辑`/etc/ssh/sshd_config`配置文件,注释掉`CRYPTO_POLICY`参数: + +```shell +# sed -ri "s/^\s*(CRYPTO_POLICY\s*=.*)$/# \1/" /etc/sysconfig/sshd +``` + +2. 重启 sshd 服务,使其生效: + +```shell +# systemctl reload sshd +``` + +## 扫描检测 + +确保全局加密策略不被覆盖。 + +1. 执行以下命令,验证`SSH`的`CRYPTO_POLICY`配置是否正确: + +```shell +# grep -i '^\s*CRYPTO_POLICY=' /etc/sysconfig/sshd +Nothing is returned +``` + +如无任何返回,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.27-ensure-password-creation-requirements-are-configured.md b/benchmarks/access-and-control/1.27-ensure-password-creation-requirements-are-configured.md new file mode 100644 index 0000000..eedbe12 --- /dev/null +++ b/benchmarks/access-and-control/1.27-ensure-password-creation-requirements-are-configured.md @@ -0,0 +1,91 @@ +# 1.27 确保设置了密码复杂性检查策略 + +## 安全等级 + +Level 1 + +## 描述 + +`pam_pwquality.so`模块用于检查密码的强度。 它进行的检查包括:确保密码不是字典中的单词,有一定的长度,包含混合的字符(如字母、数字、其他)等等。 以下是`pam_pwquality.so`选项的定义。 + +* `try_first_pass` - 从先前堆叠的 PAM 模块中检索密码。 如果不可用,则提示用户输入密码。 +* `retry=3` - 允许尝试3次,如都不符合规则,则发送失败信息。 +* `minlen=14` - 密码必须是14个字符或以上。 + +以下任何一种方法都可以用来强制执行复杂密码: + +* `minclass=4` - 为新密码提供至少四类字符。 +* `dcredit=-1` - 至少包含一个数字。 +* `ucredit=-1` - 至少包含一个大写的字符。 +* `ocredit=-1` - 至少包含一个特殊字符。 +* `lcredit=-1` - 至少提供一个小写字符。 + +可对以上参数进行修改,来制定符合实际环境的密码策略。 + +复杂密码可保护系统不被暴力入侵。 + +## 修复建议 + +编辑`/etc/security/pwquality.conf`文件,对密码复杂性检查策略进行配置。 + +1. 编辑`/etc/security/pwquality.conf`配置文件,修改或添加`minlen`参数,对密码长度进行规范: + +```shell +# minlen = 14 +``` +`minlen`默认值为`8` + +2. 编辑`/etc/security/pwquality.conf`配置文件,修改或添加`minclass`参数,对密码复杂度进行规范: + +```shell +# minclass = 4 +# dcredit = -1 +# ucredit = -1 +# ocredit = -1 +# lcredit = -1 +``` + +第2步的代码,可根据实际情况,任选一条或多条进行配置。 + +3. 执行以下命令,来更新`system-auth`和`password-auth`文件。 + +```shell +# egrep -q "^\s*password\s+requisite\s+pam_pwquality.so\s+" /etc/pam.d/system-auth && sed -ri '/^\s*password\s+requisite\s+pam_pwquality.so\s+/ { /^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*(\s+try_first_pass)(\s+.*)?$/! s/^(\s*password\s+requisite\s+pam_pwquality.so\s+)(.*)$/\1try_first_pass \2/ }' /etc/pam.d/system-auth && sed -ri '/^\s*password\s+requisite\s+pam_pwquality.so\s+/ { /^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*(\s+retry=[0-9]+)(\s+.*)?$/! s/^(\s*password\s+requisite\s+pam_pwquality.so\s+)(.*)$/\1retry=3 \2/ }' /etc/pam.d/system-auth && sed -ri 's/(^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*\s+)retry=[0-9]+(\s+.*)?$/\1retry=3\3/' /etc/pam.d/system-auth || echo Ensure\ password\ creation\ requirements\ are\ configured - /etc/pam.d/system-auth not configured. + +# egrep -q "^\s*password\s+requisite\s+pam_pwquality.so\s+" /etc/pam.d/password-auth && sed -ri '/^\s*password\s+requisite\s+pam_pwquality.so\s+/ { /^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*(\s+try_first_pass)(\s+.*)?$/! s/^(\s*password\s+requisite\s+pam_pwquality.so\s+)(.*)$/\1try_first_pass \2/ }' /etc/pam.d/password-auth && sed -ri '/^\s*password\s+requisite\s+pam_pwquality.so\s+/ { /^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*(\s+retry=[0-9]+)(\s+.*)?$/! s/^(\s*password\s+requisite\s+pam_pwquality.so\s+)(.*)$/\1retry=3 \2/ }' /etc/pam.d/password-auth && sed -ri 's/(^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*\s+)retry=[0-9]+(\s+.*)?$/\1retry=3\3/' /etc/pam.d/password-auth || echo Ensure\ password\ creation\ requirements\ are\ configured - /etc/pam.d/password-auth not configured. +``` + +## 扫描检测 + +确保设置了密码复杂性检查策略。 + +1. 执行以下命令,验证密码复杂性策略配置是否正确: + +```shell +# grep pam_pwquality.so /etc/pam.d/system-auth /etc/pam.d/password-auth +/etc/pam.d/system-auth:password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type= +/etc/pam.d/password-auth:password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type= +``` + +2. 执行以下命令,验证密码长度配置是否符合要求(`minlen>=14`): + +```shell +# grep ^minlen /etc/security/pwquality.conf +minlen=14 +``` + +3. 执行以下命令,验证密码复杂度配置是否符合要求: + +```shell +# grep ^minclass /etc/security/pwquality.conf +minclass=3 +# grep -E "^\s*\Scredit\s*=" /etc/security/pwquality.conf +dcredit=-1 +ocredit=-1 +``` + +第1条及第2条检查项目输出结果应全部符合要求,第3项检查项输出结果应符合其中1条或更多。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.28-ensure-lockout-for-failed-password-attempts-is-configured.md b/benchmarks/access-and-control/1.28-ensure-lockout-for-failed-password-attempts-is-configured.md new file mode 100644 index 0000000..95776e9 --- /dev/null +++ b/benchmarks/access-and-control/1.28-ensure-lockout-for-failed-password-attempts-is-configured.md @@ -0,0 +1,56 @@ +# 1.28 确保配置了密码验证失败超过阈值后锁定用户 + +## 安全等级 + +Level 1 + +## 描述 + +对于连续多次登录密码验证失败的用户,应锁定其账户。 + +可通过修改`system-auth`及`password-auth`配置文件中以下两个参数,对上述功能进行管理。 + +* `deny=n` -> 密码验证的尝试次数(n),超过n次后锁定用户 +* `unlock_time=n` -> 用户锁定后解锁所需的时间(秒) + +根据实际情况对密码尝试次数和解锁时间进行配置,防范密码暴力破解。 + +## 修复建议 + +对`system-auth`及`password-auth`配置文件的参数进行配置。 + +1. 运行以下两个脚本,更新`system-auth`及`password-auth`文件,添加`deny=5`和`unlock_time=900`参数。: + +```shell +cat >> /etc/pam.d/password-auth << EOF +auth required pam_faillock.so preauth silent deny=5 unlock_time=900 +auth required pam_faillock.so authfail deny=5 unlock_time=900 +EOF +``` + +```shell +cat >> /etc/pam.d/system-auth << EOF +auth required pam_faillock.so preauth silent deny=5 unlock_time=900 +auth required pam_faillock.so authfail deny=5 unlock_time=900 +EOF +``` + +## 扫描检测 + +确保配置了密码验证失败超过阈值后锁定用户 + +1. 执行以下命令,验证`system-auth`及`password-auth`配置文件的参数是否合规: + +```shell +# grep -E '^\s*auth\s+required\s+pam_faillock.so\s+' /etc/pam.d/password-auth /etc/pam.d/system-auth +/etc/pam.d/password-auth:auth required pam_faillock.so preauth silent deny=5 unlock_time=900 +/etc/pam.d/password-auth:auth required pam_faillock.so authfail deny=5 unlock_time=900 +/etc/pam.d/system-auth:auth required pam_faillock.so preauth silent deny=5 unlock_time=900 +/etc/pam.d/system-auth:auth required pam_faillock.so authfail deny=5 unlock_time=900 +``` + +输出结果中应符合:`deny<=5`、`unlock_time<=900`。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.29-ensure-password-reuse-is-limited.md b/benchmarks/access-and-control/1.29-ensure-password-reuse-is-limited.md new file mode 100644 index 0000000..b59ceb6 --- /dev/null +++ b/benchmarks/access-and-control/1.29-ensure-password-reuse-is-limited.md @@ -0,0 +1,50 @@ +# 1.29 确保正确限制密码复用 + +## 安全等级 + +Level 1 + +## 描述 + +应强制用户在修改密码时,不允许使用之前 n 次内曾使用过的密码,增强密码的安全性。 + +`/etc/security/opasswd`文件中存储了用户的旧密码,可以通过对其进行配置来对用户修改的密码进行判断,确保其无法使用近期已经使用过的密码。 + +`remember=<5>` -> 保存的旧密码个数。 + +## 修复建议 + +对`/etc/pam.d/system-auth`文件配置进行修改。 + +1. 执行以下命令,修改`/etc/pam.d/system-auth`配置文件,增加`remember`参数,使其对密码复用进行限制: + +```shell +#!/bin/bash +if authselect current | awk 'NR == 1 {print $3}' | grep -q custom/; then PTF=/etc/pam.d/"$(authselect current | awk 'NR == 1 {print $3}' | grep custom/)"/system-auth +else + PTF=/etc/pam.d/system-auth +fi +if grep -Eq '^\s*password\s+(sufficient\s+pam_unix|requi(red|site)\s+pam_pwhistory).so\s+([^#]+\s+)*remember=\S+\s*.*$' $PTF; then + sed -ri 's/^\s*(password\s+(requisite|sufficient)\s+(pam_pwhistory\.so|pam_unix\.so)\s+)(.*)(remember=\S+\s*)(.*)$/\1\4 remember=5 \6/' $PTF +else + sed -ri 's/^\s*(password\s+(requisite|sufficient)\s+(pam_pwhistory\.so|pam_unix\.so)\s+)(.*)$/\1\4 remember=5/' $PTF +fi +authselect apply-changes +``` + +## 扫描检测 + +确保正确限制密码复用 + +1. 执行以下命令,验证`/etc/pam.d/system-auth`的配置是否正确: + +```shell +# grep -P '^\h*password\h+(requisite|sufficient)\h+(pam_pwhistory\.so|pam_unix\.so)\h+([^#\n\r]+\h+)?remember=([5-9]|[1-9][0-9]+)\h*(\h+.*)?$' /etc/pam.d/system-auth +password sufficient pam_unix.so try_first_pass use_authtok nullok sha512 shadow remember=5 +``` + +如返回结果中`remember>=5`,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.3-ensure-permissions-on-etc-cron.hourly-are-configured.md b/benchmarks/access-and-control/1.3-ensure-permissions-on-etc-cron.hourly-are-configured.md new file mode 100644 index 0000000..86e5f86 --- /dev/null +++ b/benchmarks/access-and-control/1.3-ensure-permissions-on-etc-cron.hourly-are-configured.md @@ -0,0 +1,39 @@ +# 1.3 确保 /etc/cron.hourly 的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/cron.hourly`包含需要**每小时**运行的 cron 作业。 此文件中的内容不能由`crontab`命令操作,而是由系统管理员使用文本编辑器直接修改其内容。 + +应将其读、写、执行权限限制为`root`用户,防止普通用户修改和访问此文件。否则可能导致:系统作业信息泄露、未授权用户篡改或删除作业信息、普通用户运行特权命令、普通用户获得 `root` 权限等多种风险。 + +## 修复建议 + +目标:正确配置`/etc/cron.hourly`文件的权限和所有者。 + +1. 使用以下代码,配置`/etc/cron.hourly`的文件权限和所有者: + +```shell +# chown root:root /etc/cron.hourly +# chmod og-rwx /etc/cron.hourly +``` + +## 扫描检测 + +确保`/etc/cron.hourly`文件的权限配置正确。 + +1. 执行以下命令,检查`/etc/cron.hourly`文件的权限属性: + +```shell +# stat /etc/cron.hourly +Access: (0700/drwx------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如果输出结果中:`Uid`与`Gid`均为`0/root`,且`Access`中`group`与`other`没有任何权限,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.30-ensure-password-hashing-algorithm-is-sha-512.md b/benchmarks/access-and-control/1.30-ensure-password-hashing-algorithm-is-sha-512.md new file mode 100644 index 0000000..44ab672 --- /dev/null +++ b/benchmarks/access-and-control/1.30-ensure-password-hashing-algorithm-is-sha-512.md @@ -0,0 +1,39 @@ +# 1.30 确保密码哈希算法为 SHA-512 + +## 安全等级 + +Level 1 + +## 描述 + +将密码哈希算法从`MD5`改为`SHA-512`(一种更强大的散列算法)。`SHA-512`算法相比`MD5`更加复杂,提高了攻击者暴力破解密码的难度,可为系统提供额外的保护。 + +## 修复建议 + +设置密码哈希算法为 sha512。 + +1. 执行以下命令,修改`password-auth`和`system-auth`配置文件中`pam_unix.so`的哈希算法配置为`SHA-512`: + +```shell +# egrep -q "^\s*password\s+sufficient\s+pam_unix.so\s+" /etc/pam.d/system-auth && sed -ri '/^\s*password\s+sufficient\s+pam_unix.so\s+/ { /^\s*password\s+sufficient\s+pam_unix.so(\s+\S+)*(\s+sha512)(\s+.*)?$/! s/^(\s*password\s+sufficient\s+pam_unix.so\s+)(.*)$/\1sha512 \2/ }' /etc/pam.d/system-auth + +# egrep -q "^\s*password\s+sufficient\s+pam_unix.so\s+" /etc/pam.d/password-auth && sed -ri '/^\s*password\s+sufficient\s+pam_unix.so\s+/ { /^\s*password\s+sufficient\s+pam_unix.so(\s+\S+)*(\s+sha512)(\s+.*)?$/! s/^(\s*password\s+sufficient\s+pam_unix.so\s+)(.*)$/\1sha512 \2/ }' /etc/pam.d/password-auth +``` + +## 扫描检测 + +确保密码哈希算法为 SHA-512。 + +1. 执行以下命令,验证`password-auth`和`system-auth`配置文件哈希算法配置是否符合要求: + +```shell +# grep -E '^\s*password\s+sufficient\s+pam_unix.so\s+.*sha512\s*.*$' /etc/pam.d/password-auth /etc/pam.d/system-auth +/etc/pam.d/password-auth:password sufficient pam_unix.so sha512 remember=5 try_first_pass use_authtok nullok shadow +/etc/pam.d/system-auth:password sufficient pam_unix.so sha512 try_first_pass use_authtok nullok shadow remember=5 +``` + +如返回结果中`password-auth`和`system-auth`配置文件均配置了`sha512`算法,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.31-ensure-password-expiration-is-365-days-or-less.md b/benchmarks/access-and-control/1.31-ensure-password-expiration-is-365-days-or-less.md new file mode 100644 index 0000000..a74dd02 --- /dev/null +++ b/benchmarks/access-and-control/1.31-ensure-password-expiration-is-365-days-or-less.md @@ -0,0 +1,53 @@ +# 1.31 确保密码过期时间不超过 365 天 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/login.defs`文件中的`PASS_MAX_DAYS`参数,指定了密码过期时间的最大值(天)。建议最大值不超过 365 天。 + +## 修复建议 + +修改`/etc/login.defs`文件中的`PASS_MAX_DAYS`参数。 + +1. 执行以下代码,修改或添加`/etc/login.defs`文件中的`PASS_MAX_DAYS`参数,使其符合安全要求。 + +```shell +PASS_MAX_DAYS 365 +``` + +`PASS_MAX_DAYS`默认为`99999`,应修改为`365`或更小。 + +2. 将密码过期策略应用于所有用户: + +```shell +# getent passwd | cut -f1 -d ":" | xargs -n1 chage --maxdays 365 +``` + +## 扫描检测 + +确保密码过期时间不超过365天。 + +1. 执行以下命令,验证`/etc/login.defs`文件中的`PASS_MAX_DAYS`参数是否符合要求: + +```shell +# grep PASS_MAX_DAYS /etc/login.defs +PASS_MAX_DAYS 365 +``` + +2. 检查用户列表,确认所有用户的密码过期策略符合要求: + +```shell +# grep -E '^[^:]+:[^!*]' /etc/shadow | cut -d: -f1,5 +: +``` + +* 其中``为用户名,``为密码过期天数,如:`root:365`。 + +如配置文件及所有用户的密码过期时间最大值均`<=365`,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.32-ensure-minimum-days-between-password-changes-is-7-or-more.md b/benchmarks/access-and-control/1.32-ensure-minimum-days-between-password-changes-is-7-or-more.md new file mode 100644 index 0000000..cb4968a --- /dev/null +++ b/benchmarks/access-and-control/1.32-ensure-minimum-days-between-password-changes-is-7-or-more.md @@ -0,0 +1,55 @@ +# 1.32 确保修改密码的间隔时间不少于 7 天 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/login.defs`文件中的`PASS_MIN_DAYS`参数,允许系统管理员阻止用户修改密码,直到距离用户上次修改密码的时间至少过去了n天。 建议将`PASS_MIN_DAYS`参数设置为7天或以上。 + +通过限制密码修改的频率,系统管理员可以防止用户通过在短时间内频繁修改密码以刷新密码记录,从而规避密码复用限制。 + +## 修复建议 + +修改`/etc/login.defs`文件中的`PASS_MIN_DAYS`参数。 + +1. 执行以下代码,修改或添加`/etc/login.defs`文件中的`PASS_MIN_DAYS`参数,使其符合安全要求。 + +```shell +PASS_MIN_DAYS 7 +``` + +`PASS_MIN_DAYS`默认为`0`,即不限制,应修改为`7`或更大。 + +2. 将密码修改间隔策略应用于所有用户: + +```shell +# getent passwd | cut -f1 -d ":" | xargs -n1 chage --mindays 7 +``` + +## 扫描检测 + +确保修改密码的间隔时间不少于7天。 + +1. 执行以下命令,验证`/etc/login.defs`文件中的`PASS_MIN_DAYS`参数是否符合要求: + +```shell +# grep ^\s*PASS_MIN_DAYS /etc/login.defs +PASS_MIN_DAYS 7 +``` + +2. 检查用户列表,确认所有用户的密码过期策略符合要求: + +```shell +# grep -E ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1,4 +: +``` + +* 其中``为用户名,``为密码修改间隔天数,如:`root:7`。 + +如配置文件及所有用户的密码修改间隔天数均`>=7`,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.33-ensure-password-expiration-warning-days-is-7-or-more.md b/benchmarks/access-and-control/1.33-ensure-password-expiration-warning-days-is-7-or-more.md new file mode 100644 index 0000000..e2a3a84 --- /dev/null +++ b/benchmarks/access-and-control/1.33-ensure-password-expiration-warning-days-is-7-or-more.md @@ -0,0 +1,55 @@ +# 1.33 确保密码过期警告天数大于等于7天 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/login.defs`文件中的`PASS_WARN_AGE`参数,用于告知用户,其密码将在n天内过期。 + +在密码即将过期前提前发出警告,让用户有时间思考和修改一个新的符合安全规定的密码。 + +## 修复建议 + +修改`/etc/login.defs`文件中的`PASS_WARN_AGE`参数。 + +1. 执行以下代码,修改或添加`/etc/login.defs`文件中的`PASS_WARN_AGE`参数,使其符合安全要求。 + +```shell +PASS_WARN_AGE 7 +``` + +`PASS_WARN_AGE`默认为`7`。 + +2. 将密码过期警告策略应用于所有用户: + +```shell +# getent passwd | cut -f1 -d ":" | xargs -n1 chage --warndays 7 +``` + +## 扫描检测 + +确保密码过期警告天数大于等于7天。 + +1. 执行以下命令,验证`/etc/login.defs`文件中的`PASS_WARN_AGE`参数是否符合要求: + +```shell +# grep PASS_WARN_AGE /etc/login.defs +PASS_WARN_AGE 7 +``` + +2. 检查用户列表,确认所有用户的密码过期警告策略符合要求: + +```shell +# grep -E ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1,6 +: +``` + +* 其中``为用户名,``为密码过期警告天数,如:`root:7`。 + +如配置文件及所有用户的密码过期警告天数均`>=7`,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.34-ensure-inactive-password-lock-is-30-days-or-less.md b/benchmarks/access-and-control/1.34-ensure-inactive-password-lock-is-30-days-or-less.md new file mode 100644 index 0000000..eb101d8 --- /dev/null +++ b/benchmarks/access-and-control/1.34-ensure-inactive-password-lock-is-30-days-or-less.md @@ -0,0 +1,53 @@ +# 1.34 确保不活跃用户的锁定时间为 30 天或更短 + +## 安全等级 + +Level 1 + +## 描述 + +长时间不活跃(密码过期)的用户,应自动将其禁用。建议设置为:禁用在密码过期30天后仍未重新激活的用户。 + +## 修复建议 + +修改密码未激活锁定时间。 + +1. 执行以下命令,将密码未激活锁定时间设置为30天。 + +```shell +# useradd -D -f 30 +``` + +默认值为`-1`,即不锁定,需修改为建议值。 + +2. 将密码未激活锁定时间策略应用于所有用户: + +```shell +# getent passwd | cut -f1 -d ":" | xargs -n1 chage --inactive 30 +``` + +## 扫描检测 + +确保密码未激活锁定时间是30天或更短。 + +1. 执行以下命令,密码未激活锁定时间是否符合要求: + +```shell +# useradd -D | grep INACTIVE +INACTIVE=30 +``` + +2. 检查用户列表,确认所有用户的密码未激活锁定时间符合要求: + +```shell +# grep -E ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1,7 +: +``` + +* 其中``为用户名,``为密码未激活锁定天数,如:`root:30`。 + +如配置文件及所有用户的密码未激活锁定天数均`<=30`,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.35-ensure-all-users-last-password-change-date-is-in-the-past.md b/benchmarks/access-and-control/1.35-ensure-all-users-last-password-change-date-is-in-the-past.md new file mode 100644 index 0000000..0acf7f7 --- /dev/null +++ b/benchmarks/access-and-control/1.35-ensure-all-users-last-password-change-date-is-in-the-past.md @@ -0,0 +1,41 @@ +# 1.35 确保密码修改时间被正确记录 + +## 安全等级 + +Level 2 + +## 描述 + +所有用户的密码更改日期都应该早于当前时间。 + +如果一个密码修改记录文件中,某用户的密码修改日期被篡改,日期被设定在未来某个时段,那么此用户就可以绕过所有已设定的密码到期规则。 + +## 修复建议 + +定期检查用户的密码修改记录是否异常。 + +1. 执行以下命令,检查用户的密码修改记录是否异常: + +```shell +# for usr in $(cut -d: -f1 /etc/shadow); do [[ $(chage --list $usr | grep '^Last password change' | cut -d: -f2) > $(date) ]] && echo "$usr :$(chage --list $usr | grep '^Last password change' | cut -d: -f2)"; done +``` + +如无任何输出结果,说明无异常,无需进行下一步操作。 + +如有输出结果,则需对结果中的用户进行锁定,并手动修改错误、重新修改密码。 + +## 扫描检测 + +确保所有用户最后一次修改密码的时间早于当前时间。 + +1. 执行以下命令,检查用户的密码修改记录是否异常: + +```shell +# for usr in $(cut -d: -f1 /etc/shadow); do [[ $(chage --list $usr | grep '^Last password change' | cut -d: -f2) > $(date) ]] && echo "$usr :$(chage --list $usr | grep '^Last password change' | cut -d: -f2)"; done +``` + +如无任何输出结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.36-ensure-system-accounts-are-secured.md b/benchmarks/access-and-control/1.36-ensure-system-accounts-are-secured.md new file mode 100644 index 0000000..2e331d1 --- /dev/null +++ b/benchmarks/access-and-control/1.36-ensure-system-accounts-are-secured.md @@ -0,0 +1,53 @@ +# 1.36 确保虚拟用户不可通过 shell 登录 + +## 安全等级 + +Level 1 + +## 描述 + +大多数的 Linux 发行版都提供了许多用于管理应用程序的用户,此类用户不需要使用交互式 shell。 + +一般情况下,这些用户的密码字段会被设置为一个无效的字符串。即便如此,仍建议将`passwd`文件中这类用户的`shell`字段设置为`nologin`,如此可防范这些账户被用来执行恶意脚本或命令。 + +## 修复建议 + +修改`passwd`文件中虚拟用户的`shell`字段,并锁定虚拟用户。 + +1. 修改`passwd`文件中虚拟用户的`shell`字段为`nologin`: + +```shell +awk -F: '($1!="root" && $1!="sync" && $1!="shutdown" && $1!="halt" && $1!~/^\+/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"' && $7!="'"$(which nologin)"'" && $7!="/bin/false") {print $1}' /etc/passwd | +while read user +do usermod -s $(which nologin) $user +done +``` + +2. 锁定虚拟用户: + +```shell +awk -F: '($1!="root" && $1!~/^\+/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"') {print $1}' /etc/passwd | xargs -I '{}' passwd -S '{}' | awk '($2!="L" && $2!="LK") {print $1}' | +while read user +do usermod -L $user +done +``` + +## 扫描检测 + +确保虚拟用户不可通过 shell 登录。 + +1. 执行如下两条命令,确认返回结果: + +```shell +# awk -F: '($1!="root" && $1!="sync" && $1!="shutdown" && $1!="halt" && $1!~/^\+/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"' && $7!="'"$(which nologin)"'" && $7!="/bin/false") {print}' /etc/passwd +No file should be returned + +#awk -F: '($1!="root" && $1!~/^\+/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"') {print $1}' /etc/passwd | xargs -I '{}' passwd -S '{}' | awk '($2!="L" && $2!="LK") {print $1}' +No file should be returned +``` + +如以上命令,均无返回结果,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.37-ensure-default-user-shell-timeout-is-900-seconds-or-less.md b/benchmarks/access-and-control/1.37-ensure-default-user-shell-timeout-is-900-seconds-or-less.md new file mode 100644 index 0000000..f4e8d50 --- /dev/null +++ b/benchmarks/access-and-control/1.37-ensure-default-user-shell-timeout-is-900-seconds-or-less.md @@ -0,0 +1,86 @@ +# 1.37 确保用户 shell 超时时间小于等于900秒 + +## 安全等级 + +Level 1 + +## 描述 + +`TMOUT`是一个环境变量,用于指定`shell`的超时时间,单位为秒。 + +* `TMOUT=n` -> 设置shell超时时间为n秒。`TMOUT=0`表示禁用超时时间。 +* `readonly TMOUT` -> 可将`TMOUT`环境变量设置为只读,避免其被篡改。 +* `export TMOUT` -> 对`TMOUT`的值进行修改。 + +环境变量的配置文件: + +* `/etc/profile` -> 此文件内的变量为全局变量,可作用于所有用户。 +* `/etc/profile.d` -> 在系统启动或用户第一次登录 shell 时,会自动运行其目录下所有`*.sh` 文件。 +* `/etc/bashrc` -> 为每个运行 bash shell 的用户执行该文件,当 bash shell 打开时,该文件被执行,其配置对所有使用 bash 的用户打开的每个 bash 都有效。当被修改后,不用重启系统只需要打开一个新的 bash 即可生效。 + +设置 shell 超时时间可以减少未经授权的用户通过其他已登录用户的 shell 会话进行非法操作的情况,也能及时释放被不活跃用户占用的会话资源。 + +## 修复建议 + +对`TMOUT`环境变量的值进行配置。 + +1. 检查 +* `/etc/bashrc`文件 +* `/etc/profile`文件 +* `/etc/profile.d/`目录下所有以`.sh`结尾的文件 +中`TMOUT=n`条目的值,应不超过`900`且不等于`0`: + +示例: +```shell +readonly TMOUT=900 ; export TMOUT +``` + +或 + +```shell +TMOUT=900 +readonly TMOUT +export TMOUT +``` + +以上分别为单行与多行配置,符合任意一种即可。 + +## 扫描检测 + +确保用户shell超时时间小于等于900秒。 + +1. 执行以下命令,验证`TMOUT`环境变量是否正确设置: + +```shell +#!/usr/bin/env bash +CDTOS() +{ + output1="" output2="" + [ -f /etc/bashrc ] && BRC="/etc/bashrc" + for f in "$BRC" /etc/profile /etc/profile.d/*.sh ; do + grep -Pq '^\s*([^#]+\s+)?TMOUT=(900|[1-8][0-9][0-9]|[1-9][0-9]|[1-9])\b' "$f" && grep -Pq '^\s*([^#]+;\s*)?readonly\s+TMOUT(\s+|\s*;|\s*$|=(900|[1-8][0-9][0-9]|[1-9][0-9]|[1-9]))\b' "$f" && grep -Pq '^\s*([^#]+;\s*)?export\s+TMOUT(\s+|\s*;|\s*$|=(900|[1-8][0-9][0-9]|[1-9][0-9]|[1-9]))\b' "$f" && output1="$f" + done + grep -Pq '^\s*([^#]+\s+)?TMOUT=(9[0-9][1-9]|9[1-9][0-9]|0+|[1-9]\d{3,})\b' /etc/profile /etc/profile.d/*.sh "$BRC" && output2=$(grep -Ps '^\s*([^#]+\s+)?TMOUT=(9[0-9][1-9]|9[1-9][0-9]|0+|[1-9]\d{3,})\b' /etc/profile /etc/profile.d/*.sh $BRC) + if [ -n "$output1" ] && [ -z "$output2" ]; then + echo -e "\nPASSED\n\nTMOUT is configured in: \"$output1\"\n" + else + [ -z "$output1" ] && echo -e "\nFAILED\n\nTMOUT is not configured\n" + [ -n "$output2" ] && echo -e "\nFAILED\n\nTMOUT is incorrectly configured in: \"$output2\"\n" + fi +} +CDTOS +``` + +输出: + +```shell +PASSED + +TMOUT is configured in: "/etc/profile.d/login.sh" +``` + +如最输出结果为`PASSED`,则视为通过此项检查。其中`TMOUT is configured in`的值为`TMOUT`环境变量所在文件路径。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.38-ensure-default-group-for-the-root-account-is-gid-0.md b/benchmarks/access-and-control/1.38-ensure-default-group-for-the-root-account-is-gid-0.md new file mode 100644 index 0000000..3c081d3 --- /dev/null +++ b/benchmarks/access-and-control/1.38-ensure-default-group-for-the-root-account-is-gid-0.md @@ -0,0 +1,35 @@ +# 1.38 确保 root 帐号的默认组为GID 0 + +## 安全等级 + +Level 1 + +## 描述 + +配置`GID 0`为 root 用户的所属组,可防止 root 用户拥有的文件被非特权用户访问。 + +## 修复建议 + +配置 root 用户的所属组。 +1. 执行以下命令,对 root 用户的所属组进行配置: + +```shell +usermod -g 0 root +``` + +## 扫描检测 + +确保 root 帐号的默认组为`GID 0`。 + +1. 执行以下命令,验证 root 帐号的默认组是否合规: + +```shell +# grep "^root:" /etc/passwd | cut -f4 -d: +0 +``` + +如返回结果为`0`,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.39-ensure-default-user-umask-is-027-or-more-restrictive.md b/benchmarks/access-and-control/1.39-ensure-default-user-umask-is-027-or-more-restrictive.md new file mode 100644 index 0000000..de1205d --- /dev/null +++ b/benchmarks/access-and-control/1.39-ensure-default-user-umask-is-027-or-more-restrictive.md @@ -0,0 +1,110 @@ +# 1.39 确保 umask 设置为 027 或更严格 + +## 安全等级 + +Level 1 + +## 描述 + +umask 是用来指定新创建目录和文件的默认文件权限的。在Linux中,所有新创建的目录的默认权限是 0777(rwxrwxrwx),而所有新创建的文件的默认权限是 0666(rw-rw-rw-)。umask 通过限制(屏蔽)这些权限来修改Linux的默认权限。umask 不是简单的减法,而是按位处理。在生成新文件时,其默认权限会减去 umask 中设置的位。 + +umask 可以用八进制数字(4、2、1)或字母(r、w、x)来设置: + +* 八进制数字 -> 由三位或四位数字表示,即`umask 0027`或`umask 027`。 如果使用四位数的掩码,第一位数会被忽略。剩下的三位数字分别影响 user、group、other 的权限。 +* 字母 -> 用逗号分隔的列表表示 user、group、other 的权限。 +* 例:`umask u=rwx,g=rx,o=`即等于八进制数字的`umask 027`,此设置会将新建目录的默认权限配置为`drwxr-x---`,将新建文件的默认权限设置为`rw-r-----`。 + +文件和目录的真正初始权限,可通过以下的计算得到: + +``` +文件(或目录)的初始权限 = 文件(或目录)的最大默认权限 - umask权限 +``` + +配置 umask 值的方法: + +* pam_umask 模块: + * 在`/etc/login.defs`中添加或修改`umask`参数(使用八进制数字格式)。 +* 系统 Shell 配置文件(作用于所有用户): + * `/etc/profile` -> 用于为用户的 shell 设置系统范围的环境变量。 + * `/etc/profile.d` -> 会在系统启动或登录 shell 时,执行该目录下所有以`*.sh`结尾的文件。 + * `/etc/bashrc` -> 为每一个运行bash shell的用户执行此文件,当bash shell被打开时,该文件被读取。 +* 用户 shell 配置文件(作用于当前用户): + * `~/.bash_profile` -> 用户在登录时,会读取此文件中的配置。 + * `~/.bashrc` -> 该文件存储的是专属于个人bash shell的信息,当登录时以及每次打开一个新的shell时,执行这个文件,在这个文件里可以自定义用户专属的个人信息。 + +为 umask 设置一个安全的默认值可以避免新建的目录或文件具有过多的权限,被未经授权的用户读取或篡改。 + +## 修复建议 + +检查`/etc/bashrc`、`/etc/profile`以及`/etc/profile.d/`目录中所有以`*.sh`结尾的文件,添加或编辑所有的`umask`条目,使其符合安全要求:`umask 027`,`umask u=rwx,g=rx,o=`或更加严格的限制。 + +1. 在以下文件中配置`umask`参数 +* `/etc/bashrc` +* `/etc/profile` +* `/etc/profile.d/`目录中所有以`*.sh`结尾的文件: + +可使用以下命令,检查`/etc/bashrc`、`/etc/profile`以及`/etc/profile.d/`目录中所有已配置的`umask`参数: + +```shell +# grep -RPi '(^|^[^#]*)\s*umask\s+([0-7][0-7][01][0-7]\b|[0-7][0-7][0-7][0-6]\b|[0-7][01][0-7]\b|[0-7][0-7][0-6]\b|(u=[rwx]{0,3},)?(g=[rwx]{0,3},)?o=[rwx]+\b|(u=[rwx]{1,3},)?g=[^rx]{1,3}(,o=[rwx]{0,3})?\b)' /etc/login.defs /etc/profile* /etc/bashrc* +/etc/login.defs:UMASK 022 +/etc/profile: umask 002 +/etc/bashrc: umask 002 +``` + +根据以上结果,对`umask`参数进行修改,例如: + +```shell +# vi /etc/profile +umask 027 +# vi /etc/profile.d/set_umask.sh +umask 027 +``` + +2. 添加或修改`/etc/login.defs`文件中的`UMASK`及`USERGROUPS_ENAB`参数。 + +```shell +UMASK 027 +USERGROUPS_ENAB no +``` + +3. 编辑`/etc/pam.d/password-auth`及`/etc/pam.d/system-auth`,添加或编辑以下内容: + +```shell +session optional pam_umask.so +``` + +默认的 UMASK 配置为:`UMASK 022`。 + +## 扫描检测 + +确保 umask 设置为 027 或更严格。 + +1. 执行以下命令,验证 umask 参数是否符合以下要求: + +* 创建目录的默认权限为750 (drwxr-x---),创建文件的默认权限为640 (rw-r-----),或者更严格。 + +执行以下命令,观察返回结果: + +```shell +#!/bin/bash +passing="" +grep -Eiq '^\s*UMASK\s+(0[0-7][2-7]7|[0-7][2-7]7)\b' /etc/login.defs && grep -Eqi '^\s*USERGROUPS_ENAB\s*"?no"?\b' /etc/login.defs && grep -Eq '^\s*session\s+(optional|requisite|required)\s+pam_umask\.so\b' /etc/pam.d/common-session && passing=true +grep -REiq '^\s*UMASK\s+\s*(0[0-7][2-7]7|[0-7][2-7]7|u=(r?|w?|x?)(r?|w?|x?)(r?|w?|x?),g=(r?x?|x?r?),o=)\b' /etc/profile* /etc/bashrc* && passing=true +[ "$passing" = true ] && echo "Default user umask is set" +``` + +如返回`Default user umask is set`,则视为通过。 + +```shell +# grep -RPi '(^|^[^#]*)\s*umask\s+([0-7][0-7][01][0-7]\b|[0-7][0-7][0-7][0-6]\b|[0-7][01][0-7]\b|[0-7][0-7][0-6]\b|(u=[rwx]{0,3},)?(g=[rwx]{0,3},)?o=[rwx]+\b|(u=[rwx]{1,3},)?g=[^rx]{1,3}(,o=[rwx]{0,3})?\b)' /etc/login.defs /etc/profile* /etc/bashrc* +No file should be returned +``` + +如没有返回任何结果,则视为通过。 + +如以上两组命令的输出结果,均符合要求,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.4-ensure-permissions-on-etc-cron.daily-are-configured.md b/benchmarks/access-and-control/1.4-ensure-permissions-on-etc-cron.daily-are-configured.md new file mode 100644 index 0000000..a294dd3 --- /dev/null +++ b/benchmarks/access-and-control/1.4-ensure-permissions-on-etc-cron.daily-are-configured.md @@ -0,0 +1,39 @@ +# 1.4 确保 /etc/cron.daily 的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/cron.daily`目录中包含需要**每天**运行的`cron`作业。 此目录中的内容不能由`crontab`命令操作,而是由系统管理员使用文本编辑器直接修改其内容。 + +应将其读、写、执行权限限制为`root`用户,防止普通用户修改和访问此目录。否则可能导致:系统作业信息泄露、未授权用户篡改或删除作业信息、普通用户运行特权命令、普通用户获得 `root` 权限等多种风险。 + +## 修复建议 + +目标:正确配置`/etc/cron.daily`目录的权限和所有者。 + +1. 使用以下代码,配置`/etc/cron.daily`目录的权限和所有者: + +```shell +# chown root:root /etc/cron.daily +# chmod og-rwx /etc/cron.daily +``` + +## 扫描检测 + +确保`/etc/cron.daily`目录的权限配置正确。 + +1. 执行以下命令,检查`/etc/cron.daily`目录的权限属性: + +```shell +# stat /etc/cron.daily +Access: (0700/drwx------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如果输出结果中:`Uid`与`Gid`均为`0/root`,且`Access`中`group`与`other`没有任何权限,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.40-ensure-access-to-the-su-command-is-restricted.md b/benchmarks/access-and-control/1.40-ensure-access-to-the-su-command-is-restricted.md new file mode 100644 index 0000000..ac077bc --- /dev/null +++ b/benchmarks/access-and-control/1.40-ensure-access-to-the-su-command-is-restricted.md @@ -0,0 +1,53 @@ +# 1.40 确保 su 命令的使用受到限制 + +## 安全等级 + +Level 1 + +## 描述 + +`su`命令允许一个用户以另一个用户的身份执行命令或 shell 脚本。 该命令已被`sudo`取代,后者可以对特权访问进行更精细的控制。 默认情况下,`su`命令可以由任何用户执行。 通过添加配置或取消对`/etc/pam.d/su`文件中`pam_wheel.so`语句的注释,可以限制`su`命令只允许`wheel`组的用户执行。 + +限制`su`命令的使用,并使用`sudo`来代替它,可以使系统管理员更好地控制用户权限提升、执行特权命令等操作。 `sudo`有更好的审计记录机制,其可以记录通过`sudo`执行的每个命令,而`su`只能记录使用`su`的用户,无法记录具体执行的命令。 + +## 修复建议 + +限制`su`命令的使用权: + +1. 添加以下命令至`/etc/pam.d/su`文件: + +```shell +auth required pam_wheel.so use_uid +``` + +2. 可在`/etc/group`文件的`wheel`参数中创建一个逗号分隔的用户列表,在列表内的用户可使用`su`命令: + * 例: + +```shell +# wheel:x::root, +wheel:x:10:root,user1,user2,user3 +``` + +## 扫描检测 + +确保 su 命令的使用受到限制。 + +1. 执行以下命令,验证输出结果是否符合要求: + +```shell +# grep pam_wheel.so /etc/pam.d/su +auth required pam_wheel.so use_uid +``` + +2. 执行以下命令,检查`wheel`用户列表中的用户是否符合安全要求。 如果没有用户被列出,则只有`root`用户可以使用`su`命令: + +```shell +# grep wheel /etc/group +wheel:x:10: +``` + +如以上两条检查项输出结果均符合要求,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.5-ensure-permissions-on-etc-cron.weekly-are-configured.md b/benchmarks/access-and-control/1.5-ensure-permissions-on-etc-cron.weekly-are-configured.md new file mode 100644 index 0000000..f274404 --- /dev/null +++ b/benchmarks/access-and-control/1.5-ensure-permissions-on-etc-cron.weekly-are-configured.md @@ -0,0 +1,39 @@ +# 1.5 确保 /etc/cron.weekly 的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/cron.weekly`目录中包含需要**每周**运行的`cron`作业。 此目录中的内容不能由`crontab`命令操作,而是由系统管理员使用文本编辑器直接修改其内容。 + +应将其读、写、执行权限限制为`root`用户,防止普通用户修改和访问此目录。否则可能导致:系统作业信息泄露、未授权用户篡改或删除作业信息、普通用户运行特权命令、普通用户获得 `root` 权限等多种风险。 + +## 修复建议 + +目标:正确配置`/etc/cron.weekly`目录的权限和所有者。 + +1. 使用以下代码,配置`/etc/cron.weekly`目录的权限和所有者: + +```shell +# chown root:root /etc/cron.weekly +# chmod og-rwx /etc/cron.weekly +``` + +## 扫描检测 + +确保`/etc/cron.weekly`目录的权限配置正确。 + +1. 执行以下命令,检查`/etc/cron.weekly`目录的权限属性: + +```shell +# stat /etc/cron.weekly +Access: (0700/drwx------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如果输出结果中:`Uid`与`Gid`均为`0/root`,且`Access`中`group`与`other`没有任何权限,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.6-ensure-permissions-on-etc-cron.monthly-are-configured.md b/benchmarks/access-and-control/1.6-ensure-permissions-on-etc-cron.monthly-are-configured.md new file mode 100644 index 0000000..16fb2df --- /dev/null +++ b/benchmarks/access-and-control/1.6-ensure-permissions-on-etc-cron.monthly-are-configured.md @@ -0,0 +1,39 @@ +# 1.6 确保 /etc/cron.monthly 的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/cron.monthly`目录中包含需要**每月**运行的`cron`作业。 此目录中的内容不能由`crontab`命令操作,而是由系统管理员使用文本编辑器直接修改其内容。 + +应将其读、写、执行权限限制为`root`用户,防止普通用户修改和访问此目录。否则可能导致:系统作业信息泄露、未授权用户篡改或删除作业信息、普通用户运行特权命令、普通用户获得 `root` 权限等多种风险。 + +## 修复建议 + +目标:正确配置`/etc/cron.monthly`目录的权限和所有者。 + +1. 使用以下代码,配置`/etc/cron.monthly`目录的权限和所有者: + +```shell +# chown root:root /etc/cron.monthly +# chmod og-rwx /etc/cron.monthly +``` + +## 扫描检测 + +确保`/etc/cron.monthly`目录的权限配置正确。 + +1. 执行以下命令,检查`/etc/cron.monthly`目录的权限属性: + +```shell +# stat /etc/cron.monthly +Access: (0700/drwx------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如果输出结果中:`Uid`与`Gid`均为`0/root`,且`Access`中`group`与`other`没有任何权限,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.7-ensure-permissions-on-etc-cron.d-are-configured.md b/benchmarks/access-and-control/1.7-ensure-permissions-on-etc-cron.d-are-configured.md new file mode 100644 index 0000000..04df1fb --- /dev/null +++ b/benchmarks/access-and-control/1.7-ensure-permissions-on-etc-cron.d-are-configured.md @@ -0,0 +1,39 @@ +# 1.7 确保 /etc/cron.d 的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/cron.d`目录中包含了需要定时执行的作业脚本文件,相比于`cron.hourly`、`cron.daily`、`cron.weekly`等目录,此目录下的脚本支持以特定用户的身份执行,且可对执行时间进行更精细的控制。此目录中的内容不能由`crontab`命令操作,而是由系统管理员使用文本编辑器直接修改其内容。 + +应将其读、写、执行权限限制为`root`用户,防止普通用户修改和访问此目录。否则可能导致:系统作业信息泄露、未授权用户篡改或删除作业信息、普通用户运行特权命令、普通用户获得 `root` 权限等多种风险。 + +## 修复建议 + +目标:正确配置`/etc/cron.d`目录的权限和所有者。 + +1. 使用以下代码,配置`/etc/cron.d`目录的权限和所有者: + +```shell +# chown root:root /etc/cron.d +# chmod og-rwx /etc/cron.d +``` + +## 扫描检测 + +确保`/etc/cron.d`目录的权限配置正确。 + +1. 执行以下命令,检查`/etc/cron.d`目录的权限属性: + +```shell +# stat /etc/cron.d +Access: (0700/drwx------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如果输出结果中:`Uid`与`Gid`均为`0/root`,且`Access`中`group`与`other`没有任何权限,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.8-ensure-at-cron-is-restricted-to-authorized-users.md b/benchmarks/access-and-control/1.8-ensure-at-cron-is-restricted-to-authorized-users.md new file mode 100644 index 0000000..1b1e34c --- /dev/null +++ b/benchmarks/access-and-control/1.8-ensure-at-cron-is-restricted-to-authorized-users.md @@ -0,0 +1,67 @@ +# 1.8 确保 at/cron 用户权限列表配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/cron.allow`、`/etc/at.allow`、`/etc/at.deny`、`/etc/cron.deny`文件都维护着一个用户列表,以允许或阻止特定的用户使用`at`或`crontab`命令。注意,即使某个用户没有被列在`cron.allow`中,`cron`作业仍然可以以该用户的身份运行。`cron.allow`文件只控制`crontab`命令的使用权限,从而限制可对`cron`作业进行调度及修改的用户。一般情况下,只有系统管理员可以对`cron`作业进行调度及修改。 +更推荐使用`cron.allow`文件来进行权限控制,因为维护一个允许列表比维护一个拒绝列表更加容易。如果使用`cron.deny`来进行权限控制,那么将很有可能在创建一个新用户时,忘记将其添加到拒绝列表中,导致权限管理出现漏洞。 + +## 修复建议 + +目标:正确配置`at/cron.allow`文件及其权限。 + +1. 使用以下代码,配置`at/cron.allow`文件及其权限: + * 删除`/etc/cron.deny`、`/etc/at.deny` + * 创建`/etc/cron.allow`、`/etc/at.allow`并配置其权限 + +```shell +# rm /etc/cron.deny +# rm /etc/at.deny +# touch /etc/cron.allow +# touch /etc/at.allow +# chmod og-rwx /etc/cron.allow +# chmod og-rwx /etc/at.allow +# chown root:root /etc/cron.allow +# chown root:root /etc/at.allow +``` + +## 扫描检测 + +确保`at/cron`用户权限列表配置正确 + +1. 检查`/etc/cron.deny`是否存在: + +```shell +# [ -e /etc/cron.deny ] && stat /etc/cron.deny +Nothing should be returned +``` + +2. 检查`/etc/at.deny`是否存在: + +```shell +# [ -e /etc/at.deny ] && stat /etc/at.deny +Nothing should be returned +``` + +3. 检查`/etc/cron.allow`文件权限,输出应为:`Uid`与`Gid`均为`0/root`,且`Access`中`group`与`other`没有任何权限: + +```shell +# stat /etc/cron.allow +Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +4. 检查`/etc/at.allow`文件权限,输出应为:`Uid`与`Gid`均为`0/root`,且`Access`中`group`与`other`没有任何权限: + +```shell +# stat /etc/at.allow +Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如所有输出结果符合要求,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/access-and-control/1.9-ensure-permissions-on-etc-ssh-sshd_config-are-configured.md b/benchmarks/access-and-control/1.9-ensure-permissions-on-etc-ssh-sshd_config-are-configured.md new file mode 100644 index 0000000..439e3fc --- /dev/null +++ b/benchmarks/access-and-control/1.9-ensure-permissions-on-etc-ssh-sshd_config-are-configured.md @@ -0,0 +1,39 @@ +# 1.9 确保 /etc/ssh/sshd_config 的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/ssh/sshd_config`文件是`sshd`服务的配置文件。如其遭到破坏或修改,将影响对系统的远程管理,文件传输等。 + +`/etc/ssh/sshd_config`文件权限需严格控制,防止其被非授权用户修改或删除。 + +## 修复建议 + +目标:正确配置`/etc/ssh/sshd_config`的权限及所有者。 + +1. 执行以下命令,配置`/etc/ssh/sshd_config`的权限及所有者: + +```shell +# chown root:root /etc/ssh/sshd_config +# chmod og-rwx /etc/ssh/sshd_config +``` + +## 扫描检测 + +确保`/etc/ssh/sshd_config`的权限配置正确。 + +1. 执行以下命令,检查`/etc/ssh/sshd_config`目录的权限属性: + +```shell +# stat /etc/ssh/sshd_config +Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如果输出结果中:`Uid`与`Gid`均为`0/root`,且`Access`中`group`与`other`没有任何权限,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file -- Gitee