美文网首页
centos 密码批量尝试

centos 密码批量尝试

作者: 木头_95b3 | 来源:发表于2020-06-15 10:13 被阅读0次

    使用环境: 平时密码过多,批量操作机器的时候,试密码耗时很长,做大量的无用功;因此写出该脚本

    主要有五个文件:

    • check_passwd.sh 主执行文件
    • exp_login.sh 被调用的 exp 脚本
    • ip.list 放需要尝试连接的IP
    • pw.list 放需要尝试的密码
    • login-sucess 为成功登陆的 IP 及密码
    • ping-filed 为 ping 失败的 IP

    使用方法:放入 IP 到 ip.list 中,放入 密码到 pw.list 中,执行 bash check_passwd.sh 即可

    查询结果:login-sucess 为成功登陆的 IP 及密码 ;ping-filed 为 ping 失败的 IP

    #!/bi/bash
    #
    # author: HaoChuanfeng
    # create date: 2020-6-12
    #
    # check_passwd.sh 是主文件
    # exp_login.sh 是被调用的 expect 登陆文件
    # ip.list 放需要尝试连接的IP
    # pw.list 放需要尝试的密码
    # 没有ip.list 、pw.list文件 运行 check_passwd.sh 会自动创建,也可自行手动创建
    # 注意:以下文件都要在同一个目录下
    #
    # 使用方法:放入 IP 到 ip.list 中,放入 密码到 pw.list 中,执行 bash check_passwd.sh 即可 
    #
    # 查询结果:login-sucess 为成功登陆的 IP 及密码
    #           ping-filed 为 ping 失败的 IP 
    
    
    
    
    
    [ -f ./ip.list ] || touch ./ip.list
    [ -f ./pw.list ] || touch ./pw.list
    [ ! -s ./ip.list  ] && echo "./ip.list no data" && exit 1
    [ ! -s ./pw.list  ] && echo "./pw.list no data" && exit 2
    
    [ -f /usr/bin/expect ] || yum install expect -y
    
    > login-sucess
    > ping-filed
    
    for m in `cat ./ip.list`;do
            if  ping $m -c 1 &>/dev/null;then
    
            for n in  `cat ./pw.list`;do
                    num=`bash ./exp_login.sh $m $n|grep "inet $m"|wc -l` &&  [ $num -gt 0 ] &&  echo $m $n >> login-sucess  &
            sleep 1
            done
            else
                    echo "$m ping filed" >> ping-filed
    
            fi
    
    done
    
    [root@qqqq test]# cat exp_login.sh 
    #!/bin/bash
    
    ip=$1
    password=$2
    #set password "123456"
    #set time 5
    echo $ip
    /usr/bin/expect <<EOF
    
    spawn ssh root@$ip 
    expect {
            "*yes/no" { send "yes\r"; exp_continue }
            "*password:" { send "$password\r" }
    
    }
    expect "#*"
    send "ip add\r"
    expect "#*"
    send "exit\r"
    interact
    expect eof
    EOF
    

    相关文章

      网友评论

          本文标题:centos 密码批量尝试

          本文链接:https://www.haomeiwen.com/subject/wahcxktx.html