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.


85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'plugins/sounds.rb', line 85

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

  self.on_plugin_load
end

Instance Attribute Details

#baseObject

Returns the value of attribute base


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

def base
  @base
end

#excellentObject (readonly)

Returns the value of attribute excellent


17
18
19
# File 'plugins/sounds.rb', line 17

def excellent
  @excellent
end

#exploit_workedObject (readonly)

Returns the value of attribute exploit_worked


17
18
19
# File 'plugins/sounds.rb', line 17

def exploit_worked
  @exploit_worked
end

#got_a_shellObject (readonly)

Returns the value of attribute got_a_shell


17
18
19
# File 'plugins/sounds.rb', line 17

def got_a_shell
  @got_a_shell
end

#queueObject

Returns the value of attribute queue


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

def queue
  @queue
end

#queue_threadObject

Returns the value of attribute queue_thread


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

def queue_thread
  @queue_thread
end

#themeObject

Returns the value of attribute theme


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

def theme
  @theme
end

#try_harderObject (readonly)

Returns the value of attribute try_harder


17
18
19
# File 'plugins/sounds.rb', line 17

def try_harder
  @try_harder
end

#wonderfulObject (readonly)

Returns the value of attribute wonderful


17
18
19
# File 'plugins/sounds.rb', line 17

def wonderful
  @wonderful
end

Instance Method Details

#cleanupObject


99
100
101
102
103
# File 'plugins/sounds.rb', line 99

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

#descObject


109
110
111
# File 'plugins/sounds.rb', line 109

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

#init_sound_pathsObject


76
77
78
79
80
81
82
# File 'plugins/sounds.rb', line 76

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

#nameObject


105
106
107
# File 'plugins/sounds.rb', line 105

def name
  "sounds"
end

#on_plugin_loadObject


43
44
# File 'plugins/sounds.rb', line 43

def on_plugin_load
end

#on_plugin_unloadObject


46
47
# File 'plugins/sounds.rb', line 46

def on_plugin_unload
end

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


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

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

#on_session_fail(reason = '') ⇒ Object


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

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

#on_session_open(session) ⇒ Object


25
26
27
28
29
30
31
32
33
# File 'plugins/sounds.rb', line 25

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

#play_sound(event) ⇒ Object


21
22
23
# File 'plugins/sounds.rb', line 21

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

#start_sound_queueObject


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'plugins/sounds.rb', line 49

def start_sound_queue
  self.queue_thread = Thread.new do
    begin
    while(true)
      while(event = self.queue.shift)
        path = ::File.join(self.base, self.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
end

#stop_sound_queueObject


69
70
71
72
73
# File 'plugins/sounds.rb', line 69

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