Class: Msf::Modules::Metadata::Obj
- Inherits:
-
Object
- Object
- Msf::Modules::Metadata::Obj
- Defined in:
- lib/msf/core/modules/metadata/obj.rb
Constant Summary collapse
- EMPTY_ARRAY =
Frozen shared objects to avoid allocating duplicate empty containers
[].freeze
- EMPTY_HASH =
{}.freeze
Instance Attribute Summary collapse
- #actions ⇒ Hash readonly
-
#adapted_refname ⇒ String?
readonly
Name of the adapted payload if applicable.
-
#adapter_refname ⇒ String?
readonly
Name of the adapter if applicable.
- #aliases ⇒ Array<String> readonly
- #arch ⇒ String readonly
- #author ⇒ Array<String> readonly
- #autofilter_ports ⇒ Array<Integer> readonly
- #autofilter_services ⇒ Array<String> readonly
- #check ⇒ Boolean readonly
- #default_credential ⇒ Boolean (also: #default_cred?) readonly
- #description ⇒ String readonly
- #disclosure_date ⇒ Date readonly
- #fullname ⇒ String readonly
- #is_install_path ⇒ Boolean readonly
- #mod_time ⇒ Time readonly
- #name ⇒ String readonly
- #notes ⇒ Hash readonly
-
#payload_type ⇒ Integer
readonly
The type of payload, e.g.
- #platform ⇒ String readonly
- #platform_list ⇒ Msf::Module::PlatformList readonly
- #post_auth ⇒ Boolean (also: #post_auth?) readonly
- #rank ⇒ Integer readonly
- #ref_name ⇒ String readonly
- #references ⇒ Array<String> readonly
- #rport ⇒ Integer readonly
- #session_types ⇒ Array<String> readonly
-
#stage_refname ⇒ String?
readonly
Name of the stage if applicable.
-
#staged ⇒ Boolean
readonly
Whether or not the payload is staged.
-
#stager_refname ⇒ String?
readonly
Name of the stager if applicable.
- #targets ⇒ Array<String>? readonly
- #type ⇒ String readonly
Class Method Summary collapse
-
.cached_platform_list(platform_string) ⇒ Msf::Module::PlatformList?
Retrieve or build a cached PlatformList for the given platform string.
-
.dedup_notes(notes) ⇒ Object
Deduplicate notes hash keys and string values via the frozen string table.
-
.dedup_string(str) ⇒ String?
Deduplicate a string via Ruby’s built-in frozen string table (fstring).
-
.from_hash(obj_hash) ⇒ Object
Initialize this object from a hash.
Instance Method Summary collapse
-
#initialize(module_instance, obj_hash = nil) ⇒ Obj
constructor
A new instance of Obj.
- #path ⇒ Object
-
#to_json(*args) ⇒ Object
Returns the JSON representation of the module metadata.
- #update_mod_time(mod_time) ⇒ Object
Constructor Details
#initialize(module_instance, obj_hash = nil) ⇒ Obj
Returns a new instance of Obj.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 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 205 206 207 208 209 210 211 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 133 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..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
#actions ⇒ Hash (readonly)
69 70 71 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 69 def actions @actions end |
#adapted_refname ⇒ String? (readonly)
Returns Name of the adapted payload if applicable.
125 126 127 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 125 def adapted_refname @adapted_refname end |
#adapter_refname ⇒ String? (readonly)
Returns Name of the adapter if applicable.
123 124 125 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 123 def adapter_refname @adapter_refname end |
#aliases ⇒ Array<String> (readonly)
75 76 77 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 75 def aliases @aliases end |
#arch ⇒ String (readonly)
93 94 95 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 93 def arch @arch end |
#author ⇒ Array<String> (readonly)
83 84 85 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 83 def @author end |
#autofilter_ports ⇒ Array<Integer> (readonly)
97 98 99 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 97 def autofilter_ports @autofilter_ports end |
#autofilter_services ⇒ Array<String> (readonly)
99 100 101 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 99 def autofilter_services @autofilter_services end |
#check ⇒ Boolean (readonly)
109 110 111 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 109 def check @check end |
#default_credential ⇒ Boolean (readonly) Also known as: default_cred?
114 115 116 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 114 def default_credential @default_credential end |
#description ⇒ String (readonly)
85 86 87 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 85 def description @description end |
#disclosure_date ⇒ Date (readonly)
79 80 81 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 79 def disclosure_date @disclosure_date end |
#fullname ⇒ String (readonly)
73 74 75 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 73 def fullname @fullname end |
#is_install_path ⇒ Boolean (readonly)
105 106 107 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 105 def is_install_path @is_install_path end |
#mod_time ⇒ Time (readonly)
103 104 105 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 103 def mod_time @mod_time end |
#name ⇒ String (readonly)
71 72 73 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 71 def name @name end |
#notes ⇒ Hash (readonly)
117 118 119 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 117 def notes @notes end |
#payload_type ⇒ Integer (readonly)
Returns The type of payload, e.g. Single, Stager, Adapter.
121 122 123 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 121 def payload_type @payload_type end |
#platform ⇒ String (readonly)
89 90 91 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 89 def platform @platform end |
#platform_list ⇒ Msf::Module::PlatformList (readonly)
91 92 93 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 91 def platform_list @platform_list end |
#post_auth ⇒ Boolean (readonly) Also known as: post_auth?
111 112 113 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 111 def post_auth @post_auth end |
#rank ⇒ Integer (readonly)
77 78 79 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 77 def rank @rank end |
#ref_name ⇒ String (readonly)
107 108 109 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 107 def ref_name @ref_name end |
#references ⇒ Array<String> (readonly)
87 88 89 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 87 def references @references end |
#rport ⇒ Integer (readonly)
95 96 97 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 95 def rport @rport end |
#session_types ⇒ Array<String> (readonly)
119 120 121 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 119 def session_types @session_types end |
#stage_refname ⇒ String? (readonly)
Returns Name of the stage if applicable.
129 130 131 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 129 def stage_refname @stage_refname end |
#staged ⇒ Boolean (readonly)
Returns Whether or not the payload is staged.
127 128 129 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 127 def staged @staged end |
#stager_refname ⇒ String? (readonly)
Returns Name of the stager if applicable.
131 132 133 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 131 def stager_refname @stager_refname end |
#targets ⇒ Array<String>? (readonly)
101 102 103 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 101 def targets @targets end |
#type ⇒ String (readonly)
81 82 83 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 81 def type @type end |
Class Method Details
.cached_platform_list(platform_string) ⇒ Msf::Module::PlatformList?
Retrieve or build a cached PlatformList for the given platform string.
33 34 35 36 37 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 33 def cached_platform_list(platform_string) return nil if platform_string.nil? @platform_list_cache[platform_string] ||= build_platform_list(platform_string) end |
.dedup_notes(notes) ⇒ Object
Deduplicate notes hash keys and string values via the frozen string table. Keys like “Stability”, “SideEffects”, “Reliability” repeat across thousands of modules; values like “crash-safe”, “ioc-in-logs” repeat hundreds of times.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 42 def dedup_notes(notes) notes.each_with_object({}) do |(k, v), h| h[-k] = case v when Array v.map { |e| e.is_a?(String) ? -e : e } when String -v else v end end end |
.dedup_string(str) ⇒ String?
Deduplicate a string via Ruby’s built-in frozen string table (fstring). Identical string contents will share a single frozen object in memory, reducing heap usage for highly repeated values like type, platform, arch, and author.
24 25 26 27 28 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 24 def dedup_string(str) return str unless str.is_a?(String) -str end |
Instance Method Details
#path ⇒ Object
274 275 276 277 278 279 280 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 274 def path if @is_install_path return @full_path ||= ::File.join(Msf::Config.install_root, @path) end @path end |
#to_json(*args) ⇒ Object
Returns the JSON representation of the module metadata
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 216 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
270 271 272 |
# File 'lib/msf/core/modules/metadata/obj.rb', line 270 def update_mod_time(mod_time) @mod_time = mod_time end |