pattern_create.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env ruby
  2. ##
  3. # This module requires Metasploit: https://metasploit.com/download
  4. # Current source: https://github.com/rapid7/metasploit-framework
  5. ##
  6. begin
  7. msfbase = __FILE__
  8. while File.symlink?(msfbase)
  9. msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
  10. end
  11. $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
  12. $LOAD_PATH.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
  13. gem 'rex-text'
  14. require 'optparse'
  15. module PatternCreate
  16. class OptsConsole
  17. def self.parse(args)
  18. options = {}
  19. parser = OptionParser.new do |opt|
  20. opt.banner = "Usage: #{__FILE__} [options]\nExample: #{__FILE__} -l 50 -s ABC,def,123\nAd1Ad2Ad3Ae1Ae2Ae3Af1Af2Af3Bd1Bd2Bd3Be1Be2Be3Bf1Bf"
  21. opt.separator ''
  22. opt.separator 'Options:'
  23. opt.on('-l', '--length <length>', Integer, "The length of the pattern") do |len|
  24. options[:length] = len
  25. end
  26. opt.on('-s', '--sets <ABC,def,123>', Array, "Custom Pattern Sets") do |sets|
  27. options[:sets] = sets
  28. end
  29. opt.on_tail('-h', '--help', 'Show this message') do
  30. $stdout.puts opt
  31. exit
  32. end
  33. end
  34. parser.parse!(args)
  35. if options.empty?
  36. raise OptionParser::MissingArgument, 'No options set, try -h for usage'
  37. elsif options[:length].nil? && options[:sets]
  38. raise OptionParser::MissingArgument, '-l <length> is required'
  39. end
  40. options[:sets] = nil unless options[:sets]
  41. options
  42. end
  43. end
  44. class Driver
  45. def initialize
  46. begin
  47. @opts = OptsConsole.parse(ARGV)
  48. rescue OptionParser::ParseError => e
  49. $stderr.puts "[x] #{e.message}"
  50. exit
  51. end
  52. end
  53. def run
  54. require 'rex/text'
  55. puts Rex::Text.pattern_create(@opts[:length], @opts[:sets])
  56. end
  57. end
  58. end
  59. if __FILE__ == $PROGRAM_NAME
  60. driver = PatternCreate::Driver.new
  61. begin
  62. driver.run
  63. rescue ::StandardError => e
  64. $stderr.puts "[x] #{e.class}: #{e.message}"
  65. $stderr.puts "[*] If necessary, please refer to framework.log for more details."
  66. end
  67. end
  68. rescue SignalException => e
  69. puts("Aborted! #{e}")
  70. end