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.

libnotify.rb 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ###
  2. #
  3. # This plugin hooks all session creation and db events
  4. # and send desktop notifications using notify-send command.
  5. #
  6. ###
  7. module Msf
  8. class Plugin::EventLibnotify < Msf::Plugin
  9. include Msf::SessionEvent
  10. include Msf::DatabaseEvent
  11. def initialize(framework, opts)
  12. super
  13. @bin = opts[:bin] || opts['bin'] || `which notify-send`.chomp
  14. @bin_opts = opts[:opts] || opts['opts'] || '-a Metasploit'
  15. raise 'libnotify not found' if @bin.empty?
  16. self.framework.events.add_session_subscriber(self)
  17. self.framework.events.add_db_subscriber(self)
  18. end
  19. def notify_send(urgency, title, message)
  20. system("#{@bin} #{@bin_opts} -u #{urgency} '#{title}' '#{message}'")
  21. end
  22. def on_session_open(session)
  23. notify_send('normal', 'Got Shell!',
  24. "New Session: #{session.sid}\nIP: #{session.session_host}\nPeer: #{session.tunnel_peer}\n"\
  25. "Platform: #{session.platform}\nType: #{session.type}")
  26. end
  27. def on_session_close(session, reason='')
  28. notify_send('normal', 'Connection closed',
  29. "Session:#{session.sid} Type:#{session.type} closed.\n#{reason}")
  30. end
  31. def on_session_fail(reason='')
  32. notify_send('critical', 'Session Failure!', reason)
  33. end
  34. def on_db_host(host)
  35. notify_send('normal', 'New host',
  36. "Addess: #{host.address}\nOS: #{host.os_name}")
  37. end
  38. def on_db_host_state(host, ostate)
  39. notify_send('normal', "Host #{host.address} changed",
  40. "OS: #{host.os_name}\nNb Services: #{host.service_count}\nNb vulns: #{host.vuln_count}\n")
  41. end
  42. def on_db_service(service)
  43. notify_send('normal', 'New service',
  44. "New service: #{service.host.address}:#{service.port}")
  45. end
  46. def on_db_service_state(service, port, ostate)
  47. notify_send('normal', "Service #{service.host.address}:#{service.port} changed",
  48. "Name: #{service.name}\nState: #{service.state}\nProto: #{service.proto}\nInfo: #{service.info}")
  49. end
  50. def on_db_vuln(vuln)
  51. notify_send('critical', "New vulnerability on #{vuln.host.address}:#{vuln.service ? vuln.service.port : '0'}",
  52. "Vuln: #{vuln.name}\nInfos: #{vuln.info}")
  53. end
  54. def on_db_ref(ref)
  55. notify_send('normal', 'New ref', "Reference #{ref.name} added in database.")
  56. end
  57. def on_db_client(client)
  58. notify_send('critical', 'New client', "New client connected: #{client.ua_string}")
  59. end
  60. def cleanup
  61. self.framework.events.remove_session_subscriber(self)
  62. self.framework.events.remove_db_subscriber(self)
  63. end
  64. def name
  65. 'libnotify'
  66. end
  67. def desc
  68. 'Send desktop notification with libnotify on sessions & db events'
  69. end
  70. end
  71. end