예상: ""(spawn_id exp70)이 전역 패턴과 일치하는지 여부

예상: ""(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"라는 다른 파일을 반복하며 해당 서버에서 일련의 명령을 한 줄씩 실행하려고 시도합니다. 작동하는 것과 작동하지 않는 것을 기록합니다. 스크립트의 내용은 다음과 같습니다.

#!/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

파일 설명자가 부족할 수 있습니다. 리소스가 부족하지 않도록 모든 빌드에서 닫기를 호출할 수 있습니다.

답변2

당신 말이 맞습니다. exp_internal -f passcheck-debug.log 1은 pty 문제가 충분하지 않다고 지적했습니다. 나는 다음을 추가했다:

close -i $spawn_id
wait -nowait

그리고 그때까지 지속됩니다. -nowait를 추가해야 했습니다. 왜냐하면 generate_id가 없으면 영원히 기다려야 하기 때문입니다.

관련 정보