Skip to content

Commit 6decd3c

Browse files
David MaloneyDavid Maloney
authored andcommitted
fix exceptions thrown in telnet loginscanner too
1 parent bf8f722 commit 6decd3c

File tree

1 file changed

+30
-26
lines changed
  • lib/metasploit/framework/login_scanner

1 file changed

+30
-26
lines changed

lib/metasploit/framework/login_scanner/telnet.rb

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,41 +55,45 @@ def attempt_login(credential)
5555
service_name: 'telnet'
5656
}
5757

58-
if connect_reset_safe == :refused
59-
result_options[:status] = Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
60-
else
61-
if busy_message?
62-
self.sock.close unless self.sock.closed?
58+
begin
59+
if connect_reset_safe == :refused
6360
result_options[:status] = Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
64-
end
65-
end
66-
67-
unless result_options[:status]
68-
unless password_prompt?
69-
send_user(credential.public)
70-
end
71-
72-
recvd_sample = @recvd.dup
73-
# Allow for slow echos
74-
1.upto(10) do
75-
recv_telnet(self.sock, 0.10) unless @recvd.nil? or @recvd[/#{@password_prompt}/]
61+
else
62+
if busy_message?
63+
self.sock.close unless self.sock.closed?
64+
result_options[:status] = Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
65+
end
7666
end
7767

78-
if password_prompt?(credential.public)
79-
send_pass(credential.private)
68+
unless result_options[:status]
69+
unless password_prompt?
70+
send_user(credential.public)
71+
end
8072

73+
recvd_sample = @recvd.dup
8174
# Allow for slow echos
8275
1.upto(10) do
83-
recv_telnet(self.sock, 0.10) if @recvd == recvd_sample
76+
recv_telnet(self.sock, 0.10) unless @recvd.nil? or @recvd[/#{@password_prompt}/]
8477
end
85-
end
8678

87-
if login_succeeded?
88-
result_options[:status] = Metasploit::Model::Login::Status::SUCCESSFUL
89-
else
90-
result_options[:status] = Metasploit::Model::Login::Status::INCORRECT
91-
end
79+
if password_prompt?(credential.public)
80+
send_pass(credential.private)
81+
82+
# Allow for slow echos
83+
1.upto(10) do
84+
recv_telnet(self.sock, 0.10) if @recvd == recvd_sample
85+
end
86+
end
9287

88+
if login_succeeded?
89+
result_options[:status] = Metasploit::Model::Login::Status::SUCCESSFUL
90+
else
91+
result_options[:status] = Metasploit::Model::Login::Status::INCORRECT
92+
end
93+
94+
end
95+
rescue ::EOFError, Errno::ECONNRESET, Rex::AddressInUse, Rex::ConnectionError, Rex::ConnectionTimeout, ::Timeout::Error
96+
result_options[:status] = Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
9397
end
9498

9599
::Metasploit::Framework::LoginScanner::Result.new(result_options)

0 commit comments

Comments
 (0)