Class: Msf::Plugin::EventRSS
Overview
This class hooks all session events and puts it into an RSS feed
Instance Attribute Summary collapse
Attributes inherited from Msf::Plugin
#opts
#framework
Instance Method Summary
collapse
#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) ⇒ EventRSS
Returns a new instance of EventRSS.
88
89
90
91
92
93
94
95
96
97
98
|
# File 'plugins/rssfeed.rb', line 88
def initialize(framework, opts)
require 'rss'
super
@items = []
self.queue = Queue.new
self.framework.events.add_session_subscriber(self)
start_event_queue
on_plugin_load
end
|
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
10
11
12
|
# File 'plugins/rssfeed.rb', line 10
def items
@items
end
|
#queue ⇒ Object
Returns the value of attribute queue.
10
11
12
|
# File 'plugins/rssfeed.rb', line 10
def queue
@queue
end
|
#queue_thread ⇒ Object
Returns the value of attribute queue_thread.
10
11
12
|
# File 'plugins/rssfeed.rb', line 10
def queue_thread
@queue_thread
end
|
Instance Method Details
#add_event(event) ⇒ Object
14
15
16
|
# File 'plugins/rssfeed.rb', line 14
def add_event(event)
queue.push(event)
end
|
#cleanup ⇒ Object
100
101
102
103
104
|
# File 'plugins/rssfeed.rb', line 100
def cleanup
on_plugin_unload
framework.events.remove_session_subscriber(self)
stop_event_queue
end
|
#create_session_item(session, status) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'plugins/rssfeed.rb', line 38
def create_session_item(session, status)
if status == 'created'
select(nil, nil, nil, 25)
end
title = "#{session.type} session - #{session.sid} #{status}."
content = ''
if session.workspace
content << "Workspace:\t#{session.workspace}\n"
end
content << "Session Information: #{session.info}"
add_event({ title: title, date: Time.now.to_s, link: 'https://metasploit.com', content: content })
end
|
#desc ⇒ Object
110
111
112
|
# File 'plugins/rssfeed.rb', line 110
def desc
'Create an RSS feed of events'
end
|
#generate_feed(newitem) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'plugins/rssfeed.rb', line 18
def generate_feed(newitem)
items.unshift(newitem)
feed = RSS::Maker.make('atom') do |maker|
maker.channel.author = 'msfconsole'
maker.channel.updated = Time.new.to_s
maker.channel.about = 'https://metasploit.com'
maker.channel.title = 'msfconsole rss feed'
items.each do ||
maker.items.new_item do |item|
item.link = [:link]
item.title = [:title]
item.updated = [:date]
item.summary = [:content]
end
end
end
File.open('feed.rss', 'w') { |f| f.write(feed) }
end
|
#name ⇒ Object
106
107
108
|
# File 'plugins/rssfeed.rb', line 106
def name
'rss'
end
|
#on_plugin_load ⇒ Object
61
62
63
|
# File 'plugins/rssfeed.rb', line 61
def on_plugin_load
add_event({ title: 'RSS Plugin Loaded', date: Time.now.to_s, link: 'https://metasploit.com/', content: 'N/A' })
end
|
#on_plugin_unload ⇒ Object
65
66
67
|
# File 'plugins/rssfeed.rb', line 65
def on_plugin_unload
generate_feed({ title: 'RSS Plugin Unloaded', date: Time.now.to_s, link: 'https:/metasploit.com/', content: 'N/A' })
end
|
#on_session_close(session, _reason = '') ⇒ Object
55
56
57
|
# File 'plugins/rssfeed.rb', line 55
def on_session_close(session, _reason = '')
create_session_item(session, 'closed')
end
|
#on_session_fail(reason = '') ⇒ Object
59
|
# File 'plugins/rssfeed.rb', line 59
def on_session_fail(reason = ''); end
|
#on_session_open(session) ⇒ Object
51
52
53
|
# File 'plugins/rssfeed.rb', line 51
def on_session_open(session)
create_session_item(session, 'created')
end
|
#start_event_queue ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'plugins/rssfeed.rb', line 69
def start_event_queue
self.queue_thread = Rex::ThreadFactory.spawn('rss_plugin', false) do
loop do
while (event = queue.shift)
generate_feed(event)
end
select(nil, nil, nil, 0.25)
end
rescue ::Exception => e
print_status("RSS plugin: fatal error #{e} #{e.backtrace}")
end
end
|
#stop_event_queue ⇒ Object
82
83
84
85
86
|
# File 'plugins/rssfeed.rb', line 82
def stop_event_queue
queue_thread.kill if queue_thread
self.queue_thread = nil
queue.clear
end
|