Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/extensions/metasploit/extension.rb
1154 views
1
#
2
# Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
# Browser Exploitation Framework (BeEF) - https://beefproject.com
4
# See the file 'doc/COPYING' for copying permission
5
#
6
module BeEF
7
module Extension
8
module Metasploit
9
extend BeEF::API::Extension
10
11
@short_name = 'msf'
12
@full_name = 'Metasploit'
13
@description = 'Metasploit integration'
14
15
# Translates msf exploit options to beef options array
16
def self.translate_options(msf_options)
17
callback_host = BeEF::Core::Configuration.instance.get('beef.extension.metasploit.callback_host')
18
19
options = []
20
msf_options.each do |k, v|
21
next if v['advanced'] == true
22
next if v['evasion'] == true
23
24
v['allowBlank'] = 'true' if v['required'] == false
25
26
case v['type']
27
when 'string', 'address', 'port', 'integer'
28
v['type'] = 'text'
29
v['value'] = if k == 'URIPATH'
30
rand(3**20).to_s(16)
31
elsif k == 'LHOST'
32
callback_host
33
else
34
v['default']
35
end
36
when 'bool'
37
v['type'] = 'checkbox'
38
when 'enum'
39
v['type'] = 'combobox'
40
v['store_type'] = 'arraystore',
41
v['store_fields'] = ['enum'],
42
v['store_data'] = translate_enums(v['enums']),
43
v['value'] = v['default']
44
v['valueField'] = 'enum',
45
v['displayField'] = 'enum',
46
v['autoWidth'] = true,
47
v['mode'] = 'local'
48
end
49
v['name'] = k
50
v['label'] = k
51
options << v
52
end
53
54
options
55
end
56
57
# Translates msf payloads to a beef compatible drop down
58
def self.translate_payload(payloads)
59
return unless payloads.key?('payloads')
60
61
values = translate_enums(payloads['payloads'])
62
63
default_payload = values.include?('generic/shell_bind_tcp') ? 'generic/shell_bind_tcp' : values.first
64
65
return unless values.length.positive?
66
67
{
68
'name' => 'PAYLOAD',
69
'type' => 'combobox',
70
'ui_label' => 'Payload',
71
'store_type' => 'arraystore',
72
'store_fields' => ['payload'],
73
'store_data' => values,
74
'valueField' => 'payload',
75
'displayField' => 'payload',
76
'mode' => 'local',
77
'autoWidth' => true,
78
'defaultPayload' => default_payload,
79
'reloadOnChange' => true
80
}
81
end
82
83
# Translates metasploit enums to ExtJS combobox store_data
84
def self.translate_enums(enums)
85
enums.map { |e| [e] }
86
end
87
end
88
end
89
end
90
91
require 'msfrpc-client'
92
require 'extensions/metasploit/rpcclient'
93
require 'extensions/metasploit/api'
94
require 'extensions/metasploit/module'
95
require 'extensions/metasploit/rest/msf'
96
97