在 CentOS 上“拦截 exploit(漏洞利用)”通常不是一个单一操作,而是多层防御。下面按实战优先级给你一套可落地的方案,从“立刻能做的”到“长期加固”。
绝大多数 exploit 都是利用已知漏洞。
# CentOS 7
yum update -y
# CentOS 8 / Stream
dnf update -y
重点更新:
✅ 这是拦截 exploit 最根本的方法
ss -antlp
systemctl disable --now telnet
systemctl disable --now rsh
systemctl enable firewalld
systemctl start firewalld
只允许必要端口:
firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
✅ 可拦截大量扫描和 exploit 尝试
# 改端口
Port 22222
# 禁止 root 登录
PermitRootLogin no
# 使用密钥
PasswordAuthentication no
SELinux 能直接阻止很多提权 exploit
getenforce
如果是 Disabled:
vi /etc/selinux/config
SELINUX=enforcing
reboot
✅ SELinux 可在 exploit 成功后限制破坏范围
yum install epel-release -y
yum install fail2ban -y
# /etc/fail2ban/jail.local
[sshd]
enabled = true
port = ssh
logpath = /var/log/secure
maxretry = 3
bantime = 3600
systemctl enable fail2ban
systemctl start fail2ban
✅ 自动封 IP
yum install aide -y
aide --init
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
aide --check
✅ 发现被篡改的二进制文件
sysctl -a | grep kernel.randomize_va_space
确保:
kernel.randomize_va_space = 2
sysctl -w kernel.dmesg_restrict=1
CentOS 默认不支持,需定制内核(不推荐普通用户)
| exploit 类型 | 拦截方式 |
|---|---|
| SSH 爆破 | fail2ban + 密钥 |
| Web RCE | WAF + SELinux |
| 内核提权 | 更新 kernel + SELinux |
| SUID 提权 | 审计 + 权限最小化 |
| 反弹 shell | 审计 + 进程监控 |
⚠️ 不要只“修漏洞”
CentOS 拦截 exploit = 更新 + 最小权限 + SELinux + 防火墙 + 行为监控
如果你愿意,可以告诉我:
我可以给你针对性的一键加固方案。