注意:本人环境为centos,如果是ubuntu等其他系统,则下面第1步骤可能有些文件报不存在的错误,不过不影响后面的步骤
修复步骤:
1.先用控制台登录,敲下如下命令恢复远程访问
chmod o='' -R /etc/{sudoers,shadow,shadow-,libaudit.conf,gshadow,gshadow-,group-,audit,audisp} /etc/selinux/targeted/modules/active/modules/ /etc/ssh/{sshd_config,ssh_host_dsa_key,ssh_host_key,ssh_host_rsa_key,moduli} /etc/openldap/slapd.d/ /etc/{securetty,.pwd.lock,} /etc/security/opasswd /etc/openldap/certs/password
2.然后使用如下脚本在正常的机器上执行:
cat find_perm.sh
#!/bin/bash
echo > pp0
echo > pp4
echo > pp7
find /etc -perm 777 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' > pp7
find /etc -perm 700 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' > pp0
find /etc -perm 740 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp0
find /etc -perm 760 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp0
find /etc -perm 440 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp0
find /etc -perm 640 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp0
find /etc -perm 660 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp0
find /etc -perm 000 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp0
find /etc -perm 400 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp0
find /etc -perm 600 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp0
find /etc -perm 444 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' > pp4
find /etc -perm 644 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp4
find /etc -perm 664 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp4
find /etc -perm 764 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp4
find /etc -perm 744 -exec ls -lh {} \; |awk '{print $9}' |grep '^/' >> pp4
3.产生3个文件:pp0,pp4,pp7,把这三个文件和如下脚本一并上传到问题机器:
cat alter_perm.sh
#!/bin/bash
cat pp0 |xargs chmod o=''
cat pp4 |xargs chmod o=r
cat pp7 |xargs chmod o=rwx
4.执行alter_perm.sh脚本,恢复被修改的权限