6
6
require 'msfenv'
7
7
require 'rex'
8
8
require 'msf/core'
9
+ require 'msf/base'
9
10
require 'optparse'
10
11
11
12
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:'
14
20
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
16
79
end
17
80
18
81
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 ( ", " )
19
100
end
20
101
21
102
end
@@ -29,5 +110,9 @@ def run
29
110
rescue Interrupt
30
111
$stdout. puts
31
112
$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."
32
117
end
33
118
end
0 commit comments