-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
RSS feed plugin #8612
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
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 | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that so? TIL!