#!/usr/bin/env ruby # # $Id$ # $Revision$ msfbase = __FILE__ while File.symlink?(msfbase) msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase)) end $:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib'))) require 'msfenv' $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB'] require 'msf/core' require 'msf/base' require 'rex/text' require 'optparse' 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 '' opt.separator 'Specific options:' opt.on('-l', '--length ', Integer, "The length of the pattern") do |len| options[:length] = len end opt.on('-s', '--sets ', 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' elsif options[:length].blank? && options[:sets] raise OptionParser::MissingArgument, '-l is required' 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 if __FILE__ == $PROGRAM_NAME driver = PatternCreate::Driver.new 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