Skip to content

Commit 4f11dc0

Browse files
committed
fixes rapid7#4490, class.to_s should not be used for checks
1 parent 553030b commit 4f11dc0

File tree

8 files changed

+79
-81
lines changed

8 files changed

+79
-81
lines changed

lib/msf/core/db_manager/ip_address.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ def ipv6_validator(addr)
1313
end
1414

1515
def rfc3330_reserved(ip)
16-
case ip.class.to_s
17-
when "PacketFu::Octets"
16+
case ip
17+
when PacketFu::Octets
1818
ip_x = ip.to_x
1919
ip_i = ip.to_i
20-
when "String"
20+
when String
2121
if ipv46_validator(ip)
2222
ip_x = ip
2323
ip_i = Rex::Socket.addr_atoi(ip)
2424
else
2525
raise ArgumentError, "Invalid IP address: #{ip.inspect}"
2626
end
27-
when "Fixnum"
27+
when Fixnum
2828
if (0..2**32-1).include? ip
2929
ip_x = Rex::Socket.addr_itoa(ip)
3030
ip_i = ip
@@ -58,4 +58,4 @@ def validate_ips(ips)
5858
end
5959
return ret
6060
end
61-
end
61+
end

lib/msf/core/exploit/cmdstager.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ def select_flavor(opts = {})
224224
def guess_flavor
225225
# First try to guess a compatible flavor based on the module & target information.
226226
unless target_flavor.nil?
227-
case target_flavor.class.to_s
228-
when 'Array'
227+
case target_flavor
228+
when Array
229229
return target_flavor[0].to_sym
230-
when 'String'
230+
when String
231231
return target_flavor.to_sym
232-
when 'Symbol'
232+
when Symbol
233233
return target_flavor
234234
end
235235
end
@@ -283,12 +283,12 @@ def target_flavor
283283
# @return [Boolean] true if compatible, false otherwise.
284284
def compatible_flavor?(f)
285285
return true if target_flavor.nil?
286-
case target_flavor.class.to_s
287-
when 'String'
286+
case target_flavor
287+
when String
288288
return true if target_flavor == f.to_s
289-
when 'Array'
289+
when Array
290290
target_flavor.each { |tr| return true if tr.to_sym == f }
291-
when 'Symbol'
291+
when Symbol
292292
return true if target_flavor == f
293293
end
294294
false

lib/msf/core/exploit/java.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def compile(classnames, codez, compile_options=nil)
8787
raise RuntimeError, "Could not load rjb and/or the JVM: " + @java_error.to_s
8888
end
8989

90-
if compile_options.class.to_s != "Array" && compile_options
90+
if !compile_options.is_a?(Array) && compile_options
9191
raise RuntimeError, "Compiler options must be of type Array."
9292
end
9393

lib/msf/core/exploit/local/windows_kernel.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def token_stealing_shellcode(target, backup_token = nil, arch = nil)
123123
arch = target.opts['Arch'] if arch.nil? && target && target.opts['Arch']
124124
if arch.nil? && module_info['Arch']
125125
arch = module_info['Arch']
126-
arch = arch[0] if arch.class.to_s == 'Array' and arch.length == 1
126+
arch = arch[0] if arch.is_a?(Array) and arch.length == 1
127127
end
128128
if arch.nil?
129129
print_error('Can not determine the target architecture')

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,73 +2834,72 @@ def option_values_dispatch(o, str, words)
28342834
res = []
28352835
res << o.default.to_s if o.default
28362836

2837-
case o.class.to_s
2838-
2839-
when 'Msf::OptAddress'
2840-
case o.name.upcase
2841-
when 'RHOST'
2842-
option_values_target_addrs().each do |addr|
2843-
res << addr
2844-
end
2845-
when 'LHOST'
2846-
rh = self.active_module.datastore["RHOST"]
2847-
if rh and not rh.empty?
2848-
res << Rex::Socket.source_address(rh)
2849-
else
2850-
res << Rex::Socket.source_address()
2851-
end
2852-
else
2837+
case o
2838+
when Msf::OptAddress
2839+
case o.name.upcase
2840+
when 'RHOST'
2841+
option_values_target_addrs().each do |addr|
2842+
res << addr
28532843
end
2854-
2855-
when 'Msf::OptAddressRange'
2856-
case str
2857-
when /^file:(.*)/
2858-
files = tab_complete_filenames($1, words)
2859-
res += files.map { |f| "file:" + f } if files
2860-
when /\/$/
2861-
res << str+'32'
2862-
res << str+'24'
2863-
res << str+'16'
2864-
when /\-$/
2865-
res << str+str[0, str.length - 1]
2866-
else
2867-
option_values_target_addrs().each do |addr|
2868-
res << addr+'/32'
2869-
res << addr+'/24'
2870-
res << addr+'/16'
2871-
end
2844+
when 'LHOST'
2845+
rh = self.active_module.datastore["RHOST"]
2846+
if rh and not rh.empty?
2847+
res << Rex::Socket.source_address(rh)
2848+
else
2849+
res << Rex::Socket.source_address()
28722850
end
2851+
else
2852+
end
28732853

2874-
when 'Msf::OptPort'
2875-
case o.name.upcase
2876-
when 'RPORT'
2877-
option_values_target_ports().each do |port|
2878-
res << port
2879-
end
2854+
when Msf::OptAddressRange
2855+
case str
2856+
when /^file:(.*)/
2857+
files = tab_complete_filenames($1, words)
2858+
res += files.map { |f| "file:" + f } if files
2859+
when /\/$/
2860+
res << str+'32'
2861+
res << str+'24'
2862+
res << str+'16'
2863+
when /\-$/
2864+
res << str+str[0, str.length - 1]
2865+
else
2866+
option_values_target_addrs().each do |addr|
2867+
res << addr+'/32'
2868+
res << addr+'/24'
2869+
res << addr+'/16'
28802870
end
2871+
end
28812872

2882-
if (res.empty?)
2883-
res << (rand(65534)+1).to_s
2873+
when Msf::OptPort
2874+
case o.name.upcase
2875+
when 'RPORT'
2876+
option_values_target_ports().each do |port|
2877+
res << port
28842878
end
2879+
end
28852880

2886-
when 'Msf::OptEnum'
2887-
o.enums.each do |val|
2888-
res << val
2889-
end
2881+
if (res.empty?)
2882+
res << (rand(65534)+1).to_s
2883+
end
28902884

2891-
when 'Msf::OptPath'
2892-
files = tab_complete_filenames(str, words)
2893-
res += files if files
2885+
when Msf::OptEnum
2886+
o.enums.each do |val|
2887+
res << val
2888+
end
28942889

2895-
when 'Msf::OptBool'
2896-
res << 'true'
2897-
res << 'false'
2890+
when Msf::OptPath
2891+
files = tab_complete_filenames(str, words)
2892+
res += files if files
28982893

2899-
when 'Msf::OptString'
2900-
if (str =~ /^file:(.*)/)
2901-
files = tab_complete_filenames($1, words)
2902-
res += files.map { |f| "file:" + f } if files
2903-
end
2894+
when Msf::OptBool
2895+
res << 'true'
2896+
res << 'false'
2897+
2898+
when Msf::OptString
2899+
if (str =~ /^file:(.*)/)
2900+
files = tab_complete_filenames($1, words)
2901+
res += files.map { |f| "file:" + f } if files
2902+
end
29042903
end
29052904

29062905
return res

lib/rapid7/nexpose.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ def getSiteXML()
12911291
xml << ' <ScanTriggers>'
12921292
@site_config.scanConfig.scanTriggers.each do |s|
12931293

1294-
if (s.class.to_s == "Nexpose::AutoUpdate")
1294+
if s.kind_of?(Nexpose::AutoUpdate)
12951295
xml << ' <autoUpdate enabled="' + s.enabled + '" incremental="' + s.incremental + '"/>'
12961296
end
12971297
end

lib/rex/proto/http/client.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def set_config(opts = {})
8686
typ = self.config_types[var] || 'string'
8787

8888
# These are enum types
89-
if(typ.class.to_s == 'Array')
89+
if typ.is_a?(Array)
9090
if not typ.include?(val)
9191
raise RuntimeError, "The specified value for #{var} is not one of the valid choices"
9292
end
@@ -719,4 +719,3 @@ def pipelining?
719719
end
720720
end
721721
end
722-

modules/auxiliary/spoof/dns/compare_results.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ def run
9797

9898
name = name.to_s
9999
anst = data.class.to_s.gsub(/^.*Resolv::DNS::Resource::IN::/, '')
100-
case anst
101-
when 'NS'
100+
case data
101+
when Resolv::DNS::Resource::IN::NS
102102
data = data.name.to_s
103-
when 'MX'
103+
when Resolv::DNS::Resource::IN::MX
104104
data = data.exchange.to_s
105-
when 'A'
105+
when Resolv::DNS::Resource::IN::A
106106
data = data.address.to_s
107-
when 'TXT'
107+
when Resolv::DNS::Resource::IN::TXT
108108
data = data.strings.join
109-
when 'CNAME'
109+
when Resolv::DNS::Resource::IN::CNAME
110110
data = data.name.to_s
111111
else
112112
data = anst

0 commit comments

Comments
 (0)