温馨提示×

centos exploit怎样防护

小樊
48
2026-09-06 08:35:43
栏目: 智能运维

在 CentOS(以及一般 Linux 服务器)上防御 exploit(漏洞利用),核心思路是:减少攻击面 + 及时修补 + 限制权限 + 监控异常。下面按实用优先级给你一套防护方案。


一、系统与软件漏洞防护(最重要)

1. 及时打补丁

yum update -y
# 或 CentOS 8+/Stream
dnf update -y
  • 开启自动更新(谨慎):
yum install yum-cron -y
systemctl enable yum-cron

2. 移除无用服务

systemctl list-unit-files --type=service | grep enabled

关闭不必要的:

systemctl disable --now telnet vsftpd rsh

3. 使用安全内核参数

编辑 /etc/sysctl.conf

net.ipv4.tcp_syncookies = 1
net.ipv4.conf.all.rp_filter = 1
kernel.randomize_va_space = 2
sysctl -p

二、权限与账户防护

4. 禁止 root 直接登录

sed -i 's/^PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
systemctl restart sshd

5. 使用普通用户 + sudo

useradd admin
passwd admin
usermod -aG wheel admin

6. 强密码 / 密钥登录

  • 禁用密码登录(推荐):
PasswordAuthentication no
  • 使用 SSH 密钥

三、网络层防护

7. 防火墙(firewalld / iptables)

firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --remove-service=ftp
firewall-cmd --reload

8. 限制 SSH 爆破

firewall-cmd --permanent --add-rich-rule='rule service name=ssh limit value=3/m accept'

或使用 fail2ban

yum install epel-release -y
yum install fail2ban -y
systemctl enable --now fail2ban

四、内核与 exploit 缓解机制

9. 开启安全编译与缓解

  • SELinux(强烈建议开启):
getenforce
setenforce 1

配置文件:

/etc/selinux/config
SELINUX=enforcing

10. grsecurity / SELinux / AppArmor

CentOS 默认用 SELinux,不要关。


五、服务与应用层防护

11. Web / 数据库最小权限

  • Nginx / Apache 不以 root 运行
  • MySQL 禁止远程 root
DELETE FROM mysql.user WHERE User='root' AND Host='%';

12. 文件权限

chmod 644 /etc/passwd
chmod 600 /etc/shadow

六、监控与入侵检测

13. 日志监控

/var/log/secure
/var/log/messages
journalctl -xe

14. 使用入侵检测

  • AIDE(文件完整性)
yum install aide -y
aide --init
  • 或 OSSEC / Wazuh

七、针对“已知 exploit”的专项防护

如果你指的是某个具体 CentOS exploit(如:

  • CVE-2021-4034 (pkexec)
  • CVE-2022-0847 (Dirty Pipe)
  • CVE-2016-5195 (Dirty COW)

✅ 正确做法是:

  1. 查 CVE 编号
  2. 升级对应包
  3. 临时缓解(如禁用模块 / 降权)

总结一句话

CentOS 防 exploit = 及时更新 + 最小权限 + SELinux + 防火墙 + 日志监控

如果你有:

  • CentOS 版本(6 / 7 / 8 / Stream)
  • 具体服务(Web / DB / SSH)
  • 或某个 CVE / exploit 名称

我可以直接给你针对性命令

0