Skip to content

Commit d8ad105

Browse files
authored
Merge pull request rapid7#20232 from bcoles/rubocop-modules-auxiliary-afp
modules/auxiliary/scanner/afp: Resolve RuboCop violations
2 parents e09f4de + e00ed40 commit d8ad105

File tree

2 files changed

+89
-75
lines changed

2 files changed

+89
-75
lines changed

modules/auxiliary/scanner/afp/afp_login.rb

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,45 @@ class MetasploitModule < Msf::Auxiliary
1313
include Msf::Auxiliary::AuthBrute
1414
include Msf::Exploit::Remote::AFP
1515

16-
def initialize(info={})
17-
super(update_info(info,
18-
'Name' => 'Apple Filing Protocol Login Utility',
19-
'Description' => %q{
20-
This module attempts to bruteforce authentication credentials for AFP.
21-
},
22-
'References' =>
23-
[
16+
def initialize(info = {})
17+
super(
18+
update_info(
19+
info,
20+
'Name' => 'Apple Filing Protocol Login Utility',
21+
'Description' => %q{
22+
This module attempts to bruteforce authentication credentials for AFP.
23+
},
24+
'References' => [
2425
[ 'URL', 'https://web.archive.org/web/20130309051753/https://developer.apple.com/library/mac/#documentation/Networking/Reference/AFP_Reference/Reference/reference.html' ],
2526
[ 'URL', 'https://developer.apple.com/library/mac/documentation/networking/conceptual/afp/AFPSecurity/AFPSecurity.html' ]
2627

2728
],
28-
'Author' => [ 'Gregory Man <man.gregory[at]gmail.com>' ],
29-
'License' => MSF_LICENSE
30-
))
29+
'Author' => [ 'Gregory Man <man.gregory[at]gmail.com>' ],
30+
'License' => MSF_LICENSE,
31+
'Notes' => {
32+
'Stability' => [CRASH_SAFE],
33+
'SideEffects' => [IOC_IN_LOGS, ACCOUNT_LOCKOUTS],
34+
'Reliability' => []
35+
}
36+
)
37+
)
3138

3239
register_options(
3340
[
3441
Opt::Proxies,
35-
OptInt.new('LoginTimeOut', [ true, "Timeout on login", 23 ]),
36-
OptBool.new('RECORD_GUEST', [ false, "Record guest login to the database", false]),
37-
OptBool.new('CHECK_GUEST', [ false, "Check for guest login", true])
38-
], self)
42+
OptInt.new('LoginTimeOut', [ true, 'Timeout on login', 23 ]),
43+
OptBool.new('RECORD_GUEST', [ false, 'Record guest login to the database', false]),
44+
OptBool.new('CHECK_GUEST', [ false, 'Check for guest login', true])
45+
]
46+
)
3947
end
4048

4149
def run_host(ip)
42-
print_status("Scanning IP: #{ip.to_s}")
50+
print_status("Scanning IP: #{ip}")
4351

4452
cred_collection = build_credential_collection(
45-
username: datastore['USERNAME'],
46-
password: datastore['PASSWORD'],
53+
username: datastore['USERNAME'],
54+
password: datastore['PASSWORD']
4755
)
4856

4957
scanner = Metasploit::Framework::LoginScanner::AFP.new(
@@ -71,8 +79,8 @@ def run_host(ip)
7179
scanner.scan! do |result|
7280
credential_data = result.to_h
7381
credential_data.merge!(
74-
module_fullname: self.fullname,
75-
workspace_id: myworkspace_id
82+
module_fullname: fullname,
83+
workspace_id: myworkspace_id
7684
)
7785
if result.success?
7886
credential_core = create_credential(credential_data)
@@ -86,6 +94,4 @@ def run_host(ip)
8694
end
8795
end
8896
end
89-
90-
9197
end

modules/auxiliary/scanner/afp/afp_server_info.rb

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,93 +3,101 @@
33
# Current source: https://github.com/rapid7/metasploit-framework
44
##
55

6+
require 'English'
67
class MetasploitModule < Msf::Auxiliary
78
include Msf::Auxiliary::Report
89
include Msf::Auxiliary::Scanner
910
include Msf::Exploit::Remote::AFP
1011

11-
def initialize(info={})
12-
super(update_info(info,
13-
'Name' => 'Apple Filing Protocol Info Enumerator',
14-
'Description' => %q{
15-
This module fetches AFP server information, including server name,
16-
network address, supported AFP versions, signature, machine type,
17-
and server flags.
18-
},
19-
'References' =>
20-
[
12+
def initialize(info = {})
13+
super(
14+
update_info(
15+
info,
16+
'Name' => 'Apple Filing Protocol Info Enumerator',
17+
'Description' => %q{
18+
This module fetches AFP server information, including server name,
19+
network address, supported AFP versions, signature, machine type,
20+
and server flags.
21+
},
22+
'References' => [
2123
[ 'URL', 'https://web.archive.org/web/20130309051753/https://developer.apple.com/library/mac/#documentation/Networking/Reference/AFP_Reference/Reference/reference.html' ]
2224
],
23-
'Author' => [ 'Gregory Man <man.gregory[at]gmail.com>' ],
24-
'License' => MSF_LICENSE
25-
))
25+
'Author' => [ 'Gregory Man <man.gregory[at]gmail.com>' ],
26+
'License' => MSF_LICENSE,
27+
'Notes' => {
28+
'Stability' => [CRASH_SAFE],
29+
'SideEffects' => [],
30+
'Reliability' => []
31+
}
32+
)
33+
)
2634
end
2735

2836
def run_host(ip)
2937
print_status("AFP #{ip} Scanning...")
30-
begin
31-
connect
32-
response = get_info
33-
report(response)
34-
rescue ::Timeout::Error
35-
rescue ::Interrupt
36-
raise $!
37-
rescue ::Rex::ConnectionError, ::IOError, ::Errno::ECONNRESET, ::Errno::ENOPROTOOPT
38-
rescue ::Exception
39-
raise $!
40-
print_error("AFP #{rhost}:#{rport} #{$!.class} #{$!}")
41-
ensure
42-
disconnect
43-
end
38+
connect
39+
response = get_info
40+
report(response)
41+
rescue ::Timeout::Error => e
42+
vprint_error(e.message)
43+
rescue ::Rex::ConnectionError, ::IOError, ::Errno::ECONNRESET, ::Errno::ENOPROTOOPT => e
44+
vprint_error(e.message)
45+
rescue ::Interrupt
46+
raise $ERROR_INFO
47+
rescue StandardError
48+
print_error("AFP #{rhost}:#{rport} #{$ERROR_INFO.class} #{$ERROR_INFO}")
49+
raise $ERROR_INFO
50+
ensure
51+
disconnect
4452
end
4553

4654
def report(response)
47-
report_info = "AFP #{rhost}:#{rport} Server Name: #{response[:server_name]} \n" +
48-
"AFP #{rhost}:#{rport} Server Flags: \n" +
49-
format_flags_report(response[:server_flags]) +
50-
"AFP #{rhost}:#{rport} Machine Type: #{response[:machine_type]} \n" +
51-
"AFP #{rhost}:#{rport} AFP Versions: #{response[:versions].join(', ')} \n" +
52-
"AFP #{rhost}:#{rport} UAMs: #{response[:uams].join(', ')}\n" +
53-
"AFP #{rhost}:#{rport} Server Signature: #{response[:signature]}\n" +
54-
"AFP #{rhost}:#{rport} Server Network Address: \n" +
55-
format_addresses_report(response[:network_addresses]) +
56-
"AFP #{rhost}:#{rport} UTF8 Server Name: #{response[:utf8_server_name]}"
57-
55+
report_info = "AFP #{rhost}:#{rport} Server Name: #{response[:server_name]} \n" \
56+
"AFP #{rhost}:#{rport} Server Flags: \n" +
57+
format_flags_report(response[:server_flags]) +
58+
"AFP #{rhost}:#{rport} Machine Type: #{response[:machine_type]} \n" \
59+
"AFP #{rhost}:#{rport} AFP Versions: #{response[:versions].join(', ')} \n" \
60+
"AFP #{rhost}:#{rport} UAMs: #{response[:uams].join(', ')}\n" \
61+
"AFP #{rhost}:#{rport} Server Signature: #{response[:signature]}\n" \
62+
"AFP #{rhost}:#{rport} Server Network Address: \n" +
63+
format_addresses_report(response[:network_addresses]) +
64+
"AFP #{rhost}:#{rport} UTF8 Server Name: #{response[:utf8_server_name]}"
5865

5966
lines = "AFP #{rhost}:#{rport}:#{rport} AFP:\n#{report_info}"
6067

6168
lines.split(/\n/).each do |line|
6269
print_status(line)
6370
end
6471

65-
report_note(:host => datastore['RHOST'],
66-
:proto => 'tcp',
67-
:port => datastore['RPORT'],
68-
:type => 'afp_server_info',
69-
:data => { :server_info => response })
70-
71-
report_service(
72-
:host => datastore['RHOST'],
73-
:port => datastore['RPORT'],
74-
:proto => 'tcp',
75-
:name => "afp",
76-
:info => "AFP name: #{response[:utf8_server_name]}, Versions: #{response[:versions].join(', ')}"
77-
)
72+
report_note(
73+
host: datastore['RHOST'],
74+
proto: 'tcp',
75+
port: datastore['RPORT'],
76+
type: 'afp_server_info',
77+
data: { server_info: response }
78+
)
7879

80+
report_service(
81+
host: datastore['RHOST'],
82+
port: datastore['RPORT'],
83+
proto: 'tcp',
84+
name: 'afp',
85+
info: "AFP name: #{response[:utf8_server_name]}, Versions: #{response[:versions].join(', ')}"
86+
)
7987
end
8088

8189
def format_flags_report(parsed_flags)
8290
report = ''
8391
parsed_flags.each do |flag, val|
84-
report << "AFP #{rhost}:#{rport} * #{flag}: #{val.to_s} \n"
92+
report << "AFP #{rhost}:#{rport} * #{flag}: #{val} \n"
8593
end
8694
return report
8795
end
8896

8997
def format_addresses_report(parsed_network_addresses)
9098
report = ''
9199
parsed_network_addresses.each do |val|
92-
report << "AFP #{rhost}:#{rport} * #{val.to_s} \n"
100+
report << "AFP #{rhost}:#{rport} * #{val} \n"
93101
end
94102
return report
95103
end

0 commit comments

Comments
 (0)