Skip to content

Commit c45e424

Browse files
committed
Land rapid7#5492, update PCAnywhere login scanner
2 parents 5a080d0 + 302db36 commit c45e424

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

modules/auxiliary/scanner/pcanywhere/pcanywhere_login.rb

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def initialize
2121
report successful logins.
2222
},
2323
'Author' => ['theLightCosine'],
24-
'References' =>
24+
'References' =>
2525
[
2626
[ 'CVE', '1999-0502'] # Weak password
2727
],
@@ -39,31 +39,29 @@ def run_host(ip)
3939

4040
each_user_pass do |user, pass|
4141
next if user.blank? or pass.blank?
42-
print_status "Trying #{user}:#{pass}"
42+
print_status("Trying #{user}:#{pass}")
4343
result = do_login(user, pass)
4444
case result
4545
when :success
46-
print_good "#{ip}:#{rport} Login Successful #{user}:#{pass}"
47-
report_auth_info(
48-
:host => rhost,
49-
:port => datastore['RPORT'],
50-
:sname => 'pcanywhere_data',
51-
:user => user,
52-
:pass => pass,
53-
:source_type => "user_supplied",
54-
:active => true
46+
print_good("#{ip}:#{rport} Login Successful #{user}:#{pass}")
47+
report_cred(
48+
ip: rhost,
49+
port: datastore['RPORT'],
50+
service_name: 'pcanywhere',
51+
user: user,
52+
password: pass
5553
)
5654
return if datastore['STOP_ON_SUCCESS']
57-
print_status "Waiting to Re-Negotiate Connection (this may take a minute)..."
55+
print_status('Waiting to Re-Negotiate Connection (this may take a minute)...')
5856
select(nil, nil, nil, 40)
5957
connect
6058
hsr = pca_handshake(ip)
6159
return if hsr == :handshake_failed
6260
when :fail
63-
print_status "#{ip}:#{rport} Login Failure #{user}:#{pass}"
61+
print_status("#{ip}:#{rport} Login Failure #{user}:#{pass}")
6462
when :reset
65-
print_status "#{ip}:#{rport} Login Failure #{user}:#{pass}"
66-
print_status "Connection Reset Attempting to reconnect in 1 second"
63+
print_status("#{ip}:#{rport} Login Failure #{user}:#{pass}")
64+
print_status('Connection reset attempting to reconnect in 1 second')
6765
select(nil, nil, nil, 1)
6866
connect
6967
hsr = pca_handshake(ip)
@@ -73,6 +71,32 @@ def run_host(ip)
7371

7472
end
7573

74+
def report_cred(opts)
75+
service_data = {
76+
address: opts[:ip],
77+
port: opts[:port],
78+
service_name: opts[:service_name],
79+
protocol: 'tcp',
80+
workspace_id: myworkspace_id
81+
}
82+
83+
credential_data = {
84+
origin_type: :service,
85+
module_fullname: fullname,
86+
username: opts[:user],
87+
private_data: opts[:password],
88+
private_type: :password
89+
}.merge(service_data)
90+
91+
login_data = {
92+
core: create_credential(credential_data),
93+
last_attempted_at: DateTime.now,
94+
status: Metasploit::Model::Login::Status::SUCCESSFUL
95+
}.merge(service_data)
96+
97+
create_credential_login(login_data)
98+
end
99+
76100
def do_login(user, pass, nsock=self.sock)
77101
# Check if we are already at a logon prompt
78102
res = nsock.get_once(-1,5)
@@ -87,18 +111,18 @@ def do_login(user, pass, nsock=self.sock)
87111
end
88112

89113
# Check if we are now at the password prompt
90-
unless res and res.include? "Enter password"
91-
print_error "Problem Sending Login: #{res.inspect}"
114+
unless res and res.include? 'Enter password'
115+
print_error("Problem Sending Login: #{res.inspect}")
92116
return :abort
93117
end
94118

95119
epass = encryption_header(encrypt(pass))
96120
nsock.put(epass)
97121
res = nsock.get_once(-1,20)
98-
if res.include? "Login unsuccessful"
122+
if res.include? 'Login unsuccessful'
99123
disconnect()
100124
return :reset
101-
elsif res.include? "Invalid login"
125+
elsif res.include? 'Invalid login'
102126
return :fail
103127
else
104128
disconnect()
@@ -107,38 +131,38 @@ def do_login(user, pass, nsock=self.sock)
107131
end
108132

109133
def pca_handshake(ip, nsock=self.sock)
110-
print_status "Handshaking with the pcAnywhere service"
134+
print_status('Handshaking with the pcAnywhere service')
111135
nsock.put("\x00\x00\x00\x00")
112136
res = nsock.get_once(-1,5)
113-
unless res and res.include? "Please press <Enter>"
114-
print_error "Handshake(1) failed on Host #{ip} aborting. (Error: #{res.inspect} )"
137+
unless res and res.include? 'Please press <Enter>'
138+
print_error("Handshake(1) failed on Host #{ip} aborting. Error: #{res.inspect}")
115139
return :handshake_failed
116140
end
117141

118142
nsock.put("\x6F\x06\xff")
119143
res = nsock.get_once(-1,5)
120144
unless res and res.include? "\x78\x02\x1b\x61"
121-
print_error "Handshake(2) failed on Host #{ip} aborting. (Error: #{res.inspect} )"
145+
print_error("Handshake(2) failed on Host #{ip} aborting. Error: #{res.inspect}")
122146
return :handshake_failed
123147
end
124148

125149
nsock.put("\x6f\x61\x00\x09\x00\xfe\x00\x00\xff\xff\x00\x00\x00\x00")
126150
res = nsock.get_once(-1,5)
127151
unless res and res == "\x1b\x62\x00\x02\x00\x00\x00"
128-
print_error "Handshake(3) failed on Host #{ip} aborting. (Error: #{res.inspect} )"
152+
print_error("Handshake(3) failed on Host #{ip} aborting. Error: #{res.inspect}")
129153
return :handshake_failed
130154
end
131155

132156
nsock.put("\x6f\x62\x01\x02\x00\x00\x00")
133157
res = nsock.get_once(-1,5)
134158
unless res and res.include? "\x00\x7D\x08"
135-
print_error "Handshake(4) failed on Host #{ip} aborting. (Error: #{res.inspect} )"
159+
print_error("Handshake(4) failed on Host #{ip} aborting. Error: #{res.inspect}")
136160
return :handshake_failed
137161
end
138162

139163
res = nsock.get_once(-1,5) unless pca_at_login?(res)
140164
unless pca_at_login?(res)
141-
print_error "Handshake(5) failed on Host #{ip} aborting. (Error: #{res.inspect} )"
165+
print_error("Handshake(5) failed on Host #{ip} aborting. Error: #{res.inspect}")
142166
return :handshake_failed
143167
end
144168
end

0 commit comments

Comments
 (0)