Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/social_engineering/text_to_voice/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 Text_to_voice < BeEF::Core::Command
7
require 'espeak'
8
include ESpeak
9
10
def pre_send
11
# Ensure lame and espeak are installed
12
if IO.popen(%w[which lame], 'r').read.to_s.eql?('')
13
print_error('[Text to Voice] Lame is not in $PATH (apt-get install lame)')
14
return
15
end
16
if IO.popen(%w[which espeak], 'r').read.to_s.eql?('')
17
print_error('[Text to Voice] eSpeak is not in $PATH (apt-get install espeak)')
18
return
19
end
20
21
# Validate module options
22
message = nil
23
language = nil
24
@datastore.each do |input|
25
message = input['value'] if input['name'] == 'message'
26
language = input['value'] if input['name'] == 'language'
27
end
28
unless Voice.all.map(&:language).include?(language)
29
print_error("[Text to Voice] Language '#{language}' is not supported")
30
print_more("Supported languages: #{Voice.all.map(&:language).join(',')}")
31
return
32
end
33
34
# Convert text to voice, encode as mp3 and write to module directory
35
begin
36
msg = Speech.new(message.to_s, voice: language)
37
mp3_path = "modules/social_engineering/text_to_voice/mp3/msg-#{@command_id}.mp3"
38
msg.save(mp3_path)
39
rescue StandardError => e
40
print_error("[Text to Voice] Could not create mp3: #{e.message}")
41
return
42
end
43
44
# Mount the mp3 to /objects/
45
BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.bind(
46
"/#{mp3_path}",
47
"/objects/msg-#{@command_id}",
48
'mp3'
49
)
50
end
51
52
def self.options
53
[
54
{ 'name' => 'message',
55
'description' => 'Text to read',
56
'type' => 'textarea',
57
'ui_label' => 'Text',
58
'value' => 'Hello; from beef',
59
'width' => '400px' },
60
{ 'name' => 'language',
61
'description' => 'Language',
62
'type' => 'text',
63
'ui_label' => 'Language',
64
'value' => 'en' }
65
]
66
end
67
68
def post_execute
69
content = {}
70
content['result'] = @datastore['result']
71
save content
72
BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.unbind("/objects/msg-#{@command_id}.mp3")
73
end
74
end
75
76