Skip to content

Commit b0d6e12

Browse files
author
Brent Cook
committed
Land rapid7#8301, Improve msftidy checks
2 parents bbee7f8 + f879295 commit b0d6e12

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

modules/auxiliary/scanner/http/brute_dirs.rb

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

6-
7-
require 'msf/core'
86
require 'enumerable'
97

108
class MetasploitModule < Msf::Auxiliary
@@ -29,7 +27,7 @@ def initialize(info = {})
2927
[
3028
OptString.new('PATH', [ true, "The path to identify directories", '/']),
3129
OptString.new('FORMAT', [ true, "The expected directory format (a alpha, d digit, A upperalpha)", 'a,aa,aaa'])
32-
], self.class)
30+
])
3331

3432
register_advanced_options(
3533
[
@@ -40,7 +38,7 @@ def initialize(info = {})
4038
),
4139
OptBool.new('NoDetailMessages', [ false, "Do not display detailed test messages", true ]),
4240
OptInt.new('TestThreads', [ true, "Number of test threads", 25])
43-
], self.class)
41+
])
4442

4543
end
4644

spec/file_fixtures/modules/auxiliary/auxiliary_tidy.rb

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

6-
require 'msf/core'
7-
86
class MetasploitModule < Msf::Auxiliary
97
def initialize(info = {})
108
super(

tools/dev/msftidy.rb

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212

1313
CHECK_OLD_RUBIES = !!ENV['MSF_CHECK_OLD_RUBIES']
1414
SUPPRESS_INFO_MESSAGES = !!ENV['MSF_SUPPRESS_INFO_MESSAGES']
15-
TITLE_WHITELIST = %w{
16-
a an and as at avserve callmenum configdir connect debug docbase dtspcd
17-
execve file for from getinfo goaway gsad hetro historysearch htpasswd ibstat
18-
id in inetd iseemedia jhot libxslt lmgrd lnk load main map migrate mimencode
19-
multisort name net netcat nodeid ntpd nttrans of on onreadystatechange or
20-
ovutil path pbot pfilez pgpass pingstr pls popsubfolders prescan readvar
21-
relfile rev rexec rlogin rsh rsyslog sa sadmind say sblistpack spamd
22-
sreplace tagprinter the tnftp to twikidraw udev uplay user username via
23-
welcome with ypupdated zsudo
24-
}
2515

2616
if CHECK_OLD_RUBIES
2717
require 'rvm'
@@ -215,6 +205,18 @@ def check_ref_identifiers
215205
end
216206
end
217207

208+
def check_self_class
209+
in_register = false
210+
@lines.each do |line|
211+
(in_register = true) if line =~ /^\s*register_(?:advanced_)?options/
212+
(in_register = false) if line =~ /^\s*end/
213+
if in_register && line =~ /\],\s*self\.class\s*\)/
214+
warn('Explicitly using self.class in register_* is not necessary')
215+
break
216+
end
217+
end
218+
end
219+
218220
# See if 'require "rubygems"' or equivalent is used, and
219221
# warn if so. Since Ruby 1.9 this has not been necessary and
220222
# the framework only suports 1.9+
@@ -227,6 +229,15 @@ def check_rubygems
227229
end
228230
end
229231

232+
def check_msf_core
233+
@lines.each do |line|
234+
if line_has_require?(line, 'msf/core')
235+
warn('Explicitly requiring/loading msf/core is not necessary')
236+
break
237+
end
238+
end
239+
end
240+
230241
# Does the given line contain a require/load of the specified library?
231242
def line_has_require?(line, lib)
232243
line =~ /^\s*(require|load)\s+['"]#{lib}['"]/
@@ -447,19 +458,6 @@ def check_disclosure_date
447458
end
448459
end
449460

450-
def check_title_casing
451-
if @source =~ /["']Name["'][[:space:]]*=>[[:space:]]*['"](.+)['"],*$/
452-
words = $1.split
453-
words.each do |word|
454-
if TITLE_WHITELIST.include?(word)
455-
next
456-
elsif word =~ /^[a-z]+$/
457-
warn("Suspect capitalization in module title: '#{word}'")
458-
end
459-
end
460-
end
461-
end
462-
463461
def check_bad_terms
464462
# "Stack overflow" vs "Stack buffer overflow" - See explanation:
465463
# http://blogs.technet.com/b/srd/archive/2009/01/28/stack-overflow-stack-exhaustion-not-the-same-as-stack-buffer-overflow.aspx
@@ -701,15 +699,16 @@ def run_checks
701699
check_shebang
702700
check_nokogiri
703701
check_rubygems
702+
check_msf_core
704703
check_ref_identifiers
704+
check_self_class
705705
check_old_keywords
706706
check_verbose_option
707707
check_badchars
708708
check_extname
709709
check_old_rubies
710710
check_ranking
711711
check_disclosure_date
712-
check_title_casing
713712
check_bad_terms
714713
check_bad_super_class
715714
check_bad_class_name

0 commit comments

Comments
 (0)