2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2016-01-07 05:55:45 +00:00
|
|
|
|
2012-02-04 06:38:21 +00:00
|
|
|
msfbase = __FILE__
|
|
|
|
while File.symlink?(msfbase)
|
2013-09-30 18:47:53 +00:00
|
|
|
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
|
2012-02-04 06:38:21 +00:00
|
|
|
end
|
|
|
|
|
2016-05-14 02:51:54 +00:00
|
|
|
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
|
|
|
|
$LOAD_PATH.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
2016-01-07 05:55:45 +00:00
|
|
|
|
2016-04-14 19:54:30 +00:00
|
|
|
require 'msfenv'
|
2016-01-07 03:15:56 +00:00
|
|
|
require 'msf/core'
|
|
|
|
require 'msf/base'
|
2016-01-07 05:55:45 +00:00
|
|
|
require 'rex/text'
|
2016-01-07 03:15:56 +00:00
|
|
|
require 'optparse'
|
2012-02-04 06:38:21 +00:00
|
|
|
|
2016-01-07 03:15:56 +00:00
|
|
|
module PatternCreate
|
|
|
|
class OptsConsole
|
|
|
|
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 ''
|
2016-04-14 19:11:36 +00:00
|
|
|
opt.separator 'Options:'
|
2016-05-14 02:45:41 +00:00
|
|
|
opt.on('-l', '--length <length>', Integer, "The length of the pattern") do |len|
|
2016-01-07 03:15:56 +00:00
|
|
|
options[:length] = len
|
2016-05-14 02:51:54 +00:00
|
|
|
end
|
2005-12-09 00:03:52 +00:00
|
|
|
|
2016-05-14 02:45:41 +00:00
|
|
|
opt.on('-s', '--sets <ABC,def,123>', Array, "Custom Pattern Sets") do |sets|
|
2016-05-14 02:51:54 +00:00
|
|
|
options[:sets] = sets
|
2016-01-07 03:15:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
opt.on_tail('-h', '--help', 'Show this message') do
|
|
|
|
$stdout.puts opt
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
parser.parse!(args)
|
2005-12-09 00:03:52 +00:00
|
|
|
|
2016-01-07 03:15:56 +00:00
|
|
|
if options.empty?
|
|
|
|
raise OptionParser::MissingArgument, 'No options set, try -h for usage'
|
2016-01-07 03:34:58 +00:00
|
|
|
elsif options[:length].blank? && options[:sets]
|
|
|
|
raise OptionParser::MissingArgument, '-l <length> is required'
|
2016-01-07 03:15:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
options[:sets] = nil unless options[:sets]
|
|
|
|
|
|
|
|
options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-14 02:51:54 +00:00
|
|
|
class Driver
|
2016-01-07 03:15:56 +00:00
|
|
|
def initialize
|
|
|
|
begin
|
|
|
|
@opts = OptsConsole.parse(ARGV)
|
|
|
|
rescue OptionParser::ParseError => e
|
|
|
|
$stderr.puts "[x] #{e.message}"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
2016-05-14 02:45:41 +00:00
|
|
|
|
2016-01-07 03:15:56 +00:00
|
|
|
def run
|
|
|
|
pattern = Rex::Text.pattern_create(@opts[:length], @opts[:sets])
|
|
|
|
puts pattern
|
|
|
|
end
|
|
|
|
end
|
2005-12-09 00:03:52 +00:00
|
|
|
end
|
|
|
|
|
2016-01-07 03:15:56 +00:00
|
|
|
if __FILE__ == $PROGRAM_NAME
|
|
|
|
driver = PatternCreate::Driver.new
|
|
|
|
begin
|
|
|
|
driver.run
|
2016-05-14 02:51:54 +00:00
|
|
|
rescue ::StandardError => e
|
2016-01-07 03:15:56 +00:00
|
|
|
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
|