hardening-linux-endpoint-with-cis-benchmark
使用 CIS Benchmark 建议对 Ubuntu、RHEL 和 CentOS 的 Linux 端点进行加固, 以减少攻击面、执行安全基线并满足合规要求。适用于部署新 Linux 服务器、修复审计发现 或为 Linux 基础设施建立安全基线的场景。
Best use case
hardening-linux-endpoint-with-cis-benchmark is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
使用 CIS Benchmark 建议对 Ubuntu、RHEL 和 CentOS 的 Linux 端点进行加固, 以减少攻击面、执行安全基线并满足合规要求。适用于部署新 Linux 服务器、修复审计发现 或为 Linux 基础设施建立安全基线的场景。
Teams using hardening-linux-endpoint-with-cis-benchmark should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/hardening-linux-endpoint-with-cis-benchmark/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How hardening-linux-endpoint-with-cis-benchmark Compares
| Feature / Agent | hardening-linux-endpoint-with-cis-benchmark | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
使用 CIS Benchmark 建议对 Ubuntu、RHEL 和 CentOS 的 Linux 端点进行加固, 以减少攻击面、执行安全基线并满足合规要求。适用于部署新 Linux 服务器、修复审计发现 或为 Linux 基础设施建立安全基线的场景。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 使用 CIS Benchmark 加固 Linux 端点 ## 使用场景 在以下情况下使用本技能: - 按照 CIS Benchmark 加固 Linux 服务器(Ubuntu、RHEL、CentOS、Debian) - 使用 Ansible、OpenSCAP 或 Shell 脚本自动化 Linux 安全基线 - 满足 Linux 端点的合规要求(PCI DSS、HIPAA、SOC 2) - 修复漏洞扫描或安全审计中发现的问题 **不适用于** Windows 加固(使用 hardening-windows-endpoint-with-cis-benchmark)。 ## 前置条件 - 目标 Linux 端点的 root 或 sudo 访问权限 - 目标发行版的 CIS Benchmark PDF(来自 cisecurity.org) - 用于自动化评估的 OpenSCAP 或 CIS-CAT - 用于企业规模修复的 Ansible(可选) ## 操作流程 ### 步骤 1:文件系统配置(第 1 节) ```bash # 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:服务和网络(第 2-3 节) ```bash # 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 ``` ### 步骤 3:访问控制(第 4-5 节) ```bash # 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 ``` ### 步骤 4:审计和日志记录(第 4 节) ```bash # 安装并配置 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 ``` ### 步骤 5:使用 OpenSCAP 进行评估 ```bash # 安装 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 文件完整性检查工具 | ## 工具与系统 - **OpenSCAP**:Linux 自动化 CIS Benchmark 评估 - **Ansible Lockdown**:用于自动化 CIS Benchmark 修复的 Ansible 角色 - **Lynis**:适用于 Linux/Unix 系统的开源安全审计工具 - **AIDE**:Linux 端点文件完整性监控 - **auditd**:用于系统调用监控的 Linux 审计框架 ## 常见误区 - **将服务器 Benchmark 应用于工作站**:CIS 为服务器和工作站配置文件提供了独立的 Benchmark,服务器 Benchmark 会禁用桌面服务。 - **破坏 SSH 访问**:错误配置 sshd_config(特别是 PermitRootLogin、PasswordAuthentication)可能锁定管理员。务必在第二个会话中测试 SSH 配置变更。 - **未测试防火墙规则**:在允许 SSH 之前启用 UFW 将永久断开远程会话。 - **未经测试就更改内核参数**:某些 sysctl 设置可能破坏应用程序的网络功能。先在预发布环境中测试。
Related Skills
performing-privilege-escalation-on-linux
Linux 权限提升是指在已控制的系统上从低权限用户账户提升至 root 访问权限。红队通过利用错误配置、存在漏洞的服务、内核漏洞利用和弱权限来实现 root 访问。
performing-linux-log-forensics-investigation
对 Linux 系统日志(包括 syslog、auth.log、systemd journal、kern.log 和应用程序日志)进行取证调查,以重建用户活动、检测未授权访问并在被入侵的 Linux 系统上建立事件时间线。
performing-kubernetes-cis-benchmark-with-kube-bench
使用 kube-bench 对照 CIS Benchmark 审计 Kubernetes 集群安全态势,对控制平面、工作节点和 RBAC 执行自动化检查。
performing-endpoint-vulnerability-remediation
通过基于风险评分对 CVE 进行优先级排序、部署补丁、应用配置变更和验证修复 来执行端点漏洞修复。适用于修复漏洞扫描发现的问题、响应严重 CVE 公告 或维护端点合规性与补丁管理 SLA 的场景。适用于涉及漏洞修复、CVE 补丁、 端点漏洞管理或安全修复部署的请求。
performing-endpoint-forensics-investigation
对受损端点执行数字取证调查,包括内存获取、磁盘镜像、工件分析和时间线重建。 适用于调查安全事件、为法律诉讼收集证据或分析端点受损范围的场景。 适用于涉及端点取证、内存分析、磁盘取证或事件调查的请求。
performing-container-image-hardening
本技能涵盖通过最小化攻击面、移除不必要软件包、实施多阶段构建、配置非 root 用户, 以及应用 CIS Docker 基准建议来加固容器镜像,生成安全的生产就绪镜像。
implementing-rbac-hardening-for-kubernetes
通过实施最小权限策略、审计角色绑定、消除 cluster-admin 权限蔓延并集成外部身份提供商,加固 Kubernetes 基于角色的访问控制(RBAC)。
implementing-osquery-for-endpoint-monitoring
部署 osquery 计划查询进行持续终端监控,涵盖进程清单、网络连接、文件完整性和持久化机制。 生成包含查询包的 osquery.conf,配置差异结果日志记录,并分析查询结果以检测 可疑进程、未授权监听端口和系统目录中的文件修改。
implementing-endpoint-dlp-controls
实施端点数据丢失防护(DLP)控制,检测并防止敏感数据通过电子邮件、USB、 云存储和打印进行泄露。适用于部署 DLP 代理、创建内容检查策略或防止 端点上未授权数据移动的场景。适用于涉及 DLP、数据泄露防护、内容检查 或端点敏感数据保护的请求。
implementing-endpoint-detection-with-wazuh
部署并配置 Wazuh SIEM/XDR 进行终端检测,包括 Agent 管理、自定义解码器和规则 XML 创建、通过 Wazuh REST API 查询告警,以及自动化响应动作。
hunting-for-lolbins-execution-in-endpoint-logs
通过分析终端进程创建日志,识别合法 Windows 系统二进制文件(LOLBin)被用于恶意目的的可疑执行模式,狩猎攻击者的 LOLBin 滥用行为。
hardening-windows-endpoint-with-cis-benchmark
使用 CIS(互联网安全中心)Benchmark 建议对 Windows 端点进行加固, 以减少攻击面、执行安全基线并满足合规要求。适用于部署新 Windows 工作站或服务器、 修复审计发现或为组织建立全面安全基线的场景。适用于涉及 Windows 加固、 CIS Benchmark、GPO 安全基线或端点配置合规的请求。