Skip to content

Commit fede672

Browse files
author
Brent Cook
committed
further revise templates
1 parent a2ce374 commit fede672

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,30 @@ def self.generate(module_path)
77
mod = Msf::Modules::External::Bridge.open(module_path)
88
return '' unless mod.meta
99
case mod.meta['type']
10-
when 'remote_exploit.cmd_stager.wget'
10+
when 'remote_exploit_cmd_stager'
1111
remote_exploit_cmd_stager(mod)
1212
end
1313
end
1414

15+
def self.render_template(name, meta = {})
16+
template = File.join(File.dirname(__FILE__), 'templates', name)
17+
ERB.new(File.read(template)).result(binding)
18+
end
19+
20+
def self.common_metadata(meta = {})
21+
render_template('common_metadata.erb', meta)
22+
end
23+
1524
def self.mod_meta_common(mod, meta = {})
1625
meta[:path] = mod.path.dump
1726
meta[:name] = mod.meta['name'].dump
18-
meta[:description] = mod.meta['description'].dump.strip
27+
meta[:description] = mod.meta['description'].dump
1928
meta[:authors] = mod.meta['authors'].map(&:dump).join(",\n ")
2029
meta[:date] = mod.meta['date'].dump
2130
meta[:references] = mod.meta['references'].map do |r|
2231
"[#{r['type'].upcase.dump}, #{r['ref'].dump}]"
2332
end.join(",\n ")
33+
2434
meta[:options] = mod.meta['options'].map do |n, o|
2535
"Opt#{o['type'].capitalize}.new(#{n.dump},
2636
[#{o['required']}, #{o['description'].dump}, #{o['default'].inspect}])"
@@ -37,14 +47,15 @@ def self.mod_meta_exploit(mod, meta = {})
3747
meta[:targets] = mod.meta['targets'].map do |t|
3848
"[#{t['platform'].dump} + ' ' + #{t['arch'].dump}, {'Arch' => ARCH_#{t['arch'].upcase}, 'Platform' => #{t['platform'].dump} }]"
3949
end.join(",\n ")
40-
4150
meta
4251
end
4352

4453
def self.remote_exploit_cmd_stager(mod)
4554
meta = mod_meta_common(mod)
4655
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)
56+
meta[:command_stager_flavor] = mod.meta['payload']['command_stager_flavor'].dump
57+
out = render_template('remote_exploit_cmd_stager.erb', meta)
58+
File.write("/tmp/blah.rb", out)
59+
out
4960
end
5061
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'Name' => <%= meta[:name] %>,
2+
'Description' => <%= meta[:description] %>,
3+
'Author' =>
4+
[
5+
<%= meta[:authors] %>
6+
],
7+
'License' => MSF_LICENSE,

lib/msf/core/modules/external/remote_exploit_cmd_stager.erb renamed to lib/msf/core/modules/external/templates/remote_exploit_cmd_stager.erb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ class MetasploitModule < Msf::Exploit::Remote
99

1010
def initialize(info = {})
1111
super(update_info(info,
12-
'Name' => <%= meta[:name] %>,
13-
'Description' => <%= meta[:description] %>,
14-
'Author' =>
15-
[
16-
<%= meta[:authors] %>
17-
],
18-
'License' => MSF_LICENSE,
12+
<%= common_metadata meta %>
1913
'References' =>
2014
[
2115
<%= meta[:references] %>
@@ -49,6 +43,6 @@ class MetasploitModule < Msf::Exploit::Remote
4943

5044
def exploit
5145
print_status("Exploiting...")
52-
execute_cmdstager({:flavor => :wget})
46+
execute_cmdstager({:flavor => :<%= meta[:command_stager_flavor] %>})
5347
end
5448
end

modules/exploits/linux/smtp/haraka.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@
3434
{'type': 'edb', 'ref': '41162'},
3535
{'type': 'url', 'ref': 'https://github.com/haraka/Haraka/pull/1606'},
3636
],
37-
'type': 'remote_exploit.cmd_stager.wget',
37+
'type': 'remote_exploit_cmd_stager',
38+
'wfsdelay': 5,
3839
'privileged': True,
3940
'targets': [
4041
{'platform': 'linux', 'arch': 'x64'},
4142
{'platform': 'linux', 'arch': 'x86'}
4243
],
44+
'payload': {
45+
'command_stager_flavor': 'wget'
46+
},
4347
'options': {
4448
'email_to': {'type': 'string', 'description': 'Email to send to, must be accepted by the server', 'required': True, 'default': 'admin@localhost'},
4549
'email_from': {'type': 'string', 'description': 'Address to send from', 'required': True, 'default': '[email protected]'},

0 commit comments

Comments
 (0)