From bfa89bb3a55835d5fbbf60ffc11d2b853362ff66 Mon Sep 17 00:00:00 2001 From: Jon Hart Date: Mon, 21 Jul 2014 14:22:15 -0700 Subject: [PATCH] Enforce binary encoding on non-modules, no encoding on modules --- .rubocop.yml | 5 +++++ lib/rex/proto/sip.rb | 2 +- lib/rex/proto/sip/response.rb | 2 +- modules/auxiliary/scanner/sip/options.rb | 1 - modules/auxiliary/scanner/sip/options_tcp.rb | 1 - tools/msftidy.rb | 23 ++++++++++++++++++++ 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6ef2a9c590..c9ba4d1bb3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -39,6 +39,11 @@ Style/MethodLength: often exceed 200 lines. Max: 300 +# Basically everything in metasploit needs binary encoding, not UTF-8. +# Disable this here and enforce it through msftidy +Style/Encoding: + Enabled: false + Style/NumericLiterals: Enabled: false Description: 'This often hurts readability for exploit-ish code.' diff --git a/lib/rex/proto/sip.rb b/lib/rex/proto/sip.rb index 2550ee0948..3c0098cb54 100644 --- a/lib/rex/proto/sip.rb +++ b/lib/rex/proto/sip.rb @@ -1,4 +1,4 @@ -# -*- coding: binary -*- +# encoding: binary # SIP protocol support require 'rex/proto/sip/response' diff --git a/lib/rex/proto/sip/response.rb b/lib/rex/proto/sip/response.rb index c770fc54b6..3135052471 100644 --- a/lib/rex/proto/sip/response.rb +++ b/lib/rex/proto/sip/response.rb @@ -1,4 +1,4 @@ -# -*- coding: binary -*- +# encoding: binary module Rex module Proto diff --git a/modules/auxiliary/scanner/sip/options.rb b/modules/auxiliary/scanner/sip/options.rb index b44a84f30a..d4886c1751 100644 --- a/modules/auxiliary/scanner/sip/options.rb +++ b/modules/auxiliary/scanner/sip/options.rb @@ -1,4 +1,3 @@ -# -*- coding: binary -*- ## # This module requires Metasploit: http//metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework diff --git a/modules/auxiliary/scanner/sip/options_tcp.rb b/modules/auxiliary/scanner/sip/options_tcp.rb index 5f064f55b2..b211cbd416 100644 --- a/modules/auxiliary/scanner/sip/options_tcp.rb +++ b/modules/auxiliary/scanner/sip/options_tcp.rb @@ -1,4 +1,3 @@ -# -*- coding: binary -*- ## # This module requires Metasploit: http//metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework diff --git a/tools/msftidy.rb b/tools/msftidy.rb index cee49583d0..ff6affc211 100755 --- a/tools/msftidy.rb +++ b/tools/msftidy.rb @@ -12,6 +12,7 @@ require 'time' CHECK_OLD_RUBIES = !!ENV['MSF_CHECK_OLD_RUBIES'] SUPPRESS_INFO_MESSAGES = !!ENV['MSF_SUPPRESS_INFO_MESSAGES'] +ENCODING_REGEX = /^# (?:\-\*\- )?encoding:\s*(\S+)/ if CHECK_OLD_RUBIES require 'rvm' @@ -109,6 +110,27 @@ class Msftidy end end + # Check that modules don't have any encoding comment and that + # non-modules have an explicity binary encoding comment + def check_encoding + # coding/encoding lines must be the first or second line if present + encoding_lines = @source.lines.to_a[0,2].select { |l| l =~ ENCODING_REGEX } + if @full_filepath =~ /(?:^|\/)modules\// + warn('Modules do not need an encoding comment') unless encoding_lines.empty? + else + if encoding_lines.empty? + warn('Non-modules must have an encoding comment') + else + encoding_line = encoding_lines.first + encoding_line =~ ENCODING_REGEX + encoding_type = Regexp.last_match(1) + unless encoding_type == 'binary' + warn("Non-modules must have a binary encoding comment, not #{encoding_type}") + end + end + end + end + def check_shebang if @source.lines.first =~ /^#!/ warn("Module should not have a #! line") @@ -583,6 +605,7 @@ def run_checks(full_filepath) tidy = Msftidy.new(full_filepath) tidy.check_mode tidy.check_shebang + tidy.check_encoding tidy.check_nokogiri tidy.check_rubygems tidy.check_ref_identifiers