Class: Msf::Modules::Metadata::Obj

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/modules/metadata/obj.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(module_instance, obj_hash = nil) ⇒ Obj

Returns a new instance of Obj.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/msf/core/modules/metadata/obj.rb', line 76

def initialize(module_instance, obj_hash = nil)
  unless obj_hash.nil?
    init_from_hash(obj_hash)
    return
  end

  @name               = module_instance.name
  @fullname           = module_instance.realname
  @aliases            = module_instance.aliases
  @disclosure_date    = module_instance.disclosure_date
  @rank               = module_instance.rank.to_i
  @type               = module_instance.type
  @description        = module_instance.description.to_s.strip
  @author             = module_instance.author.map{|x| x.to_s}
  @references         = module_instance.references.map{|x| [x.ctx_id, x.ctx_val].join("-") }
  @post_auth          = module_instance.post_auth?
  @default_credential = module_instance.default_cred?

  @platform           = module_instance.platform_to_s
  @platform_list      = module_instance.platform
  # Done to ensure that differences do not show up for the same array grouping
  sort_platform_string

  @arch               = module_instance.arch_to_s
  @rport              = module_instance.datastore['RPORT']
  @path               = module_instance.file_path
  @mod_time           = ::File.mtime(@path) rescue Time.now
  @ref_name           = module_instance.class.refname
  @needs_cleanup      = module_instance.respond_to?(:needs_cleanup) && module_instance.needs_cleanup

  if module_instance.respond_to?(:actions)
    @actions = module_instance.actions.sort_by(&:name).map do |action|
      {
        'name' => action.name,
        'description' => action.description
      }
    end
  end

  if module_instance.respond_to?(:autofilter_ports)
    @autofilter_ports = module_instance.autofilter_ports
  end
  if module_instance.respond_to?(:autofilter_services)
    @autofilter_services = module_instance.autofilter_services
  end

  install_path = Msf::Config.install_root.to_s
  if (@path.to_s.include? (install_path))
    @path = @path.sub(install_path, '')
    @is_install_path = true
  end

  if module_instance.respond_to?(:targets) and module_instance.targets
    @targets = module_instance.targets.map{|x| x.name}
  end

  # Store whether a module has a check method
  @check = module_instance.has_check?

  @notes = module_instance.notes

  @session_types = module_instance.respond_to?(:session_types) && module_instance.session_types

  if module_instance.respond_to?(:payload_type)
    @payload_type = module_instance.payload_type
    @staged = module_instance.staged?
  end
  if @staged
    @stage_refname = module_instance.stage_refname
    @stager_refname = module_instance.stager_refname
  end
  if @payload_type == Payload::Type::Adapter
    @adapter_refname = module_instance.adapter_refname
    @adapted_refname = module_instance.adapted_refname
  end

  # Due to potentially non-standard ASCII we force UTF-8 to ensure no problem with JSON serialization
  force_encoding(::Encoding::UTF_8)
end

Instance Attribute Details

#actionsHash (readonly)

Returns:

  • (Hash)


12
13
14
# File 'lib/msf/core/modules/metadata/obj.rb', line 12

def actions
  @actions
end

#adapted_refnameString? (readonly)

Returns Name of the adapted payload if applicable.

Returns:

  • (String, nil)

    Name of the adapted payload if applicable



68
69
70
# File 'lib/msf/core/modules/metadata/obj.rb', line 68

def adapted_refname
  @adapted_refname
end

#adapter_refnameString? (readonly)

Returns Name of the adapter if applicable.

Returns:

  • (String, nil)

    Name of the adapter if applicable



66
67
68
# File 'lib/msf/core/modules/metadata/obj.rb', line 66

def adapter_refname
  @adapter_refname
end

#aliasesArray<String> (readonly)

Returns:

  • (Array<String>)


18
19
20
# File 'lib/msf/core/modules/metadata/obj.rb', line 18

def aliases
  @aliases
end

#archString (readonly)

Returns:

  • (String)


36
37
38
# File 'lib/msf/core/modules/metadata/obj.rb', line 36

def arch
  @arch
end

#authorArray<String> (readonly)

Returns:

  • (Array<String>)


26
27
28
# File 'lib/msf/core/modules/metadata/obj.rb', line 26

def author
  @author
end

#autofilter_portsArray<Integer> (readonly)

Returns:

  • (Array<Integer>)


40
41
42
# File 'lib/msf/core/modules/metadata/obj.rb', line 40

def autofilter_ports
  @autofilter_ports
end

#autofilter_servicesArray<String> (readonly)

Returns:

  • (Array<String>)


42
43
44
# File 'lib/msf/core/modules/metadata/obj.rb', line 42

def autofilter_services
  @autofilter_services
end

#checkBoolean (readonly)

Returns:

  • (Boolean)


52
53
54
# File 'lib/msf/core/modules/metadata/obj.rb', line 52

def check
  @check
end

#default_credentialBoolean (readonly) Also known as: default_cred?

Returns:

  • (Boolean)


57
58
59
# File 'lib/msf/core/modules/metadata/obj.rb', line 57

def default_credential
  @default_credential
end

#descriptionString (readonly)

Returns:

  • (String)


28
29
30
# File 'lib/msf/core/modules/metadata/obj.rb', line 28

def description
  @description
end

#disclosure_dateDate (readonly)

Returns:

  • (Date)


22
23
24
# File 'lib/msf/core/modules/metadata/obj.rb', line 22

def disclosure_date
  @disclosure_date
end

#fullnameString (readonly)

Returns:

  • (String)


16
17
18
# File 'lib/msf/core/modules/metadata/obj.rb', line 16

def fullname
  @fullname
end

#is_install_pathBoolean (readonly)

Returns:

  • (Boolean)


48
49
50
# File 'lib/msf/core/modules/metadata/obj.rb', line 48

def is_install_path
  @is_install_path
end

#mod_timeTime (readonly)

Returns:

  • (Time)


46
47
48
# File 'lib/msf/core/modules/metadata/obj.rb', line 46

def mod_time
  @mod_time
end

#nameString (readonly)

Returns:

  • (String)


14
15
16
# File 'lib/msf/core/modules/metadata/obj.rb', line 14

def name
  @name
end

#notesHash (readonly)

Returns:

  • (Hash)


60
61
62
# File 'lib/msf/core/modules/metadata/obj.rb', line 60

def notes
  @notes
end

#payload_typeInteger (readonly)

Returns The type of payload, e.g. Single, Stager, Adapter.

Returns:

  • (Integer)

    The type of payload, e.g. Single, Stager, Adapter



64
65
66
# File 'lib/msf/core/modules/metadata/obj.rb', line 64

def payload_type
  @payload_type
end

#platformString (readonly)

Returns:

  • (String)


32
33
34
# File 'lib/msf/core/modules/metadata/obj.rb', line 32

def platform
  @platform
end

#platform_listMsf::Module::PlatformList (readonly)



34
35
36
# File 'lib/msf/core/modules/metadata/obj.rb', line 34

def platform_list
  @platform_list
end

#post_authBoolean (readonly) Also known as: post_auth?

Returns:

  • (Boolean)


54
55
56
# File 'lib/msf/core/modules/metadata/obj.rb', line 54

def post_auth
  @post_auth
end

#rankInteger (readonly)

Returns:

  • (Integer)


20
21
22
# File 'lib/msf/core/modules/metadata/obj.rb', line 20

def rank
  @rank
end

#ref_nameString (readonly)

Returns:

  • (String)


50
51
52
# File 'lib/msf/core/modules/metadata/obj.rb', line 50

def ref_name
  @ref_name
end

#referencesArray<String> (readonly)

Returns:

  • (Array<String>)


30
31
32
# File 'lib/msf/core/modules/metadata/obj.rb', line 30

def references
  @references
end

#rportInteger (readonly)

Returns:

  • (Integer)


38
39
40
# File 'lib/msf/core/modules/metadata/obj.rb', line 38

def rport
  @rport
end

#session_typesArray<String> (readonly)

Returns:

  • (Array<String>)


62
63
64
# File 'lib/msf/core/modules/metadata/obj.rb', line 62

def session_types
  @session_types
end

#stage_refnameString? (readonly)

Returns Name of the stage if applicable.

Returns:

  • (String, nil)

    Name of the stage if applicable



72
73
74
# File 'lib/msf/core/modules/metadata/obj.rb', line 72

def stage_refname
  @stage_refname
end

#stagedBoolean (readonly)

Returns Whether or not the payload is staged.

Returns:

  • (Boolean)

    Whether or not the payload is staged



70
71
72
# File 'lib/msf/core/modules/metadata/obj.rb', line 70

def staged
  @staged
end

#stager_refnameString? (readonly)

Returns Name of the stager if applicable.

Returns:

  • (String, nil)

    Name of the stager if applicable



74
75
76
# File 'lib/msf/core/modules/metadata/obj.rb', line 74

def stager_refname
  @stager_refname
end

#targetsArray<String>? (readonly)

Returns:

  • (Array<String>, nil)


44
45
46
# File 'lib/msf/core/modules/metadata/obj.rb', line 44

def targets
  @targets
end

#typeString (readonly)

Returns:

  • (String)


24
25
26
# File 'lib/msf/core/modules/metadata/obj.rb', line 24

def type
  @type
end

Class Method Details

.from_hash(obj_hash) ⇒ Object

Initialize this object from a hash



209
210
211
# File 'lib/msf/core/modules/metadata/obj.rb', line 209

def self.from_hash(obj_hash)
  return Obj.new(nil, obj_hash)
end

Instance Method Details

#pathObject



217
218
219
220
221
222
223
# File 'lib/msf/core/modules/metadata/obj.rb', line 217

def path
  if @is_install_path
    return ::File.join(Msf::Config.install_root, @path)
  end

  @path
end

#to_json(*args) ⇒ Object

Returns the JSON representation of the module metadata



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/msf/core/modules/metadata/obj.rb', line 159

def to_json(*args)
  data = {
    'name'               => @name,
    'fullname'           => @fullname,
    'aliases'            => @aliases,
    'rank'               => @rank,
    'disclosure_date'    => @disclosure_date.nil? ? nil : @disclosure_date.to_s,
    'type'               => @type,
    'author'             => @author,
    'description'        => @description,
    'references'         => @references,
    'platform'           => @platform,
    'arch'               => @arch,
    'rport'              => @rport,
    'autofilter_ports'   => @autofilter_ports,
    'autofilter_services'=> @autofilter_services,
    'targets'            => @targets,
    'mod_time'           => @mod_time.to_s,
    'path'               => @path,
    'is_install_path'    => @is_install_path,
    'ref_name'           => @ref_name,
    'check'              => @check,
    'post_auth'          => @post_auth,
    'default_credential' => @default_credential,
    'notes'              => @notes,
    'session_types'      => @session_types,
    'needs_cleanup'      => @needs_cleanup,
  }

  data['actions'] = @actions if @actions

  if @payload_type
    payload_data = {
      'payload_type'       => @payload_type,
      'adapter_refname'    => @adapter_refname,
      'adapted_refname'    => @adapted_refname,
      'adapted'            => @adapted,
      'staged'             => @staged,
      'stage_refname'      => @stage_refname,
      'stager_refname'     => @stager_refname,
    }.compact
    data.merge!(payload_data)
  end

  data.to_json(*args)
end

#update_mod_time(mod_time) ⇒ Object



213
214
215
# File 'lib/msf/core/modules/metadata/obj.rb', line 213

def update_mod_time(mod_time)
  @mod_time = mod_time
end