Skip to content

Commit af8f645

Browse files
committed
This starts to work
1 parent fe267fb commit af8f645

File tree

1 file changed

+88
-3
lines changed

1 file changed

+88
-3
lines changed

tools/egghunter.rb

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,97 @@
66
require 'msfenv'
77
require 'rex'
88
require 'msf/core'
9+
require 'msf/base'
910
require 'optparse'
1011

1112
module Egghunter
12-
class Driver < Msf::Auxiliary
13-
include Msf::Exploit::Remote::Egghunter
13+
class OptsConsole
14+
def self.parse(args)
15+
options = {}
16+
parser = OptionParser.new do |opt|
17+
opt.banner = "Usage: #{__FILE__} [options]"
18+
opt.separator ''
19+
opt.separator 'Specific options:'
1420

15-
def initialize(opts={})
21+
options[:badchars] = ''
22+
options[:platform] = 'windows'
23+
options[:arch] = ARCH_X86 # 'x86'
24+
25+
opt.on('-f', '--format <String>', "See --list-formats for a list of supported output formats") do |v|
26+
options[:format] = v
27+
end
28+
29+
opt.on('-b', '--badchars <String>', "(Optional) Bad characters to avoid for the egg") do |v|
30+
options[:badchars] = v
31+
end
32+
33+
opt.on('-e', '--egg <String>', "Egg") do |v|
34+
options[:eggtag] = v
35+
end
36+
37+
opt.on('-p', '--platform <String>', "(Optional) Platform") do |v|
38+
options[:platform] = v
39+
end
40+
41+
opt.on('-a', '--arch <String>', "(Optional) Architecture") do |v|
42+
options[:arch] = v
43+
end
44+
45+
opt.on('--list-formats', "List all supported output formats") do
46+
options[:list_formats] = true
47+
end
48+
49+
opt.on_tail('-h', '--help', 'Show this message') do
50+
$stdout.puts opt
51+
exit
52+
end
53+
end
54+
55+
parser.parse!(args)
56+
57+
if options.empty?
58+
raise OptionParser::MissingArgument, 'No options set, try -h for usage'
59+
elsif options[:format].blank? && !options[:list_formats]
60+
raise OptionParser::MissingArgument, '-f is required'
61+
elsif options[:format] && !::Msf::Simple::Buffer.transform_formats.include?(options[:format])
62+
raise OptionParser::InvalidOption, "#{options[:format]} is not a valid format"
63+
elsif options[:eggtag].blank?
64+
raise OptionParser::MissingArgument, '-e is required'
65+
end
66+
67+
options
68+
end
69+
end
70+
71+
class Driver
72+
def initialize
73+
begin
74+
@opts = OptsConsole.parse(ARGV)
75+
rescue OptionParser::ParseError => e
76+
$stderr.puts "[x] #{e.message}"
77+
exit
78+
end
1679
end
1780

1881
def run
82+
# list_formats should check first
83+
if @opts[:list_formats]
84+
list_formats
85+
return
86+
end
87+
88+
egghunter = Rex::Exploitation::Egghunter.new(@opts[:platform], @opts[:arch])
89+
raw_code = egghunter.hunter_stub('', @opts[:badchars], @opts)
90+
output_stream = $stdout
91+
output_stream.binmode
92+
output_stream.write ::Msf::Simple::Buffer.transform(raw_code, @opts[:format])
93+
end
94+
95+
private
96+
97+
def list_formats
98+
$stderr.puts "[*] Supported output formats:"
99+
$stderr.puts ::Msf::Simple::Buffer.transform_formats.join(", ")
19100
end
20101

21102
end
@@ -29,5 +110,9 @@ def run
29110
rescue Interrupt
30111
$stdout.puts
31112
$stdout.puts "Good bye"
113+
rescue ::Exception => e
114+
elog("#{e.class}: #{e.message}\n#{e.backtrace * "\n"}")
115+
$stderr.puts "[x] #{e.class}: #{e.message}"
116+
$stderr.puts "[*] If necessary, please refer to framework.log for more details."
32117
end
33118
end

0 commit comments

Comments
 (0)