forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibnotify.rb
91 lines (71 loc) · 2.61 KB
/
libnotify.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
###
#
# This plugin hooks all session creation and db events
# and send desktop notifications using notify-send command.
#
###
module Msf
class Plugin::EventLibnotify < Msf::Plugin
include Msf::SessionEvent
include Msf::DatabaseEvent
def initialize(framework, opts)
super
@bin = opts[:bin] || opts['bin'] || `which notify-send`.chomp
@bin_opts = opts[:opts] || opts['opts'] || '-a Metasploit'
raise 'libnotify not found' if @bin.empty?
self.framework.events.add_session_subscriber(self)
self.framework.events.add_db_subscriber(self)
end
def notify_send(urgency, title, message)
system("#{@bin} #{@bin_opts} -u #{urgency} '#{title}' '#{message}'")
end
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
def on_session_close(session, reason='')
notify_send('normal', 'Connection closed',
"Session:#{session.sid} Type:#{session.type} closed.\n#{reason}")
end
def on_session_fail(reason='')
notify_send('critical', 'Session Failure!', reason)
end
def on_db_host(host)
notify_send('normal', 'New host',
"Addess: #{host.address}\nOS: #{host.os_name}")
end
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
def on_db_service(service)
notify_send('normal', 'New service',
"New service: #{service.host.address}:#{service.port}")
end
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
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
def on_db_ref(ref)
notify_send('normal', 'New ref', "Reference #{ref.name} added in database.")
end
def on_db_client(client)
notify_send('critical', 'New client', "New client connected: #{client.ua_string}")
end
def cleanup
self.framework.events.remove_session_subscriber(self)
self.framework.events.remove_db_subscriber(self)
end
def name
'libnotify'
end
def desc
'Send desktop notification with libnotify on sessions & db events'
end
end
end