Centos基线问题修复
下面这个是修复脚本-直接复制粘贴就可以。
我的修复规则是先修复权重值较高的部分,再修复低的。
################### lxy 20210916 ###################echo "1.修复口令生存期"sed -i '25s#99999#90#' /etc/login.defssed -i '26s#0#10#' /etc/login.defssed -i '27s#5#12#' /etc/login.defsif [ $? -eq 0 ]thenecho "1. 修复口令生存期 ok"elseecho "1. 修复口令生存期 flase"exit 1fi# 2. 设置口令复杂度sed -i 's#try_first_pass retry=3 type=#try_first_pass local_users_only retry=3 authtok_type= difok=3 minlen=12 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1#' /etc/pam.d/system-authif [ $? -eq 0 ]thenecho "2. 设置口令复杂度 ok"elseecho "2. 设置口令复杂度 flase"exit 1fi# 3. 认证授权-使用PAM认证模块禁止wheel组之外的用户su为rootsed -i '6s/#auth/auth/' /etc/pam.d/suif [ $? -eq 0 ]thenecho "3. 认证授权-使用PAM认证模块禁止wheel组之外的用户su为root ok"elseecho "3. 认证授权-使用PAM认证模块禁止wheel组之外的用户su为root flase"exit 1fi# 4. 文件权限-文件与目录缺省权限控制echo "umask 027" >> /etc/profileif [ $? -eq 0 ]thenecho "4. 文件权限-文件与目录缺省权限控制 ok"elseecho "4. 文件权限-文件与目录缺省权限控制 flase"exit 1fi# 5. 文件权限-配置用户最小授权chmod -R 600 /etc/securityif [ $? -eq 0 ]thenecho "5. 文件权限-配置用户最小授权 ok"elseecho "5. 文件权限-配置用户最小授权 flase"exit 1fi# 6. 文件权限-禁止ICMP重定向echo "net.ipv4.conf.all.accept_redirects = 0" >> /etc/sysctl.confsysctl -p# 7. 系统漏洞-系统core dump状态echo "* soft core 0" >> /etc/security/limits.confecho "* hard core 0" >> /etc/security/limits.confif [ $? -eq 0 ]thenecho "7. 系统漏洞-系统core dump状态 ok"elseecho "7. 系统漏洞-系统core dump状态 flase"exit 1fi# 8. 其它配置-登录超时时间设置echo "TMOUT=300" >> /etc/profileecho "export TMOUT" >> /etc/profileif [ $? -eq 0 ]thenecho "8. 其它配置-登录超时时间设置 ok"elseecho "8. 其它配置-登录超时时间设置 flase"exit 1fi# 9. 其它配置-设置关键文件的属性chattr +a /var/log/messagesif [ $? -eq 0 ]thenecho "9. 其它配置-设置关键文件的属性 ok"elseecho "9. 其它配置-设置关键文件的属性 flase"exit 1fi# 10. 其它配置-历史命令设置echo "HISTFILESIZE=5" >> /etc/profilesed -i 's/HISTSIZE=1000/HISTSIZE=5/g' /etc/profileif [ $? -eq 0 ]thenecho "10. 其它配置-历史命令设置 ok"elseecho "10. 其它配置-历史命令设置 flase"exit 1fi# 11. 设置登录失败处理功能策略sed -i '/pam_env.so/i auth required pam_tally2.so deny=5 onerr=fail no_magic_root unlock_time=180' /etc/pam.d/system-authif [ $? -eq 0 ]thenecho "11. 设置登录失败处理功能策略 ok"elseecho "11. 设置登录失败处理功能策略 flase"exit 1fi# 12. 设置口令重复次数限制sed -i 's#use_authtok#use_authtok remember=5#g' /etc/pam.d/system-authif [ $? -eq 0 ]thenecho "12. 设置口令重复次数限制 ok"elseecho "12. 设置口令重复次数限制 flase"exit 1fi# 13. 修改SSH的Banner信息echo "welcome landz test" > /etc/motdif [ $? -eq 0 ]thenecho "13. 修改SSH的Banner信息 ok"elseecho "13. 修改SSH的Banner信息 flase"exit 1fi# 14. 修改SSH的Banner警告信息sed -i '/Banner/i Banner /etc/sshbanner' /etc/ssh/sshd_configecho "Authorized users only. All activity may be monitored and reported" > /etc/sshbannerif [ $? -eq 0 ]thenecho "14. 修改SSH的Banner警告信息 ok"elseecho "14. 修改SSH的Banner警告信息 flase"exit 1fi# 15. 日志文件安全chmod 640 /var/log/boot.logif [ $? -eq 0 ]thenecho "15. 日志文件安全 ok"elseecho "15. 日志文件安全 flase"exit 1fi# 16. 启用远程日志功能sed -i '/remote-host:514/i *.* @日志审计服务器IP:514' /etc/rsyslog.confchmod 640 /var/log/boot.logif [ $? -eq 0 ]thenecho "16. 启用远程日志功能 ok"elseecho "16. 启用远程日志功能 flase"exit 1fi# 17. 记录安全事件日志echo "*.err;kern.debug;daemon.notice /var/adm/messages" >> /etc/rsyslog.confif [ $? -eq 0 ]thenecho "17. 记录安全事件日志 ok"elseecho "17. 记录安全事件日志 flase"exit 1fi# 18. 口令锁定策略sed -i '/pam_localuser.so/i account required pam_tally2.so' /etc/pam.d/system-authif [ $? -eq 0 ]thenecho "18. 口令锁定策略 ok"elseecho "18. 口令锁定策略 flase"exit 1fi
