Created
February 11, 2015 20:16
-
-
Save wchen-r7/aab69df542a5dc384925 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# $Id$ | |
# $Revision$ | |
# | |
module Msf | |
### | |
# | |
# This class hooks all session creation events and plays a sound | |
# | |
### | |
class Plugin::EventSounds < Msf::Plugin | |
attr_accessor :theme, :base, :queue, :queue_thread | |
# | |
# The following callbacks come from: | |
# lib/msf/core/database_event.rb | |
# | |
def on_db_client(client) | |
$stderr.puts "---------- Client is added to the database" | |
end | |
def on_db_host_state(host, ostate) | |
$stderr.puts "---------- Some host's state has changed" | |
end | |
def on_db_ref(ref) | |
$stderr.puts "---------- A new reference is created" | |
end | |
def on_db_service(service) | |
$stderr.puts "---------- A new service has been added" | |
end | |
def on_db_service_state(host, port, ostate) | |
$stderr.puts "---------- Service state changed" | |
end | |
def on_db_vuln(vuln) | |
$stderr.puts "--------- Some vuln reported" | |
end | |
# | |
# The following callbacks come from: | |
# lib/msf/core/event_dispatcher.rb | |
# | |
def on_module_load(refname, klass) | |
$stderr.puts "---------- Some module loaded" | |
end | |
def on_module_created(instance) | |
$stderr.puts "---------- new module created" | |
end | |
def on_module_run(instance) | |
$stderr.puts "---------- Module is running" | |
end | |
def on_module_complete(instance) | |
$stderr.puts "---------- Module completed" | |
end | |
def on_module_error(instance, exception) | |
$stderr.puts "---------- Module raised an exception" | |
end | |
# | |
# The following callback come from: | |
# lib/msf/core/exploit.rb | |
# | |
def on_exploit_success(exploit, session) | |
$stderr.puts "---------- My exploit" | |
end | |
# | |
# The following callbacks come from: | |
# lib/msf/core/session.rb | |
# | |
def on_session_interact(session) | |
$stderr.puts "---------- Interacting with a session" | |
end | |
def on_session_command(session, command) | |
$stderr.puts "---------- Writing data to a session" | |
end | |
def on_session_output(session, output) | |
$stderr.puts "---------- Output" | |
end | |
def on_session_upload(session, local_path, remote_path) | |
$stderr.puts "---------- Uploading a file" | |
end | |
def on_session_download(session, remote_path, local_path) | |
$stderr.puts "----------- Downloading a file" | |
end | |
def on_session_filedelete(session, path) | |
$stderr.puts "----------- Deleting a file" | |
end | |
def on_session_open(session) | |
$stderr.puts "---------- A session has opened" | |
end | |
def on_session_close(session, reason='') | |
$stderr.puts "---------- A session has closed" | |
end | |
# | |
# The following callbacks come from: | |
# The sounds.rb plugin | |
# | |
def on_plugin_load | |
$stderr.puts "---------- The plugin has loaded" | |
end | |
def on_plugin_unload | |
$stderr.puts "---------- The plugin has unloaded" | |
end | |
def initialize(framework, opts) | |
super | |
self.queue = [] | |
self.theme = opts['theme'] || 'default' | |
self.base = File.join(Msf::Config.data_directory, "sounds") | |
self.framework.events.add_session_subscriber(self) | |
self.framework.events.add_general_subscriber(self) | |
self.framework.events.add_db_subscriber(self) | |
self.framework.events.add_exploit_subscriber(self) | |
self.framework.events.add_event_subscriber(self) | |
start_sound_queue | |
self.on_plugin_load | |
end | |
def cleanup | |
self.on_plugin_unload | |
self.framework.events.remove_session_subscriber(self) | |
stop_sound_queue | |
end | |
def name | |
"sounds" | |
end | |
def desc | |
"Automatically plays a sound when various framework events occur" | |
end | |
private | |
def play_sound(event) | |
self.queue.push(event) | |
end | |
def start_sound_queue | |
self.queue_thread = Thread.new do | |
begin | |
while(true) | |
while(event = self.queue.shift) | |
$stderr.puts "---- Event: #{event.inspect}" | |
path = ::File.join(self.base, self.theme, "#{event}.wav") | |
if(::File.exists?(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 | |
def stop_sound_queue | |
self.queue_thread.kill if self.queue_thread | |
self.queue_thread = nil | |
self.queue = [] | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment