metasploit-framework/tools/exploit/pattern_create.rb

86 lines
2.2 KiB
Ruby
Raw Normal View History

#!/usr/bin/env ruby
2016-01-07 05:55:45 +00:00
2018-03-20 11:33:34 +00:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
msfbase = __FILE__
while File.symlink?(msfbase)
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
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
gem '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 ''
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|
options[:length] = len
2016-05-14 02:51:54 +00:00
end
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
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].nil? && options[:sets]
2016-01-07 03:34:58 +00:00
raise OptionParser::MissingArgument, '-l <length> is required'
end
options[:sets] = nil unless options[:sets]
options
end
end
2016-05-14 02:51:54 +00:00
class Driver
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
def run
2016-05-14 14:50:02 +00:00
require 'msfenv'
require 'msf/core'
require 'msf/base'
require 'rex/text'
puts Rex::Text.pattern_create(@opts[:length], @opts[:sets])
end
end
end
if __FILE__ == $PROGRAM_NAME
driver = PatternCreate::Driver.new
begin
driver.run
2016-05-14 02:51:54 +00:00
rescue ::StandardError => e
$stderr.puts "[x] #{e.class}: #{e.message}"
$stderr.puts "[*] If necessary, please refer to framework.log for more details."
end
end