Class: Msf::Serializer::Json

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/base/serializer/json.rb

Overview

This class formats information in a json format that is meant to be displayed on a console or some other non-GUI medium.

Class Method Summary collapse

Class Method Details

.dump_authors(mod) ⇒ Array

Returns an array of all authors

Parameters:

Returns:

  • (Array)

    an array of all authors



157
158
159
160
161
162
# File 'lib/msf/base/serializer/json.rb', line 157

def self.dump_authors(mod)
  # Authors
  authors = []
  mod.each_author { |author| authors.push(author.to_s) }
  authors
end

.dump_auxiliary_module(mod) ⇒ String

Dumps information about an auxiliary module.

Parameters:

Returns:

  • (String)

    the string form of the information.



114
115
116
117
118
119
120
121
122
# File 'lib/msf/base/serializer/json.rb', line 114

def self.dump_auxiliary_module(mod)
  # Return a json dump of auxiliary module data
  {
    'license' => mod.license,
    'disclosure_date' => (mod.disclosure_date if mod.disclosure_date),
    'actions' => dump_module_actions(mod),
    'references' => dump_references(mod)
  }.merge(dump_common_module_info(mod)).to_json
end

.dump_basic_module(mod) ⇒ String

Dumps information about a module, just the basics.

Parameters:

Returns:

  • (String)

    the string form of the information.



168
169
170
171
172
173
174
# File 'lib/msf/base/serializer/json.rb', line 168

def self.dump_basic_module(mod)
  {
    'platform' => mod.platform_to_s,
    'arch' => mod.arch_to_s,
    'references' => dump_references(mod)
  }.merge(dump_common_module_info(mod)).to_json
end

.dump_common_module_info(mod) ⇒ Object

Dumps information common to all modules



80
81
82
83
84
85
86
87
88
89
# File 'lib/msf/base/serializer/json.rb', line 80

def self.dump_common_module_info(mod)
  {
    'name' => mod.name,
    'fullname' => mod.fullname,
    'authors' => dump_authors(mod),
    'rank' => mod.rank_to_s.capitalize,
    'description' => Rex::Text.compress(mod.description),
    'options' => dump_options(mod)
  }
end

.dump_exploit_module(mod) ⇒ String

Dumps information about an exploit module.

Parameters:

Returns:

  • (String)

    the json string form of the information.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/msf/base/serializer/json.rb', line 95

def self.dump_exploit_module(mod)
  # Return a json dump of exploit module data
  {
    'platform' => mod.platform_to_s,
    'privileged' => (mod.privileged? ? "Yes" : "No"),
    'license' => mod.license,
    'disclosure_date' => (mod.disclosure_date if mod.disclosure_date),
    'payload' => {
      'space' => (mod.payload_space.to_s if mod.payload_space),
      'badchars' => (mod.payload_badchars.length.to_s if mod.payload_badchars)
    },
    'references' => dump_references(mod)
  }.merge(dump_common_module_info(mod)).to_json
end

.dump_exploit_targets(mod) ⇒ Array

Dumps an exploit’s targets.

Parameters:

  • mod (Msf::Exploit)

    the exploit module to dump targets for.

Returns:

  • (Array)

    the exploit targets



43
44
45
46
47
48
49
# File 'lib/msf/base/serializer/json.rb', line 43

def self.dump_exploit_targets(mod)
  list = []

  mod.targets.each { |target| list.push(target.name || 'All') }

  list
end

.dump_module(mod, _indent = "") ⇒ String

Returns a formatted string that contains information about the supplied module instance.

Parameters:

  • mod (Msf::Module)

    the module to dump information for.

  • _indent (String) (defaults to: "")

    the indentation to use.

Returns:

  • (String)

    formatted text output of the dump.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/msf/base/serializer/json.rb', line 19

def self.dump_module(mod, _indent = "")
  case mod.type
  when Msf::MODULE_PAYLOAD
    return dump_payload_module(mod)
  when Msf::MODULE_NOP
    return dump_basic_module(mod)
  when Msf::MODULE_ENCODER
    return dump_basic_module(mod)
  when Msf::MODULE_EXPLOIT
    return dump_exploit_module(mod)
  when Msf::MODULE_AUX
    return dump_auxiliary_module(mod)
  when Msf::MODULE_POST
    return dump_post_module(mod)
  else
    return dump_basic_module(mod)
  end
end

.dump_module_action(mod) ⇒ Array

Dumps the module’s selected action

Parameters:

Returns:

  • (Array)

    the module options



70
71
72
73
74
75
76
77
# File 'lib/msf/base/serializer/json.rb', line 70

def self.dump_module_action(mod)
  list = []

  list.push('name' => (mod.action.name || 'All'),
            'description' => (mod.action.description || ''))

  list
end

.dump_module_actions(mod) ⇒ Array

Dumps a module’s actions

Parameters:

Returns:

  • (Array)

    the module actions



55
56
57
58
59
60
61
62
63
64
# File 'lib/msf/base/serializer/json.rb', line 55

def self.dump_module_actions(mod)
  list = []

  mod.actions.each do |target|
    list.push('name' => (target.name || 'All'),
              'description' => (target.description || ''))
  end

  list
end

.dump_options(mod) ⇒ Array

Dumps the list of options associated with the supplied module.

Parameters:

Returns:

  • (Array)

    the array of the information.



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/msf/base/serializer/json.rb', line 181

def self.dump_options(mod)
  list = []
  mod.options.sorted.each do |entry|
    name, opt = entry
    val = mod.datastore[name] || opt.default

    next if opt.advanced? || opt.evasion?

    list.push('name' => name,
              'display_value' => opt.display_value(val),
              'required' => opt.required? ? 'true' : 'false',
              'description' => opt.desc.strip)
  end

  list
end

.dump_payload_module(mod) ⇒ String

Dumps information about a payload module.

Parameters:

Returns:

  • (String)

    the string form of the information.



143
144
145
146
147
148
149
150
151
# File 'lib/msf/base/serializer/json.rb', line 143

def self.dump_payload_module(mod)
  # Return a json dump of post module data
  {
    'platform' => mod.platform_to_s,
    'arch' => mod.arch_to_s,
    'privileged' => (mod.privileged? ? "true" : "false"),
    'size' => mod.size
  }.merge(dump_common_module_info(mod)).to_json
end

.dump_post_module(mod) ⇒ String

Dumps information about a post module.

Parameters:

Returns:

  • (String)

    the string form of the information.



128
129
130
131
132
133
134
135
136
137
# File 'lib/msf/base/serializer/json.rb', line 128

def self.dump_post_module(mod)
  # Return a json dump of post module data
  {
    'platform' => mod.platform_to_s,
    'arch' => mod.arch_to_s,
    'disclosure_date' => (mod.disclosure_date if mod.disclosure_date),
    'actions' => dump_module_actions(mod),
    'references' => dump_references(mod)
  }.merge(dump_common_module_info(mod)).to_json
end

.dump_references(mod) ⇒ Array

Dumps the references associated with the supplied module.

Parameters:

Returns:

  • (Array)

    the array of the information.



202
203
204
205
206
207
208
209
# File 'lib/msf/base/serializer/json.rb', line 202

def self.dump_references(mod)
  if (mod.respond_to? :references) && mod.references && (mod.references.length > 0)
    refs = []
    mod.references.each { |ref| refs.push(ref.to_s) }
  end

  refs
end