温馨提示×

centos exploit如何加固

小樊
36
2026-10-23 19:08:30
栏目: 智能运维

“CentOS exploit”通常指针对 CentOS 系统漏洞的利用(攻击)。加固的核心目标是:减少攻击面、及时打补丁、最小化权限、做好监控。下面按实用优先级给你一套加固清单。


一、系统与补丁加固(最重要)

1. 及时更新系统

yum update -y

或(CentOS 8+):

dnf update -y

2. 只启用必要仓库

yum repolist

关闭无用第三方源,避免引入风险包。

3. 开启自动安全更新

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

二、SSH 加固(最常见 exploit 入口)

4. 禁止 root 直接登录

vi /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no

使用 密钥登录。

5. 修改默认端口(可选)

Port 22222

6. 限制登录 IP(防火墙或 sshd)

AllowUsers admin@192.168.1.0/24

重启:

systemctl restart sshd

三、防火墙与端口最小化

7. 开启 firewalld

systemctl enable firewalld
systemctl start firewalld

只开放必要端口:

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

8. 关闭不必要服务

systemctl list-unit-files | grep enabled

禁用如:

systemctl disable telnet vsftpd rsh

四、权限与账户加固

9. 删除或锁定无用账户

passwd -l username

10. 使用 sudo 而非 root

visudo
admin ALL=(ALL) NOPASSWD: /usr/bin/systemctl

11. 文件权限检查

chmod 700 /etc/shadow
chmod 644 /etc/passwd

五、内核与系统防护

12. 开启 SELinux

getenforce
setenforce 1

永久:

vi /etc/selinux/config
SELINUX=enforcing

13. 内核参数加固(防网络攻击)

vi /etc/sysctl.conf

示例:

net.ipv4.ip_forward=0
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.all.send_redirects=0
sysctl -p

六、日志与入侵检测

14. 开启 audit

systemctl enable auditd
systemctl start auditd

15. 安装 fail2ban(防暴力破解)

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

七、针对“已知 exploit”的专项处理

如果你指的是某个具体漏洞(如:

  • CentOS 7 polkit(CVE-2021-4034)
  • glibc / sudo / kernel 漏洞
  • Samba / NFS / rpcbind 漏洞

请告诉我: ✅ CentOS 版本
✅ 内核版本(uname -a)
✅ 具体 exploit 名称或 CVE

我可以给你精准补丁方案。


八、总结一句话

CentOS 加固 = 打补丁 + 关端口 + 禁 root + 开 SELinux + 看日志

如果你愿意,我可以给你一份**“CentOS 安全基线检查脚本”**,一键检测风险。

0 踩