Class: Msf::Plugin::EventLibnotify

Inherits:
Msf::Plugin show all
Includes:
DatabaseEvent, SessionEvent
Defined in:
plugins/libnotify.rb

Instance Attribute Summary

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) ⇒ EventLibnotify

Returns a new instance of EventLibnotify.


14
15
16
17
18
19
20
21
22
23
24
# File 'plugins/libnotify.rb', line 14

def initialize(framework, opts)
  super

  @bin = opts[:bin] || opts['bin'] || `which notify-send`.chomp
  @bin_opts = opts[:opts] || opts['opts'] || '--app-name=Metasploit'

  raise 'libnotify not found' if @bin.empty?

  self.framework.events.add_session_subscriber(self)
  self.framework.events.add_db_subscriber(self)
end

Instance Method Details

#cleanupObject


82
83
84
85
# File 'plugins/libnotify.rb', line 82

def cleanup
  self.framework.events.remove_session_subscriber(self)
  self.framework.events.remove_db_subscriber(self)
end

#descObject


91
92
93
# File 'plugins/libnotify.rb', line 91

def desc
  'Send desktop notification with libnotify on sessions & db events'
end

#nameObject


87
88
89
# File 'plugins/libnotify.rb', line 87

def name
  'libnotify'
end

#notify_send(urgency, title, message) ⇒ Object


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

def notify_send(urgency, title, message)
  begin
    system(@bin, @bin_opts, '-u', urgency, title, message)
  rescue StandarError => e
    puts "Error running #{@bin}: #{e.message}"
  end
end

#on_db_client(client) ⇒ Object


78
79
80
# File 'plugins/libnotify.rb', line 78

def on_db_client(client)
  notify_send('critical', 'New client', "New client connected: #{client.ua_string}")
end

#on_db_host(host) ⇒ Object


49
50
51
52
# File 'plugins/libnotify.rb', line 49

def on_db_host(host)
  notify_send('normal', 'New host',
              "Addess: #{host.address}\nOS: #{host.os_name}")
end

#on_db_host_state(host, ostate) ⇒ Object


54
55
56
57
# File 'plugins/libnotify.rb', line 54

def on_db_host_state(host, ostate)
  notify_send('normal', "Host #{host.address} changed",
              "OS: #{host.os_name}\nNb Services: #{host.service_count}\nNb vulns: #{host.vuln_count}\n")
end

#on_db_ref(ref) ⇒ Object


74
75
76
# File 'plugins/libnotify.rb', line 74

def on_db_ref(ref)
  notify_send('normal', 'New ref', "Reference #{ref.name} added in database.")
end

#on_db_service(service) ⇒ Object


59
60
61
62
# File 'plugins/libnotify.rb', line 59

def on_db_service(service)
  notify_send('normal', 'New service',
              "New service: #{service.host.address}:#{service.port}")
end

#on_db_service_state(service, port, ostate) ⇒ Object


64
65
66
67
# File 'plugins/libnotify.rb', line 64

def on_db_service_state(service, port, ostate)
  notify_send('normal', "Service #{service.host.address}:#{service.port} changed",
              "Name: #{service.name}\nState: #{service.state}\nProto: #{service.proto}\nInfo: #{service.info}")
end

#on_db_vuln(vuln) ⇒ Object


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

def on_db_vuln(vuln)
  notify_send('critical', "New vulnerability on #{vuln.host.address}:#{vuln.service ? vuln.service.port : '0'}",
              "Vuln: #{vuln.name}\nInfos: #{vuln.info}")
end

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


40
41
42
43
# File 'plugins/libnotify.rb', line 40

def on_session_close(session, reason='')
  notify_send('normal', 'Connection closed',
              "Session:#{session.sid} Type:#{session.type} closed.\n#{reason}")
end

#on_session_fail(reason = '') ⇒ Object


45
46
47
# File 'plugins/libnotify.rb', line 45

def on_session_fail(reason='')
  notify_send('critical', 'Session Failure!', reason)
end

#on_session_open(session) ⇒ Object


34
35
36
37
38
# File 'plugins/libnotify.rb', line 34

def on_session_open(session)
  notify_send('normal', 'Got Shell!',
              "New Session: #{session.sid}\nIP: #{session.session_host}\nPeer: #{session.tunnel_peer}\n"\
              "Platform: #{session.platform}\nType: #{session.type}")
end