Class: Msf::Plugin::EventSounds

Inherits:
Msf::Plugin show all
Includes:
SessionEvent
Defined in:
plugins/sounds.rb

Overview

This class hooks all session creation events and plays a sound

Instance Attribute Summary collapse

Attributes inherited from Msf::Plugin

#opts

Attributes included from Framework::Offspring

#framework

Instance Method Summary collapse

Methods included from SessionEvent

#on_session_command, #on_session_download, #on_session_filedelete, #on_session_interact, #on_session_output, #on_session_upload

Methods inherited from Msf::Plugin

#add_console_dispatcher, create, #flush, #input, #output, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #remove_console_dispatcher

Constructor Details

#initialize(framework, opts) ⇒ EventSounds

Returns a new instance of EventSounds.



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'plugins/sounds.rb', line 73

def initialize(framework, opts)
  super

  init_sound_paths

  self.queue = []
  self.theme = opts['theme'] || 'default'
  self.base = File.join(Msf::Config.data_directory, 'sounds')
  self.framework.events.add_session_subscriber(self)
  start_sound_queue

  on_plugin_load
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



10
11
12
# File 'plugins/sounds.rb', line 10

def base
  @base
end

#excellentObject (readonly)

Returns the value of attribute excellent.



11
12
13
# File 'plugins/sounds.rb', line 11

def excellent
  @excellent
end

#exploit_workedObject (readonly)

Returns the value of attribute exploit_worked.



11
12
13
# File 'plugins/sounds.rb', line 11

def exploit_worked
  @exploit_worked
end

#got_a_shellObject (readonly)

Returns the value of attribute got_a_shell.



11
12
13
# File 'plugins/sounds.rb', line 11

def got_a_shell
  @got_a_shell
end

#queueObject

Returns the value of attribute queue.



10
11
12
# File 'plugins/sounds.rb', line 10

def queue
  @queue
end

#queue_threadObject

Returns the value of attribute queue_thread.



10
11
12
# File 'plugins/sounds.rb', line 10

def queue_thread
  @queue_thread
end

#themeObject

Returns the value of attribute theme.



10
11
12
# File 'plugins/sounds.rb', line 10

def theme
  @theme
end

#try_harderObject (readonly)

Returns the value of attribute try_harder.



11
12
13
# File 'plugins/sounds.rb', line 11

def try_harder
  @try_harder
end

#wonderfulObject (readonly)

Returns the value of attribute wonderful.



11
12
13
# File 'plugins/sounds.rb', line 11

def wonderful
  @wonderful
end

Instance Method Details

#cleanupObject



87
88
89
90
91
# File 'plugins/sounds.rb', line 87

def cleanup
  on_plugin_unload
  framework.events.remove_session_subscriber(self)
  stop_sound_queue
end

#descObject



97
98
99
# File 'plugins/sounds.rb', line 97

def desc
  'Automatically plays a sound when various framework events occur'
end

#init_sound_pathsObject



65
66
67
68
69
70
71
# File 'plugins/sounds.rb', line 65

def init_sound_paths
  @try_harder = 'try_harder'
  @excellent = 'excellent'
  @got_a_shell = 'got_a_shell'
  @exploit_worked = 'exploit_worked'
  @wonderful = 'wonderful'
end

#nameObject



93
94
95
# File 'plugins/sounds.rb', line 93

def name
  'sounds'
end

#on_plugin_loadObject



37
# File 'plugins/sounds.rb', line 37

def on_plugin_load; end

#on_plugin_unloadObject



39
# File 'plugins/sounds.rb', line 39

def on_plugin_unload; end

#on_session_close(session, reason = '') ⇒ Object



29
30
31
# File 'plugins/sounds.rb', line 29

def on_session_close(session, reason = '')
  # Cannot find an audio clip of muts saying something suitable for this.
end

#on_session_fail(_reason = '') ⇒ Object



33
34
35
# File 'plugins/sounds.rb', line 33

def on_session_fail(_reason = '')
  play_sound(try_harder)
end

#on_session_open(_session) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'plugins/sounds.rb', line 19

def on_session_open(_session)
  sound = [
    excellent,
    got_a_shell,
    exploit_worked,
    wonderful
  ].sample
  play_sound(sound)
end

#play_sound(event) ⇒ Object



15
16
17
# File 'plugins/sounds.rb', line 15

def play_sound(event)
  queue.push(event)
end

#start_sound_queueObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'plugins/sounds.rb', line 41

def start_sound_queue
  self.queue_thread = Thread.new do
    loop do
      while (event = queue.shift)
        path = ::File.join(base, theme, "#{event}.wav")
        if ::File.exist?(path)
          Rex::Compat.play_sound(path)
        else
          print_status("Warning: sound file not found: #{path}")
        end
      end
      select(nil, nil, nil, 0.25)
    end
  rescue ::Exception => e
    print_status("Sound plugin: fatal error #{e} #{e.backtrace}")
  end
end

#stop_sound_queueObject



59
60
61
62
63
# File 'plugins/sounds.rb', line 59

def stop_sound_queue
  queue_thread.kill if queue_thread
  self.queue_thread = nil
  self.queue = []
end