Path: blob/master/modules/social_engineering/text_to_voice/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 Text_to_voice < BeEF::Core::Command6require 'espeak'7include ESpeak89def pre_send10# Ensure lame and espeak are installed11if IO.popen(%w[which lame], 'r').read.to_s.eql?('')12print_error('[Text to Voice] Lame is not in $PATH (apt-get install lame)')13return14end15if IO.popen(%w[which espeak], 'r').read.to_s.eql?('')16print_error('[Text to Voice] eSpeak is not in $PATH (apt-get install espeak)')17return18end1920# Validate module options21message = nil22language = nil23@datastore.each do |input|24message = input['value'] if input['name'] == 'message'25language = input['value'] if input['name'] == 'language'26end27unless Voice.all.map(&:language).include?(language)28print_error("[Text to Voice] Language '#{language}' is not supported")29print_more("Supported languages: #{Voice.all.map(&:language).join(',')}")30return31end3233# Convert text to voice, encode as mp3 and write to module directory34begin35msg = Speech.new(message.to_s, voice: language)36mp3_path = "modules/social_engineering/text_to_voice/mp3/msg-#{@command_id}.mp3"37msg.save(mp3_path)38rescue StandardError => e39print_error("[Text to Voice] Could not create mp3: #{e.message}")40return41end4243# Mount the mp3 to /objects/44BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.bind(45"/#{mp3_path}",46"/objects/msg-#{@command_id}",47'mp3'48)49end5051def self.options52[53{ 'name' => 'message',54'description' => 'Text to read',55'type' => 'textarea',56'ui_label' => 'Text',57'value' => 'Hello; from beef',58'width' => '400px' },59{ 'name' => 'language',60'description' => 'Language',61'type' => 'text',62'ui_label' => 'Language',63'value' => 'en' }64]65end6667def post_execute68content = {}69content['result'] = @datastore['result']70save content71BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.unbind("/objects/msg-#{@command_id}.mp3")72end73end747576