Re-write pattern_create layout and options

Updated pattern_create.rb to be more consistent other tools and modules in Metasploit.  Provided a usage example for undocumented custom set feature that allows removal of bad characters.

Usage: ./pattern_create.rb [options]
Example: ./pattern_create.rb -l 50 -s ABC,def,123
Ad1Ad2Ad3Ae1Ae2Ae3Af1Af2Af3Bd1Bd2Bd3Be1Be2Be3Bf1Bf

Specific options:
    -l, --length <length>            The length of the pattern
    -s, --sets <ABC,def,123>         Custom Pattern Sets
    -h, --help                       Show this message
bug/bundler_fix
x90" * 365 2016-01-06 22:15:56 -05:00
parent f058564e7f
commit 7e70cb6fe8
1 changed files with 63 additions and 11 deletions

View File

@ -2,7 +2,6 @@
# #
# $Id$ # $Id$
# $Revision$ # $Revision$
#
msfbase = __FILE__ msfbase = __FILE__
while File.symlink?(msfbase) while File.symlink?(msfbase)
@ -11,18 +10,71 @@ end
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib'))) $:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
require 'msfenv' require 'msfenv'
require 'msf/core'
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB'] require 'msf/base'
require 'rex' require 'rex'
require 'optparse'
if (!(length = ARGV.shift)) module PatternCreate
$stderr.puts("Usage: #{File.basename($0)} length [set a] [set b] [set c]\n") class OptsConsole
exit def self.parse(args)
options = {}
parser = OptionParser.new do |opt|
opt.banner = "Usage: #{__FILE__} [options]\nExample: #{__FILE__} -l 50 -s ABC,def,123\nAd1Ad2Ad3Ae1Ae2Ae3Af1Af2Af3Bd1Bd2Bd3Be1Be2Be3Bf1Bf"
opt.separator ''
opt.separator 'Specific options:'
opt.on('-l', '--length <length>', Integer, "The length of the pattern") do |len|
options[:length] = len
end
opt.on('-s', '--sets <ABC,def,123>', Array, "Custom Pattern Sets") do |sets|
options[:sets] = sets
end
opt.on_tail('-h', '--help', 'Show this message') do
$stdout.puts opt
exit
end
end
parser.parse!(args)
if options.empty?
raise OptionParser::MissingArgument, 'No options set, try -h for usage'
end
options[:sets] = nil unless options[:sets]
options
end
end
class Driver
def initialize
begin
@opts = OptsConsole.parse(ARGV)
rescue OptionParser::ParseError => e
$stderr.puts "[x] #{e.message}"
exit
end
end
def run
pattern = Rex::Text.pattern_create(@opts[:length], @opts[:sets])
puts pattern
end
end
end end
# If the user supplied custom sets, use those. Otherwise, use the default if __FILE__ == $PROGRAM_NAME
# sets. driver = PatternCreate::Driver.new
sets = ARGV.length > 0 ? ARGV : Rex::Text::DefaultPatternSets begin
driver.run
rescue ::Exception => e
elog("#{e.class}: #{e.message}\n#{e.backtrace * "\n"}")
$stderr.puts "[x] #{e.class}: #{e.message}"
$stderr.puts "[*] If necessary, please refer to framework.log for more details."
end
end
puts Rex::Text.pattern_create(length.to_i, sets)