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.


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
# File 'lib/msf/core/modules/metadata/obj.rb', line 57

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
  # 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?(: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

  # 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

#aliasesArray<String> (readonly)

Returns:

  • (Array<String>)

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

def aliases
  @aliases
end

#archString (readonly)

Returns:

  • (String)

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

def arch
  @arch
end

#authorArray<String> (readonly)

Returns:

  • (Array<String>)

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

def author
  @author
end

#autofilter_portsArray<Integer> (readonly)

Returns:

  • (Array<Integer>)

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

def autofilter_ports
  @autofilter_ports
end

#autofilter_servicesArray<String> (readonly)

Returns:

  • (Array<String>)

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

def autofilter_services
  @autofilter_services
end

#checkBoolean (readonly)

Returns:

  • (Boolean)

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

def check
  @check
end

#default_credentialBoolean (readonly)

Returns:

  • (Boolean)

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

def default_credential
  @default_credential
end

#descriptionString (readonly)

Returns:

  • (String)

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

def description
  @description
end

#disclosure_dateDate (readonly)

Returns:

  • (Date)

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

def disclosure_date
  @disclosure_date
end

#fullnameString (readonly)

Returns:

  • (String)

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

def fullname
  @fullname
end

#is_install_pathBoolean (readonly)

Returns:

  • (Boolean)

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

def is_install_path
  @is_install_path
end

#mod_timeTime (readonly)

Returns:

  • (Time)

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

def mod_time
  @mod_time
end

#nameString (readonly)

Returns:

  • (String)

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

def name
  @name
end

#notesHash (readonly)

Returns:

  • (Hash)

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

def notes
  @notes
end

#platformBoolean (readonly)

Returns:

  • (Boolean)

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

def platform
  @platform
end

#post_authBoolean (readonly)

Returns:

  • (Boolean)

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

def post_auth
  @post_auth
end

#rankInteger (readonly)

Returns:

  • (Integer)

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

def rank
  @rank
end

#ref_nameString (readonly)

Returns:

  • (String)

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

def ref_name
  @ref_name
end

#referencesArray<String> (readonly)

Returns:

  • (Array<String>)

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

def references
  @references
end

#rportInteger (readonly)

Returns:

  • (Integer)

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

def rport
  @rport
end

#targetsArray<String> (readonly)

Returns:

  • (Array<String>)

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

def targets
  @targets
end

#typeString (readonly)

Returns:

  • (String)

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

def type
  @type
end

Class Method Details

.from_hash(obj_hash) ⇒ Object

Initialize this object from a hash


147
148
149
# File 'lib/msf/core/modules/metadata/obj.rb', line 147

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

Instance Method Details

#pathObject


155
156
157
158
159
160
161
# File 'lib/msf/core/modules/metadata/obj.rb', line 155

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


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
# File 'lib/msf/core/modules/metadata/obj.rb', line 115

def to_json(*args)
  {
    '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,
    'needs_cleanup'      => @needs_cleanup
  }.to_json(*args)
end

#update_mod_time(mod_time) ⇒ Object


151
152
153
# File 'lib/msf/core/modules/metadata/obj.rb', line 151

def update_mod_time(mod_time)
  @mod_time = mod_time
end