Files
metasploit-gs/plugins/rssfeed.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
2.8 KiB
Ruby
Raw Normal View History

2017-06-25 13:22:46 -05:00
module Msf
2023-01-30 12:25:46 +11:00
###
#
# This class hooks all session events and puts it into an RSS feed
#
###
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
class Plugin::EventRSS < Msf::Plugin
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
attr_accessor :items, :queue, :queue_thread
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
include Msf::SessionEvent
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def add_event(event)
queue.push(event)
end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
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 |rssitem|
maker.items.new_item do |item|
item.link = rssitem[:link]
item.title = rssitem[:title]
item.updated = rssitem[:date]
item.summary = rssitem[:content]
end
2017-06-25 13:22:46 -05:00
end
end
2023-01-30 12:25:46 +11:00
File.open('feed.rss', 'w') { |f| f.write(feed) }
2017-06-25 13:22:46 -05:00
end
2023-01-30 12:25:46 +11:00
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 })
2017-07-24 13:47:37 -07:00
end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def on_session_open(session)
create_session_item(session, 'created')
end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def on_session_close(session, _reason = '')
create_session_item(session, 'closed')
end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def on_session_fail(reason = ''); end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def on_plugin_load
add_event({ title: 'RSS Plugin Loaded', date: Time.now.to_s, link: 'https://metasploit.com/', content: 'N/A' })
end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def on_plugin_unload
generate_feed({ title: 'RSS Plugin Unloaded', date: Time.now.to_s, link: 'https:/metasploit.com/', content: 'N/A' })
end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def start_event_queue
self.queue_thread = Rex::ThreadFactory.spawn('rss_plugin', false) do
2023-01-30 13:05:34 +11:00
loop do
2023-01-30 12:25:46 +11:00
while (event = queue.shift)
generate_feed(event)
end
select(nil, nil, nil, 0.25)
2017-06-25 13:22:46 -05:00
end
2023-01-30 13:07:16 +11:00
rescue ::Exception => e
print_status("RSS plugin: fatal error #{e} #{e.backtrace}")
2017-06-25 13:22:46 -05:00
end
end
2023-01-30 12:25:46 +11:00
def stop_event_queue
queue_thread.kill if queue_thread
self.queue_thread = nil
queue.clear
end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def initialize(framework, opts)
require 'rss'
super
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
@items = []
self.queue = Queue.new
self.framework.events.add_session_subscriber(self)
start_event_queue
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
on_plugin_load
end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def cleanup
on_plugin_unload
framework.events.remove_session_subscriber(self)
stop_event_queue
end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def name
'rss'
end
2017-06-25 13:22:46 -05:00
2023-01-30 12:25:46 +11:00
def desc
'Create an RSS feed of events'
end
2017-06-25 13:22:46 -05:00
end
end