CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/plugins/sounds.rb
Views: 1903
1
module Msf
2
###
3
#
4
# This class hooks all session creation events and plays a sound
5
#
6
###
7
8
class Plugin::EventSounds < Msf::Plugin
9
10
attr_accessor :theme, :base, :queue, :queue_thread
11
attr_reader :try_harder, :excellent, :got_a_shell, :exploit_worked, :wonderful
12
13
include Msf::SessionEvent
14
15
def play_sound(event)
16
queue.push(event)
17
end
18
19
def on_session_open(_session)
20
sound = [
21
excellent,
22
got_a_shell,
23
exploit_worked,
24
wonderful
25
].sample
26
play_sound(sound)
27
end
28
29
def on_session_close(session, reason = '')
30
# Cannot find an audio clip of muts saying something suitable for this.
31
end
32
33
def on_session_fail(_reason = '')
34
play_sound(try_harder)
35
end
36
37
def on_plugin_load; end
38
39
def on_plugin_unload; end
40
41
def start_sound_queue
42
self.queue_thread = Thread.new do
43
loop do
44
while (event = queue.shift)
45
path = ::File.join(base, theme, "#{event}.wav")
46
if ::File.exist?(path)
47
Rex::Compat.play_sound(path)
48
else
49
print_status("Warning: sound file not found: #{path}")
50
end
51
end
52
select(nil, nil, nil, 0.25)
53
end
54
rescue ::Exception => e
55
print_status("Sound plugin: fatal error #{e} #{e.backtrace}")
56
end
57
end
58
59
def stop_sound_queue
60
queue_thread.kill if queue_thread
61
self.queue_thread = nil
62
self.queue = []
63
end
64
65
def init_sound_paths
66
@try_harder = 'try_harder'
67
@excellent = 'excellent'
68
@got_a_shell = 'got_a_shell'
69
@exploit_worked = 'exploit_worked'
70
@wonderful = 'wonderful'
71
end
72
73
def initialize(framework, opts)
74
super
75
76
init_sound_paths
77
78
self.queue = []
79
self.theme = opts['theme'] || 'default'
80
self.base = File.join(Msf::Config.data_directory, 'sounds')
81
self.framework.events.add_session_subscriber(self)
82
start_sound_queue
83
84
on_plugin_load
85
end
86
87
def cleanup
88
on_plugin_unload
89
framework.events.remove_session_subscriber(self)
90
stop_sound_queue
91
end
92
93
def name
94
'sounds'
95
end
96
97
def desc
98
'Automatically plays a sound when various framework events occur'
99
end
100
101
end
102
end
103
104