CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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