Skip to content

Commit 2e880c9

Browse files
author
Brent Cook
committed
move module template to an ERB
1 parent 97095ab commit 2e880c9

File tree

2 files changed

+105
-81
lines changed

2 files changed

+105
-81
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
require 'msf/core/modules/external/bridge'
2+
3+
class MetasploitModule < Msf::Exploit::Remote
4+
Rank = ExcellentRanking
5+
6+
include Msf::Exploit::CmdStager
7+
8+
def initialize(info = {})
9+
super(update_info(info,
10+
'Name' => <%= meta[:name] %>,
11+
'Description' => <%= meta[:description] %>,
12+
'Author' =>
13+
[
14+
<%= meta[:authors] %>
15+
],
16+
'License' => MSF_LICENSE,
17+
'References' =>
18+
[
19+
<%= meta[:references] %>
20+
],
21+
'DisclosureDate' => <%= meta[:date] %>,
22+
'Privileged' => <%= meta[:privileged] %>,
23+
'Platform' => [<%= meta[:platform] %>],
24+
'Payload' =>
25+
{
26+
'DisableNops' => true
27+
},
28+
'Targets' =>
29+
[
30+
<%= meta[:targets] %>
31+
],
32+
'DefaultTarget' => 0,
33+
'DefaultOptions' => { 'WfsDelay' => <%= meta[:delay] %> }
34+
))
35+
36+
register_options([
37+
<%= meta[:options] %>
38+
], self.class)
39+
end
40+
41+
def execute_command(cmd, opts)
42+
mod = Msf::Modules::External::Bridge.open(<%= meta[:path] %>)
43+
mod.run(datastore.merge(command: cmd))
44+
wait_status(mod)
45+
true
46+
end
47+
48+
def exploit
49+
print_status("Exploiting...")
50+
execute_cmdstager({:flavor => :wget})
51+
end
52+
53+
def wait_status(mod)
54+
while mod.running
55+
m = mod.get_status
56+
if m
57+
case m['level']
58+
when 'error'
59+
print_error m['message']
60+
when 'warning'
61+
print_warning m['message']
62+
when 'good'
63+
print_good m['message']
64+
when 'info'
65+
print_status m['message']
66+
when 'debug'
67+
vprint_status m['message']
68+
else
69+
print_status m['message']
70+
end
71+
end
72+
end
73+
end
74+
end
75+

lib/msf/core/modules/external/shim.rb

Lines changed: 30 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -12,90 +12,39 @@ def self.generate(module_path)
1212
end
1313
end
1414

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.mod_meta_common(mod, meta = {})
16+
meta[:path] = mod.path.dump
17+
meta[:name] = mod.meta['name'].dump
18+
meta[:description] = mod.meta['description'].dump.strip
19+
meta[:authors] = mod.meta['authors'].map(&:dump).join(",\n ")
20+
meta[:date] = mod.meta['date'].dump
21+
meta[:references] = mod.meta['references'].map do |r|
22+
"[#{r['type'].upcase.dump}, #{r['ref'].dump}]"
23+
end.join(",\n ")
24+
meta[:options] = mod.meta['options'].map do |n, o|
25+
"Opt#{o['type'].capitalize}.new(#{n.dump},
26+
[#{o['required']}, #{o['description'].dump}, #{o['default'].inspect}])"
27+
end.join(",\n ")
28+
meta
6329
end
6430

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
31+
def self.mod_meta_exploit(mod, meta = {})
32+
meta[:delay] = mod.meta['delay'] || 5
33+
meta[:privileged] = mod.meta['privileged'].inspect
34+
meta[:platform] = mod.meta['targets'].map do |t|
35+
t['platform'].dump
36+
end.uniq.join(",\n ")
37+
meta[:targets] = mod.meta['targets'].map do |t|
38+
"[#{t['platform'].dump} + ' ' + #{t['arch'].dump}, {'Arch' => ARCH_#{t['arch'].upcase}, 'Platform' => #{t['platform'].dump} }]"
39+
end.join(",\n ")
40+
41+
meta
7042
end
7143

72-
def exploit
73-
print_status("Exploiting...")
74-
execute_cmdstager({:flavor => :wget})
75-
end
76-
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
97-
end
98-
end
99-
|
44+
def self.remote_exploit_cmd_stager(mod)
45+
meta = mod_meta_common(mod)
46+
meta = mod_meta_exploit(mod, meta)
47+
template = File.join(File.dirname(__FILE__), 'remote_exploit_cmd_stager.erb')
48+
ERB.new(File.read(template)).result(binding)
10049
end
10150
end

0 commit comments

Comments
 (0)