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
1875 views
1
#
2
# Copyright (c) 2006-2026 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
def pre_send
8
# Check for required binaries
9
if IO.popen(%w[which espeak], 'r').read.to_s.eql?('')
10
print_error('[Text to Voice] eSpeak is not in $PATH (brew install espeak on macOS, apt-get install espeak on Linux)')
11
return
12
end
13
if IO.popen(%w[which lame], 'r').read.to_s.eql?('')
14
print_error('[Text to Voice] Lame is not in $PATH (brew install lame on macOS, apt-get install lame on Linux)')
15
return
16
end
17
18
# Load espeak gem (only if binaries are available)
19
begin
20
require 'espeak'
21
include ESpeak
22
rescue LoadError, StandardError => e
23
print_error("[Text to Voice] Failed to load espeak gem: #{e.message}")
24
return
25
end
26
27
# Validate module options
28
message = nil
29
language = nil
30
@datastore.each do |input|
31
message = input['value'] if input['name'] == 'message'
32
language = input['value'] if input['name'] == 'language'
33
end
34
35
# Validate language
36
begin
37
unless Voice.all.map(&:language).include?(language)
38
print_error("[Text to Voice] Language '#{language}' is not supported")
39
print_more("Supported languages: #{Voice.all.map(&:language).join(',')}")
40
return
41
end
42
rescue StandardError => e
43
print_error("[Text to Voice] Could not validate language: #{e.message}")
44
return
45
end
46
47
# Convert text to voice, encode as mp3 and write to module directory
48
begin
49
msg = Speech.new(message.to_s, voice: language)
50
mp3_path = "modules/social_engineering/text_to_voice/mp3/msg-#{@command_id}.mp3"
51
msg.save(mp3_path)
52
rescue StandardError => e
53
print_error("[Text to Voice] Could not create mp3: #{e.message}")
54
return
55
end
56
57
# Mount the mp3 to /objects/
58
BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.bind(
59
"/#{mp3_path}",
60
"/objects/msg-#{@command_id}",
61
'mp3'
62
)
63
end
64
65
def self.options
66
[
67
{ 'name' => 'message',
68
'description' => 'Text to read',
69
'type' => 'textarea',
70
'ui_label' => 'Text',
71
'value' => 'Hello; from beef',
72
'width' => '400px' },
73
{ 'name' => 'language',
74
'description' => 'Language',
75
'type' => 'text',
76
'ui_label' => 'Language',
77
'value' => 'en' }
78
]
79
end
80
81
def post_execute
82
content = {}
83
content['result'] = @datastore['result']
84
save content
85
BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.unbind("/objects/msg-#{@command_id}.mp3")
86
end
87
end
88
89