Skip to content

Commit d92088f

Browse files
authored
Land rapid7#20239, resolves RuboCop violations in auxiliary/scanner/dcerpc
modules/auxiliary/scanner/dcerpc: Resolve RuboCop violations
2 parents b0b0022 + e9d682d commit d92088f

File tree

6 files changed

+284
-251
lines changed

6 files changed

+284
-251
lines changed

modules/auxiliary/scanner/dcerpc/dfscoerce.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ def initialize
3030
'References' => [
3131
[ 'URL', 'https://github.com/Wh04m1001/DFSCoerce' ]
3232
],
33-
'License' => MSF_LICENSE
33+
'License' => MSF_LICENSE,
34+
'Notes' => {
35+
'Stability' => [CRASH_SAFE],
36+
'SideEffects' => [IOC_IN_LOGS],
37+
'Reliability' => []
38+
}
3439
)
3540

3641
register_options(

modules/auxiliary/scanner/dcerpc/endpoint_mapper.rb

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Current source: https://github.com/rapid7/metasploit-framework
44
##
55

6+
require 'English'
67
class MetasploitModule < Msf::Auxiliary
78

89
# Exploit mixins should be called first
@@ -15,66 +16,70 @@ class MetasploitModule < Msf::Auxiliary
1516

1617
def initialize
1718
super(
18-
'Name' => 'Endpoint Mapper Service Discovery',
19+
'Name' => 'Endpoint Mapper Service Discovery',
1920
'Description' => %q{
2021
This module can be used to obtain information from the
2122
Endpoint Mapper service.
2223
},
23-
'Author' => 'hdm',
24-
'License' => MSF_LICENSE
24+
'Author' => 'hdm',
25+
'License' => MSF_LICENSE,
26+
'Notes' => {
27+
'Stability' => [CRASH_SAFE],
28+
'SideEffects' => [],
29+
'Reliability' => []
30+
}
2531
)
2632

2733
register_options(
2834
[
2935
Opt::RPORT(135)
30-
])
36+
]
37+
)
3138
end
3239

3340
# Obtain information about a single host
3441
def run_host(ip)
35-
begin
42+
ids = dcerpc_endpoint_list
43+
return unless ids
44+
45+
name = nil
46+
ids.each do |id|
47+
next if !id[:prot]
3648

37-
ids = dcerpc_endpoint_list()
38-
return if not ids
39-
name = nil
40-
ids.each do |id|
41-
next if not id[:prot]
42-
line = "#{id[:uuid]} v#{id[:vers]} "
43-
line << "#{id[:prot].upcase} "
44-
line << "(#{id[:port]}) " if id[:port]
45-
line << "(#{id[:pipe]}) " if id[:pipe]
46-
line << "#{id[:host]} " if id[:host]
47-
line << "[#{id[:note]}]" if id[:note]
48-
print_status(line)
49-
if (id[:host] and id[:host][0,2] == "\\\\")
50-
name = id[:host][2..-1]
51-
end
52-
if id[:prot].downcase == "tcp" or id[:prot].downcase == "udp"
53-
report_service(
54-
:host => ip,
55-
:port => id[:port],
56-
:proto => id[:prot].downcase,
57-
:name => "dcerpc",
58-
:info => "#{id[:uuid]} v#{id[:vers]} #{id[:note]}"
59-
)
60-
end
49+
line = "#{id[:uuid]} v#{id[:vers]} "
50+
line << "#{id[:prot].upcase} "
51+
line << "(#{id[:port]}) " if id[:port]
52+
line << "(#{id[:pipe]}) " if id[:pipe]
53+
line << "#{id[:host]} " if id[:host]
54+
line << "[#{id[:note]}]" if id[:note]
55+
print_status(line)
56+
if id[:host] && (id[:host][0, 2] == '\\\\')
57+
name = id[:host][2..]
6158
end
62-
report_host(:host => ip, :name => name) if name
59+
next unless (id[:prot].downcase == 'tcp') || (id[:prot].downcase == 'udp')
60+
6361
report_service(
64-
:host => ip,
65-
:port => rport,
66-
:proto => 'tcp',
67-
:name => "dcerpc",
68-
:info => "Endpoint Mapper (#{ids.length} services)"
62+
host: ip,
63+
port: id[:port],
64+
proto: id[:prot].downcase,
65+
name: 'dcerpc',
66+
info: "#{id[:uuid]} v#{id[:vers]} #{id[:note]}"
6967
)
70-
71-
rescue ::Interrupt
72-
raise $!
73-
rescue ::Rex::Proto::DCERPC::Exceptions::Fault
74-
rescue ::Exception => e
75-
print_error("#{ip}:#{rport} error: #{e}")
7668
end
77-
end
78-
7969

70+
report_host(host: ip, name: name) if name
71+
report_service(
72+
host: ip,
73+
port: rport,
74+
proto: 'tcp',
75+
name: 'dcerpc',
76+
info: "Endpoint Mapper (#{ids.length} services)"
77+
)
78+
rescue ::Interrupt
79+
raise $ERROR_INFO
80+
rescue ::Rex::Proto::DCERPC::Exceptions::Fault => e
81+
vprint_error("#{ip}:#{rport} error: #{e}")
82+
rescue StandardError => e
83+
print_error("#{ip}:#{rport} error: #{e}")
84+
end
8085
end

modules/auxiliary/scanner/dcerpc/hidden.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ def initialize
2525
and analyzed to see whether anonymous access is permitted.
2626
},
2727
'Author' => 'hdm',
28-
'License' => MSF_LICENSE
28+
'License' => MSF_LICENSE,
29+
'Notes' => {
30+
'Stability' => [CRASH_SAFE],
31+
'SideEffects' => [],
32+
'Reliability' => []
33+
}
2934
)
3035

3136
deregister_options('RPORT')
@@ -76,17 +81,17 @@ def run_host(ip)
7681
dcerpc.call(0, NDR.long(0) * 128)
7782
call = true
7883

79-
if (!dcerpc.last_response.nil? && !dcerpc.last_response.stub_data.nil?)
84+
if !dcerpc.last_response.nil? && !dcerpc.last_response.stub_data.nil?
8085
data = dcerpc.last_response.stub_data
8186
end
8287
rescue ::Interrupt
8388
raise $ERROR_INFO
84-
rescue ::Exception => e
89+
rescue StandardError => e
8590
error = e.to_s
8691
end
8792

8893
if error
89-
if error =~ (/DCERPC FAULT/) && error !~ (/nca_s_fault_access_denied/)
94+
if error =~ /DCERPC FAULT/ && error !~ /nca_s_fault_access_denied/
9095
call = true
9196
else
9297
elog(e)
@@ -103,20 +108,18 @@ def run_host(ip)
103108
print_status(status)
104109
print_status('')
105110

106-
## Add Report
107111
report_note(
108112
host: ip,
109113
proto: 'tcp',
110114
port: datastore['RPORT'],
111115
type: "DCERPC HIDDEN: UUID #{id[0]} v#{id[1]}",
112-
data: { :status => status }
116+
data: { status: status }
113117
)
114118
end
115119
end
116120
rescue ::Interrupt
117121
raise $ERROR_INFO
118-
rescue ::Exception => e
122+
rescue StandardError => e
119123
print_status("Error: #{e}")
120124
end
121-
122125
end

modules/auxiliary/scanner/dcerpc/management.rb

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

6+
require 'English'
67
class MetasploitModule < Msf::Auxiliary
78

89
# Exploit mixins should be called first
@@ -15,71 +16,72 @@ class MetasploitModule < Msf::Auxiliary
1516

1617
def initialize
1718
super(
18-
'Name' => 'Remote Management Interface Discovery',
19+
'Name' => 'Remote Management Interface Discovery',
1920
'Description' => %q{
2021
This module can be used to obtain information from the Remote
2122
Management Interface DCERPC service.
2223
},
23-
'Author' => 'hdm',
24-
'License' => MSF_LICENSE
24+
'Author' => 'hdm',
25+
'License' => MSF_LICENSE,
26+
'Notes' => {
27+
'Stability' => [CRASH_SAFE],
28+
'SideEffects' => [],
29+
'Reliability' => []
30+
}
2531
)
2632

2733
register_options(
2834
[
2935
Opt::RPORT(135)
30-
])
36+
]
37+
)
3138
end
3239

3340
# Obtain information about a single host
3441
def run_host(ip)
35-
begin
36-
37-
ids = dcerpc_mgmt_inq_if_ids(rport)
38-
return if not ids
39-
ids.each do |id|
40-
print_status("UUID #{id[0]} v#{id[1]}")
41-
42-
reportdata = ""
42+
ids = dcerpc_mgmt_inq_if_ids(rport)
43+
return unless ids
4344

44-
stats = dcerpc_mgmt_inq_if_stats(rport)
45-
if stats
46-
print_status("\t stats: " + stats.map{|i| "0x%.8x" % i}.join(", "))
47-
reportdata << "stats: " + stats.map{|i| "0x%.8x" % i}.join(", ") + " "
48-
end
45+
ids.each do |id|
46+
print_status("UUID #{id[0]} v#{id[1]}")
4947

50-
live = dcerpc_mgmt_is_server_listening(rport)
51-
if live
52-
print_status("\t listening: %.8x" % live)
53-
#reportdata << "listening: %.8x" % live + " "
54-
end
48+
reportdata = ''
5549

56-
dead = dcerpc_mgmt_stop_server_listening(rport)
57-
if dead
58-
print_status("\t killed: %.8x" % dead)
59-
#reportdata << "killed: %.8x" % dead + " "
60-
end
50+
stats = dcerpc_mgmt_inq_if_stats(rport)
51+
if stats
52+
print_status("\t stats: " + stats.map { |i| '0x%.8x' % i }.join(', '))
53+
reportdata << 'stats: ' + stats.map { |i| '0x%.8x' % i }.join(', ') + ' '
54+
end
6155

62-
princ = dcerpc_mgmt_inq_princ_name(rport)
63-
if princ
64-
print_status("\t name: #{princ.unpack("H*")[0]}")
65-
#reportdata << "name: #{princ.unpack("H*")[0]}"
66-
end
56+
live = dcerpc_mgmt_is_server_listening(rport)
57+
if live
58+
print_status("\t listening: %.8x" % live)
59+
# reportdata << "listening: %.8x" % live + " "
60+
end
6761

68-
# Add Report
69-
report_note(
70-
:host => ip,
71-
:proto => 'tcp',
72-
:port => datastore['RPORT'],
73-
:type => "DCERPC UUID #{id[0]} v#{id[1]}",
74-
:data => { :report_data => reportdata }
75-
)
62+
dead = dcerpc_mgmt_stop_server_listening(rport)
63+
if dead
64+
print_status("\t killed: %.8x" % dead)
65+
# reportdata << "killed: %.8x" % dead + " "
66+
end
7667

68+
princ = dcerpc_mgmt_inq_princ_name(rport)
69+
if princ
70+
print_status("\t name: #{princ.unpack('H*')[0]}")
71+
# reportdata << "name: #{princ.unpack("H*")[0]}"
7772
end
7873

79-
rescue ::Interrupt
80-
raise $!
81-
rescue ::Exception => e
82-
print_error("Error: #{e}")
74+
report_note(
75+
host: ip,
76+
proto: 'tcp',
77+
port: datastore['RPORT'],
78+
type: "DCERPC UUID #{id[0]} v#{id[1]}",
79+
data: { report_data: reportdata }
80+
)
8381
end
82+
rescue ::Interrupt
83+
raise $ERROR_INFO
84+
rescue StandardError => e
85+
print_error("Error: #{e}")
8486
end
8587
end

0 commit comments

Comments
 (0)