From e82efc5ec91bbcc3eb276cc7f3aac7f52670d796 Mon Sep 17 00:00:00 2001 From: YuQing Date: Mon, 13 Jun 2022 15:54:29 +0800 Subject: [PATCH] benchmarks/system-configurations:add items from 4.1 to 4.65 Fixes: #I57ZM0 Signed-off-by: YuQing --- ...ssage-of-the-day-is-configured-properly.md | 49 +++++++++++ .../4.10-ensure-bootloader-password-is-set.md | 57 +++++++++++++ ...ons-on-bootloader-config-are-configured.md | 82 +++++++++++++++++++ ...ntication-required-for-single-user-mode.md | 47 +++++++++++ .../4.13-ensure-core-dumps-are-restricted.md | 56 +++++++++++++ ...-layout-randomization-(ASLR)-is-enabled.md | 48 +++++++++++ ...system-wide-crypto-policy-is-not-legacy.md | 52 ++++++++++++ ...s-set-on-all-world-writable-directories.md | 36 ++++++++ ...ermissions-on-etc-passwd-are-configured.md | 40 +++++++++ ...ermissions-on-etc-shadow-are-configured.md | 42 ++++++++++ ...permissions-on-etc-group-are-configured.md | 38 +++++++++ ...n-warning-banner-is-configured-properly.md | 66 +++++++++++++++ ...rmissions-on-etc-gshadow-are-configured.md | 42 ++++++++++ ...rmissions-on-etc-passwd--are-configured.md | 40 +++++++++ ...rmissions-on-etc-shadow--are-configured.md | 42 ++++++++++ ...ermissions-on-etc-group--are-configured.md | 38 +++++++++ ...missions-on-etc-gshadow--are-configured.md | 42 ++++++++++ ...25-ensure-no-world-writable-files-exist.md | 33 ++++++++ ...e-no-unowned-files-or-directories-exist.md | 33 ++++++++ ...no-ungrouped-files-or-directories-exist.md | 33 ++++++++ ...ensure-no-password-fields-are-not-empty.md | 41 ++++++++++ .../4.29-ensure-root-path-integrity.md | 73 +++++++++++++++++ ...n-warning-banner-is-configured-properly.md | 64 +++++++++++++++ ...0-ensure-root-is-the-only-uid-0-account.md | 44 ++++++++++ ...permissions-are-750-or-more-restrictive.md | 62 ++++++++++++++ ...ensure-users-own-their-home-directories.md | 72 ++++++++++++++++ ...t-files-are-not-group-or-world-writable.md | 62 ++++++++++++++ ....34-ensure-no-users-have-.forward-files.md | 53 ++++++++++++ .../4.35-ensure-no-users-have-.netrc-files.md | 53 ++++++++++++ ...files-are-not-group-or-world-accessible.md | 63 ++++++++++++++ ...4.37-ensure-no-users-have-.rhosts-files.md | 58 +++++++++++++ ...groups-in-etc-passwd-exist-in-etc-group.md | 38 +++++++++ .../4.39-ensure-no-duplicate-uids-exist.md | 40 +++++++++ ...-permissions-on-etc-motd-are-configured.md | 39 +++++++++ .../4.40-ensure-no-duplicate-gids-exist.md | 35 ++++++++ ...41-ensure-no-duplicate-user-names-exist.md | 35 ++++++++ ...2-ensure-no-duplicate-group-names-exist.md | 35 ++++++++ ...ensure-all-users-home-directories-exist.md | 50 +++++++++++ .../4.44-ensure-sctp-is-disabled.md | 43 ++++++++++ .../4.45-ensure-dccp-is-disabled.md | 44 ++++++++++ ...ensure-wireless-interfaces-are-disabled.md | 77 +++++++++++++++++ .../4.47-ensure-ip-forwarding-is-disabled.md | 47 +++++++++++ ...ure-packet-redirect-sending-is-disabled.md | 54 ++++++++++++ ...-source-routed-packets-are-not-accepted.md | 67 +++++++++++++++ ...permissions-on-etc-issue-are-configured.md | 39 +++++++++ ...-ensure-icmp-redirects-are-not-accepted.md | 67 +++++++++++++++ ...-secure-icmp-redirects-are-not-accepted.md | 56 +++++++++++++ ...52-ensure-suspicious-packets-are-logged.md | 54 ++++++++++++ ...ure-broadcast-icmp-requests-are-ignored.md | 41 ++++++++++ ...ensure-bogus-icmp-responses-are-ignored.md | 41 ++++++++++ ...nsure-reverse-path-filtering-is-enabled.md | 58 +++++++++++++ .../4.56-ensure-tcp-syn-cookies-is-enabled.md | 41 ++++++++++ ...-router-advertisements-are-not-accepted.md | 54 ++++++++++++ ...-ensure-a-firewall-package-is-installed.md | 69 ++++++++++++++++ ...irewalld-service-is-enabled-and-running.md | 43 ++++++++++ ...issions-on-etc-issue.net-are-configured.md | 39 +++++++++ .../4.60-ensure-iptables-is-not-enabled.md | 48 +++++++++++ .../4.61-ensure-nftables-is-not-enabled.md | 62 ++++++++++++++ ...4.62-ensure-nftables-service-is-enabled.md | 52 ++++++++++++ ...-ensure-iptables-packages-are-installed.md | 41 ++++++++++ .../4.64-ensure-nftables-is-not-installed.md | 54 ++++++++++++ ...-is-not-installed-or-stopped-and-masked.md | 59 +++++++++++++ ...7-ensure-gpgcheck-is-globally-activated.md | 51 ++++++++++++ .../4.8-ensure-aide-is-installed.md | 46 +++++++++++ ...lesystem-integrity-is-regularly-checked.md | 48 +++++++++++ 65 files changed, 3228 insertions(+) create mode 100644 benchmarks/system-configurations/4.1-ensure-message-of-the-day-is-configured-properly.md create mode 100644 benchmarks/system-configurations/4.10-ensure-bootloader-password-is-set.md create mode 100644 benchmarks/system-configurations/4.11-ensure-permissions-on-bootloader-config-are-configured.md create mode 100644 benchmarks/system-configurations/4.12-ensure-authentication-required-for-single-user-mode.md create mode 100644 benchmarks/system-configurations/4.13-ensure-core-dumps-are-restricted.md create mode 100644 benchmarks/system-configurations/4.14-ensure-address-space-layout-randomization-(ASLR)-is-enabled.md create mode 100644 benchmarks/system-configurations/4.15-ensure-system-wide-crypto-policy-is-not-legacy.md create mode 100644 benchmarks/system-configurations/4.16-ensure-sticky-bit-is-set-on-all-world-writable-directories.md create mode 100644 benchmarks/system-configurations/4.17-ensure-permissions-on-etc-passwd-are-configured.md create mode 100644 benchmarks/system-configurations/4.18-ensure-permissions-on-etc-shadow-are-configured.md create mode 100644 benchmarks/system-configurations/4.19-ensure-permissions-on-etc-group-are-configured.md create mode 100644 benchmarks/system-configurations/4.2-ensure-local-login-warning-banner-is-configured-properly.md create mode 100644 benchmarks/system-configurations/4.20-ensure-permissions-on-etc-gshadow-are-configured.md create mode 100644 benchmarks/system-configurations/4.21-ensure-permissions-on-etc-passwd--are-configured.md create mode 100644 benchmarks/system-configurations/4.22-ensure-permissions-on-etc-shadow--are-configured.md create mode 100644 benchmarks/system-configurations/4.23-ensure-permissions-on-etc-group--are-configured.md create mode 100644 benchmarks/system-configurations/4.24-ensure-permissions-on-etc-gshadow--are-configured.md create mode 100644 benchmarks/system-configurations/4.25-ensure-no-world-writable-files-exist.md create mode 100644 benchmarks/system-configurations/4.26-ensure-no-unowned-files-or-directories-exist.md create mode 100644 benchmarks/system-configurations/4.27-ensure-no-ungrouped-files-or-directories-exist.md create mode 100644 benchmarks/system-configurations/4.28-ensure-no-password-fields-are-not-empty.md create mode 100644 benchmarks/system-configurations/4.29-ensure-root-path-integrity.md create mode 100644 benchmarks/system-configurations/4.3-ensure-remote-login-warning-banner-is-configured-properly.md create mode 100644 benchmarks/system-configurations/4.30-ensure-root-is-the-only-uid-0-account.md create mode 100644 benchmarks/system-configurations/4.31-ensure-users-home-directories-permissions-are-750-or-more-restrictive.md create mode 100644 benchmarks/system-configurations/4.32-ensure-users-own-their-home-directories.md create mode 100644 benchmarks/system-configurations/4.33-ensure-users-dot-files-are-not-group-or-world-writable.md create mode 100644 benchmarks/system-configurations/4.34-ensure-no-users-have-.forward-files.md create mode 100644 benchmarks/system-configurations/4.35-ensure-no-users-have-.netrc-files.md create mode 100644 benchmarks/system-configurations/4.36-ensure-users-.netrc-files-are-not-group-or-world-accessible.md create mode 100644 benchmarks/system-configurations/4.37-ensure-no-users-have-.rhosts-files.md create mode 100644 benchmarks/system-configurations/4.38-ensure-all-groups-in-etc-passwd-exist-in-etc-group.md create mode 100644 benchmarks/system-configurations/4.39-ensure-no-duplicate-uids-exist.md create mode 100644 benchmarks/system-configurations/4.4-ensure-permissions-on-etc-motd-are-configured.md create mode 100644 benchmarks/system-configurations/4.40-ensure-no-duplicate-gids-exist.md create mode 100644 benchmarks/system-configurations/4.41-ensure-no-duplicate-user-names-exist.md create mode 100644 benchmarks/system-configurations/4.42-ensure-no-duplicate-group-names-exist.md create mode 100644 benchmarks/system-configurations/4.43-ensure-all-users-home-directories-exist.md create mode 100644 benchmarks/system-configurations/4.44-ensure-sctp-is-disabled.md create mode 100644 benchmarks/system-configurations/4.45-ensure-dccp-is-disabled.md create mode 100644 benchmarks/system-configurations/4.46-ensure-wireless-interfaces-are-disabled.md create mode 100644 benchmarks/system-configurations/4.47-ensure-ip-forwarding-is-disabled.md create mode 100644 benchmarks/system-configurations/4.48-ensure-packet-redirect-sending-is-disabled.md create mode 100644 benchmarks/system-configurations/4.49-ensure-source-routed-packets-are-not-accepted.md create mode 100644 benchmarks/system-configurations/4.5-ensure-permissions-on-etc-issue-are-configured.md create mode 100644 benchmarks/system-configurations/4.50-ensure-icmp-redirects-are-not-accepted.md create mode 100644 benchmarks/system-configurations/4.51-ensure-secure-icmp-redirects-are-not-accepted.md create mode 100644 benchmarks/system-configurations/4.52-ensure-suspicious-packets-are-logged.md create mode 100644 benchmarks/system-configurations/4.53-ensure-broadcast-icmp-requests-are-ignored.md create mode 100644 benchmarks/system-configurations/4.54-ensure-bogus-icmp-responses-are-ignored.md create mode 100644 benchmarks/system-configurations/4.55-ensure-reverse-path-filtering-is-enabled.md create mode 100644 benchmarks/system-configurations/4.56-ensure-tcp-syn-cookies-is-enabled.md create mode 100644 benchmarks/system-configurations/4.57-ensure-ipv6-router-advertisements-are-not-accepted.md create mode 100644 benchmarks/system-configurations/4.58-ensure-a-firewall-package-is-installed.md create mode 100644 benchmarks/system-configurations/4.59-ensure-firewalld-service-is-enabled-and-running.md create mode 100644 benchmarks/system-configurations/4.6-ensure-permissions-on-etc-issue.net-are-configured.md create mode 100644 benchmarks/system-configurations/4.60-ensure-iptables-is-not-enabled.md create mode 100644 benchmarks/system-configurations/4.61-ensure-nftables-is-not-enabled.md create mode 100644 benchmarks/system-configurations/4.62-ensure-nftables-service-is-enabled.md create mode 100644 benchmarks/system-configurations/4.63-ensure-iptables-packages-are-installed.md create mode 100644 benchmarks/system-configurations/4.64-ensure-nftables-is-not-installed.md create mode 100644 benchmarks/system-configurations/4.65-ensure-firewalld-is-not-installed-or-stopped-and-masked.md create mode 100644 benchmarks/system-configurations/4.7-ensure-gpgcheck-is-globally-activated.md create mode 100644 benchmarks/system-configurations/4.8-ensure-aide-is-installed.md create mode 100644 benchmarks/system-configurations/4.9-ensure-filesystem-integrity-is-regularly-checked.md diff --git a/benchmarks/system-configurations/4.1-ensure-message-of-the-day-is-configured-properly.md b/benchmarks/system-configurations/4.1-ensure-message-of-the-day-is-configured-properly.md new file mode 100644 index 0000000..723d90d --- /dev/null +++ b/benchmarks/system-configurations/4.1-ensure-message-of-the-day-is-configured-properly.md @@ -0,0 +1,49 @@ +# 4.1 确保登录提示消息的内容符合要求 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/motd`文件的内容会在用户登录后展示给用户。 + +类 Unix 系统通常会在登录系统时显示当前操作系统的版本信息和补丁信息。这些信息对于为特定操作系统平台开发软件的开发者来说是很有用的。但这样做也有一个副作用:会将系统版本的详细提供给针对特定系统漏洞的攻击者。而这些信息,对于已授权的用户来说,可以通过`uname -a`命令轻松获得。 + +综上,登录提示信息不应展示操作系统版本信息及补丁信息。 + +## 修复建议 + +编辑或删除`/etc/motd`文件,确保系统信息不展示在登录消息内。 + +1. 可根据使用环境,自行编辑登录提示消息,但要确保其内容没有系统版本或补丁信息。如不需要登录提示消息,直接删除`/etc/motd`文件即可。 + +* 参考内容: + +```shell +# echo "Authorized uses only. All activity may be monitored and reported." > /etc/motd +``` + +## 扫描检测 + +确保登录提示消息的内容符合要求。 + +1. 执行以下命令,检查输出内容是否有不符合安全要求的信息(系统版本信息、补丁信息等): + +```shell +# cat /etc/motd +Authorized uses only. All activity may be monitored and reported. +``` + +2. 执行以下命令,确保没有返回任何信息: + +```shell +# grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/motd +No information is returned. +``` + +如`/etc/motd`内没有任何不符合安全要求的信息(系统版本信息、补丁信息等),且第2条命令执行后没有返回任何内容,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.10-ensure-bootloader-password-is-set.md b/benchmarks/system-configurations/4.10-ensure-bootloader-password-is-set.md new file mode 100644 index 0000000..ed291a8 --- /dev/null +++ b/benchmarks/system-configurations/4.10-ensure-bootloader-password-is-set.md @@ -0,0 +1,57 @@ +# 4.10 确保设置了 bootloader 密码 + +## 安全等级 + +Level 2 + +## 描述 + +需要配置引导加密,要求所有人在 grub 设置启动参数之前必须进行密码验证。 + +这样做可以防止未经授权的用户进行启动参数修改或改变启动分区。(例如在启动时关闭`SELinux`)。 + +## 修复建议 + +设置 bootloader 密码。 + +1. 使用以下命令,配置 bootloader 密码: + +```shell +# grub2-setpassword +Enter password: +Confirm password: +``` + +需自定义符合要求的密码。 + +2. 执行以下脚本更新`grub2`配置: + +```shell +#!/usr/bin/env bash +GFCU() +{ + grubfile=$(find /boot -type f \( -name 'grubenv' -o -name 'grub.conf' -o -name 'grub.cfg' \) -exec grep -Pl '^\h*(kernelopts=|linux|kernel)' {} \;) + grubdir=$(dirname "$grubfile") + grub2-mkconfig -o "$grubdir/grub.cfg" +} +GFCU +``` + + +## 扫描检测 + +确保设置了 bootloader 密码。 + +1. 执行以下命令,验证是否配置了 bootloader 密码: + +```shell +# grep -P '^\h*GRUB2_PASSWORD\h*=\h*.+$' /boot/grub2/user.cfg +GRUB2_PASSWORD=grub.pbkdf2.sha512...... +``` + +如返回结果符合预期,则视为通过此项检查。如返回为空或无此文件,则未通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.11-ensure-permissions-on-bootloader-config-are-configured.md b/benchmarks/system-configurations/4.11-ensure-permissions-on-bootloader-config-are-configured.md new file mode 100644 index 0000000..d5f34af --- /dev/null +++ b/benchmarks/system-configurations/4.11-ensure-permissions-on-bootloader-config-are-configured.md @@ -0,0 +1,82 @@ +# 4.11 确保 bootloader 配置文件的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +grub 文件包含启动信息和 bootloader 密码信息。grub2 的配置通常在`grub.cfg`文件中。 + +如系统使用 UEFI ,则`/boot/efi`为vfat文件系统。vfat文件系统本身没有权限的概念,但是可以在Linux下使用所需的任何权限进行挂载。 + +应将 grub 配置文件的权限配置为,仅 root 用户可访问,防止其他未授权用户读取或修改启动参数。 + +## 修复建议 + +修改 grub 配置文件的权限。 + +1. 使用以下命令,配置`/boot/grub2/`目录下,配置文件的权限及所有权: + +```shell +# [ -f /boot/grub2/grub.cfg ] && chown root:root /boot/grub2/grub.cfg +# [ -f /boot/grub2/grub.cfg ] && chmod og-rwx /boot/grub2/grub.cfg +# [ -f /boot/grub2/grubenv ] && chown root:root /boot/grub2/grubenv +# [ -f /boot/grub2/grubenv ] && chmod og-rwx /boot/grub2/grubenv +# [ -f /boot/grub2/user.cfg ] && chown root:root /boot/grub2/user.cfg +# [ -f /boot/grub2/user.cfg ] && chmod og-rwx /boot/grub2/user.cfg +# [ -f /boot/efi/EFI/anolis/grubenv ] && chown root:root /boot/efi/EFI/anolis/grubenv +# [ -f /boot/efi/EFI/anolis/grubenv ] && chmod og-rwx /boot/efi/EFI/anolis/grubenv +``` + +2. 如为 UEFI 模式,则需编辑`/etc/fstab`文件,添加以下参数: + +```shell + /boot/efi vfat defaults,umask=0027,fmask=0077,uid=0,gid=0 0 0 +``` + +*\* 可能需要重启系统以启用更改。* + +## 扫描检测 + +确保 bootloader 配置文件的权限配置正确。 + +1. 执行以下命令,验证 bootloader 配置文件的权限配置正确: + +```shell +#!/usr/bin/env bash +GFPT() +{ + tst1="" tst2="" tst3="" tst4="" tst5="" tst6="" output="" output2="" output3="" output4="" output5="" output6="" + grubfile=$(find /boot -type f \( -name 'grubenv' -o -name 'grub.conf' -o -name 'grub.cfg' \) -exec grep -Pl '^\h*(kernelopts=|linux|kernel)' {} \;) + grubdir=$(dirname "$grubfile") + stat -c "%a" "$grubfile" | grep -Pq '^\h*[0-7]00$' && tst1=pass output="Permissions on \"$grubfile\" are \"$(stat -c "%a" "$grubfile")\"" + stat -c "%u:%g" "$grubfile" | grep -Pq '^\h*0:0$' && tst2=pass output2="\"$grubfile\" is owned by \"$(stat -c "%U" "$grubfile")\" and belongs to group \"$(stat -c "%G" "$grubfile")\"" + if [ -f "$grubdir/user.cfg" ]; then + stat -c "%a" "$grubdir/user.cfg" | grep -Pq '^\h*[0-7]00$' && tst3=pass output3="Permissions on \"$grubdir/user.cfg\" are \"$(stat -c "%a" "$grubdir/user.cfg")\"" + stat -c "%u:%g" "$grubdir/user.cfg" | grep -Pq '^\h*0:0$' && tst4=pass output4="\"$grubdir/user.cfg\" is owned by \"$(stat -c "%U" "$grubdir/user.cfg")\" and belongs to group \"$(stat -c "%G" "$grubdir/user.cfg")\"" + else + tst3=pass;tst4=pass + fi + if [ -f "$grubdir/grub.cfg" ]; then + stat -c "%a" "$grubdir/grub.cfg" | grep -Pq '^\h*[0-7]00$' && tst5=pass output5="Permissions on \"$grubdir/grub.cfg\" are \"$(stat -c "%a" "$grubdir/grub.cfg")\"" + stat -c "%u:%g" "$grubdir/grub.cfg" | grep -Pq '^\h*0:0$' && tst6=pass output6="\"$grubdir/grub.cfg\" is owned by \"$(stat -c "%U" "$grubdir/grub.cfg")\" and belongs to group \"$(stat -c "%G" "$grubdir/grub.cfg")\"" + else + tst5=pass;tst6=pass + fi + if [ "$tst1" = "pass" ] && [ "$tst2" = "pass" ] && [ "$tst3" = "pass" ] && [ "$tst4" = "pass" ] && [ "$tst5" = "pass" ] && [ "$tst6" = "pass" ]; then + echo "PASSED: " + else + echo "FAILED: " + fi + [ -n "$output" ] && echo "$output";[ -n "$output2" ] && echo "$output2";[ -n "$output3" ] && echo "$output3" [ -n "$output4" ] && echo "$output4";[ -n "$output5" ] && echo "$output5";[ -n "$output6" ] && echo "$output6" +} +GFPT +``` + +如返回`PASSED`,则视为通过此项检查。如返回`FAILED`,则未通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.12-ensure-authentication-required-for-single-user-mode.md b/benchmarks/system-configurations/4.12-ensure-authentication-required-for-single-user-mode.md new file mode 100644 index 0000000..38ceb30 --- /dev/null +++ b/benchmarks/system-configurations/4.12-ensure-authentication-required-for-single-user-mode.md @@ -0,0 +1,47 @@ +# 4.12 确保进入单用户模式需要进行身份验证 + +## 安全等级 + +Level 1 + +## 描述 + +单用户模式(救援模式):Linux 的单用户模式有些类似 Windows 的安全模式,只启动最少的程序用于系统修复。在单用户模式(运行级别为 1)中,Linux 引导进入根 Shell,网络被禁用,只有少数进程运行。单用户模式可以用来修改文件系统损坏、还原配置文件、移动用户数据等。 + +要求在进入单用户模式(救援模式)时进行身份验证,以防止未经授权用户进入此模式,对系统进行破坏。 + +## 修复建议 + +配置单用户模式身份验证。 + +1. 编辑`/usr/lib/systemd/system/rescue.service`文件,并添加以下参数: + +```shell +ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue +``` + +2. 编辑`/usr/lib/systemd/system/rescue.service`文件,并添加以下参数: + +```shell +ExecStart=-/usr/lib/systemd/systemd-sulogin-shell emergency +``` + +## 扫描检测 + +确保进入单用户模式需要进行身份验证。 + +1. 执行以下命令,单用户模式身份验证是否正确配置: + +```shell +# grep /systemd-sulogin-shell /usr/lib/systemd/system/rescue.service +ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue +# grep /systemd-sulogin-shell /usr/lib/systemd/system/emergency.service +ExecStart=-/usr/lib/systemd/systemd-sulogin-shell emergency +``` + +如返回值符合要求,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.13-ensure-core-dumps-are-restricted.md b/benchmarks/system-configurations/4.13-ensure-core-dumps-are-restricted.md new file mode 100644 index 0000000..1684a9a --- /dev/null +++ b/benchmarks/system-configurations/4.13-ensure-core-dumps-are-restricted.md @@ -0,0 +1,56 @@ +# 4.13 确保核心转储受到限制 + +## 安全等级 + +Level 1 + +## 描述 + +当程序运行的过程中异常终止或崩溃,操作系统会将程序当时的内存状态记录下来,保存在一个文件中,这种行为就叫做核心转储(core dumps)。它还可以用于从核心文件中收集机密信息。 + +系统自身提供了核心转储的限制功能,但用户可能会重写这个限制。对核心转储设置硬性限制可以防止其被用户覆盖。 + +## 修复建议 + +配置单用户模式身份验证。 + +1. 编辑`/etc/security/limits.conf`文件,修改或添加`* hard core 0`参数: + +```shell +egrep -q "^(\s*)\*\s+hard\s+core\s+\S+(\s*#.*)?\s*$" /etc/security/limits.conf && sed -ri "s/^(\s*)\*\s+hard\s+core\s+\S+(\s*#.*)?\s*$/\1* hard core 0\2/" /etc/security/limits.conf || echo "* hard core 0" >> /etc/security/limits.conf +``` + +2. 编辑`/etc/sysctl.conf`文件,修改或添加`fs.suid_dumpable = 0`参数: + +```shell +egrep -q "^(\s*)fs.suid_dumpable\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)fs.suid_dumpable\s*=\s*\S+(\s*#.*)?\s*$/\1fs.suid_dumpable = 0\2/" /etc/sysctl.conf || echo "fs.suid_dumpable = 0" >> /etc/sysctl.conf +``` + +3. 执行以下命令,设置活动内核参数: + +```shell +# sysctl -w fs.suid_dumpable=0 +``` + +## 扫描检测 + +确保核心转储受到限制。 + +1. 执行以下命令,检查输出结果是否匹配: + +```shell +# grep -E "^\s*\*\s+hard\s+core" /etc/security/limits.conf +* hard core 0 +# sysctl fs.suid_dumpable +fs.suid_dumpable = 0 +# grep "fs\.suid_dumpable" /etc/sysctl.conf /etc/sysctl.d/* +/etc/sysctl.conf:fs.suid_dumpable = 0 +/etc/sysctl.d/99-sysctl.conf:fs.suid_dumpable = 0 +``` + +如返回值符合要求,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.14-ensure-address-space-layout-randomization-(ASLR)-is-enabled.md b/benchmarks/system-configurations/4.14-ensure-address-space-layout-randomization-(ASLR)-is-enabled.md new file mode 100644 index 0000000..cc0d966 --- /dev/null +++ b/benchmarks/system-configurations/4.14-ensure-address-space-layout-randomization-(ASLR)-is-enabled.md @@ -0,0 +1,48 @@ +# 4.14 确保地址空间布局随机化(ASLR)被启用 + +## 安全等级 + +Level 1 + +## 描述 + +ASLR (Address Space Layout Randomization,地址空间布局随机化),是一种针对缓冲区溢出的安全保护技术。借助 ASLR,PE 文件每次加载到内存的起始地址都会随机变化。 + +## 修复建议 + +启用 ASLR。 + +1. 编辑`/etc/sysctl.conf`或`/etc/sysctl.d/*`文件,添加`kernel.randomize_va_space = 2`参数: + +```shell +printf " +kernel.randomize_va_space = 2 +" >> /etc/sysctl.d/50-kernel_sysctl.conf +``` + +2. 执行以下命令,设置活动内核参数: + +```shell +# sysctl -w kernel.randomize_va_space=2 +``` + +## 扫描检测 + +确保地址空间布局随机化(ASLR)被启用。 + +1. 执行以下命令,检查输出结果是否匹配: + +```shell +# sysctl kernel.randomize_va_space +kernel.randomize_va_space = 2 +# grep -s -- "kernel\.randomize_va_space" /run/sysctl.d/*.conf /etc/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf /etc/sysctl.conf +/etc/sysctl.d/99-sysctl.conf:kernel.randomize_va_space = 2 +/etc/sysctl.conf:kernel.randomize_va_space = 2 +``` + +如返回值符合要求,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.15-ensure-system-wide-crypto-policy-is-not-legacy.md b/benchmarks/system-configurations/4.15-ensure-system-wide-crypto-policy-is-not-legacy.md new file mode 100644 index 0000000..795fb1f --- /dev/null +++ b/benchmarks/system-configurations/4.15-ensure-system-wide-crypto-policy-is-not-legacy.md @@ -0,0 +1,52 @@ +# 4.15 确保系统全局加密策略符合要求 + +## 安全等级 + +Level 1 + +## 描述 + +系统全局加密策略,目前有以下等级: + +* LEGACY +* DEFAULT +* FUTURE +* FIPS + +Legacy 等级的加密策略包含(TLS 1.0、TLS 1.1、SSH2协议或更高版本、DSA、3DES、RC4)等。但这些加密策略目前已不够安全,建议使用 DEFAULT 等级。 + +## 修复建议 + +配置系统加密策略为 DEFAULT。 + +1. 执行以下命令,配置系统加密策略等级: + +```shell +# update-crypto-policies --set DEFAULT +``` + +2. 执行以下命令,激活加密策略: + +```shell +# update-crypto-policies +``` + +默认系统加密策略为:`DEFAULT`。 + +## 扫描检测 + +确保系统全局加密策略符合要求。 + +1. 执行以下命令,检查系统加密策略是否符合要求: + +```shell +# grep -E -i '^\s*LEGACY\s*(\s+#.*)?$' /etc/crypto-policies/config +No information is returned. +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.16-ensure-sticky-bit-is-set-on-all-world-writable-directories.md b/benchmarks/system-configurations/4.16-ensure-sticky-bit-is-set-on-all-world-writable-directories.md new file mode 100644 index 0000000..7d014c0 --- /dev/null +++ b/benchmarks/system-configurations/4.16-ensure-sticky-bit-is-set-on-all-world-writable-directories.md @@ -0,0 +1,36 @@ +# 4.16 确保所有全局可写目录都设置了 sticky 位 + +## 安全等级 + +Level 1 + +## 描述 + +设置全局可写目录的 sticky 位可以防止用户删除或重命名该目录中不属于自己的文件。 + +## 修复建议 + +配置全局可写目录 sticky 位。 + +1. 执行以下命令,配置全局可写目录 sticky 位: + +```shell +# df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -type d \( -perm -0002 -a ! -perm -1000 \) 2>/dev/null | xargs -I '{}' chmod a+t '{}' +``` + +## 扫描检测 + +确保所有全局可写目录都设置了 sticky 位。 + +1. 执行以下命令,检查全局可写目录 sticky 位是否正确配置: + +```shell +# df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -type d \( -perm -0002 -a ! -perm -1000 \) 2>/dev/null +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.17-ensure-permissions-on-etc-passwd-are-configured.md b/benchmarks/system-configurations/4.17-ensure-permissions-on-etc-passwd-are-configured.md new file mode 100644 index 0000000..c4da231 --- /dev/null +++ b/benchmarks/system-configurations/4.17-ensure-permissions-on-etc-passwd-are-configured.md @@ -0,0 +1,40 @@ +# 4.17 确保 /etc/passwd 文件权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/passwd`文件中也存储了所有用户账户信息,所有用户都需要读取此文件。也包含了许多系统级应用所使用的用户账户信息(虚拟用户),这些应用对`passwd`文件也必须有可读权限,才可正常运行。 + +正由于其对所有用户都可读,因此,`/etc/passwd`文件的安全性要求是非常高的。需要确保`/etc/passwd`文件不被未经授权的用户访问或修改。 + +## 修复建议 + +配置`/etc/passwd`文件的所有者与权限。 + +1. 执行以下命令,配置`/etc/passwd`文件的所有者与权限: + +```shell +# chown root:root /etc/passwd +# chmod 644 /etc/passwd +``` + +## 扫描检测 + +确保`/etc/passwd`文件权限配置正确。 + +1. 执行以下命令,`/etc/passwd`文件权限配置是否正确: + +```shell +# stat /etc/passwd +Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如返回结果中:`Uid`与`Gid`均为`(0/root)`,且`Access`为`0644`或更严格的限制,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.18-ensure-permissions-on-etc-shadow-are-configured.md b/benchmarks/system-configurations/4.18-ensure-permissions-on-etc-shadow-are-configured.md new file mode 100644 index 0000000..2b6054e --- /dev/null +++ b/benchmarks/system-configurations/4.18-ensure-permissions-on-etc-shadow-are-configured.md @@ -0,0 +1,42 @@ +# 4.18 确保 /etc/shadow 文件权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/shadow`文件用于存储系统内用户账户的重要安全信息,如哈希密码等。 + +如果攻击者获得了`/etc/shadow`文件的读取权限,就可以轻易的获得用户的哈希密码,并运行密码破解程序来破解它。存储在`/etc/shadow`文件中的其他安全信息(如过期时间等)也可以用来对用户账户进行破坏。 + +因此,`/etc/shadow`文件的安全性要求是非常高的。需要确保`/etc/shadow`文件不被未经授权的用户访问或修改。 + +## 修复建议 + +配置`/etc/shadow`文件的所有者与权限。 + +1. 执行以下命令,配置`/etc/shadow`文件的所有者与权限: + +```shell +# chown root:root /etc/shadow +# chmod 0000 /etc/shadow +``` + +## 扫描检测 + +确保`/etc/shadow`文件权限配置正确。 + +1. 执行以下命令,`/etc/shadow`文件权限配置是否正确: + +```shell +# stat /etc/shadow +Access: (0000/----------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如返回结果中:`Uid`与`Gid`均为`(0/root)`,且`Access`为`0000`,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.19-ensure-permissions-on-etc-group-are-configured.md b/benchmarks/system-configurations/4.19-ensure-permissions-on-etc-group-are-configured.md new file mode 100644 index 0000000..b16c3b6 --- /dev/null +++ b/benchmarks/system-configurations/4.19-ensure-permissions-on-etc-group-are-configured.md @@ -0,0 +1,38 @@ +# 4.19 确保 /etc/group 文件权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/group`文件包含了系统中所有有效用户组的列表。其权限应配置为,`root`用户对其有读写权限,其余用户对其仅有读权限。 + +## 修复建议 + +配置`/etc/group`文件的所有者与权限。 + +1. 执行以下命令,配置`/etc/group`文件的所有者与权限: + +```shell +# chown root:root /etc/group +# chmod u-x,g-wx,o-wx /etc/group +``` + +## 扫描检测 + +确保`/etc/group`文件权限配置正确。 + +1. 执行以下命令,`/etc/group`文件权限配置是否正确: + +```shell +# stat /etc/group +Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如返回结果中:`Uid`与`Gid`均为`(0/root)`,且`Access`为`0644`或更严格的限制,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.2-ensure-local-login-warning-banner-is-configured-properly.md b/benchmarks/system-configurations/4.2-ensure-local-login-warning-banner-is-configured-properly.md new file mode 100644 index 0000000..b13a443 --- /dev/null +++ b/benchmarks/system-configurations/4.2-ensure-local-login-warning-banner-is-configured-properly.md @@ -0,0 +1,66 @@ +# 4.2 确保本地登录提示消息的内容符合要求 + +## 安全等级 + +Level 1 + +## 描述 + +在**本地终端**登录时会展示`/etc/issue`文件中的内容。 + +类 Unix 系统通常会在登录系统时显示当前操作系统的版本信息和补丁信息。这些信息对于为特定操作系统平台开发软件的开发者来说是很有用的。但这样做也有一个副作用:会将系统版本的详细提供给针对特定系统漏洞的攻击者。而这些信息,对于已授权的用户来说,可以通过`uname -a`命令轻松获得。 + +综上,登录提示信息不应展示操作系统版本信息及补丁信息。 + +`/etc/issue`文件的内容解析: + +```shell +# cat /etc/issue +\S +Kernel \r on an \m +``` + +其中`\*`参数对应输出内容如下: + +``` +\m 给出当前操作系统的位数 +\r 详细的内核版本 +\s 操作系统的名称 +\v 操作系统的版本 +``` + +## 修复建议 + +编辑或删除`/etc/issue`文件,确保系统信息不展示在登录消息内。 + +1. 可根据使用环境,自行编辑登录提示消息,但要确保其内容没有系统版本或补丁信息。删除任何含有`\m`、`\r`、`\s`、`\v`的信息。 + +* 参考内容: + +```shell +# echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue +``` + +## 扫描检测 + +确保登录提示消息的内容符合要求。 + +1. 执行以下命令,检查输出内容是否有不符合安全要求的信息(系统版本信息、补丁信息等): + +```shell +# cat /etc/issue +Authorized uses only. All activity may be monitored and reported. +``` + +2. 执行以下命令,确保没有返回任何信息: + +```shell +# grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/issue +No information is returned. +``` + +如`/etc/issue`内没有任何不符合安全要求的信息(系统版本信息、补丁信息等),且第2条命令执行后没有返回任何内容,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.20-ensure-permissions-on-etc-gshadow-are-configured.md b/benchmarks/system-configurations/4.20-ensure-permissions-on-etc-gshadow-are-configured.md new file mode 100644 index 0000000..ffaf29b --- /dev/null +++ b/benchmarks/system-configurations/4.20-ensure-permissions-on-etc-gshadow-are-configured.md @@ -0,0 +1,42 @@ +# 4.20 确保 /etc/gshadow 文件权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/gshadow`文件用于存储系统内用户组的重要安全信息,如哈希密码等。 + +如果攻击者获得了`/etc/gshadow`文件的读取权限,就可以轻易的获得用户组的哈希密码,并运行密码破解程序来破解它。存储在`/etc/gshadow`文件中的其他安全信息(如组管理员等)也可以用来对用户组进行破坏。 + +因此,`/etc/gshadow`文件的安全性要求是非常高的。需要确保`/etc/gshadow`文件不被未经授权的用户访问或修改。 + +## 修复建议 + +配置`/etc/gshadow`文件的所有者与权限。 + +1. 执行以下命令,配置`/etc/gshadow`文件的所有者与权限: + +```shell +# chown root:root /etc/gshadow +# chmod 0000 /etc/gshadow +``` + +## 扫描检测 + +确保`/etc/gshadow`文件权限配置正确。 + +1. 执行以下命令,`/etc/gshadow`文件权限配置是否正确: + +```shell +# stat /etc/gshadow +Access: (0000/----------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如返回结果中:`Uid`与`Gid`均为`(0/root)`,且`Access`为`0000`,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.21-ensure-permissions-on-etc-passwd--are-configured.md b/benchmarks/system-configurations/4.21-ensure-permissions-on-etc-passwd--are-configured.md new file mode 100644 index 0000000..6b52d09 --- /dev/null +++ b/benchmarks/system-configurations/4.21-ensure-permissions-on-etc-passwd--are-configured.md @@ -0,0 +1,40 @@ +# 4.21 确保 /etc/passwd- 文件权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/passwd-`文件中包含备份的用户帐号信息。 + +需要确保`/etc/passwd-`文件不被未经授权的用户访问或修改。 + +## 修复建议 + +配置`/etc/passwd-`文件的所有者与权限。 + +1. 执行以下命令,配置`/etc/passwd-`文件的所有者与权限: + +```shell +# chown root:root /etc/passwd- +# chmod chmod u-x,go-wx /etc/passwd- +``` + +## 扫描检测 + +确保`/etc/passwd-`文件权限配置正确。 + +1. 执行以下命令,`/etc/passwd-`文件权限配置是否正确: + +```shell +# stat /etc/passwd- +Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如返回结果中:`Uid`与`Gid`均为`(0/root)`,且`Access`为`0644`或更严格的限制,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.22-ensure-permissions-on-etc-shadow--are-configured.md b/benchmarks/system-configurations/4.22-ensure-permissions-on-etc-shadow--are-configured.md new file mode 100644 index 0000000..c9d7d92 --- /dev/null +++ b/benchmarks/system-configurations/4.22-ensure-permissions-on-etc-shadow--are-configured.md @@ -0,0 +1,42 @@ +# 4.22 确保 /etc/shadow- 文件权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/shadow-`文件用于备份系统内用户账户安全信息,如哈希密码等。 + +如果攻击者获得了`/etc/shadow-`文件的读取权限,就可以轻易的获得用户的哈希密码,并运行密码破解程序来破解它。存储在`/etc/shadow-`文件中的其他安全信息(如过期时间等)也可以用来对用户账户进行破坏。 + +需要确保`/etc/shadow-`文件不被未经授权的用户访问或修改。 + +## 修复建议 + +配置`/etc/shadow-`文件的所有者与权限。 + +1. 执行以下命令,配置`/etc/shadow-`文件的所有者与权限: + +```shell +# chown root:root /etc/shadow- +# chmod 0000 /etc/shadow- +``` + +## 扫描检测 + +确保`/etc/shadow-`文件权限配置正确。 + +1. 执行以下命令,`/etc/shadow-`文件权限配置是否正确: + +```shell +# stat /etc/shadow- +Access: (0000/----------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如返回结果中:`Uid`与`Gid`均为`(0/root)`,且`Access`为`0000`,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.23-ensure-permissions-on-etc-group--are-configured.md b/benchmarks/system-configurations/4.23-ensure-permissions-on-etc-group--are-configured.md new file mode 100644 index 0000000..c02e114 --- /dev/null +++ b/benchmarks/system-configurations/4.23-ensure-permissions-on-etc-group--are-configured.md @@ -0,0 +1,38 @@ +# 4.23 确保 /etc/group- 文件权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/group-`文件包含了系统中所有有效用户组列表的备份。其权限应配置为,`root`用户对其有读写权限,其余用户对其仅有读权限。 + +## 修复建议 + +配置`/etc/group-`文件的所有者与权限。 + +1. 执行以下命令,配置`/etc/group-`文件的所有者与权限: + +```shell +# chown root:root /etc/group- +# chmod u-x,go-wx /etc/group- +``` + +## 扫描检测 + +确保`/etc/group-`文件权限配置正确。 + +1. 执行以下命令,`/etc/group-`文件权限配置是否正确: + +```shell +# stat /etc/group- +Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如返回结果中:`Uid`与`Gid`均为`(0/root)`,且`Access`为`0644`或更严格的限制,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.24-ensure-permissions-on-etc-gshadow--are-configured.md b/benchmarks/system-configurations/4.24-ensure-permissions-on-etc-gshadow--are-configured.md new file mode 100644 index 0000000..f511ee8 --- /dev/null +++ b/benchmarks/system-configurations/4.24-ensure-permissions-on-etc-gshadow--are-configured.md @@ -0,0 +1,42 @@ +# 4.24 确保 /etc/gshadow- 文件权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/gshadow-`文件备份了系统内用户组的重要安全信息,如哈希密码等。 + +如果攻击者获得了`/etc/gshadow-`文件的读取权限,就可以轻易的获得用户组的哈希密码,并运行密码破解程序来破解它。 + +需要确保`/etc/gshadow-`文件不被未经授权的用户访问或修改。 + +## 修复建议 + +配置`/etc/gshadow-`文件的所有者与权限。 + +1. 执行以下命令,配置`/etc/gshadow-`文件的所有者与权限: + +```shell +# chown root:root /etc/gshadow- +# chmod 0000 /etc/gshadow- +``` + +## 扫描检测 + +确保`/etc/gshadow-`文件权限配置正确。 + +1. 执行以下命令,`/etc/gshadow-`文件权限配置是否正确: + +```shell +# stat /etc/gshadow- +Access: (0000/----------) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如返回结果中:`Uid`与`Gid`均为`(0/root)`,且`Access`为`0000`,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.25-ensure-no-world-writable-files-exist.md b/benchmarks/system-configurations/4.25-ensure-no-world-writable-files-exist.md new file mode 100644 index 0000000..37c79df --- /dev/null +++ b/benchmarks/system-configurations/4.25-ensure-no-world-writable-files-exist.md @@ -0,0 +1,33 @@ +# 4.25 确保没有所有人可写的文件 + +## 安全等级 + +Level 2 + +## 描述 + +所有人可写的文件中的数据可以被系统中的任何用户修改和破坏,极易被未授权用户注入恶意脚本。所有人可写的文件很有可能是一个恶意脚本或程序,在其被执行后,可能对系统造成破坏。 + +所以需要扫描出系统内所有人可写的文件,对其进行甄别与清理。 + +## 修复建议 + +建议删除所有人可写的文件,但在操作前,应阅读供应商或软件服务文档,以免破坏正常程序的依赖文件。 + +## 扫描检测 + +确保没有所有人可写的文件。 + +1. 执行以下命令,检查是否有返回结果: + +```shell +# df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -type f -perm -0002 +Nothing should be returned +``` + +如没有任何返回结果,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.26-ensure-no-unowned-files-or-directories-exist.md b/benchmarks/system-configurations/4.26-ensure-no-unowned-files-or-directories-exist.md new file mode 100644 index 0000000..79958cc --- /dev/null +++ b/benchmarks/system-configurations/4.26-ensure-no-unowned-files-or-directories-exist.md @@ -0,0 +1,33 @@ +# 4.26 确保所有文件或目录都配置了所有者 + +## 安全等级 + +Level 2 + +## 描述 + +当系统管理员从`/etc/passwd`中删除用户时,如果忘记从系统中删除这些用户拥有的文件,那么这些被删除的用户ID在重新分配给新用户后,新用户可能会直接拥有这些文件,从而获得比预期更多的文件访问权限。 + +所以,定期对这些无主文件或目录进行权限的重新分配或清理是很有必要的。 + +## 修复建议 + +建议对无主文件或目录的拥有者权限进行重新分配:可使用`chown`命令,将这些文件或目录的拥有者重置为系统上的某个活动用户。但在操作前,应阅读供应商或软件服务文档,以免破坏正常程序的依赖文件。 + +## 扫描检测 + +确保所有文件或目录都配置了所有者。 + +1. 执行以下命令,检查是否有返回结果: + +```shell +# df --local -P | awk {'if (NR!=1) print $6'} | xargs -I '{}' find '{}' -xdev -nouser +Nothing should be returned +``` + +如没有任何返回结果,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.27-ensure-no-ungrouped-files-or-directories-exist.md b/benchmarks/system-configurations/4.27-ensure-no-ungrouped-files-or-directories-exist.md new file mode 100644 index 0000000..73efaad --- /dev/null +++ b/benchmarks/system-configurations/4.27-ensure-no-ungrouped-files-or-directories-exist.md @@ -0,0 +1,33 @@ +# 4.27 确保所有文件或目录都配置了所属组 + +## 安全等级 + +Level 2 + +## 描述 + +当系统管理员删除用户组时,如果忘记从系统中删除这些用户组拥有的文件,那么这些被删除的用户组ID在重新分配给新用户后,新用户可能会直接拥有这些文件,从而获得比预期更多的文件访问权限。 + +所以,定期对这些无所属组的文件或目录进行权限的重新分配或清理是很有必要的。 + +## 修复建议 + +建议对无所属组的文件或目录的组权限进行重新分配:可使用`chown`命令,将这些文件或目录的所属组重置为系统上的某个活动用户组。但在操作前,应阅读供应商或软件服务文档,以免破坏正常程序的依赖文件。 + +## 扫描检测 + +确保所有文件或目录都配置了所属组。 + +1. 执行以下命令,检查是否有返回结果: + +```shell +# df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -nogroup +Nothing should be returned +``` + +如没有任何返回结果,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.28-ensure-no-password-fields-are-not-empty.md b/benchmarks/system-configurations/4.28-ensure-no-password-fields-are-not-empty.md new file mode 100644 index 0000000..11d0b42 --- /dev/null +++ b/benchmarks/system-configurations/4.28-ensure-no-password-fields-are-not-empty.md @@ -0,0 +1,41 @@ +# 4.28 确保所有用户的密码不为空 + +## 安全等级 + +Level 2 + +## 描述 + +如果一个用户的密码为空,则代表任何人都可以以该用户身份登录系统。这对于操作系统来说非常不安全,未经授权登录的用户可能会对系统进行恶意破坏或盗取敏感信息。 + +所以,系统内所有用户账户必须配置了密码,没有密码的用户,必须为锁定状态。 + +## 修复建议 + +锁定没有密码的用户账户,不允许其登录。 + +1. 可使用以下命令,对用户进行锁定。 + +```shell +# passwd -l +``` + +``为需要被锁定的用户名。 + +## 扫描检测 + +确保所有用户的密码不为空。 + +1. 执行以下命令,检查是否有返回结果: + +```shell +# awk -F: '($2 == "" ) { print $1 " does not have a password "}' /etc/shadow +Nothing should be returned +``` + +如没有任何返回结果,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.29-ensure-root-path-integrity.md b/benchmarks/system-configurations/4.29-ensure-root-path-integrity.md new file mode 100644 index 0000000..029b5a2 --- /dev/null +++ b/benchmarks/system-configurations/4.29-ensure-root-path-integrity.md @@ -0,0 +1,73 @@ +# 4.29 确保 root 用户 PATH 环境变量内所有目录的权限配置符合要求 + +## 安全等级 + +Level 2 + +## 描述 + +PATH 环境变量的内容是由一个个目录组成的,各目录之间用冒号`:`隔开。当执行某个命令时,Linux 会依照 PATH 中包含的目录依次搜寻该命令的可执行文件,一旦找到,则会立即执行。 + +在 Linux 系统中,root 用户的权限极大,几乎可执行任何命令。攻击者可通过替换或修改 root 用户 PATH 变量涉及的目录下的可执行文件,导致 root 用户在执行基础命令时,无意识的使用 root 权限执行恶意程序,对系统进行攻击。 + +所以 root 用户 PATH 变量内所有目录的权限配置极为重要,需保证仅有 root 用户对这些目录有完全的管理权限,对于其他用户来说没有可写权限,避免其中可执行文件被未授权用户替换或篡改。 + +## 修复建议 + +规范 root 用户 PATH 变量中所有目录的权限。 + +* 需根据检查情况,自行判断,对不符合安全要求的目录权限进行规范。 + +1. 如目录权限不符合要求,则执行以下命令,将目录权限配置为`755`或更加严格: + +```shell +# chmod 755 +``` + +``为需要修改权限的目录路径。 + +2. 如目录所有者或所属组不符合要求,则执行以下命令,将目录所有者和所属组配置为`root`: + +```shell +# chown root:root +``` + +``为需要修改权限的目录路径。 + +3. 如 PATH 变量内有不存在的目录,则执行以下命令,创建该目录,并执行第1、2步命令,对其权限进行配置: + +```shell +# mkdir -p +``` + +``为需要创建的目录路径。 + +## 扫描检测 + +确保 root 用户 PATH 环境变量内所有目录的权限配置符合要求。 + +1. 执行以下命令,检查是否有返回结果: + +```shell +#!/bin/bash +RPCV="$(sudo -Hiu root env | grep '^PATH=' | cut -d= -f2)" +echo "$RPCV" | grep -q "::" && echo "root's path contains a empty directory (::)" +echo "$RPCV" | grep -q ":$" && echo "root's path contains a trailing (:)" +for x in $(echo "$RPCV" | tr ":" " "); do + if [ -d "$x" ]; then + ls -ldH "$x" | awk '$9 == "." {print "PATH contains current working directory (.)"} + $3 != "root" {print $9, "is not owned by root"} + substr($1,6,1) != "-" {print $9, "is group writable"} + substr($1,9,1) != "-" {print $9, "is world writable"}' + else + echo "$x is not a directory" + fi +done +``` + +如没有任何返回结果,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.3-ensure-remote-login-warning-banner-is-configured-properly.md b/benchmarks/system-configurations/4.3-ensure-remote-login-warning-banner-is-configured-properly.md new file mode 100644 index 0000000..4efc0ac --- /dev/null +++ b/benchmarks/system-configurations/4.3-ensure-remote-login-warning-banner-is-configured-properly.md @@ -0,0 +1,64 @@ +# 4.3 确保远程登录提示消息的内容符合要求 + +## 安全等级 + +Level 1 + +## 描述 + +在**远程终端**登录时会展示`/etc/issue.net`文件中的内容。 + +类 Unix 系统通常会在登录系统时显示当前操作系统的版本信息和补丁信息。这些信息对于为特定操作系统平台开发软件的开发者来说是很有用的。但这样做也有一个副作用:会将系统版本的详细提供给针对特定系统漏洞的攻击者。而这些信息,对于已授权的用户来说,可以通过`uname -a`命令轻松获得。 + +综上,登录提示信息不应展示操作系统版本信息及补丁信息。 + +`/etc/issue.net`文件的内容解析: + +```shell +# cat /etc/issue.net +\S +Kernel \r on an \m +``` +其中`\*`参数对应输出内容如下: +``` +\m 给出当前操作系统的位数 +\r 详细的内核版本 +\s 操作系统的名称 +\v 操作系统的版本 +``` + +## 修复建议 + +编辑或删除`/etc/issue.net`文件,确保系统信息不展示在登录消息内。 + +1. 可根据使用环境,自行编辑登录提示消息,但要确保其内容没有系统版本或补丁信息。删除任何含有`\m`、`\r`、`\s`、`\v`的信息。 + +* 参考内容: + +```shell +# echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue.net +``` + +## 扫描检测 + +确保登录提示消息的内容符合要求。 + +1. 执行以下命令,检查输出内容是否有不符合安全要求的信息(系统版本信息、补丁信息等): + +```shell +# cat /etc/issue.net +Authorized uses only. All activity may be monitored and reported. +``` + +2. 执行以下命令,确保没有返回任何信息: + +```shell +# grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/issue.net +No information is returned. +``` + +如`/etc/issue.net`内没有任何不符合安全要求的信息(系统版本信息、补丁信息等),且第2条命令执行后没有返回任何内容,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.30-ensure-root-is-the-only-uid-0-account.md b/benchmarks/system-configurations/4.30-ensure-root-is-the-only-uid-0-account.md new file mode 100644 index 0000000..41cb876 --- /dev/null +++ b/benchmarks/system-configurations/4.30-ensure-root-is-the-only-uid-0-account.md @@ -0,0 +1,44 @@ +# 4.30 确保 UID 为 0 的用户只有 root + +## 安全等级 + +Level 2 + +## 描述 + +在 Linux 操作系统中,任何 UID 为 0 的用户,都具有超级用户权限。 + +需确保系统中,只有 root 用户的 UID 为 0。 + +## 修复建议 + +检查`/etc/passwd`文件中所有用户的 UID:删除除 root 用户以外,所有 UID 为 0 的用户,或为他们分配一个新的 ID。 + +例: + +```shell +# cat /etc/passwd +root:x:0:0:root:/root:/bin/bash +bin:x:1:1:bin:/bin:/sbin/nologin +daemon:x:2:2:daemon:/sbin:/sbin/nologin +``` + +`/etc/passwd`文件格式:`用户名:密码:UID:GID:描述信息:主目录:默认shell` + +## 扫描检测 + +确保 UID 为 0 的用户只有 root。 + +1. 执行以下命令,检查返回结果: + +```shell +# awk -F: '($3 == 0) { print $1 }' /etc/passwd +root +``` + +如返回结果为`root`,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.31-ensure-users-home-directories-permissions-are-750-or-more-restrictive.md b/benchmarks/system-configurations/4.31-ensure-users-home-directories-permissions-are-750-or-more-restrictive.md new file mode 100644 index 0000000..7184874 --- /dev/null +++ b/benchmarks/system-configurations/4.31-ensure-users-home-directories-permissions-are-750-or-more-restrictive.md @@ -0,0 +1,62 @@ +# 4.31 确保用户的主目录权限为 750 或更严格 + +## 安全等级 + +Level 1 + +## 描述 + +在创建新用户时,系统管理员会为用户的主目录配置符合安全要求的权限,但后期用户可以很容易地修改这些权限。 + +如果用户主目录的权限对 group 与 other 可写,可能使恶意用户窃取或修改其他用户的数据,或获得其他用户的系统特权。 + +建议对所有用户的主目录权限进行限制,配置为 750 或更严格权限策略。 + +## 修复建议 + +配置用户主目录的权限。 + +* 在不通知用户的情况下对用户主目录进行全局修改可能会导致程序意外中断和用户不满。因此建议建立监控策略,及时上报用户文件权限,并根据实际情况,判断采取的措施。 + +1. 执行以下脚本,删除用户主目录 750 以上的权限: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && +$7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) {print $6}' /etc/passwd | while read -r dir; do + if [ -d "$dir" ]; then + dirperm=$(stat -L -c "%A" "$dir") + if [ "$(echo "$dirperm" | cut -c6)" != "-" ] || [ "$(echo "$dirperm" | cut -c8)" != "-" ] || [ "$(echo "$dirperm" | cut -c9)" != "-" ] || [ "$(echo "$dirperm" | cut -c10)" != "-" ]; then + chmod g-w,o-rwx "$dir" + fi + fi +done +``` + +## 扫描检测 + +确保用户的主目录权限为 750 或更严格。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && +$7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) {print $1 " " $6}' /etc/passwd | while read -r user dir; do + if [ ! -d "$dir" ]; then + echo "User: \"$user\" home directory: \"$dir\" doesn't exist" + else + dirperm=$(stat -L -c "%A" "$dir") + if [ "$(echo "$dirperm" | cut -c6)" != "-" ] || [ "$(echo "$dirperm" | cut -c8)" != "-" ] || [ "$(echo "$dirperm" | cut -c9)" != "-" ] || [ "$(echo "$dirperm" | cut -c10)" != "-" ]; then + echo "User: \"$user\" home directory: \"$dir\" has permissions: \"$(stat -L -c "%a" "$dir")\"" + fi + fi +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.32-ensure-users-own-their-home-directories.md b/benchmarks/system-configurations/4.32-ensure-users-own-their-home-directories.md new file mode 100644 index 0000000..349ea52 --- /dev/null +++ b/benchmarks/system-configurations/4.32-ensure-users-own-their-home-directories.md @@ -0,0 +1,72 @@ +# 4.32 确保用户拥有自己的主目录 + +## 安全等级 + +Level 1 + +## 描述 + +用户主目录(家目录)是为每个普通用户定义的主工作目录,用于设置用户本地环境变量和存储用户个人文件。 + +每个用户对存储在自己主目录中的文件负责,因此所有用户(包括 root )必须是自己主目录的所有者。 + +## 修复建议 + +配置用户主目录的所有权。 + +1. 执行以下脚本,将对所有权配置错误的用户主目录进行修正: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do + if [ ! -d "$dir" ]; then + echo "User: \"$user\" home directory: \"$dir\" does not exist, creating home directory" + mkdir "$dir" + chmod g-w,o-rwx "$dir" + chown "$user" "$dir" + else + owner=$(stat -L -c "%U" "$dir") + if [ "$owner" != "$user" ]; then + chmod g-w,o-rwx "$dir" + chown "$user" "$dir" + fi + fi +done +``` + +## 扫描检测 + +确保用户拥有自己的主目录。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/usr/bin/env bash +UHOC() +{ +for i in $( awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) {print $1":"$6}' /etc/passwd); do + output='' + output2='' + user=$(echo "$i" | cut -d: -f1) + dir=$(echo "$i" | cut -d: -f2) + if [ ! -d "$dir" ]; then + [ -z "$output2" ] && output2="The following users' home directories don't exist: \"$user\"" || output2="$output2, \"$user\"" + echo $output2 + else + owner="$(stat -L -c "%U" "$dir")" + if [ "$owner" != "$user" ] && [ "$owner" != "root" ]; then + [ -z "$output" ] && output="The following users' don't own their home directory: \"$user\" home directory is owned by \"$owner\"" || output="$output, \"$user\" home directory is owned by \"$owner\"" + echo $output + fi + fi +done +} +UHOC +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.33-ensure-users-dot-files-are-not-group-or-world-writable.md b/benchmarks/system-configurations/4.33-ensure-users-dot-files-are-not-group-or-world-writable.md new file mode 100644 index 0000000..5d2f5d1 --- /dev/null +++ b/benchmarks/system-configurations/4.33-ensure-users-dot-files-are-not-group-or-world-writable.md @@ -0,0 +1,62 @@ +# 4.33 确保用户的 dot 文件权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +在 Linux 下,各种软件的配置文件大多存储于以`.`开头以`rc`结尾的文件中并存放于用户的主目录`~/`中,也就是俗称的 dotfile 者 rcfile,例如 zsh 的配置文件`.zshrc`,vim 的配置文件`.vimrc`等等。 + +如果用户的 dotfile 权限对 group 与 other 可写,可能使恶意用户窃取或修改其他用户的配置数据。 + +## 修复建议 + +* 在不通知用户的情况下对用户的 dotfile 进行全局修改可能会导致程序意外中断和用户不满。因此建议建立监控策略,及时上报用户 dotfile 权限,并根据实际情况,判断采取的措施。 + +1. 执行以下脚本,删除用户 dotfile 多余的权限: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $6 }' /etc/passwd | while read -r dir; do + if [ -d "$dir" ]; then + for file in "$dir"/.*; do + if [ ! -h "$file" ] && [ -f "$file" ]; then + fileperm=$(stat -L -c "%A" "$file") + if [ "$(echo "$fileperm" | cut -c6)" != "-" ] || [ "$(echo "$fileperm" | cut -c9)" != "-" ]; then + chmod go-w "$file" + fi + fi + done + fi +done +``` + +## 扫描检测 + +确保用户的 dot 文件权限配置正确。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do + if [ -d "$dir" ]; then + for file in "$dir"/.*; do + if [ ! -h "$file" ] && [ -f "$file" ]; then + fileperm=$(stat -L -c "%A" "$file") + if [ "$(echo "$fileperm" | cut -c6)" != "-" ] || [ "$(echo "$fileperm" | cut -c9)" != "-" ]; then + echo "User: \"$user\" file: \"$file\" has permissions: \"$fileperm\"" + fi + fi + done + fi +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.34-ensure-no-users-have-.forward-files.md b/benchmarks/system-configurations/4.34-ensure-no-users-have-.forward-files.md new file mode 100644 index 0000000..ed8c3e7 --- /dev/null +++ b/benchmarks/system-configurations/4.34-ensure-no-users-have-.forward-files.md @@ -0,0 +1,53 @@ +# 4.34 确保没有用户拥有 .forward 文件 + +## 安全等级 + +Level 1 + +## 描述 + +`.forward`文件指定了一个电子邮件地址来转发用户的邮件。 + +使用`.forward`文件会带来额外的安全风险,容易导致敏感数据在无意中被转发到可信组织外。`.forward`文件本身也有被用来执行恶意代码的风险。 + +## 修复建议 + +* 在不通知用户的情况下对用户`.forward`文件进行全局修改可能会导致程序意外中断和用户不满。因此建议建立监控策略,及时上报用户`.forward`文件使用情况,并根据实际情况,判断采取的措施。 + +1. 执行以下脚本,删除用户主目录下的`.forward`文件: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { +print $6 }' /etc/passwd | while read -r dir; do + if [ -d "$dir" ]; then + file="$dir/.forward" + [ ! -h "$file" ] && [ -f "$file" ] && rm -rf "$file" + fi +done +``` + +## 扫描检测 + +确保没有用户拥有`.forward`文件。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do + if [ -d "$dir" ]; then + file="$dir/.forward" + if [ ! -h "$file" ] && [ -f "$file" ]; then + echo "User: \"$user\" file: \"$file\" exists" + fi + fi +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.35-ensure-no-users-have-.netrc-files.md b/benchmarks/system-configurations/4.35-ensure-no-users-have-.netrc-files.md new file mode 100644 index 0000000..3dce60a --- /dev/null +++ b/benchmarks/system-configurations/4.35-ensure-no-users-have-.netrc-files.md @@ -0,0 +1,53 @@ +# 4.35 确保没有用户拥有 .netrc 文件 + +## 安全等级 + +Level 1 + +## 描述 + +`.netrc`文件包含用于登录远程主机的数据,以便通过FTP进行文件传输。 + +由于`.netrc`文件以明文形式存储密码,因此存在很大的安全风险。 + +## 修复建议 + +* 在不通知用户的情况下对用户`.netrc`文件进行全局修改可能会导致程序意外中断和用户不满。因此建议建立监控策略,及时上报用户`.netrc`文件使用情况,并根据实际情况,判断采取的措施。 + +1. 执行以下脚本,删除用户主目录下的`.netrc`文件: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { +print $6 }' /etc/passwd | while read -r dir; do + if [ -d "$dir" ]; then + file="$dir/.netrc" + [ ! -h "$file" ] && [ -f "$file" ] && rm -rf "$file" + fi +done +``` + +## 扫描检测 + +确保没有用户拥有`.netrc`文件。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do + if [ -d "$dir" ]; then + file="$dir/.netrc" + if [ ! -h "$file" ] && [ -f "$file" ]; then + echo "User: \"$user\" file: \"$file\" exists" + fi + fi +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.36-ensure-users-.netrc-files-are-not-group-or-world-accessible.md b/benchmarks/system-configurations/4.36-ensure-users-.netrc-files-are-not-group-or-world-accessible.md new file mode 100644 index 0000000..9e3ecb4 --- /dev/null +++ b/benchmarks/system-configurations/4.36-ensure-users-.netrc-files-are-not-group-or-world-accessible.md @@ -0,0 +1,63 @@ +# 4.36 确保用户 .netrc 文件权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`.netrc`文件包含用于登录远程主机的数据,以便通过FTP进行文件传输。由于`.netrc`文件以明文形式存储密码,因此存在很大的安全风险。 + +如果确实需要一个`.netrc`文件,则需正确配置其权限,使其符合安全要求。应将其权限配置为`600`或更加严格。 + +## 修复建议 + +* 在不通知用户的情况下对用户`.netrc`文件进行全局修改可能会导致程序意外中断和用户不满。因此建议建立监控策略,及时上报用户`.netrc`文件使用情况,并根据实际情况,判断采取的措施。 + +1. 执行以下脚本,配置用户`.netrc`文件的权限: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && +$7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { +print $6 }' /etc/passwd | while read -r dir; do + if [ -d "$dir" ]; then + file="$dir/.netrc" + [ ! -h "$file" ] && [ -f "$file" ] && chmod 600 "$file" + fi +done +``` + +## 扫描检测 + +确保用户`.netrc`文件权限配置正确。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do + if [ -d "$dir" ]; then + file="$dir/.netrc" + if [ ! -h "$file" ] && [ -f "$file" ]; then + if stat -L -c "%A" "$file" | cut -c4-10 | grep -Eq '[^-]+'; then + echo "FAILED: User: \"$user\" file: \"$file\" exists with permissions: \"$(stat -L -c "%a" "$file")\", remove file or excessive permissions" + else + echo "WARNING: User: \"$user\" file: \"$file\" exists with permissions: \"$(stat -L -c "%a" "$file")\", remove file unless required" + fi + fi + fi +done +``` + +查看返回值: + +* FAILED:表示`.netrc`文件的权限不符合要求,应尽快对其权限进行限制,使其权限为`600`或更加严格。如非必要应删除此文件。 +* WARNING:表示有用户主目录下存在`.netrc`文件,其权限符合要求,如非必要应删除此文件。 + +如返回值为`WARNING`,则视为通过此项检查。但仍需根据实际情况判断,如非必要应删除`.netrc`文件。删除文件的方法请参考`4.35`项目内的修复代码。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.37-ensure-no-users-have-.rhosts-files.md b/benchmarks/system-configurations/4.37-ensure-no-users-have-.rhosts-files.md new file mode 100644 index 0000000..1d3185f --- /dev/null +++ b/benchmarks/system-configurations/4.37-ensure-no-users-have-.rhosts-files.md @@ -0,0 +1,58 @@ +# 4.37 确保没有用户拥有 .rhosts 文件 + +## 安全等级 + +Level 1 + +## 描述 + +`.rhosts`文件是`/etc/hosts.equiv`文件的用户等效文件。此文件包含主机-用户组合列表,而不包含一般意义的主机。如果此文件中列出了主机-用户组合,则指定用户将被授予从指定主机登录而不必提供口令的权限。注意,`.rhosts`文件必须驻留在用户起始目录的顶层。如果`.rhost`文件位于子目录中,则不会生效。 + +遗憾的是,`.rhosts`文件存在严重的安全问题。`/etc/hosts.equiv`文件受系统管理员的控制并且可以有效地管理,但任何用户都可以创建属于自己的`.rhosts`文件,从而可以在系统管理员不知情时对其选择的任何人授予访问权限。 + +如果所有用户起始目录都在一台服务器上,并且只有某些人员才在该服务器上具有超级用户权限,则防止用户使用`.rhosts`文件的一种好方法就是以超级用户身份在用户起始目录中创建一个空文件。然后,将此文件的权限更改为`000`,这样即使作为超级用户也很难更改它。这种方式可有效地防止用户因不负责任地使用`.rhosts`文件而导致的系统安全风险。但是,如果用户能够更改指向其起始目录的有效路径,则此更改将不能解决任何问题。 + +管理`.rhosts`文件的唯一安全方法是完全删除并禁用它们。作为系统管理员,需要经常检查系统以了解`.rhosts`文件的违规情况。 + +可能存在一种例外情况:即超级用户帐户可能需要使用`.rhosts`文件来执行网络备份和其他远程服务。 + +## 修复建议 + +* 在不通知用户的情况下对用户`.rhosts`文件进行全局修改可能会导致程序意外中断和用户不满。因此建议建立监控策略,及时上报用户`.rhosts`文件使用情况,并根据实际情况,判断采取的措施。 + +1. 执行以下脚本,删除用户主目录下的`.rhosts`文件: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $6 }' /etc/passwd | while read -r dir; do + if [ -d "$dir" ]; then + file="$dir/.rhosts" + [ ! -h "$file" ] && [ -f "$file" ] && rm -rf "$file" + fi +done +``` + +## 扫描检测 + +确保没有用户拥有`.rhosts`文件。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do + if [ -d "$dir" ]; then + file="$dir/.rhosts" + if [ ! -h "$file" ] && [ -f "$file" ]; then + echo "User: \"$user\" file: \"$file\" exists" + fi + fi +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.38-ensure-all-groups-in-etc-passwd-exist-in-etc-group.md b/benchmarks/system-configurations/4.38-ensure-all-groups-in-etc-passwd-exist-in-etc-group.md new file mode 100644 index 0000000..17c7a3a --- /dev/null +++ b/benchmarks/system-configurations/4.38-ensure-all-groups-in-etc-passwd-exist-in-etc-group.md @@ -0,0 +1,38 @@ +# 4.38 确保 /etc/passwd 中所有组都存在于 /etc/group 中 + +## 安全等级 + +Level 2 + +## 描述 + +随着时间的推移,系统管理员的失误或更改可能导致有些在`/etc/passwd`中定义的组,在`/etc/group`中没有。 + +这种情况会对系统安全造成威胁,因为这种组的权限没有得到正确的监管与配置。 + +## 修复建议 + +1. 对出现异常的组,根据实际情况进行修复,如删除或重新正确配置。 + +## 扫描检测 + +确保`/etc/passwd`中所有组都存在于`/etc/group`中。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +for i in $(cut -s -d: -f4 /etc/passwd | sort -u ); do + grep -q -P "^.*?:[^:]*:$i:" /etc/group + if [ $? -ne 0 ]; then + echo "Group $i is referenced by /etc/passwd but does not exist in /etc/group" + fi +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.39-ensure-no-duplicate-uids-exist.md b/benchmarks/system-configurations/4.39-ensure-no-duplicate-uids-exist.md new file mode 100644 index 0000000..b6f0928 --- /dev/null +++ b/benchmarks/system-configurations/4.39-ensure-no-duplicate-uids-exist.md @@ -0,0 +1,40 @@ +# 4.39 确保没有重复的 UID + +## 安全等级 + +Level 2 + +## 描述 + +使用`useradd`命令创建用户时,UID 为自动分配且不会重复。但系统管理员可以手动编辑`/etc/passwd`文件并更改UID字段。如在工作中出现失误,就有可能导致 UID 的重复。 + +在正常的系统中,必须为所有用户分配唯一的 UID,以正确监控用户的权限和确保审计责任信息的准确性。 + +## 修复建议 + +1. 对出现异常的 UID,根据实际情况进行修复:删除无用用户或重新分配正确的 UID。 + +## 扫描检测 + +确保没有重复的 UID。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +cut -f3 -d":" /etc/passwd | sort -n | uniq -c | while read x ; do + [ -z "$x" ] && break + set - $x + if [ $1 -gt 1 ]; then + users=$(awk -F: '($3 == n) { print $1 }' n=$2 /etc/passwd | xargs) + echo "Duplicate UID ($2): $users" + fi +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.4-ensure-permissions-on-etc-motd-are-configured.md b/benchmarks/system-configurations/4.4-ensure-permissions-on-etc-motd-are-configured.md new file mode 100644 index 0000000..39e3757 --- /dev/null +++ b/benchmarks/system-configurations/4.4-ensure-permissions-on-etc-motd-are-configured.md @@ -0,0 +1,39 @@ +# 4.4 确保 /etc/motd 的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +`/etc/motd`文件的内容会在用户登录后展示给用户。 + +如果`/etc/motd`文件的权限及所有者没有正确配置,其内容就可能被未经授权的用户篡改,从而展示不正确或误导性的登录信息。 + +## 修复建议 + +目标:正确配置`/etc/motd`文件的权限和所有者。 + +1. 使用以下代码,配置`/etc/motd`文件的权限和所有者: + +```shell +# chown root:root /etc/motd +# chmod u-x,go-wx /etc/motd +``` + +## 扫描检测 + +确保`/etc/motd`目录的权限配置正确。 + +1. 执行以下命令,检查`/etc/motd`目录的权限属性: + +```shell +# stat /etc/motd +Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如果输出结果中:`Uid`与`Gid`均为`0/root`,且`Acces`为`0644`或更加严格,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.40-ensure-no-duplicate-gids-exist.md b/benchmarks/system-configurations/4.40-ensure-no-duplicate-gids-exist.md new file mode 100644 index 0000000..08e39f4 --- /dev/null +++ b/benchmarks/system-configurations/4.40-ensure-no-duplicate-gids-exist.md @@ -0,0 +1,35 @@ +# 4.40 确保没有重复的 GID + +## 安全等级 + +Level 2 + +## 描述 + +使用`groupadd`命令创建用户组时,GID 为自动分配且不会重复。但系统管理员可以手动编辑`/etc/group`文件并更改GID字段。如在工作中出现失误,就有可能导致 GID 的重复。 + +在正常的系统中,必须为所有用户组分配唯一的 GID,以正确监控用户组的权限和确保审计责任信息的准确性。 + +## 修复建议 + +1. 对出现异常的 GID,根据实际情况进行修复:删除无用用户组或重新分配正确的 GID。 + +## 扫描检测 + +确保没有重复的 GID。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +cut -d: -f3 /etc/group | sort | uniq -d | while read x ; do + echo "Duplicate GID ($x) in /etc/group" +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.41-ensure-no-duplicate-user-names-exist.md b/benchmarks/system-configurations/4.41-ensure-no-duplicate-user-names-exist.md new file mode 100644 index 0000000..11ca600 --- /dev/null +++ b/benchmarks/system-configurations/4.41-ensure-no-duplicate-user-names-exist.md @@ -0,0 +1,35 @@ +# 4.41 确保没有重复的用户名 + +## 安全等级 + +Level 2 + +## 描述 + +使用`useradd`命令创建用户时,不允许创建同名用户。但系统管理员可以手动编辑`/etc/passwd`文件并更改用户名字段。如在工作中出现失误,就有可能导致用户名的重复。 + +在正常的系统中,必须为所有用户分配唯一的用户名,以正确监控用户的权限和确保审计责任信息的准确性。 + +## 修复建议 + +1. 对出现异常的用户名,根据实际情况进行修复:删除无用用户或重新分配正确的用户名。 + +## 扫描检测 + +确保没有重复的用户名。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +cut -d: -f1 /etc/passwd | sort | uniq -d | while read x; do + echo "Duplicate login name ${x} in /etc/passwd" +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.42-ensure-no-duplicate-group-names-exist.md b/benchmarks/system-configurations/4.42-ensure-no-duplicate-group-names-exist.md new file mode 100644 index 0000000..23f5e59 --- /dev/null +++ b/benchmarks/system-configurations/4.42-ensure-no-duplicate-group-names-exist.md @@ -0,0 +1,35 @@ +# 4.42 确保没有重复的组名 + +## 安全等级 + +Level 2 + +## 描述 + +使用`groupadd`命令创建用户组时,不允许创建同名用户组。但系统管理员可以手动编辑`/etc/group`文件并更改组名字段。如在工作中出现失误,就有可能导致组名的重复。 + +在正常的系统中,必须为所有用户组分配唯一的组名,以正确监控用户组的权限和确保审计责任信息的准确性。 + +## 修复建议 + +1. 对出现异常的组名,根据实际情况进行修复:删除无用用户组或重新分配正确的组名。 + +## 扫描检测 + +确保没有重复的组名。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +cut -d: -f1 /etc/group | sort | uniq -d | while read -r x; do + echo "Duplicate group name ${x} in /etc/group" +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.43-ensure-all-users-home-directories-exist.md b/benchmarks/system-configurations/4.43-ensure-all-users-home-directories-exist.md new file mode 100644 index 0000000..d5b9f02 --- /dev/null +++ b/benchmarks/system-configurations/4.43-ensure-all-users-home-directories-exist.md @@ -0,0 +1,50 @@ +# 4.43 确保所有用户的主目录都存在 + +## 安全等级 + +Level 1 + +## 描述 + +管理员有可能在`/etc/passwd`中定义没有主目录的用户,或定义一个实际上不存在的主目录。 + +如果用户的主目录不存在或未分配,则该用户将被放置在根目录(`/`)中,且不能写入任何文件或设置本地环境变量。所以为每个用户配置一个正确的主目录是非常重要的。 + +## 修复建议 + +对主目录异常的用户进行修复。 + +1. 使用以下脚本,对没有配置主目录的用户创建主目录: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do + if [ ! -d "$dir" ]; then + mkdir "$dir" + chmod g-w,o-wrx "$dir" + chown "$user" "$dir" + fi +done +``` + +## 扫描检测 + +确保所有用户的主目录都存在。 + +1. 执行以下脚本,检查返回结果: + +```shell +#!/bin/bash +awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do + if [ ! -d "$dir" ]; then + echo "User: \"$user\" home directory: \"$dir\" does not exist." + fi +done +``` + +如没有任何返回值,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.44-ensure-sctp-is-disabled.md b/benchmarks/system-configurations/4.44-ensure-sctp-is-disabled.md new file mode 100644 index 0000000..041f71d --- /dev/null +++ b/benchmarks/system-configurations/4.44-ensure-sctp-is-disabled.md @@ -0,0 +1,43 @@ +# 4.44 确保禁用 SCTP + +## 安全等级 + +Level 1 + +## 描述 + +流控制传输协议(SCTP)是一个传输层协议,用于支持面向消息的通信,在一个连接中有多个消息流。它的功能类似于 TCP 和 UDP ,并融合了二者的特性:它像 UDP 一样是面向消息的,并像 TCP 一样通过拥塞控制来确保可靠的消息顺序传输。 + +如果不使用该协议,建议禁用该服务以减少潜在的攻击面。 + +## 修复建议 + +禁用 SCTP。 + +1. 在`/etc/modprobe.d/`目录下,创建一个以`.conf`结尾的文件,如:`sctp.conf`,并执行以下代码,在文件内添内容: + +```shell +printf " +install sctp /bin/true +" >> /etc/modprobe.d/sctp.conf +``` + +## 扫描检测 + +确保禁用 SCTP。 + +1. 执行以下命令,检查返回结果: + +```shell +# modprobe -n -v sctp +install /bin/true +# lsmod | grep sctp + +``` + +如返回结果符合要求,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.45-ensure-dccp-is-disabled.md b/benchmarks/system-configurations/4.45-ensure-dccp-is-disabled.md new file mode 100644 index 0000000..23a09f6 --- /dev/null +++ b/benchmarks/system-configurations/4.45-ensure-dccp-is-disabled.md @@ -0,0 +1,44 @@ +# 4.45 确保禁用 DCCP + +## 安全等级 + +Level 1 + +## 描述 + +数据拥塞控制协议 (Datagram Congestion Control Protocol, DCCP)是由(因特网工程工作小组IETF)提出一个针对传输层中UDP的新传输的协议而发展出来,用来传输实时业务。它是一个可以进行拥塞控制的非可靠传输协议,并同时提供多种拥塞控制机制,在通信开始时由用户进行协商选择。除预留和自定义方式外,目前DCCP定义了两种拥塞控制机制:TCP-Like和TFRC。TCP-Like类似TCP的AIMD机制,而TFRC是TCP友好的速率控制机制。 +建立、维护和拆卸不可靠连接的数据流以及对不可靠性数据流进行拥塞控制,是DCCP主要提供的两大功能。实时业务需要快速且低开销的传输协议,要使包头带来的开销和终端处理的工程量尽量小。因此,DCCP尽可能做到简单合理、低延迟和快速响应,避免提供更高层的传输功能。DCCP没有TCP的可靠性和顺序发送的特性。基于单播的应用功能也被涵盖在DCCP中。 + +如果不使用 DCCP ,建议不安装驱动程序,以减少潜在的攻击面。 + +## 修复建议 + +禁用 DCCP。 + +1. 在`/etc/modprobe.d/`目录下,创建一个以`.conf`结尾的文件,如:`dccp.conf`,并执行以下代码,在文件内添内容: + +```shell +printf " +install dccp /bin/true +" >> /etc/modprobe.d/dccp.conf +``` + +## 扫描检测 + +确保禁用 DCCP。 + +1. 执行以下命令,检查返回结果: + +```shell +# modprobe -n -v dccp +install /bin/true +# lsmod | grep dccp + +``` + +如返回结果符合要求,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.46-ensure-wireless-interfaces-are-disabled.md b/benchmarks/system-configurations/4.46-ensure-wireless-interfaces-are-disabled.md new file mode 100644 index 0000000..9b7d9d8 --- /dev/null +++ b/benchmarks/system-configurations/4.46-ensure-wireless-interfaces-are-disabled.md @@ -0,0 +1,77 @@ +# 4.46 确保禁用无线网卡接口 + +## 安全等级 + +Level 1 + +## 描述 + +如对无线网络没有需求,应禁用无线设备,以减少潜在的攻击面。 + +## 修复建议 + +禁用无线网卡接口。 + +1. 执行以下脚本,禁用所有无线网络接口: + +```shell +#!/usr/bin/env bash +wireless_disable() +{ + if command -v nmcli >/dev/null 2>&1 ; then + nmcli radio all off + else + if [ -n "$(find /sys/class/net/*/ -type d -name wireless)" ]; then + mname=$(for driverdir in $(find /sys/class/net/*/ -type d -name wireless | xargs -0 dirname); do basename "$(readlink -f "$driverdir"/device/driver/module)";done | sort -u) + for dm in $mname; do + echo "install $dm /bin/true" >> /etc/modprobe.d/disable_wireless.conf + done + fi + fi +} +wireless_disable +``` + +## 扫描检测 + +确保禁用无线网卡接口。 + +1. 执行以下命令,检查返回结果: + +```shell +#!/usr/bin/env bash +wireless_chk() +{ + if command -v nmcli >/dev/null 2>&1 ; then + if nmcli radio all | grep -Eq '\s*\S+\s+disabled\s+\S+\s+disabled\b'; +then + echo "Wireless is not enabled" + else + nmcli radio all + fi + elif [ -n "$(find /sys/class/net/*/ -type d -name wireless)" ]; then + t=0 + mname=$(for driverdir in $(find /sys/class/net/*/ -type d -name +wireless | xargs -0 dirname); do basename "$(readlink -f "$driverdir"/device/driver/module)";done | sort -u) + for dm in $mname; do + if grep -Eq "^\s*install\s+$dm\s+/bin/(true|false)" /etc/modprobe.d/*.conf; then + /bin/true + else + echo "$dm is not disabled" + t=1 + fi + done + [ "$t" -eq 0 ] && echo "Wireless is not enabled" + else + echo "Wireless is not enabled" + fi +} +wireless_chk +``` + +如返回:`Wireless is not enabled`,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.47-ensure-ip-forwarding-is-disabled.md b/benchmarks/system-configurations/4.47-ensure-ip-forwarding-is-disabled.md new file mode 100644 index 0000000..f415f66 --- /dev/null +++ b/benchmarks/system-configurations/4.47-ensure-ip-forwarding-is-disabled.md @@ -0,0 +1,47 @@ +# 4.47 确保禁用 IP 转发功能 + +## 安全等级 + +Level 1 + +## 描述 + +`net.ipv4.ip_forward`和`net.ipv6.conf.all.forwarding`转发标志是用来告诉系统是否可以转发此数据包。 + +将这些标志设置为`0`可以确保有多个接口的系统(例如,一个硬代理),不能够转发数据包,不能作为一个路由器使用。这对于信息安全来说是非常重要的。 + +## 修复建议 + +禁用 IP 转发功能。 + +1. 执行以下代码,禁用 IP 转发功能: + +```shell +# grep -Els "^\s*net\.ipv4\.ip_forward\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | while read filename; do sed -ri "s/^\s*(net\.ipv4\.ip_forward\s*)(=)(\s*\S+\b).*$/# *REMOVED* \1/" $filename; done; sysctl -w net.ipv4.ip_forward=0; sysctl -w net.ipv4.route.flush=1 + +# grep -Els "^\s*net\.ipv6\.conf\.all\.forwarding\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | while read filename; do sed -ri "s/^\s*(net\.ipv6\.conf\.all\.forwarding\s*)(=)(\s*\S+\b).*$/# *REMOVED* \1/" $filename; done; sysctl -w net.ipv6.conf.all.forwarding=0; sysctl -w net.ipv6.route.flush=1 +``` + +## 扫描检测 + +确保禁用 IP 转发功能。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv4.ip_forward +net.ipv4.ip_forward = 0 +# grep -E -s "^\s*net\.ipv4\.ip_forward\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf +No value should be returned +# sysctl net.ipv6.conf.all.forwarding +net.ipv6.conf.all.forwarding = 0 +# grep -E -s "^\s*net\.ipv6\.conf\.all\.forwarding\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf +No value should be returned +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.48-ensure-packet-redirect-sending-is-disabled.md b/benchmarks/system-configurations/4.48-ensure-packet-redirect-sending-is-disabled.md new file mode 100644 index 0000000..45c7b24 --- /dev/null +++ b/benchmarks/system-configurations/4.48-ensure-packet-redirect-sending-is-disabled.md @@ -0,0 +1,54 @@ +# 4.48 确保禁用报文重定向发送 + +## 安全等级 + +Level 1 + +## 描述 + +ICMP 重定向用来向其他主机发送路由信息。 如当前环境下,此主机没有充当路由器的需求,就没有必要发送重定向。 + +攻击者可以利用被攻击的主机向其他路由器设备发送无效的 ICMP 重定向,破坏路由指向,将正常用户的访问流量导向至一个由攻击者设置的系统,而不是用户期望访问的系统。 + +## 修复建议 + +禁用报文重定向发送功能。 + +1. 修改`/etc/sysctl.conf`文件及`/etc/sysctl.d`路径下所有后缀为`.conf`文件中以下参数的值。如没有以下参数,则需在`/etc/sysctl.conf`文件中添加: + +```shell +net.ipv4.conf.all.send_redirects = 0 +net.ipv4.conf.default.send_redirects = 0 +``` + +2. 执行以下命令,设置活动内核参数: + +```shell +# sysctl -w net.ipv4.conf.all.send_redirects=0 +# sysctl -w net.ipv4.conf.default.send_redirects=0 +# sysctl -w net.ipv4.route.flush=1 +``` + +## 扫描检测 + +确保禁用报文重定向发送。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv4.conf.all.send_redirects +net.ipv4.conf.all.send_redirects = 0 +# sysctl net.ipv4.conf.default.send_redirects +net.ipv4.conf.default.send_redirects = 0 +# grep "net\.ipv4\.conf\.all\.send_redirects" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.all.send_redirects = 0 +# grep "net\.ipv4\.conf\.default\.send_redirects" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.default.send_redirects = 0 +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.49-ensure-source-routed-packets-are-not-accepted.md b/benchmarks/system-configurations/4.49-ensure-source-routed-packets-are-not-accepted.md new file mode 100644 index 0000000..ba563a9 --- /dev/null +++ b/benchmarks/system-configurations/4.49-ensure-source-routed-packets-are-not-accepted.md @@ -0,0 +1,67 @@ +# 4.49 确保不接受源路由报文 + +## 安全等级 + +Level 1 + +## 描述 + +源路由的用户可以指定他所发送的数据包沿途经过的部分或者全部路由器。它区别于由主机或者路由器的互联层(IP)软件自行选择路由后得出的路径。 + +禁止接受源路由报文可防止黑客利用 IP 地址欺骗对系统进行攻击。源路由在过去被广泛使用,以防止单一网络故障引起重大网络波动,但今天的互联网路由协议使得这种技术不再必要。 + +## 修复建议 + +不接受源路由报文。 + +1. 修改`/etc/sysctl.conf`文件及`/etc/sysctl.d`路径下所有后缀为`.conf`文件中以下参数的值。如没有以下参数,则需在`/etc/sysctl.conf`文件中添加: + +```shell +net.ipv4.conf.all.accept_source_route = 0 +net.ipv4.conf.default.accept_source_route = 0 +net.ipv6.conf.all.accept_source_route = 0 +net.ipv6.conf.default.accept_source_route = 0 +``` + +2. 执行以下命令,设置活动内核参数: + +```shell +# sysctl -w net.ipv4.conf.all.accept_source_route=0 +# sysctl -w net.ipv4.conf.default.accept_source_route=0 +# sysctl -w net.ipv6.conf.all.accept_source_route=0 +# sysctl -w net.ipv6.conf.default.accept_source_route=0 +# sysctl -w net.ipv4.route.flush=1 +# sysctl -w net.ipv6.route.flush=1 +``` + +## 扫描检测 + +确保不接受源路由报文。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv4.conf.all.accept_source_route +net.ipv4.conf.all.accept_source_route = 0 +# sysctl net.ipv4.conf.default.accept_source_route +net.ipv4.conf.default.accept_source_route = 0 +# grep "net\.ipv4\.conf\.all\.accept_source_route" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.all.accept_source_route = 0 +# grep "net\.ipv4\.conf\.default\.accept_source_route" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.default.accept_source_route = 0 +# sysctl net.ipv6.conf.all.accept_source_route +net.ipv6.conf.all.accept_source_route = 0 +# sysctl net.ipv6.conf.default.accept_source_route +net.ipv6.conf.default.accept_source_route = 0 +# grep "net\.ipv6\.conf\.all\.accept_source_route" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.all.accept_source_route = 0 +# grep "net\.ipv6\.conf\.default\.accept_source_route" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv6.conf.default.accept_source_route = 0 +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.5-ensure-permissions-on-etc-issue-are-configured.md b/benchmarks/system-configurations/4.5-ensure-permissions-on-etc-issue-are-configured.md new file mode 100644 index 0000000..2886d46 --- /dev/null +++ b/benchmarks/system-configurations/4.5-ensure-permissions-on-etc-issue-are-configured.md @@ -0,0 +1,39 @@ +# 4.5 确保 /etc/issue 的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +在本地终端登录时会展示`/etc/issue`文件中的内容。 + +如果`/etc/issue`文件的权限及所有者没有正确配置,其内容就可能被未经授权的用户篡改,从而展示不正确或误导性的登录信息。 + +## 修复建议 + +目标:正确配置`/etc/issue`文件的权限和所有者。 + +1. 使用以下代码,配置`/etc/issue`文件的权限和所有者: + +```shell +# chown root:root /etc/issue +# chmod u-x,go-wx /etc/issue +``` + +## 扫描检测 + +确保`/etc/issue`目录的权限配置正确。 + +1. 执行以下命令,检查`/etc/issue`目录的权限属性: + +```shell +# stat /etc/issue +Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如果输出结果中:`Uid`与`Gid`均为`0/root`,且`Acces`为`0644`或更加严格,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.50-ensure-icmp-redirects-are-not-accepted.md b/benchmarks/system-configurations/4.50-ensure-icmp-redirects-are-not-accepted.md new file mode 100644 index 0000000..0589f0d --- /dev/null +++ b/benchmarks/system-configurations/4.50-ensure-icmp-redirects-are-not-accepted.md @@ -0,0 +1,67 @@ +# 4.50 确保不接受 ICMP 重定向 + +## 安全等级 + +Level 1 + +## 描述 + +ICMP重定向报文是ICMP控制报文中的一种。在特定的情况下,当路由器检测到一台机器使用非优化路由的时候,它会向该主机发送一个ICMP重定向报文,请求主机改变路由。路由器也会把初始数据报向它的目的地转发。 + +攻击者可以使用虚假的ICMP重定向消息恶意地改变系统路由表,使被攻击者的报文发送向不正确的路径,并截获其发出的报文。 + +## 修复建议 + +不接受 ICMP 重定向。 + +1. 修改`/etc/sysctl.conf`文件及`/etc/sysctl.d`路径下所有后缀为`.conf`文件中以下参数的值。如没有以下参数,则需在`/etc/sysctl.conf`文件中添加: + +```shell +net.ipv4.conf.all.accept_redirects = 0 +net.ipv4.conf.default.accept_redirects = 0 +net.ipv6.conf.all.accept_redirects = 0 +net.ipv6.conf.default.accept_redirects = 0 +``` + +2. 执行以下命令,设置活动内核参数: + +```shell +# sysctl -w net.ipv4.conf.all.accept_redirects=0 +# sysctl -w net.ipv4.conf.default.accept_redirects=0 +# sysctl -w net.ipv6.conf.all.accept_redirects=0 +# sysctl -w net.ipv6.conf.default.accept_redirects=0 +# sysctl -w net.ipv4.route.flush=1 +# sysctl -w net.ipv6.route.flush=1 +``` + +## 扫描检测 + +确保不接受源路由报文。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv4.conf.all.accept_redirects +net.ipv4.conf.all.accept_redirects = 0 +# sysctl net.ipv4.conf.default.accept_redirects +net.ipv4.conf.default.accept_redirects = 0 +# grep "net\.ipv4\.conf\.all\.accept_redirects" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.all.accept_redirects = 0 +# grep "net\.ipv4\.conf\.default\.accept_redirects" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.default.accept_redirects = 0 +# sysctl net.ipv6.conf.all.accept_redirects +net.ipv6.conf.all.accept_redirects = 0 +# sysctl net.ipv6.conf.default.accept_redirects +net.ipv6.conf.default.accept_redirects = 0 +# grep "net\.ipv6\.conf\.all\.accept_redirects" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv6.conf.all.accept_redirects = 0 +# grep "net\.ipv6\.conf\.default\.accept_redirects" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv6.conf.default.accept_redirects = 0 +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.51-ensure-secure-icmp-redirects-are-not-accepted.md b/benchmarks/system-configurations/4.51-ensure-secure-icmp-redirects-are-not-accepted.md new file mode 100644 index 0000000..7166bdc --- /dev/null +++ b/benchmarks/system-configurations/4.51-ensure-secure-icmp-redirects-are-not-accepted.md @@ -0,0 +1,56 @@ +# 4.51 确保不接受安全的ICMP重定向 + +## 安全等级 + +Level 1 + +## 描述 + +ICMP重定向报文是ICMP控制报文中的一种。在特定的情况下,当路由器检测到一台机器使用非优化路由的时候,它会向该主机发送一个ICMP重定向报文,请求主机改变路由。路由器也会把初始数据报向它的目的地转发。 + +安全ICMP重定向与ICMP重定向基本相同,不同之处在于它们来自已知的且可信的网关,这类报文很可能是安全的。但即使是已知的网关也有可能被劫持或破坏。攻击者可以使用虚假的ICMP重定向消息恶意地改变系统路由表,使被攻击者的报文发送向不正确的路径,并截获其发出的报文。 + +综上,配置不接受安全的ICMP重定向。进一步加强系统的安全性。 + +## 修复建议 + +不接受 ICMP 重定向。 + +1. 修改`/etc/sysctl.conf`文件及`/etc/sysctl.d`路径下所有后缀为`.conf`文件中以下参数的值。如没有以下参数,则需在`/etc/sysctl.conf`文件中添加: + +```shell +net.ipv4.conf.all.secure_redirects = 0 +net.ipv4.conf.default.secure_redirects = 0 +``` + +2. 执行以下命令,设置活动内核参数: + +```shell +# sysctl -w net.ipv4.conf.all.secure_redirects=0 +# sysctl -w net.ipv4.conf.default.secure_redirects=0 +# sysctl -w net.ipv4.route.flush=1 +``` + +## 扫描检测 + +确保不接受源路由报文。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv4.conf.all.secure_redirects +net.ipv4.conf.all.secure_redirects = 0 +# sysctl net.ipv4.conf.default.secure_redirects +net.ipv4.conf.default.secure_redirects = 0 +# grep "net\.ipv4\.conf\.all\.secure_redirects" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.all.secure_redirects = 0 +# grep "net\.ipv4\.conf\.default\.secure_redirects" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.default.secure_redirects = 0 +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.52-ensure-suspicious-packets-are-logged.md b/benchmarks/system-configurations/4.52-ensure-suspicious-packets-are-logged.md new file mode 100644 index 0000000..18bfacf --- /dev/null +++ b/benchmarks/system-configurations/4.52-ensure-suspicious-packets-are-logged.md @@ -0,0 +1,54 @@ +# 4.52 确保对可疑报文进行日志记录 + +## 安全等级 + +Level 1 + +## 描述 + +启用该特性后,系统会将源地址不可达的报文记录到内核日志。 + +启用此功能并记录这些数据包,能够使管理员了解和防范攻击者向系统发送欺骗数据包。 + +## 修复建议 + +开启可疑报文日志记录功能。 + +1. 修改`/etc/sysctl.conf`文件及`/etc/sysctl.d`路径下所有后缀为`.conf`文件中以下参数的值。如没有以下参数,则需在`/etc/sysctl.conf`文件中添加: + +```shell +net.ipv4.conf.all.log_martians = 1 +net.ipv4.conf.default.log_martians = 1 +``` + +2. 执行以下命令,设置活动内核参数: + +```shell +# sysctl -w net.ipv4.conf.all.log_martians=1 +# sysctl -w net.ipv4.conf.default.log_martians=1 +# sysctl -w net.ipv4.route.flush=1 +``` + +## 扫描检测 + +确保对可疑报文进行日志记录。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv4.conf.all.log_martians +net.ipv4.conf.all.log_martians = 1 +# sysctl net.ipv4.conf.default.log_martians +net.ipv4.conf.default.log_martians = 1 +# grep "net\.ipv4\.conf\.all\.log_martians" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.all.log_martians = 1 +# grep "net\.ipv4\.conf\.default\.log_martians" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv4.conf.default.log_martians = 1 +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.53-ensure-broadcast-icmp-requests-are-ignored.md b/benchmarks/system-configurations/4.53-ensure-broadcast-icmp-requests-are-ignored.md new file mode 100644 index 0000000..d30188e --- /dev/null +++ b/benchmarks/system-configurations/4.53-ensure-broadcast-icmp-requests-are-ignored.md @@ -0,0 +1,41 @@ +# 4.53 确保忽略 ICMP 广播请求 + +## 安全等级 + +Level 1 + +## 描述 + +接受带有广播或多播目的地的 ICMP echo 和时间戳请求可能会欺骗您的主机启动(或参与) Smurf 攻击。Smurf 攻击者使用虚假的源地址发送大量 ICMP 广播消息,所有接收到此消息并作出响应的主机都会发送响应报文到此虚假的地址,此地址可能是不可路由的。如果响应这些数据包的主机达到一定数量,那么网络上的通信量将大大增加,引起通信阻塞。 + +应配置系统忽略所有向广播和多播地址发送的 ICMP echo 和时间戳请求。 + +## 修复建议 + +忽略 ICMP 广播请求。 + +1. 执行以下命令,修改配置文件,并设置活动内核参数。 + +```shell +# grep -Els "^\s*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | while read filename; do sed -ri "s/^\s*(net\.ipv4\.icmp_ignore_bogus_error_responses\s*)(=)(\s*\S+\b).*$/# *REMOVED* \1/" $filename; done; sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1; sysctl -w net.ipv4.route.flush=1 +``` + +## 扫描检测 + +确保忽略 ICMP 广播请求。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv4.icmp_echo_ignore_broadcasts +net.ipv4.icmp_echo_ignore_broadcasts = 1 +# grep -E -s "^\s*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf +Nothing should be returned +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.54-ensure-bogus-icmp-responses-are-ignored.md b/benchmarks/system-configurations/4.54-ensure-bogus-icmp-responses-are-ignored.md new file mode 100644 index 0000000..7cbd0cf --- /dev/null +++ b/benchmarks/system-configurations/4.54-ensure-bogus-icmp-responses-are-ignored.md @@ -0,0 +1,41 @@ +# 4.54 确保忽略伪造的 ICMP 响应 + +## 安全等级 + +Level 1 + +## 描述 + +一些攻击者会伪装为路由器发送违反RFC-1122的响应,并试图用大量无用的错误消息填充日志文件系统。 + +禁止内核记录来自广播帧的虚假响应(RFC-1122不合规),从而避免文件系统被无用的日志消息填满,影响系统性能与日志准确性。 + +## 修复建议 + +忽略伪造的 ICMP 响应。 + +1. 执行以下命令,修改配置文件,并设置活动内核参数: + +```shell +# grep -Els "^\s*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | while read filename; do sed -ri "s/^\s*(net\.ipv4\.icmp_ignore_bogus_error_responses\s*)(=)(\s*\S+\b).*$/# *REMOVED* \1/" $filename; done; sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1; sysctl -w net.ipv4.route.flush=1 +``` + +## 扫描检测 + +确保忽略伪造的 ICMP 响应。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv4.icmp_ignore_bogus_error_responses +net.ipv4.icmp_ignore_bogus_error_responses = 1 +# grep -E -s "^\s*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf +Nothing should be returned +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.55-ensure-reverse-path-filtering-is-enabled.md b/benchmarks/system-configurations/4.55-ensure-reverse-path-filtering-is-enabled.md new file mode 100644 index 0000000..b7764dd --- /dev/null +++ b/benchmarks/system-configurations/4.55-ensure-reverse-path-filtering-is-enabled.md @@ -0,0 +1,58 @@ +# 4.55 确保启用反向路径过滤 + +## 安全等级 + +Level 1 + +## 描述 + +反向路径过滤:强制 Linux 内核对接收到的数据包进行反向路径过滤来验证数据包的有效性。如果返回的数据包与源数据包来自不同的接口,此数据包将被丢弃(如果设置了 log_martians,则会记录日志)。此功能能够有效的阻止攻击者向您的系统发送无法回应的虚假数据包。 + +**此功能在不对称路由的环境中是不适用的。如果您的系统上使用了不对称路由(bgp, ospf等),启用此功能将影响您的路由通信。** + +## 修复建议 + +开启反向路径过滤功能。 + +1. 执行以下命令,修改配置文件,并设置活动内核参数: + +```shell +# grep -Els "^\s*net\.ipv4\.conf\.all\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | while read filename; do sed -ri "s/^\s*(net\.ipv4\.conf\.all\.rp_filter\s*)(=)(\s*\S+\b).*$/# *REMOVED* \1/" $filename; done; sysctl -w net.ipv4.conf.all.rp_filter=1; sysctl -w net.ipv4.route.flush=1 +``` + +2. 修改`/etc/sysctl.conf`文件及`/etc/sysctl.d`路径下所有后缀为`.conf`文件中以下参数的值。如没有以下参数,则需在`/etc/sysctl.conf`文件中添加: + +```shell +net.ipv4.conf.default.rp_filter = 1 +``` + +3. 设置活动内核参数: + +```shell +# sysctl -w net.ipv4.conf.default.rp_filter=1 +# sysctl -w net.ipv4.route.flush=1 +``` + +## 扫描检测 + +确保启用反向路径过滤。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv4.conf.all.rp_filter +net.ipv4.conf.all.rp_filter = 1 +# sysctl net.ipv4.conf.default.rp_filter +net.ipv4.conf.default.rp_filter = 1 +# grep -E -s "^\s*net\.ipv4\.conf\.all\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf +Nothing should be returned +# grep -E -s "^\s*net\.ipv4\.conf\.default\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf +net.ipv4.conf.default.rp_filter = 1 +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.56-ensure-tcp-syn-cookies-is-enabled.md b/benchmarks/system-configurations/4.56-ensure-tcp-syn-cookies-is-enabled.md new file mode 100644 index 0000000..8346903 --- /dev/null +++ b/benchmarks/system-configurations/4.56-ensure-tcp-syn-cookies-is-enabled.md @@ -0,0 +1,41 @@ +# 4.56 确保已启用 TCP SYN cookie + +## 安全等级 + +Level 1 + +## 描述 + +SYN Cookie是对TCP服务器端的三次握手协议作一些修改,专门用来防范SYN Flood攻击的一种手段。它的原理是,在TCP服务器收到TCP SYN包并返回TCP SYN+ACK包时,不分配一个专门的数据区,而是根据这个SYN包计算出一个cookie值。在收到TCP ACK包时,TCP服务器再根据那个cookie值检查这个TCP ACK包的合法性。如果合法,再分配专门的数据区进行处理未来的TCP连接。 + +SYN Flood是一种非常危险而常见的DoS攻击方式。到目前为止,能够有效防范SYN Flood攻击的手段并不多,SYN Cookie就是其中最著名的一种。 + +## 修复建议 + +启用 TCP SYN cookie 功能。 + +1. 执行以下命令,修改配置文件,并设置活动内核参数: + +```shell +# grep -Els "^\s*net\.ipv4\.tcp_syncookies\s*=\s*[02]*" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | while read filename; do sed -ri "s/^\s*(net\.ipv4\.tcp_syncookies\s*)(=)(\s*\S+\b).*$/# *REMOVED* \1/" $filename; done; sysctl -w net.ipv4.tcp_syncookies=1; sysctl -w net.ipv4.route.flush=1 +``` + +## 扫描检测 + +确保已启用 TCP SYN cookie。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv4.tcp_syncookies +net.ipv4.tcp_syncookies = 1 +# grep -E -r "^\s*net\.ipv4\.tcp_syncookies\s*=\s*[02]" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf +Nothing should be returned +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.57-ensure-ipv6-router-advertisements-are-not-accepted.md b/benchmarks/system-configurations/4.57-ensure-ipv6-router-advertisements-are-not-accepted.md new file mode 100644 index 0000000..642a193 --- /dev/null +++ b/benchmarks/system-configurations/4.57-ensure-ipv6-router-advertisements-are-not-accepted.md @@ -0,0 +1,54 @@ +# 4.57 确保不接受 IPv6 路由器通告 + +## 安全等级 + +Level 1 + +## 描述 + +建议在系统内配置不接受路由器的广播通告,因为这种路由很可能是一种攻击手段,用于劫持或恶意引导主机的流量。在系统内配置一条可信的默认路由可以保护系统不受恶意路由的影响。 + +应禁用 IPv6 路由通告的接受功能。 + +## 修复建议 + +禁用 IPv6 路由通告的接受功能。 + +1. 修改`/etc/sysctl.conf`文件及`/etc/sysctl.d`路径下所有后缀为`.conf`文件中以下参数的值。如没有以下参数,则需在`/etc/sysctl.conf`文件中添加: + +```shell +net.ipv6.conf.all.accept_ra = 0 +net.ipv6.conf.default.accept_ra = 0 +``` + +2. 执行以下命令,设置活动内核参数: + +```shell +# sysctl -w net.ipv6.conf.all.accept_ra=0 +# sysctl -w net.ipv6.conf.default.accept_ra=0 +# sysctl -w net.ipv6.route.flush=1 +``` + +## 扫描检测 + +确保不接受 IPv6 路由器通告。 + +1. 执行以下命令,检查返回结果: + +```shell +# sysctl net.ipv6.conf.all.accept_ra +net.ipv6.conf.all.accept_ra = 0 +# sysctl net.ipv6.conf.default.accept_ra +net.ipv6.conf.default.accept_ra = 0 +# grep "net\.ipv6\.conf\.all\.accept_ra" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv6.conf.all.accept_ra = 0 +# grep "net\.ipv6\.conf\.default\.accept_ra" /etc/sysctl.conf /etc/sysctl.d/* +net.ipv6.conf.default.accept_ra = 0 +``` + +如返回结果均符合预期,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.58-ensure-a-firewall-package-is-installed.md b/benchmarks/system-configurations/4.58-ensure-a-firewall-package-is-installed.md new file mode 100644 index 0000000..1b8d0dc --- /dev/null +++ b/benchmarks/system-configurations/4.58-ensure-a-firewall-package-is-installed.md @@ -0,0 +1,69 @@ +# 4.58 确保已安装防火墙软件包 + +## 安全等级 + +Level 1 + +## 描述 + +应选择一个防火墙包安装。 大多数防火墙配置工具是作为`nftables`或`iptables`的前端运行。 + +防火墙包是防火墙管理和配置所必需的。 + +## 修复建议 + +安装防火墙软件包。 + +1. 根据实际环境,执行以下3条命令中任一1条,安装一种防火墙软件包: + +* firewalld: + +```shell +# dnf install firewalld -y +``` + +* nftables: + +```shell +# dnf install nftables -y +``` + +* iptables: + +```shell +# dnf install iptables -y +``` + +## 扫描检测 + +确保已安装防火墙软件包。 + +1. 执行以下命令,检查以下3款软件包,是否正确安装了其中任一1款: + +* firewalld: + +```shell +# rpm -q firewalld +firewalld- +``` + +* nftables: + +```shell +# rpm -q nftables +nftables- +``` + +* iptables: + +```shell +# rpm -q iptables +iptables- +``` + +返回值中``为软件版本,如以上3款软件包,正确安装了其中1款,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.59-ensure-firewalld-service-is-enabled-and-running.md b/benchmarks/system-configurations/4.59-ensure-firewalld-service-is-enabled-and-running.md new file mode 100644 index 0000000..3cad462 --- /dev/null +++ b/benchmarks/system-configurations/4.59-ensure-firewalld-service-is-enabled-and-running.md @@ -0,0 +1,43 @@ +# 4.59 确保防火墙服务已启用且运行状态正常 + +## 安全等级 + +Level 1 + +## 描述 + +确保启用了防火墙服务以保护系统及网络环境。 + +* firewald、iptables、nftables 三种防火墙工具,可根据实际生产使用环境,使用其中一种即可。 + +## 修复建议 + +启用防火墙服务。 + +1. 执行以下命令,启用防火墙服务: + +```shell +# systemctl --now enable firewalld +``` + +## 扫描检测 + +确保防火墙服务已启用且运行状态正常。 + +1. 执行以下命令,检查防火墙是否开启: + +```shell +# systemctl is-enabled firewalld +enabled +``` + +2. 执行以下命令,检查防火墙是否正常运行: + +```shell +# firewall-cmd --state +running +``` + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.6-ensure-permissions-on-etc-issue.net-are-configured.md b/benchmarks/system-configurations/4.6-ensure-permissions-on-etc-issue.net-are-configured.md new file mode 100644 index 0000000..b6660cf --- /dev/null +++ b/benchmarks/system-configurations/4.6-ensure-permissions-on-etc-issue.net-are-configured.md @@ -0,0 +1,39 @@ +# 4.6 确保 /etc/issue.net 的权限配置正确 + +## 安全等级 + +Level 1 + +## 描述 + +在远程终端登录时会展示`/etc/issue.net`文件中的内容。 + +如果`/etc/issue.net`文件的权限及所有者没有正确配置,其内容就可能被未经授权的用户篡改,从而展示不正确或误导性的登录信息。 + +## 修复建议 + +目标:正确配置`/etc/issue.net`文件的权限和所有者。 + +1. 使用以下代码,配置`/etc/issue.net`文件的权限和所有者: + +```shell +# chown root:root /etc/issue.net +# chmod u-x,go-wx /etc/issue.net +``` + +## 扫描检测 + +确保`/etc/issue.net`目录的权限配置正确。 + +1. 执行以下命令,检查`/etc/issue.net`目录的权限属性: + +```shell +# stat /etc/issue.net +Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) +``` + +如果输出结果中:`Uid`与`Gid`均为`0/root`,且`Acces`为`0644`或更加严格,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.60-ensure-iptables-is-not-enabled.md b/benchmarks/system-configurations/4.60-ensure-iptables-is-not-enabled.md new file mode 100644 index 0000000..d6ea1ec --- /dev/null +++ b/benchmarks/system-configurations/4.60-ensure-iptables-is-not-enabled.md @@ -0,0 +1,48 @@ +# 4.60 确保 iptables 未启用 + +## 安全等级 + +Level 1 + +## 描述 + +iptables 是集成在 Linux 内核中的包过滤防火墙系统。使用 iptables 可以添加、删除具体的过滤规则,iptables 默认维护着 4 个表和 5 个链,所有的防火墙策略规则都被分别写入这些表与链中。 + +同时运行 firewald 和 iptables 可能会导致冲突,因此 iptables 应该在使用防火墙时被停止和屏蔽。 + +* firewald、iptables、nftables 三种防火墙工具,可根据实际生产使用环境,使用其中一种即可。 + +## 修复建议 + +停止 iptables 服务。 + +1. 执行以下命令,停止 iptables 服务: + +```shell +# systemctl --now mask iptables +``` + +## 扫描检测 + +确保 iptables 未启用。 + +1. 执行以下命令,检查 iptables 是否已停止: + +```shell +# systemctl status iptables + Loaded: disabled (/dev/null; bad) + Active: inactive (dead) +``` + +2. 执行以下命令,检查 iptables 是否已停止: + +```shell +# systemctl is-enabled iptables +(disabled|masked) +``` + +如输出结果均符合预期,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.61-ensure-nftables-is-not-enabled.md b/benchmarks/system-configurations/4.61-ensure-nftables-is-not-enabled.md new file mode 100644 index 0000000..ed10669 --- /dev/null +++ b/benchmarks/system-configurations/4.61-ensure-nftables-is-not-enabled.md @@ -0,0 +1,62 @@ +# 4.61 确保 nftables 未启用 + +## 安全等级 + +Level 1 + +## 描述 + +nftables 提供了一个新的包过滤框架,该框架基于特定于网络的虚拟机(VM),一个新的用户空间实用程序(nft)和一个用于{ip,ip6}表的兼容层。从Linux内核3.13版本开始(2013),nftables已经成为Linux内核主线的一部分。正在逐渐替换iptables。 + +相比于iptables,nftables有了如下改进: + +* 查表取代线性处理 + +* ipv4 ipv6使用同一个框架 + +* 以原子方式应用规则,而不是获取、更新和存储完整的规则集 + +* 支持在规则集中debug和trace + +* 更一致紧凑的语法,没有特定协议的扩展 + +* 为第三方应用提供Netlink API + +在运行了 firewalld 的系统内,同时运行 nftables 可能会导致冲突,因此 nftables 应该会在使用 firewalld 时被停止和屏蔽。 + +* firewald、iptables、nftables 三种防火墙工具,可根据实际生产使用环境,使用其中一种即可。 + +## 修复建议 + +停止 nftables 服务。 + +1. 执行以下命令,停止 nftables 服务: + +```shell +# systemctl --now mask nftables +``` + +## 扫描检测 + +确保 nftables 未启用。 + +1. 执行以下命令,检查 nftables 是否已停止: + +```shell +# systemctl status nftables + Loaded: masked (/dev/null; bad) + Active: inactive (dead) +``` + +2. 执行以下命令,检查 nftables 是否已停止: + +```shell +# systemctl is-enabled nftables +(disabled|masked) +``` + +如输出结果均符合预期,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.62-ensure-nftables-service-is-enabled.md b/benchmarks/system-configurations/4.62-ensure-nftables-service-is-enabled.md new file mode 100644 index 0000000..13448e7 --- /dev/null +++ b/benchmarks/system-configurations/4.62-ensure-nftables-service-is-enabled.md @@ -0,0 +1,52 @@ +# 4.62 确保 nftables 服务已启用 + +## 安全等级 + +Level 1 + +## 描述 + +nftables 提供了一个新的包过滤框架,该框架基于特定于网络的虚拟机(VM),一个新的用户空间实用程序(nft)和一个用于{ip,ip6}表的兼容层。从Linux内核3.13版本开始(2013),nftables已经成为Linux内核主线的一部分。正在逐渐替换iptables。 + +相比于iptables,nftables有了如下改进: + +* 查表取代线性处理 + +* ipv4 ipv6使用同一个框架 + +* 以原子方式应用规则,而不是获取、更新和存储完整的规则集 + +* 支持在规则集中debug和trace + +* 更一致紧凑的语法,没有特定协议的扩展 + +* 为第三方应用提供Netlink API + +**firewald、iptables、nftables 三种防火墙工具,可根据实际生产使用环境,使用其中一种即可。** + +## 修复建议 + +开启 nftables 服务。 + +1. 执行以下命令,开启 nftables 服务: + +```shell +# systemctl --now enable nftables +``` + +## 扫描检测 + +确保 nftables 服务已启用。 + +1. 执行以下命令,检查 nftables 是否已启用: + +```shell +# systemctl is-enabled nftables +enabled +``` + +如输出结果符合预期,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.63-ensure-iptables-packages-are-installed.md b/benchmarks/system-configurations/4.63-ensure-iptables-packages-are-installed.md new file mode 100644 index 0000000..19603ac --- /dev/null +++ b/benchmarks/system-configurations/4.63-ensure-iptables-packages-are-installed.md @@ -0,0 +1,41 @@ +# 4.63 确保正确安装 iptables 软件包 + +## 安全等级 + +Level 1 + +## 描述 + +iptables 是集成在 Linux 内核中的包过滤防火墙系统。使用 iptables 可以添加、删除具体的过滤规则,iptables 默认维护着 4 个表和 5 个链,所有的防火墙策略规则都被分别写入这些表与链中。 + +需确保系统中安装了 iptables 软件包。 + +* **firewald、iptables、nftables 三种防火墙工具,可根据实际生产使用环境,使用其中一种即可。** + +## 修复建议 + +安装 iptables 软件包。 + +1. 执行以下命令,安装 iptables 软件包: + +```shell +# yum install -y iptables iptables-services +``` + +## 扫描检测 + +确保正确安装 iptables 软件包。 + +1. 执行以下命令,检查 iptables 软件包是否已安装: + +```shell +# rpm -q iptables iptables-services +iptables- +iptables-services- +``` + +输出结果中``为软件版本。如输出结果符合预期,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.64-ensure-nftables-is-not-installed.md b/benchmarks/system-configurations/4.64-ensure-nftables-is-not-installed.md new file mode 100644 index 0000000..2279620 --- /dev/null +++ b/benchmarks/system-configurations/4.64-ensure-nftables-is-not-installed.md @@ -0,0 +1,54 @@ +# 4.64 确保未安装 nftables + +## 安全等级 + +Level 1 + +## 描述 + +nftables 提供了一个新的包过滤框架,该框架基于特定于网络的虚拟机(VM),一个新的用户空间实用程序(nft)和一个用于{ip,ip6}表的兼容层。从Linux内核3.13版本开始(2013),nftables已经成为Linux内核主线的一部分。正在逐渐替换iptables。 + +相比于iptables,nftables有了如下改进: + +* 查表取代线性处理 + +* ipv4 ipv6使用同一个框架 + +* 以原子方式应用规则,而不是获取、更新和存储完整的规则集 + +* 支持在规则集中debug和trace + +* 更一致紧凑的语法,没有特定协议的扩展 + +* 为第三方应用提供Netlink API + +在运行了 iptables 的系统内,同时运行 nftables 可能会导致冲突,因此 nftables 应该会在使用 iptables 时被停止和屏蔽。 + +**firewald、iptables、nftables 三种防火墙工具,可根据实际生产使用环境,使用其中一种即可**。 + +## 修复建议 + +卸载 nftables 软件包。 + +1. 执行以下命令,卸载 nftables 软件包: + +```shell +# yum remove -y nftables +``` + +## 扫描检测 + +确保未安装 nftables。 + +1. 执行以下命令,检查 nftables 软件包是否未安装: + +```shell +# rpm -q nftables +package nftables is not installed +``` + +如输出结果符合预期,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.65-ensure-firewalld-is-not-installed-or-stopped-and-masked.md b/benchmarks/system-configurations/4.65-ensure-firewalld-is-not-installed-or-stopped-and-masked.md new file mode 100644 index 0000000..67f07b5 --- /dev/null +++ b/benchmarks/system-configurations/4.65-ensure-firewalld-is-not-installed-or-stopped-and-masked.md @@ -0,0 +1,59 @@ +# 4.65 确保防火墙没有安装或服务已停止 + +## 安全等级 + +Level 1 + +## 描述 + +同时运行 firewalld和 iptables 可能会导致冲突,因此 firewalld应该在使用 iptables 时被停止和屏蔽。 + +**firewald、iptables、nftables 三种防火墙工具,可根据实际生产使用环境,使用其中一种即可**。 + +## 修复建议 + +卸载 firewalld软件包或停止 firewalld服务。 + +1. 执行以下命令,卸载 firewalld软件包: + +```shell +# yum remove -y firewalld +``` + +OR + +2. 执行以下命令,停止 firewalld服务: + +```shell +# systemctl --now mask firewalld +``` + +以上2条命令,根据实际生产使用环境,选择其中1条执行即可。 + +## 扫描检测 + +确保防火墙没有安装或服务已停止。 + +1. 执行以下命令,检查 firewalld软件包是否未安装: + +```shell +# rpm -q firewalld +package nftables is not installed +``` + +OR + +2. 执行以下命令,检查 firewalld服务是否已停止: + +```shell +# systemctl status firewalld | grep "Active: " | grep -v "active (running) " +Active: inactive (dead) +# systemctl is-enabled firewalld +masked +``` + +如输出结果符合预期,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.7-ensure-gpgcheck-is-globally-activated.md b/benchmarks/system-configurations/4.7-ensure-gpgcheck-is-globally-activated.md new file mode 100644 index 0000000..5d53e24 --- /dev/null +++ b/benchmarks/system-configurations/4.7-ensure-gpgcheck-is-globally-activated.md @@ -0,0 +1,51 @@ +# 4.7 确保 gpgcheck 全局激活 + +## 安全等级 + +Level 1 + +## 描述 + +在`/etc/dnf/dnf.conf`文件及`/etc/yum.repos.d/*`目录下的部分文件中,包含`gpgcheck`配置参数。`gpgcheck`参数的配置决定了在安装软件前是否检查RPM包的签名。 + +在安装软件之前,一定要检查RPM包的签名,以确保软件是从可信的来源获得的,这一点非常重要。 + +## 修复建议 + +目标:激活 gpgcheck 签名检查。 + +1. 编辑`/etc/dnf/dnf.conf`文件,在`[main]`部分设置`gpgcheck=1`: + +```shell +# sed -i 's/^gpgcheck\s*=\s*.*/gpgcheck=1/' /etc/dnf/dnf.conf +``` + +2. 编辑`/etc/yum.repos.d/`目录下所有文件内`gpgcheck`参数的值为1: + +```shell +# find /etc/yum.repos.d/ -name "*.repo" -exec echo "Checking:" {} \; -exec sed -i 's/^gpgcheck\s*=\s*.*/gpgcheck=1/' {} \; +``` + +## 扫描检测 + +确保 gpgcheck 全局激活。 + +1. 执行以下命令,检查`/etc/dnf/dnf.conf`文件中`gpgcheck`参数配置是否正确: + +```shell +# grep ^gpgcheck /etc/dnf/dnf.conf +gpgcheck=1 +``` + +2. 配置在`/etc/yum.repos.d/`目录下的`gpgcheck`参数,优先级大于全局配置。执行以下命令,确认没有`gpgcheck=0`的配置项。 + +```shell +# grep -P "^gpgcheck\h*=\h*[^1].*\h*$" /etc/yum.repos.d/* +No information is returned. +``` + +如果以上2条检查项目的输出结果均符合要求,则视为通过此项检查。 + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.8-ensure-aide-is-installed.md b/benchmarks/system-configurations/4.8-ensure-aide-is-installed.md new file mode 100644 index 0000000..9c4f159 --- /dev/null +++ b/benchmarks/system-configurations/4.8-ensure-aide-is-installed.md @@ -0,0 +1,46 @@ +# 4.8 确保正确安装 AIDE + +## 安全等级 + +Level 1 + +## 描述 + +AIDE (Advanced Intrusion Detection Environment)是一种入侵检测工具,它在Linux操作系统下使用预定义的规则对文件和目录的完整性进行检测。 + +AIDE有自己的数据库来检查文件和目录的完整性:AIDE获取文件和目录的快照,包括修改时间、权限和文件哈希值,然后使用该快照与文件系统的当前状态进行比较,以检测文件系统的修改。 + +## 修复建议 + +目标:正确安装`AIDE`。 + +1. 执行以下命令,安装`AIDE`软件: + +```shell +# dnf install aide -y +``` + +2. 初始化`AIDE`服务: + +```shell +# aide --init +# mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz +``` + +## 扫描检测 + +确保正确安装 AIDE。 + +1. 执行以下命令,验证是否正确安装了AIDE: + +```shell +# rpm -q aide +aide- +``` + +``为版本号,如:`aide-0.16-14.an8_5.1.x86_64`。如有返回`aide`及版本号,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file diff --git a/benchmarks/system-configurations/4.9-ensure-filesystem-integrity-is-regularly-checked.md b/benchmarks/system-configurations/4.9-ensure-filesystem-integrity-is-regularly-checked.md new file mode 100644 index 0000000..767ab5c --- /dev/null +++ b/benchmarks/system-configurations/4.9-ensure-filesystem-integrity-is-regularly-checked.md @@ -0,0 +1,48 @@ +# 4.9 确保定期检查文件系统完整性 + +## 安全等级 + +Level 1 + +## 描述 + +定期进行文件系统完整性检查,有助于系统管理员跟踪了解关键文件的变化,及时发现关键文件是否有被未经授权的更改或删除。 + +## 修复建议 + +建立对文件系统的定期检查机制。 + +1. 使用`cron`工具调度和执行文件系统检查: + +* 打开定时任务编辑: + +```shell +# crontab -u root -e +``` + +* 写入以下内容: + +```shell +0 5 * * * /usr/sbin/aide --check +``` + +以上内容表示:每5小时执行一次文件系统检查。 + + +## 扫描检测 + +确保定期检查文件系统完整性。 + +1. 执行以下命令,验证`cron`作业项目: + +```shell +# crontab -u root -l | grep aide +0 5 * * * /usr/sbin/aide --check +``` + +如返回aide的定时任务,则视为通过此项检查。 + + +## 参考 + +- cis: 'https://www.cisecurity.org/benchmark/aliyun_linux' \ No newline at end of file -- Gitee