Files
metasploit-gs/tools/exploit/pattern_create.rb
T

80 lines
2.1 KiB
Ruby
Raw Normal View History

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