@@ -7,95 +7,53 @@ def self.generate(module_path)
7
7
mod = Msf ::Modules ::External ::Bridge . open ( module_path )
8
8
return '' unless mod . meta
9
9
case mod . meta [ 'type' ]
10
- when 'remote_exploit.cmd_stager.wget '
10
+ when 'remote_exploit_cmd_stager '
11
11
remote_exploit_cmd_stager ( mod )
12
12
end
13
13
end
14
14
15
- def self . remote_exploit_cmd_stager ( mod )
16
- %Q|
17
- require 'msf/core/modules/external/bridge'
18
-
19
- class MetasploitModule < Msf::Exploit::Remote
20
- Rank = ExcellentRanking
21
-
22
- include Msf::Exploit::CmdStager
23
-
24
- def initialize(info = {})
25
- super(update_info(info,
26
- 'Name' => #{ mod . meta [ 'name' ] . dump } ,
27
- 'Description' => #{ mod . meta [ 'description' ] . dump } ,
28
- 'Author' =>
29
- [
30
- #{ mod . meta [ 'authors' ] . map ( &:dump ) . join ( ', ' ) }
31
- ],
32
- 'License' => MSF_LICENSE,
33
- 'References' =>
34
- [
35
- #{ mod . meta [ 'references' ] . map do |r |
36
- "[#{ r [ 'type' ] . upcase . dump } , #{ r [ 'ref' ] . dump } ]"
37
- end . join ( ', ' ) }
38
- ],
39
- 'DisclosureDate' => #{ mod . meta [ 'date' ] . dump } ,
40
- 'Privileged' => #{ mod . meta [ 'privileged' ] . inspect } ,
41
- 'Platform' => [#{ mod . meta [ 'targets' ] . map { |t | t [ 'platform' ] . dump } . uniq . join ( ', ' ) } ],
42
- 'Payload' =>
43
- {
44
- 'DisableNops' => true
45
- },
46
- 'Targets' =>
47
- [
48
- #{ mod . meta [ 'targets' ] . map do |t |
49
- %Q^[#{ t [ 'platform' ] . dump } + ' ' + #{ t [ 'arch' ] . dump } ,
50
- {'Arch' => ARCH_#{ t [ 'arch' ] . upcase } , 'Platform' => #{ t [ 'platform' ] . dump } }]^
51
- end . join ( ', ' ) }
52
- ],
53
- 'DefaultTarget' => 0,
54
- 'DefaultOptions' => { 'WfsDelay' => 5 }
55
- ))
56
-
57
- register_options([
58
- #{ mod . meta [ 'options' ] . map do |n , o |
59
- "Opt#{ o [ 'type' ] . capitalize } .new(#{ n . dump } ,
60
- [#{ o [ 'required' ] } , #{ o [ 'description' ] . dump } , #{ o [ 'default' ] . inspect } ])"
61
- end . join ( ', ' ) }
62
- ], self.class)
15
+ def self . render_template ( name , meta = { } )
16
+ template = File . join ( File . dirname ( __FILE__ ) , 'templates' , name )
17
+ ERB . new ( File . read ( template ) ) . result ( binding )
63
18
end
64
19
65
- def execute_command(cmd, opts)
66
- mod = Msf::Modules::External::Bridge.open(#{ mod . path . dump } )
67
- mod.run(datastore.merge(command: cmd))
68
- wait_status(mod)
69
- true
20
+ def self . common_metadata ( meta = { } )
21
+ render_template ( 'common_metadata.erb' , meta )
70
22
end
71
23
72
- def exploit
73
- print_status("Exploiting...")
74
- execute_cmdstager({:flavor => :wget})
24
+ def self . mod_meta_common ( mod , meta = { } )
25
+ meta [ :path ] = mod . path . dump
26
+ meta [ :name ] = mod . meta [ 'name' ] . dump
27
+ meta [ :description ] = mod . meta [ 'description' ] . dump
28
+ meta [ :authors ] = mod . meta [ 'authors' ] . map ( &:dump ) . join ( ",\n " )
29
+ meta [ :date ] = mod . meta [ 'date' ] . dump
30
+ meta [ :references ] = mod . meta [ 'references' ] . map do |r |
31
+ "[#{ r [ 'type' ] . upcase . dump } , #{ r [ 'ref' ] . dump } ]"
32
+ end . join ( ",\n " )
33
+
34
+ meta [ :options ] = mod . meta [ 'options' ] . map do |n , o |
35
+ "Opt#{ o [ 'type' ] . capitalize } .new(#{ n . dump } ,
36
+ [#{ o [ 'required' ] } , #{ o [ 'description' ] . dump } , #{ o [ 'default' ] . inspect } ])"
37
+ end . join ( ",\n " )
38
+ meta
75
39
end
76
40
77
- def wait_status(mod)
78
- while mod.running
79
- m = mod.get_status
80
- if m
81
- case m['level']
82
- when 'error'
83
- print_error m['message']
84
- when 'warning'
85
- print_warning m['message']
86
- when 'good'
87
- print_good m['message']
88
- when 'info'
89
- print_status m['message']
90
- when 'debug'
91
- vprint_status m['message']
92
- else
93
- print_status m['message']
94
- end
95
- end
96
- end
41
+ def self . mod_meta_exploit ( mod , meta = { } )
42
+ meta [ :wfsdelay ] = mod . meta [ 'wfsdelay' ] || 5
43
+ meta [ :privileged ] = mod . meta [ 'privileged' ] . inspect
44
+ meta [ :platform ] = mod . meta [ 'targets' ] . map do |t |
45
+ t [ 'platform' ] . dump
46
+ end . uniq . join ( ",\n " )
47
+ meta [ :targets ] = mod . meta [ 'targets' ] . map do |t |
48
+ "[#{ t [ 'platform' ] . dump } + ' ' + #{ t [ 'arch' ] . dump } , {'Arch' => ARCH_#{ t [ 'arch' ] . upcase } , 'Platform' => #{ t [ 'platform' ] . dump } }]"
49
+ end . join ( ",\n " )
50
+ meta
97
51
end
98
- end
99
- |
52
+
53
+ def self . remote_exploit_cmd_stager ( mod )
54
+ meta = mod_meta_common ( mod )
55
+ meta = mod_meta_exploit ( mod , meta )
56
+ meta [ :command_stager_flavor ] = mod . meta [ 'payload' ] [ 'command_stager_flavor' ] . dump
57
+ render_template ( 'remote_exploit_cmd_stager.erb' , meta )
100
58
end
101
59
end
0 commit comments