Hardens Ubuntu, RHEL, CentOS Linux endpoints using CIS Benchmark: filesystem configs, disable services, network sysctls, SSH hardening. For new servers, audits, compliance baselines.
npx claudepluginhub killvxk/cybersecurity-skills-zhThis skill uses the workspace's default tool permissions.
在以下情况下使用本技能:
Hardens Linux endpoints (Ubuntu, RHEL, CentOS) using CIS Benchmark via bash scripts for filesystem, services, network config, and boot settings. For server deployment, audit remediation, compliance.
Hardens Linux servers (Ubuntu, RHEL, CentOS) per CIS Benchmarks using bash scripts for filesystem, services, network, and boot security. For compliance and audits.
Hardens Windows 10/11 and Server 2019/2022 endpoints using CIS Benchmarks via GPO templates and CIS-CAT verification. For new deployments, audit fixes, and compliance baselines.
Share bugs, ideas, or general feedback.
在以下情况下使用本技能:
不适用于 Windows 加固(使用 hardening-windows-endpoint-with-cis-benchmark)。
# 1.1.1 禁用未使用的文件系统
cat >> /etc/modprobe.d/CIS.conf << 'EOF'
install cramfs /bin/true
install freevxfs /bin/true
install jffs2 /bin/true
install hfs /bin/true
install hfsplus /bin/true
install squashfs /bin/true
install udf /bin/true
EOF
# 1.1.2 确保 /tmp 是带有 nodev,nosuid,noexec 的独立分区
# /etc/fstab 条目:
# tmpfs /tmp tmpfs defaults,rw,nosuid,nodev,noexec,relatime 0 0
systemctl unmask tmp.mount
systemctl enable tmp.mount
# 1.1.8 确保 /dev/shm 有 nodev 选项
mount -o remount,nodev,nosuid,noexec /dev/shm
echo "tmpfs /dev/shm tmpfs defaults,nodev,nosuid,noexec 0 0" >> /etc/fstab
# 1.4 安全引导设置
chown root:root /boot/grub/grub.cfg
chmod 600 /boot/grub/grub.cfg
# 设置 GRUB 密码
grub-mkpasswd-pbkdf2 # 生成哈希,添加到 /etc/grub.d/40_custom
# 2.1 禁用不必要的服务
systemctl disable --now avahi-daemon
systemctl disable --now cups
systemctl disable --now rpcbind
systemctl disable --now xinetd
# 2.2 确保已配置 NTP
apt install chrony -y # 或 systemd-timesyncd
systemctl enable --now chrony
# 3.1 网络参数(仅主机,非路由器)
cat >> /etc/sysctl.d/99-cis.conf << 'EOF'
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.default.log_martians = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.tcp_syncookies = 1
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.default.accept_ra = 0
EOF
sysctl --system
# 3.4 配置防火墙(UFW 或 firewalld)
ufw enable
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
# 5.2 SSH 服务器配置(/etc/ssh/sshd_config)
sed -i 's/#Protocol 2/Protocol 2/' /etc/ssh/sshd_config
cat >> /etc/ssh/sshd_config << 'EOF'
LogLevel VERBOSE
MaxAuthTries 4
PermitRootLogin no
PermitEmptyPasswords no
PasswordAuthentication no
X11Forwarding no
MaxStartups 10:30:60
LoginGraceTime 60
AllowTcpForwarding no
ClientAliveInterval 300
ClientAliveCountMax 3
EOF
systemctl restart sshd
# 5.3 密码策略(PAM)
# /etc/security/pwquality.conf
minlen = 14
dcredit = -1
ucredit = -1
ocredit = -1
lcredit = -1
# 5.4 用户账户设置
# /etc/login.defs
PASS_MAX_DAYS 365
PASS_MIN_DAYS 1
PASS_WARN_AGE 7
# 锁定非活跃账号
useradd -D -f 30
# 安装并配置 auditd
apt install auditd audispd-plugins -y
systemctl enable --now auditd
# /etc/audit/rules.d/cis.rules
cat > /etc/audit/rules.d/cis.rules << 'EOF'
-w /etc/sudoers -p wa -k scope
-w /etc/sudoers.d/ -p wa -k scope
-w /var/log/sudo.log -p wa -k actions
-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change
-a always,exit -F arch=b64 -S sethostname -S setdomainname -k system-locale
-w /etc/group -p wa -k identity
-w /etc/passwd -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /var/log/faillog -p wa -k logins
-w /var/log/lastlog -p wa -k logins
-a always,exit -F arch=b64 -S chmod -S fchmod -S fchmodat -k perm_mod
-a always,exit -F arch=b64 -S unlink -S rmdir -S rename -k delete
-w /sbin/insmod -p x -k modules
-w /sbin/modprobe -p x -k modules
-e 2
EOF
augenrules --load
# 配置 rsyslog 进行远程日志记录
echo "*.* @@syslog-server.corp.com:514" >> /etc/rsyslog.d/50-remote.conf
systemctl restart rsyslog
# 安装 OpenSCAP
apt install openscap-scanner scap-security-guide -y
# 运行 CIS benchmark 评估
oscap xccdf eval \
--profile xccdf_org.ssgproject.content_profile_cis_level1_server \
--results /tmp/cis_results.xml \
--report /tmp/cis_report.html \
/usr/share/xml/scap/ssg/content/ssg-ubuntu2204-ds.xml
# 在浏览器中查看 HTML 报告以获取详细结果
| 术语 | 定义 |
|---|---|
| OpenSCAP | 用于自动合规检查的开源 SCAP(安全内容自动化协议)扫描器 |
| auditd | 用于监控系统调用和文件访问的 Linux 审计框架 |
| PAM | 可插拔认证模块(Pluggable Authentication Modules),Linux 的可配置认证框架 |
| sysctl | 用于网络和系统安全调优的 Linux 内核参数配置 |
| AIDE | 高级入侵检测环境(Advanced Intrusion Detection Environment),Linux 文件完整性检查工具 |