温馨提示×

如何防范CentOS exploit

小樊
42
2026-07-09 05:01:38
栏目: 智能运维

防范 CentOS 系统的 exploit(漏洞利用),核心思路是:减少攻击面 + 及时修补 + 严格权限 + 多层防护。下面按实战优先级给你一套可操作的防护方案。


一、及时修补漏洞(最关键)

1. 定期更新系统

yum update -y

或仅更新安全补丁:

yum update --security

2. 启用自动安全更新

yum install yum-cron -y
systemctl enable yum-cron
systemctl start yum-cron

编辑:

/etc/yum/yum-cron.conf

确保:

apply_updates = yes

二、关闭不必要服务(减少攻击面)

1. 查看运行服务

systemctl list-units --type=service --state=running

2. 关闭无用服务

systemctl disable 服务名
systemctl stop 服务名

常见高危服务:

  • telnet(用 SSH)
  • rsh / rlogin
  • FTP(用 SFTP)
  • NFS(无需时关闭)

三、SSH 防护(最常见入侵入口)

1. 禁止 root 直接登录

vim /etc/ssh/sshd_config
PermitRootLogin no

2. 使用密钥登录

ssh-keygen
ssh-copy-id user@server

并禁用密码登录:

PasswordAuthentication no

3. 修改默认端口

Port 22222

重启 SSH:

systemctl restart sshd

四、内核与系统加固

1. 启用 SELinux

getenforce

若为 Disabled,改为:

vim /etc/selinux/config
SELINUX=enforcing

重启生效。


2. 限制内核参数(防提权)

编辑:

/etc/sysctl.conf
kernel.randomize_va_space = 2
net.ipv4.ip_forward = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0

生效:

sysctl -p

五、账户与权限控制

1. 最小权限原则

  • 不用 root 运行应用
  • 应用使用独立用户

2. 强密码策略

vim /etc/security/pwquality.conf
minlen = 12
dcredit = -1
ucredit = -1

3. 锁定闲置账户

passwd -l 用户名

六、防火墙与端口控制

1. firewalld

systemctl enable firewalld
systemctl start firewalld

只开放必要端口:

firewall-cmd --permanent --add-port=22222/tcp
firewall-cmd --reload

2. 用 fail2ban 防暴力破解

yum install epel-release -y
yum install fail2ban -y

配置 SSH 防护:

vim /etc/fail2ban/jail.local
[sshd]
enabled = true
port = 22222
maxretry = 3
bantime = 3600

七、日志与入侵检测

1. 审计日志

systemctl enable auditd
systemctl start auditd

2. 检查异常

last
lastb
journalctl -xe

3. 使用 AIDE(文件完整性检测)

yum install aide -y
aide --init
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
aide --check

八、CentOS 生命周期特别说明(非常重要)

版本 状态
CentOS 7 已 EOL(2024-06-30)
CentOS 8 已 EOL
CentOS Stream 滚动更新

建议:

  • 迁移到 Rocky / Alma / RHEL
  • 或订阅 RHEL
  • 至少使用 Extended Lifecycle Support(ELS)

九、高危 exploit 应对流程

  1. 立即查看:
    rpm -qa | grep 软件名
    
  2. 查 CVE:
    https://access.redhat.com/security/cve/
    
  3. 打补丁或临时禁用服务
  4. 检查是否被入侵
  5. 重启受影响服务

十、总结一句话

CentOS 防 exploit = 及时更新 + 少开服务 + 强 SSH + SELinux + 防火墙 + 日志监控 + 尽快迁移新系统

如果你愿意,我可以:

  • ✅ 给你一份 CentOS 加固检查清单
  • ✅ 针对 某次具体 CVE/exploit 做专项防护
  • ✅ 帮你评估是否该迁移 Rocky / Alma

直接告诉我你的 CentOS 版本 + 服务器用途 即可。

0