CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/plugins/rssfeed.rb
Views: 11705
1
module Msf
2
###
3
#
4
# This class hooks all session events and puts it into an RSS feed
5
#
6
###
7
8
class Plugin::EventRSS < Msf::Plugin
9
10
attr_accessor :items, :queue, :queue_thread
11
12
include Msf::SessionEvent
13
14
def add_event(event)
15
queue.push(event)
16
end
17
18
def generate_feed(newitem)
19
items.unshift(newitem)
20
feed = RSS::Maker.make('atom') do |maker|
21
maker.channel.author = 'msfconsole'
22
maker.channel.updated = Time.new.to_s
23
maker.channel.about = 'https://metasploit.com'
24
maker.channel.title = 'msfconsole rss feed'
25
26
items.each do |rssitem|
27
maker.items.new_item do |item|
28
item.link = rssitem[:link]
29
item.title = rssitem[:title]
30
item.updated = rssitem[:date]
31
item.summary = rssitem[:content]
32
end
33
end
34
end
35
File.open('feed.rss', 'w') { |f| f.write(feed) }
36
end
37
38
def create_session_item(session, status)
39
if status == 'created'
40
select(nil, nil, nil, 25)
41
end
42
title = "#{session.type} session - #{session.sid} #{status}."
43
content = ''
44
if session.workspace
45
content << "Workspace:\t#{session.workspace}\n"
46
end
47
content << "Session Information: #{session.info}"
48
add_event({ title: title, date: Time.now.to_s, link: 'https://metasploit.com', content: content })
49
end
50
51
def on_session_open(session)
52
create_session_item(session, 'created')
53
end
54
55
def on_session_close(session, _reason = '')
56
create_session_item(session, 'closed')
57
end
58
59
def on_session_fail(reason = ''); end
60
61
def on_plugin_load
62
add_event({ title: 'RSS Plugin Loaded', date: Time.now.to_s, link: 'https://metasploit.com/', content: 'N/A' })
63
end
64
65
def on_plugin_unload
66
generate_feed({ title: 'RSS Plugin Unloaded', date: Time.now.to_s, link: 'https:/metasploit.com/', content: 'N/A' })
67
end
68
69
def start_event_queue
70
self.queue_thread = Rex::ThreadFactory.spawn('rss_plugin', false) do
71
loop do
72
while (event = queue.shift)
73
generate_feed(event)
74
end
75
select(nil, nil, nil, 0.25)
76
end
77
rescue ::Exception => e
78
print_status("RSS plugin: fatal error #{e} #{e.backtrace}")
79
end
80
end
81
82
def stop_event_queue
83
queue_thread.kill if queue_thread
84
self.queue_thread = nil
85
queue.clear
86
end
87
88
def initialize(framework, opts)
89
require 'rss'
90
super
91
92
@items = []
93
self.queue = Queue.new
94
self.framework.events.add_session_subscriber(self)
95
start_event_queue
96
97
on_plugin_load
98
end
99
100
def cleanup
101
on_plugin_unload
102
framework.events.remove_session_subscriber(self)
103
stop_event_queue
104
end
105
106
def name
107
'rss'
108
end
109
110
def desc
111
'Create an RSS feed of events'
112
end
113
114
end
115
end
116
117