Class: Msf::PersistentStorage::Flatfile

Inherits:
Msf::PersistentStorage show all
Defined in:
lib/msf/base/persistent_storage/flatfile.rb

Overview

This class persists the state of the framework to a flatfile in a human readable format. At the moment, the level of information it conveys is rather basic and ugly, but this is just a prototype, so it will be improved. Oh yes, it will be improved.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Msf::PersistentStorage

add_storage_class, create, #fetch

Constructor Details

#initialize(path) ⇒ Flatfile

Initializes the flatfile for storage based on the parameters specified. The hash must contain a FilePath attribute.

Initializes the flatfile with the set path.

Parameters:

  • path (String)

    path of the flatfile.

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/msf/base/persistent_storage/flatfile.rb', line 17

def initialize(*params)
  raise ArgumentError, "You must specify a file path" if (params.length == 0)

  self.path = params[0]
end

Instance Attribute Details

#fdObject (protected)

:nodoc:



41
42
43
# File 'lib/msf/base/persistent_storage/flatfile.rb', line 41

def fd
  @fd
end

#pathObject (protected)

:nodoc:



41
42
43
# File 'lib/msf/base/persistent_storage/flatfile.rb', line 41

def path
  @path
end

Instance Method Details

#store(framework) ⇒ void

This method returns an undefined value.

This method stores the current state of the framework in human readable form to a flatfile. This can be used as a reporting mechanism.

Parameters:

  • framework (Msf:::Framework)

    the Framework to store.



28
29
30
31
32
33
34
35
36
37
# File 'lib/msf/base/persistent_storage/flatfile.rb', line 28

def store(framework)
  # Open the supplied file path for writing.
  self.fd = File.new(self.path, "w")

  begin
    store_general(framework)
  ensure
    self.fd.close
  end
end

#store_general(framework) ⇒ void (protected)

This method returns an undefined value.

This method stores general information about the current state of the framework instance.

Parameters:



48
49
50
51
52
53
54
# File 'lib/msf/base/persistent_storage/flatfile.rb', line 48

def store_general(framework)
  fd.print(
    "\n" +
    "Metasploit Framework Report\n" +
    "===========================\n\n" +
    "Generated: #{Time.now}\n\n")
end