Path: blob/master/modules/social_engineering/text_to_voice/module.rb
1875 views
#1# Copyright (c) 2006-2026 Wade Alcorn - [email protected]2# Browser Exploitation Framework (BeEF) - https://beefproject.com3# See the file 'doc/COPYING' for copying permission4#5class Text_to_voice < BeEF::Core::Command6def pre_send7# Check for required binaries8if IO.popen(%w[which espeak], 'r').read.to_s.eql?('')9print_error('[Text to Voice] eSpeak is not in $PATH (brew install espeak on macOS, apt-get install espeak on Linux)')10return11end12if IO.popen(%w[which lame], 'r').read.to_s.eql?('')13print_error('[Text to Voice] Lame is not in $PATH (brew install lame on macOS, apt-get install lame on Linux)')14return15end1617# Load espeak gem (only if binaries are available)18begin19require 'espeak'20include ESpeak21rescue LoadError, StandardError => e22print_error("[Text to Voice] Failed to load espeak gem: #{e.message}")23return24end2526# Validate module options27message = nil28language = nil29@datastore.each do |input|30message = input['value'] if input['name'] == 'message'31language = input['value'] if input['name'] == 'language'32end3334# Validate language35begin36unless Voice.all.map(&:language).include?(language)37print_error("[Text to Voice] Language '#{language}' is not supported")38print_more("Supported languages: #{Voice.all.map(&:language).join(',')}")39return40end41rescue StandardError => e42print_error("[Text to Voice] Could not validate language: #{e.message}")43return44end4546# Convert text to voice, encode as mp3 and write to module directory47begin48msg = Speech.new(message.to_s, voice: language)49mp3_path = "modules/social_engineering/text_to_voice/mp3/msg-#{@command_id}.mp3"50msg.save(mp3_path)51rescue StandardError => e52print_error("[Text to Voice] Could not create mp3: #{e.message}")53return54end5556# Mount the mp3 to /objects/57BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.bind(58"/#{mp3_path}",59"/objects/msg-#{@command_id}",60'mp3'61)62end6364def self.options65[66{ 'name' => 'message',67'description' => 'Text to read',68'type' => 'textarea',69'ui_label' => 'Text',70'value' => 'Hello; from beef',71'width' => '400px' },72{ 'name' => 'language',73'description' => 'Language',74'type' => 'text',75'ui_label' => 'Language',76'value' => 'en' }77]78end7980def post_execute81content = {}82content['result'] = @datastore['result']83save content84BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.unbind("/objects/msg-#{@command_id}.mp3")85end86end878889