Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sounds.rb 2.2KB

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