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