Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/plugins/libnotify.rb
Views: 11705
###1#2# This plugin hooks all session creation and db events3# and send desktop notifications using notify-send command.4#5###67module Msf8class Plugin::EventLibnotify < Msf::Plugin9include Msf::SessionEvent10include Msf::DatabaseEvent1112def initialize(framework, opts)13super1415@bin = opts[:bin] || opts['bin'] || `which notify-send`.chomp16@bin_opts = opts[:opts] || opts['opts'] || '--app-name=Metasploit'1718raise 'libnotify not found' if @bin.empty?1920self.framework.events.add_session_subscriber(self)21self.framework.events.add_db_subscriber(self)22end2324def notify_send(urgency, title, message)25system(@bin, @bin_opts, '-u', urgency, title, message)26rescue StandarError => e27puts "Error running #{@bin}: #{e.message}"28end2930def on_session_open(session)31notify_send('normal', 'Got Shell!',32"New Session: #{session.sid}\nIP: #{session.session_host}\nPeer: #{session.tunnel_peer}\n"\33"Platform: #{session.platform}\nType: #{session.type}")34end3536def on_session_close(session, reason = '')37notify_send('normal', 'Connection closed',38"Session:#{session.sid} Type:#{session.type} closed.\n#{reason}")39end4041def on_session_fail(reason = '')42notify_send('critical', 'Session Failure!', reason)43end4445def on_db_host(host)46notify_send('normal', 'New host',47"Address: #{host.address}\nOS: #{host.os_name}")48end4950def on_db_host_state(host, _ostate)51notify_send('normal', "Host #{host.address} changed",52"OS: #{host.os_name}\nNb Services: #{host.service_count}\nNb vulns: #{host.vuln_count}\n")53end5455def on_db_service(service)56notify_send('normal', 'New service',57"New service: #{service.host.address}:#{service.port}")58end5960def on_db_service_state(service, _port, _ostate)61notify_send('normal', "Service #{service.host.address}:#{service.port} changed",62"Name: #{service.name}\nState: #{service.state}\nProto: #{service.proto}\nInfo: #{service.info}")63end6465def on_db_vuln(vuln)66notify_send('critical', "New vulnerability on #{vuln.host.address}:#{vuln.service ? vuln.service.port : '0'}",67"Vuln: #{vuln.name}\nInfos: #{vuln.info}")68end6970def on_db_ref(ref)71notify_send('normal', 'New ref', "Reference #{ref.name} added in database.")72end7374def on_db_client(client)75notify_send('critical', 'New client', "New client connected: #{client.ua_string}")76end7778def cleanup79framework.events.remove_session_subscriber(self)80framework.events.remove_db_subscriber(self)81end8283def name84'libnotify'85end8687def desc88'Send desktop notification with libnotify on sessions and db events'89end90end91end929394