CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/metasploit/framework/login_scanner/ftp.rb
Views: 1904
1
require 'metasploit/framework/ftp/client'
2
require 'metasploit/framework/login_scanner/base'
3
require 'metasploit/framework/login_scanner/rex_socket'
4
5
module Metasploit
6
module Framework
7
module LoginScanner
8
9
# This is the LoginScanner class for dealing with FTP.
10
# It is responsible for taking a single target, and a list of credentials
11
# and attempting them. It then saves the results.
12
class FTP
13
include Metasploit::Framework::LoginScanner::Base
14
include Metasploit::Framework::LoginScanner::RexSocket
15
include Metasploit::Framework::Ftp::Client
16
17
DEFAULT_PORT = 21
18
LIKELY_PORTS = [ DEFAULT_PORT, 2121 ]
19
LIKELY_SERVICE_NAMES = [ 'ftp' ]
20
PRIVATE_TYPES = [ :password ]
21
REALM_KEY = nil
22
23
# @!attribute ftp_timeout
24
# @return [Integer] The timeout in seconds to wait for a response to an FTP command
25
attr_accessor :ftp_timeout
26
27
validates :ftp_timeout,
28
presence: true,
29
numericality: {
30
only_integer: true,
31
greater_than_or_equal_to: 1
32
}
33
34
35
36
# (see Base#attempt_login)
37
def attempt_login(credential)
38
result_options = {
39
credential: credential
40
}
41
42
begin
43
success = connect_login(credential.public, credential.private)
44
rescue ::EOFError, Errno::ECONNRESET, Rex::ConnectionError, Rex::ConnectionTimeout, ::Timeout::Error
45
result_options[:status] = Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
46
success = false
47
ensure
48
disconnect
49
end
50
51
if success
52
result_options[:status] = Metasploit::Model::Login::Status::SUCCESSFUL
53
elsif !(result_options.has_key? :status)
54
result_options[:status] = Metasploit::Model::Login::Status::INCORRECT
55
end
56
57
result = ::Metasploit::Framework::LoginScanner::Result.new(result_options)
58
result.host = host
59
result.port = port
60
result.protocol = 'tcp'
61
result.service_name = 'ftp'
62
result
63
end
64
65
private
66
67
# This method sets the sane defaults for things
68
# like timeouts and TCP evasion options
69
def set_sane_defaults
70
self.connection_timeout ||= 30
71
self.port ||= DEFAULT_PORT
72
self.max_send_size ||= 0
73
self.send_delay ||= 0
74
self.ftp_timeout ||= 16
75
end
76
77
end
78
79
end
80
end
81
end
82
83