更新时间:2024-07-02 GMT+08:00
分享

安全加固工具

概述

HCE 2.0作为面向华为云用户的通用Linux发行版,默认发布的OS ISO安装后未进行安全加固。

security-tool是自研的符合华为相关基础安全加固要求的加固工具包,默认不随HCE 2.0安装,当需要执行加固时选择性安装,安装完成后在OS首次启动时执行自动化加固。用户还可以参考《HCE 2.0安全配置基线》里的加固指导,合理选择加固项目对自己使用的OS进行加固,HCE对此不做任何约束。

详细加固内容请参见security-tool RPM包内的相关加固配置,概括起来包括:

  • 系统服务:例如SSH配置、删除postfix.service、启用haveged.service
  • 内核参数:例如内核网络协议栈加固
  • 账号口令:例如PAM参数加固
  • 授权认证:例如warning banner、umask
  • 文件权限:例如cron配置

security-tool工具使用

  1. 安装security-tool工具包

    若repo源中有该工具包,则可直接使用yum命令进行安装。
    yum install -y security-tool

    若没有,则可在华为云官网 repo 源获取 security-tool 工具包:https://repo.huaweicloud.com/hce/2.0/updates/

  2. 在/etc/hce_security/hce_enhance_type.conf中写入需要加固的配置类型。

    当前支持3种配置:cybersecurity(等保加固配置)、hwsecurity(云服务加固配置)、general(通用加固配置),推荐使用general(通用加固配置)。本示例以general为例。

    echo general > /etc/hce_security/hce_enhance_type.conf

  3. 启动 hce-security服务

    systemctl start hce-security

    执行完成后使用systemctl status hce-security查看服务状态,状态为 active(exited) 即为加固成功。

    加固日志见/var/log/hce_security.log。

    用户可自行修改 /etc/hce_security/usr-security.conf 配置自己的加固项,完成个性化加固,配置文件具体修改方式如下:

    ########################################################################
    #
    # HowTo:
    #       # delete key, and difference caused by blankspace/tab on key is ignored
    #       id@d@file@key
    #
    #       # modify option: find line started with key, and get the value changed
    #       id@m@file@key[@value]
    #
    #       # modify sub-option: find line started with key, and then change the value of key2 to value2(prepostive seperator should not be blank characters) in the line
    #       id@M@file@key@key2[@value2]
    #
    #       # check existence of commands
    #       id@which@command1 [command2 ...]
    #
    #       # execute command on the files found
    #       id@find@dir@condition@command
    #
    #       # any command(with or without parameter), such as 'rm -f','chmod 700','which','touch', used to extend functions, return 0 is ok
    #       id@command@file1 [file2 ...]
    #
    # Notes:
    #       1. The comment line should start with '#'
    #       2. "value" related with "key" should contain prepositive separator("="," " and so on), if there is any.
    #       3. When item starts with "d", "m" or "M", "file" should be a single normal file, otherwise multi-objects(separated by blankspace) are allowed.
    #
    ########################################################################

    如果云服务希望执行更多的安全加固项目,可以参考《HCE 2.0安全配置基线》或华为云其他OS安全加固规范。

SElinux开启会影响系统性能,HCE默认关闭。启用SElinux需要多次重启操作系统,不具备一键开启的能力,如果需要开启,请参考如何开启HCE OS操作系统的SELinux功能?

general/hwsecurity/cybersecurity三种类型的差异

检查项类型

检查项名称

检查内容

general

hwsecurity

cybersecurity

default

初始配置

文件系统配置

应当对系统关键目录进行分区挂载

-

-

-

-

确保禁用不需要的文件系统

-

-

-

-

确保无需修改的分区以只读方式挂载

-

-

-

-

确保无需挂载设备的分区以nodev方式挂载

-

-

-

-

确保无可执行文件的分区以noexec方式挂载

-

-

-

-

确保无需SUID和SGID的分区以nosuid方式挂载

-

-

-

-

避免使用USB存储

-

-

软件服务配置

禁止安装X Window系统

-

-

-

禁止启用debug-shell服务

-

-

禁止启用rsync服务

-

-

禁止启用avahi服务

-

禁止启用SNMP服务

-

禁止启用squid服务

-

避免启用samba服务

-

禁止启用FTP服务

-

禁止启用TFTP服务

-

禁止启用DNS服务

-

-

禁止启用NFS服务

-

禁止启用rpcbind服务

-

禁止启用LDAP服务

-

禁止启用DHCP服务

-

禁止安装CUPS服务软件

-

-

-

禁止安装NIS服务软件

-

-

-

禁止安装telnet软件

-

-

-

禁止安装NIS客户端

-

-

-

禁止安装LDAP客户端

-

-

-

禁止安装调测类工具

-

-

-

禁止安装开发编译类工具

-

-

-

禁止安装网络嗅探类工具

-

-

-

软件升级配置

确保配置GPG公钥

-

-

-

确保配置启用gpgcheck

-

-

-

确保配置软件仓库源

-

-

-

文件完整性检查

确保安装AIDE

-

-

-

-

应当定期检查文件完整性

-

-

-

-

通用进程加固

确保启用ASLR

-

-

确保core dump配置正确

-

-

应当合理限制用户可打开文件数量

-

-

-

-

确保链接文件保护配置正确

-

-

确保dmesg访问权限配置正确

-

-

确保内核符号地址受限访问

-

应当合理限制进程ptrace能力

-

-

-

-

禁止全局加解密策略配置为LEGACY

-

-

-

系统服务

时间同步服务

应当正确配置ntpd服务

-

-

-

-

应当正确配置chronyd服务

-

-

-

定时任务服务

确保cron服务正常运行

-

-

确保cron配置权限正确

-

-

SSH服务

确保/etc/ssh/sshd_config权限配置正确

-

确保SSH私钥文件权限配置正确

-

确保SSH公钥文件权限配置正确

-

确保启用IgnoreRhosts

-

-

应当合理配置认证黑白名单

-

-

-

-

确保SSH使能PAM认证

-

-

禁止SSH root登录

-

-

-

禁止SSH空口令登录

-

-

禁止使用HostbasedAuthentication

-

-

确保配置Warning Banner文件路径

-

-

确保正确配置SSH日志级别

-

应当配置SSH服务侦听IP

-

-

-

-

应当正确配置SSH并发未认证连接数

-

-

-

禁止使用X11Forwarding

-

-

应当配置SSH MaxSessions不超过10

-

-

应当正确配置MaxAuthTries

-

-

-

禁止使用PermitUserEnvironment

-

-

应当配置LoginGraceTime不超过60秒

-

-

确保配置空闲超时间隔时间

-

-

禁止使用AllowTcpForwarding

-

-

确保SSH KexAlgorithms配置强算法

-

确保SSH MACs配置强算法

-

确保SSH Ciphers配置强算法

-

禁止配置SSH将弃用的选项

-

-

网络服务

禁用不使用的网络协议和设备

避免使用不常见网络协议

-

-

-

-

避免使用无线网络

-

-

-

内核网络协议栈

禁止系统响应ICMP广播报文

-

禁止接收ICMP重定向报文

-

-

禁止转发ICMP重定向报文

-

-

应当忽略所有ICMP请求

-

-

-

-

确保忽略伪造的ICMP报文

-

-

确保启用反向地址过滤

-

-

禁止IP转发

-

禁止接收源路由报文

-

-

确保启用TCP-SYN cookie保护

-

应当启用日志记录可疑的网络包

-

-

-

避免启用tcp_timestamps

-

-

-

-

确保TIME_WAIT TCP协议等待时间已配置

-

-

应当合理配置SYN_RECV状态队列数量

-

-

-

-

禁止使用ARP代理

-

-

-

防火墙配置

配置firewalld服务

应当启用firewalld服务

-

-

-

确保iptables未启用

-

-

-

确保nftables未启用

-

-

-

应当配置正确的默认区域

-

-

-

-

应当确保网络接口绑定正确区域

-

-

-

-

避免开启不必要的服务和端口

-

-

-

-

配置iptables服务

应当启用iptables服务

-

-

-

-

确保firewalld未启用

-

-

-

-

确保nftables未启用

-

-

-

应当正确配置iptables默认拒绝策略

-

-

-

-

应当正确配置iptables loopback策略

-

-

-

-

应当正确配置iptables INPUT策略

-

-

-

-

应当正确配置iptables OUTPUT策略

-

-

-

-

应当正确配置iptables INPUT、OUTPUT关联策略

-

-

-

-

配置nftables服务

应当启用nftables服务

-

-

-

-

确保iptables未启用

-

-

-

确保firewealld未启用

-

-

-

-

应当配置nftables默认拒绝策略

-

-

-

-

应当配置nftables loopback策略

-

-

-

-

应当正确配置nftables input策略

-

-

-

-

应当正确配置nftables output策略

-

-

-

-

应当正确配置nftables input、output关联策略

-

-

-

-

日志审计

auditd

确保auditd审计已启用

-

-

应当在启动阶段启用auditd

-

-

-

-

应当正确配置audit_backlog_limit

-

-

-

-

确保配置单个日志大小限制

-

-

-

确保审计日志rotate已启用

-

-

-

-

确保审计日志不被自动删除

-

-

-

应当合理配置磁盘空间阈值

-

-

-

避免配置审计日志限速阈值过小

-

-

-

应当配置sudoers审计规则

-

-

应当配置登录审计规则

-

-

-

应当配置会话审计规则

-

-

-

应当配置时间修改审计规则

-

-

应当配置SELinux审计规则

-

-

-

-

应当配置网络环境审计规则

-

-

-

应当配置文件访问控制权限审计规则

-

-

-

-

应当配置文件访问失败审计规则

-

-

-

-

应当配置文件删除审计规则

-

-

-

-

应当配置账号信息修改审计规则

-

-

应当配置文件系统挂载审计规则

-

-

-

-

应当配置提权命令审计规则

-

-

-

-

应当配置内核模块变更审计规则

-

-

-

应当配置修改sudo日志文件审计规则

-

-

-

-

rsyslog

确保rsyslog服务已启用

-

确保系统认证相关事件日志已记录

-

-

-

确保cron服务日志已记录

-

-

应当正确配置各服务日志记录

-

-

-

应当正确配置rsyslog默认文件权限

-

确保rsyslog日志rotate已配置

-

-

-

-

应当配置发送日志到远程日志服务器

-

-

-

-

应当仅在指定的日志主机上接收远程rsyslog消息

-

-

-

-

确保rsyslog转储journald日志已配置

-

-

-

-

账号与口令管理

账号管理

禁止无需登录的账号拥有登录能力

-

-

-

-

禁止存在不使用的账号

-

-

-

-

应当正确设置账号有效期

-

-

-

-

禁止存在UID为0的非root账号

-

-

-

确保UID唯一

-

-

-

确保GID唯一

-

-

-

确保账号名唯一

-

-

-

确保组名唯一

-

-

-

确保/etc/passwd中的组都存在

-

-

-

确保账号拥有自己的Home目录

-

-

-

确保账号Home目录权限是750或更严格

-

-

-

避免账号Home目录下存在.forward文件

-

-

-

避免账号Home目录下存在.netrc文件

-

-

-

确保用户PATH变量被严格定义

-

-

-

口令管理

确保配置口令复杂度

-

确保限制重用历史口令次数

-

确保口令中不包含账号字符串

-

-

-

确保口令使用SHA512算法加密

-

确保口令过期时间设置正确

-

确保口令过期告警时间设置正确

-

应当设置口令修改周期设置正确

-

确保不活跃口令锁定时间不超过30天

-

-

确保Grub已设置口令保护

-

-

-

确保单用户模式已设置口令保护

-

-

-

身份认证

登录管理

确保登录失败一定次数后锁定账号

-

避免root用户本地接入系统

-

-

-

-

确保会话超时时间设置正确

-

确保Warning Banner包含合理的信息

确保本地登录Warning Banner包含合理的信息

-

-

确保远程登录Warning Banner包含合理的信息

-

-

确保motd文件包含合理的信息

-

-

确保/etc/issue权限配置正确

-

确保/etc/issue.net权限配置正确

-

确保/etc/motd权限配置正确

-

访问控制

SELinux

应当启用enforce模式

-

-

-

应当正确配置SELinux策略

-

-

-

避免标签为unconfined_service_t的服务存在

-

-

-

-

确保SETroubleshoot服务未安装

-

-

-

确保MCS转换服务未安装

-

-

-

特权命令

确保su受限使用

-

确保su命令继承用户环境变量不会引入提权

-

确保普通用户通过sudo运行特权程序

-

-

-

-

确保配置sudo日志文件

-

-

-

禁止使用SysRq键

-

-

-

系统文件权限

确保/etc/passwd权限配置正确

-

-

确保/etc/passwd-权限配置正确

-

-

确保/etc/shadow权限配置正确

-

-

确保/etc/shadow-权限配置正确

-

-

确保/etc/group权限配置正确

-

-

确保/etc/group-权限配置正确

-

-

确保/etc/gshadow权限配置正确

-

-

确保/etc/gshadow-权限配置正确

-

-

确保全局可写目录已设置sticky位

-

-

-

禁止存在无属主或属组的文件或目录

-

-

-

禁止存在全局可写的文件

-

-

-

禁止存在空链接文件

-

-

-

禁止存在隐藏的可执行文件

-

-

-

确保删除文件非必要的SUID和SGID位

-

-

-

确保umask是027或更严格

-

  • “√”表示默认满足。
  • “〇”表示执行。
  • “-”表示不执行。
分享:

    相关文档

    相关产品