“CentOS exploit”通常指利用 CentOS 系统或其上服务的漏洞进行攻击/提权。没有一种“一键阻止”的办法,而是要从系统加固、漏洞管理、访问控制、监控响应几方面综合防护。
下面按实用优先级给你一套可落地的做法。
绝大多数 exploit 都针对已知漏洞。
# CentOS 7
yum update -y
# CentOS 8(已 EOL,建议迁移到 Rocky/Alma/RHEL)
dnf update -y
建议:
yum update --security很多 exploit 来自开放但无用的服务。
# 查看监听端口
ss -tulnp
# 禁用不需要的服务
systemctl disable --now telnet
systemctl disable --now rsh
systemctl disable --now nfs
常见建议:
vim /etc/ssh/sshd_config
推荐配置:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
Port 2222 # 可选
然后:
systemctl restart sshd
补充:
yum install epel-release -y
yum install fail2ban -y
systemctl enable --now fail2ban
systemctl enable --now firewalld
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --remove-service=telnet
firewall-cmd --reload
原则:
getenforce
如果是 disabled,建议改为:
vim /etc/selinux/config
SELINUX=enforcing
重启后生效。
SELinux 能显著限制 exploit 的破坏范围。
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
# 漏洞扫描
yum install openscap-scanner
oscap xccdf eval --profile standard /usr/share/xml/scap/ssg/content/ssg-centos7-ds.xml
或外部工具:
# 查看异常登录
journalctl -u sshd
last
建议:
/var/log/secure立即:
如果你愿意,可以告诉我:
我可以直接给你针对性的加固命令清单。