12 |
my $resend_search_delay = 3; |
my $resend_search_delay = 3; |
13 |
my $tftp_path = '/srv/tftp/'; |
my $tftp_path = '/srv/tftp/'; |
14 |
|
|
15 |
my $user_id = 'Administrator'; |
# tab-delimited list of user id/passwd to try on ants |
16 |
my $user_pwd = ''; |
my @try_accounts = ( "Administrator\t" ); |
17 |
|
|
18 |
|
my $passwd_path = $0; |
19 |
|
$passwd_path =~ s/[^\/]+$/passwd/; |
20 |
|
|
21 |
|
if (-e $passwd_path) { |
22 |
|
open(my $fh, $passwd_path) || die "can't open $passwd_path: $!"; |
23 |
|
while(<$fh>) { |
24 |
|
chomp; |
25 |
|
next if /^#/ || /^$/ || /^\s+$/; |
26 |
|
if (/^\S+\t\S+$/) { |
27 |
|
push @try_accounts, $_; |
28 |
|
} else { |
29 |
|
warn "invalid $passwd_path entry: $_\n"; |
30 |
|
} |
31 |
|
} |
32 |
|
print "found ", $#try_accounts, " accounts to try on password protected ants\n"; |
33 |
|
} |
34 |
|
|
35 |
warn "search for ants every ${resend_search_delay}s\ntftp server path: $tftp_path\n"; |
warn "search for ants every ${resend_search_delay}s\ntftp server path: $tftp_path\n"; |
36 |
|
|
88 |
} |
} |
89 |
} |
} |
90 |
|
|
91 |
|
my $ant_passwd_try; |
92 |
|
|
93 |
|
sub ant_credentials { |
94 |
|
my $ant = shift || die "no ant?"; |
95 |
|
my $i = $ant_passwd_try->{$ant} || 0; |
96 |
|
my ($user_id,$user_pwd) = split(/\t/, $try_accounts[$i]); |
97 |
|
#warn "ant $ant as [$i] $user_id / $user_pwd\n"; |
98 |
|
return ($user_id,$user_pwd); |
99 |
|
} |
100 |
|
|
101 |
|
sub ant_another_passwd { |
102 |
|
my $ant = shift || die "no ant?"; |
103 |
|
$ant_passwd_try->{$ant}++; |
104 |
|
$ant_passwd_try->{$ant} = 0 if ( $ant_passwd_try->{$ant} > $#try_accounts ); |
105 |
|
} |
106 |
|
|
107 |
local $SIG{ALRM} = sub { |
local $SIG{ALRM} = sub { |
108 |
mdap_send("ANT-SEARCH MDAP/1.1\r\n"); |
mdap_send("ANT-SEARCH MDAP/1.1\r\n"); |
109 |
alarm( $resend_search_delay ); |
alarm( $resend_search_delay ); |
130 |
|
|
131 |
warn dump($h),$/ if ($debug); |
warn dump($h),$/ if ($debug); |
132 |
|
|
133 |
# we are getting our own INFO messages |
# we are getting our own messages (since our source port |
134 |
|
# is same as destination) |
135 |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
136 |
|
|
137 |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
138 |
|
|
139 |
|
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
140 |
|
|
141 |
if ($type eq 'REPLY-ANT-SEARCH') { |
if ($type eq 'REPLY-ANT-SEARCH') { |
142 |
mdap_send("INFO MDAP/$mdap_ver\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); |
mdap_send("INFO MDAP/$mdap_ver\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); |
143 |
} elsif ($type eq 'REPLY-INFO') { |
} elsif ($type eq 'REPLY-INFO') { |
144 |
|
|
145 |
if ($h->{'SEQ-NR'} < 0) { |
if ($h->{'SEQ-NR'} < 0) { |
146 |
warn "!! password protected ant $ant, skipping\n"; |
warn "!! password protected ant $ant, skipping\n"; |
147 |
|
ant_another_passwd( $ant ); |
148 |
next; |
next; |
149 |
} |
} |
150 |
|
|