期待: "" (spawn_id exp70) がグローバルパターンと一致するかどうか

期待:

私は私のリストを何度も繰り返した後、デバッグ出力に一致するものが表示されなくなるまでネットワーク上のパスワードをテストするのに効果的だった期待されるスクリプトを書いた。

以下は、バッファにデータがあり、次のデバッグではデータが生成されないことを示すいくつかのデバッグです。

ssh: connect to host 12.23.34.56 port 22: No route to host

expect: does "ssh: connect to host 12.23.34.56 port 22: No route to host\r\r\n" (spawn_id exp69) match glob pattern "(yes/no)? "? no
"assword: "? no
"]# "? no
"oute to host"? yes
expect: set expect_out(0,string) "oute to host"
expect: set expect_out(spawn_id) "exp69"
expect: set expect_out(buffer) "ssh: connect to host 12.23.34.56 port 22: No route to host"
spawn ssh -o PreferredAuthentications=password -o NumberOfPasswordPrompts=3 [email protected]
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {26418}

expect: does "" (spawn_id exp70) match glob pattern "(yes/no)? "? no
"assword: "? no
"]# "? no
"oute to host"? no
"onnection refused"? no
"isconnected from"? no
expect: timed out

exp69以降のすべてのgenerate_idには、does ""一致部分には何もありません。

私はこれがバッファに関連していると思いますが、次のことを試しました。

match_max 200000
match_max 600000

これはあまり差がないようです。実際のIPを削除してxxxxに変更しました。私は実際にxxxxをテストしませんでした(しかし、12.23.34.56が確認のために私のサーバーのリストに挿入されました)。

スクリプト自体は Expect を実行し、"servers.txt" という別のファイルを繰り返し、そのサーバー上で一連のコマンドを 1 行ずつ実行しようとします。動作しているものと動作しないものを記録します。スクリプトの内容は次のとおりです。

#!/usr/bin/expect

# where to log info, open "writable", this is our homegrown log
# unlike the others that follow
set logfile [open "passcheck-results" "w"]

# clobber and log
log_file -noappend passcheck-logfile

# disable user viewing of process as it happens
# 1=on, 0=off
# disables screen output only, recommended 0
log_user 1

# enable verbose debugging, from expect
# 1=on, 0=off
# useful for debugging the script itself, recommended: 0
exp_internal -f debug.log 0

# default waits for 10s, and if no response, kills process
# too low and machines may not respond fast enough
# in particular real timeouts are not registered if too low
# set to -1 for infinite, real timeouts can take 60s or more
# instead of waiting 60s for EVERY failure, set this lower
# recommend the 10s default
set timeout 10


# if you do not get all the response, you expect, increase buffer
match_max 600000

# get by argv functions instead
# set nohistory save on CLI/bash
set passwords { password1 password2 password3 }

# open the list of servers to process
# warning, no error checking on file open
set input [open "servers.txt" "r"]

# loop over the list of servers with prompt logic
foreach ip [split [read $input] "\n"] {


    # slowing it down a bit
    sleep 2

    # had to change =password to get results I wanted
    # loop over line of servers
    spawn ssh -o PreferredAuthentications=password \
             -o NumberOfPasswordPrompts=[llength $passwords] admin@$ip

    # verify where exactly to reset this count
    set try 0

    # account for other possibilities
    expect {
        "(yes/no)? " {
            # new host detected
            sleep 1
            send "yes\r"
            exp_continue
        }
        "assword: " {
            if { $try >= [llength $passwords] } {
                puts $logfile "Bad_Passwords $ip"
                #send_error ">>> wrong passwords\n"
                exit 1
            }
            sleep 1
            send [lindex $passwords $try]\r
            incr try
            exp_continue
        }
        "\]\# " {
            puts $logfile "succeeded_$try $ip"
            sleep 1
            send "exit\r"
        }
        "oute to host" {
            puts $logfile "No_Route_to_Host $ip"
        }
        "onnection refused" {
            puts $logfile "Refused $ip"
        }
        "isconnected from" {
            puts $logfile "Disconnected $ip"
        }
        timeout {
            puts $logfile "timed_out_or_fail $ip"
        }
    }
}

ベストアンサー1

ファイル記述子が不足している可能性があります。リソースが不足しないように、すべてのビルドでクローズを呼び出すことができます。

おすすめ記事