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/modules/auxiliary/scanner/nessus/nessus_ntp_login.rb
Views: 1904
1
##
2
# nessus_ntp_login.rb
3
##
4
5
# This module requires Metasploit: https://metasploit.com/download
6
# Current source: https://github.com/rapid7/metasploit-framework
7
##
8
9
class MetasploitModule < Msf::Auxiliary
10
include Msf::Exploit::Remote::Tcp
11
include Msf::Auxiliary::Scanner
12
include Msf::Auxiliary::Report
13
include Msf::Auxiliary::AuthBrute
14
15
def initialize
16
super(
17
'Name' => 'Nessus NTP Login Utility',
18
'Description' => 'This module attempts to authenticate to a Nessus NTP service.',
19
'Author' => [ 'Vlatko Kosturjak <kost[at]linux.hr>' ],
20
'License' => MSF_LICENSE
21
)
22
register_options(
23
[
24
Opt::RPORT(1241),
25
OptBool.new('BLANK_PASSWORDS', "Try blank passwords for all users")
26
]
27
)
28
end
29
30
def run_host(ip)
31
begin
32
print_status("#{msg} Connecting and checking username and passwords")
33
each_user_pass do |user, pass|
34
do_login(user, pass)
35
end
36
end
37
rescue ::Rex::ConnectionError
38
rescue ::Exception => e
39
vprint_error("#{msg} #{e.to_s} #{e.backtrace}")
40
end
41
42
def ntp_send(data=nil, con=true)
43
begin
44
@result=''
45
@coderesult=''
46
if (con)
47
@connected=false
48
connect
49
select(nil,nil,nil,0.4)
50
end
51
@connected=true
52
sock.put(data)
53
@result=sock.get_once
54
rescue ::Exception => err
55
print_error("#{msg} Error: #{err.to_s}")
56
end
57
end
58
59
def report_cred(opts)
60
service_data = {
61
address: opts[:ip],
62
port: opts[:port],
63
service_name: opts[:service_name],
64
protocol: 'tcp',
65
workspace_id: myworkspace_id
66
}
67
68
credential_data = {
69
origin_type: :service,
70
module_fullname: fullname,
71
username: opts[:user],
72
private_data: opts[:password],
73
private_type: :password
74
}.merge(service_data)
75
76
login_data = {
77
last_attempted_at: Time.now,
78
core: create_credential(credential_data),
79
status: Metasploit::Model::Login::Status::SUCCESSFUL,
80
proof: opts[:proof]
81
}.merge(service_data)
82
83
create_credential_login(login_data)
84
end
85
86
def do_login(user=nil,pass=nil)
87
begin
88
ntp_send("< NTP/1.0 >\n",true) # send hello
89
if @result !~ /\<\ NTP\/1\.0 \>/
90
print_error("#{msg} Nessus NTP does not appear to be running: did not get response to NTP hello: #{@result}")
91
return :abort
92
end
93
94
vprint_status("#{msg} Trying user:'#{user}' with password:'#{pass}'")
95
ntp_send(nil,!@connected)
96
if @result !~ /User\ \:/
97
print_error("#{msg} Nessus NTP did not send User request: #{@result}")
98
end
99
ntp_send("#{user}\n",!@connected)
100
if @result !~ /Password\ \:/
101
print_error("#{msg} Nessus NTP did not send Password request: #{@result}")
102
end
103
ntp_send("#{pass}\n",!@connected)
104
if @result =~ /SERVER <|>.*<|> SERVER/is
105
print_good("#{msg} SUCCESSFUL login for '#{user}' : '#{pass}'")
106
report_cred(
107
ip: rhost,
108
port: rport,
109
service_name: 'nessus-ntp',
110
user: user,
111
password: pass,
112
proof: @result
113
)
114
115
disconnect
116
@connected = false
117
return :next_user
118
else
119
if (@connected)
120
disconnect # Sometime nessus disconnect the client after wrongs attempts
121
@connected = false
122
end
123
vprint_error("#{msg} Rejected user: '#{user}' with password: '#{pass}': #{@result}")
124
return :fail
125
end
126
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
127
rescue ::Timeout::Error, ::Errno::EPIPE
128
end
129
end
130
131
def msg
132
"#{rhost}:#{rport} Nessus NTP -"
133
end
134
end
135
136