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/lib/msf/base/persistent_storage/flatfile.rb
Views: 11783
1
# -*- coding: binary -*-
2
module Msf
3
class PersistentStorage
4
5
# This class persists the state of the framework to a flatfile in a human
6
# readable format. At the moment, the level of information it conveys is
7
# rather basic and ugly, but this is just a prototype, so it will be improved.
8
# Oh yes, it will be improved.
9
class Flatfile < PersistentStorage
10
11
# Initializes the flatfile for storage based on the parameters specified.
12
# The hash must contain a FilePath attribute.
13
#
14
# @overload initialize(path)
15
# Initializes the flatfile with the set path.
16
# @param path [String] path of the flatfile.
17
def initialize(*params)
18
raise ArgumentError, "You must specify a file path" if (params.length == 0)
19
20
self.path = params[0]
21
end
22
23
# This method stores the current state of the framework in human readable
24
# form to a flatfile. This can be used as a reporting mechanism.
25
#
26
# @param framework [Msf:::Framework] the Framework to store.
27
# @return [void]
28
def store(framework)
29
# Open the supplied file path for writing.
30
self.fd = File.new(self.path, "w")
31
32
begin
33
store_general(framework)
34
ensure
35
self.fd.close
36
end
37
end
38
39
protected
40
41
attr_accessor :fd, :path # :nodoc:
42
43
# This method stores general information about the current state of the
44
# framework instance.
45
#
46
# @param framework [Msf::Framework] the Framework to store.
47
# @return [void]
48
def store_general(framework)
49
fd.print(
50
"\n" +
51
"Metasploit Framework Report\n" +
52
"===========================\n\n" +
53
"Generated: #{Time.now}\n\n")
54
end
55
56
Msf::PersistentStorage.add_storage_class('flatfile', self)
57
58
end
59
60
end
61
end
62
63