Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSS feed plugin #8612

Merged
merged 3 commits into from
Jul 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions plugins/rssfeed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
module Msf

###
#
# This class hooks all session events and puts it into an RSS feed
#
###

class Plugin::EventRSS < Msf::Plugin

attr_accessor :items, :queue, :queue_thread

include Msf::SessionEvent

def add_event(event)
self.queue.push(event)
end

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
end
end
File.open("feed.rss", 'w') {|f| f.write(feed) }
end

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

def on_session_open(session)
create_session_item(session, "created")
end

def on_session_close(session, reason='')
create_session_item(session, "closed")
end

def on_session_fail(reason='')
end

def on_plugin_load
add_event({title: "RSS Plugin Loaded", date: Time.now.to_s, link: "https://metasploit.com/", content: "N/A"})
end

def on_plugin_unload
generate_feed({title: "RSS Plugin Unloaded", date: Time.now.to_s, link: "https:/metasploit.com/", content: "N/A"})
end

def start_event_queue
self.queue_thread = Rex::ThreadFactory.spawn("rss_plugin", false) do
begin
while(true)
while(event = self.queue.shift)
generate_feed(event)
end
select(nil, nil, nil, 0.25)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to double check how the select call here actually traverses the overrides, but im leaning toward "this is a native select call" which may also have some issues esp in a GIL-free VM. Where have a Rex::ThreadSafe.select method which should handle those potential edge cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The man himself overloaded Kernel.select to avoid these calls being a problem - withdrawn.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that so? TIL!

end
rescue ::Exception => e
print_status("RSS plugin: fatal error #{e} #{e.backtrace}")
end
end
end

def stop_event_queue
self.queue_thread.kill if self.queue_thread
self.queue_thread = nil
self.queue.clear
end


def initialize(framework, opts)
require 'rss'
super

@items = []
self.queue = Queue.new
self.framework.events.add_session_subscriber(self)
start_event_queue

self.on_plugin_load
end

def cleanup
self.on_plugin_unload
self.framework.events.remove_session_subscriber(self)
stop_event_queue
end

def name
"rss"
end

def desc
"Create an RSS feed of events"
end

end
end