Class: Msf::Plugin::EventRSS

Inherits:
Msf::Plugin show all
Includes:
SessionEvent
Defined in:
plugins/rssfeed.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Msf::Plugin

#opts

Attributes included from Framework::Offspring

#framework

Instance Method Summary collapse

Methods included from SessionEvent

#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.


93
94
95
96
97
98
99
100
101
102
103
# File 'plugins/rssfeed.rb', line 93

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

Instance Attribute Details

#itemsObject

Returns the value of attribute items


11
12
13
# File 'plugins/rssfeed.rb', line 11

def items
  @items
end

#queueObject

Returns the value of attribute queue


11
12
13
# File 'plugins/rssfeed.rb', line 11

def queue
  @queue
end

#queue_threadObject

Returns the value of attribute queue_thread


11
12
13
# File 'plugins/rssfeed.rb', line 11

def queue_thread
  @queue_thread
end

Instance Method Details

#add_event(event) ⇒ Object


15
16
17
# File 'plugins/rssfeed.rb', line 15

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

#cleanupObject


105
106
107
108
109
# File 'plugins/rssfeed.rb', line 105

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

#create_session_item(session, status) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
# File 'plugins/rssfeed.rb', line 39

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

#descObject


115
116
117
# File 'plugins/rssfeed.rb', line 115

def desc
  "Create an RSS feed of events"
end

#generate_feed(newitem) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'plugins/rssfeed.rb', line 19

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

#nameObject


111
112
113
# File 'plugins/rssfeed.rb', line 111

def name
  "rss"
end

#on_plugin_loadObject


63
64
65
# File 'plugins/rssfeed.rb', line 63

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_unloadObject


67
68
69
# File 'plugins/rssfeed.rb', line 67

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


56
57
58
# File 'plugins/rssfeed.rb', line 56

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

#on_session_fail(reason = '') ⇒ Object


60
61
# File 'plugins/rssfeed.rb', line 60

def on_session_fail(reason='')
end

#on_session_open(session) ⇒ Object


52
53
54
# File 'plugins/rssfeed.rb', line 52

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

#start_event_queueObject


71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'plugins/rssfeed.rb', line 71

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

#stop_event_queueObject


86
87
88
89
90
# File 'plugins/rssfeed.rb', line 86

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