|
1 | 1 | # -*- coding: binary -*-
|
2 |
| - |
3 | 2 | # Concerns reloading modules
|
4 |
| - |
5 | 3 | module Msf::ModuleManager::Reloading
|
6 | 4 | # Reloads the module specified in mod. This can either be an instance of a module or a module class.
|
7 | 5 | #
|
8 | 6 | # @param [Msf::Module, Class] mod either an instance of a module or a module class
|
9 | 7 | # @return (see Msf::Modules::Loader::Base#reload_module)
|
10 | 8 | def reload_module(mod)
|
11 |
| - # if it's an instance, then get its class |
| 9 | + # if it's can instance, then get its class |
12 | 10 | if mod.is_a? Msf::Module
|
13 | 11 | metasploit_class = mod.class
|
14 | 12 | else
|
15 | 13 | metasploit_class = mod
|
16 | 14 | end
|
17 | 15 |
|
18 |
| - if aliased_as = inv_aliases[metasploit_class.fullname] |
| 16 | + if aliased_as = self.inv_aliases[metasploit_class.fullname] |
19 | 17 | aliased_as.each do |a|
|
20 |
| - aliases.delete a |
| 18 | + self.aliases.delete a |
21 | 19 | end
|
22 |
| - inv_aliases.delete metasploit_class.fullname |
23 |
| - end |
24 |
| - |
25 |
| - if mod.payload? |
26 |
| - return reload_payload_module(mod) |
27 |
| - end |
28 |
| - |
29 |
| - if aliased_as = inv_aliases[metasploit_class.fullname] |
30 |
| - aliased_as.each do |a| |
31 |
| - aliases.delete a |
32 |
| - end |
33 |
| - inv_aliases.delete metasploit_class.fullname |
| 20 | + self.inv_aliases.delete metasploit_class.fullname |
34 | 21 | end
|
35 | 22 |
|
36 | 23 | namespace_module = metasploit_class.module_parent
|
37 |
| - |
38 |
| - # Check if the namespace module has a loader |
39 |
| - unless namespace_module.respond_to?(:loader) |
40 |
| - elog('Module does not have loader') |
41 |
| - return mod |
42 |
| - end |
43 |
| - |
44 | 24 | loader = namespace_module.loader
|
45 | 25 | loader.reload_module(mod)
|
46 | 26 | end
|
47 | 27 |
|
48 |
| - def manual_reload(parent_path, type, ref_name) |
49 |
| - loaders.each { |loader| loader.load_module(parent_path, type, ref_name, { force: true }) } |
50 |
| - end |
51 |
| - |
52 |
| - # Reload payload module, separately from other categories. This is due to complexity of payload module and due to the fact they don't follow class structure as rest of the modules. |
53 |
| - # @param [Msf::Module, Class] mod either an instance of a module or a module class |
54 |
| - # @return (see Msf::Modules::Loader::Base#reload_module) |
55 |
| - def reload_payload_module(mod) |
56 |
| - if mod.is_a? Msf::Module |
57 |
| - metasploit_class = mod.class |
58 |
| - original_instance = mod |
59 |
| - else |
60 |
| - metasploit_class = mod |
61 |
| - original_instance = nil |
62 |
| - end |
63 |
| - if (module_set = module_set_by_type.fetch(metasploit_class.type, nil)) |
64 |
| - module_set.delete(metasploit_class.refname) |
65 |
| - end |
66 |
| - module_info = module_info_by_path[metasploit_class.file_path] |
67 |
| - unless module_info && (parent_path = module_info[:parent_path]) |
68 |
| - elog('Failed to get parent_path from module object') |
69 |
| - return mod |
70 |
| - end |
71 |
| - |
72 |
| - # reload adapters if any |
73 |
| - manual_reload(parent_path, module_info[:type], File.join('adapters', mod.adapter_refname)) if mod.adapter_refname |
74 |
| - |
75 |
| - # reload stagers if any |
76 |
| - manual_reload(parent_path, module_info[:type], File.join('stagers', mod.stager_refname)) if mod.stager_refname |
77 |
| - |
78 |
| - # reload stages if any |
79 |
| - manual_reload(parent_path, module_info[:type], File.join('stages', mod.stage_refname)) if mod.stage_refname |
80 |
| - |
81 |
| - # reload single if any |
82 |
| - manual_reload(parent_path, module_info[:type], File.join('singles', module_info[:reference_name])) if original_instance.payload_type == Msf::Payload::Type::Single |
83 |
| - |
84 |
| - # Get reloaded module |
85 |
| - new_instance = framework.modules.create(metasploit_class.fullname) |
86 |
| - |
87 |
| - if new_instance.blank? |
88 |
| - elog('Failed create new instance') |
89 |
| - return mod |
90 |
| - end |
91 |
| - |
92 |
| - # Restore the datastore |
93 |
| - new_instance.datastore.merge!(original_instance.datastore) |
94 |
| - |
95 |
| - # Return the new instance, which the framework will make the active module. |
96 |
| - return new_instance |
97 |
| - rescue StandardError => e |
98 |
| - elog("Failed to reload payload #{fullname}: #{e.message}") |
99 |
| - return mod |
100 |
| - end |
101 |
| - |
102 | 28 | # Reloads modules from all module paths
|
103 | 29 | #
|
104 | 30 | # @return (see Msf::ModuleManager::Loading#load_modules)
|
105 | 31 | def reload_modules
|
106 |
| - enablement_by_type.each_key do |type| |
| 32 | + self.enablement_by_type.each_key do |type| |
107 | 33 | module_set_by_type[type].clear
|
108 | 34 | init_module_set(type)
|
109 | 35 | end
|
110 |
| - aliases.clear |
111 |
| - inv_aliases.clear |
| 36 | + self.aliases.clear |
| 37 | + self.inv_aliases.clear |
112 | 38 |
|
113 | 39 | # default the count to zero the first time a type is accessed
|
114 | 40 | count_by_type = Hash.new(0)
|
|
0 commit comments