Class: Msf::Modules::External::Shim
- Inherits:
-
Object
- Object
- Msf::Modules::External::Shim
- Defined in:
- lib/msf/core/modules/external/shim.rb
Class Method Summary collapse
- .capture_server(mod) ⇒ Object
- .common_check(meta = {}) ⇒ Object
- .common_metadata(meta = {}, default_options: {}) ⇒ Object
- .dos(mod) ⇒ Object
- .evasion(mod) ⇒ Object
- .generate(module_path, framework) ⇒ Object
- .mod_meta_common(mod, meta = {}, ignore_options: []) ⇒ Object
- .mod_meta_common_options(mod, ignore_options: [], advanced: false) ⇒ Object
- .mod_meta_exploit(mod, meta = {}) ⇒ Object
- .multi_scanner(mod) ⇒ Object
- .remote_exploit(mod) ⇒ Object
- .remote_exploit_cmd_stager(mod) ⇒ Object
- .render_template(name, meta = {}) ⇒ Object
- .single_host_login_scanner(mod) ⇒ Object
- .single_scanner(mod) ⇒ Object
-
.transform_notes(notes) ⇒ Object
In case certain notes are not properly capitalized in the external module definition, ensure that they are properly capitalized before rendering.
Class Method Details
.capture_server(mod) ⇒ Object
120 121 122 123 |
# File 'lib/msf/core/modules/external/shim.rb', line 120 def self.capture_server(mod) = (mod) render_template('capture_server.erb', ) end |
.common_check(meta = {}) ⇒ Object
44 45 46 |
# File 'lib/msf/core/modules/external/shim.rb', line 44 def self.common_check( = {}) render_template('common_check.erb', ) end |
.common_metadata(meta = {}, default_options: {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/msf/core/modules/external/shim.rb', line 38 def self.( = {}, default_options: {}) # Combine any template defaults with the defaults specified within the external module's metadata = .merge([:default_options]) render_template('common_metadata.erb', .merge(default_options: )) end |
.dos(mod) ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'lib/msf/core/modules/external/shim.rb', line 154 def self.dos(mod) = (mod) [:date] = mod.['date'].dump [:references] = mod.['references'].map do |r| "[#{r['type'].upcase.dump}, #{r['ref'].dump}]" end.join(",\n ") render_template('dos.erb', ) end |
.evasion(mod) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/msf/core/modules/external/shim.rb', line 164 def self.evasion(mod) = (mod, ignore_options: ['payload_raw', 'payload_encoded', 'target']) [:platform] = mod.['targets'].map do |t| t['platform'].dump end.uniq.join(",\n ") [:arch] = mod.['targets'].map do |t| t['arch'].dump end.uniq.join(",\n ") [:references] = mod.['references'].map do |r| "[#{r['type'].upcase.dump}, #{r['ref'].dump}]" end.join(",\n ") [:targets] = mod.['targets'].map do |t| if t['name'] "[#{t['name'].dump}, {'Arch' => ARCH_#{t['arch'].upcase}, 'Platform' => #{t['platform'].dump} }]" else "[#{t['platform'].dump} + ' ' + #{t['arch'].dump}, {'Arch' => ARCH_#{t['arch'].upcase}, 'Platform' => #{t['platform'].dump} }]" end end.join(",\n ") render_template('evasion.erb', ) end |
.generate(module_path, framework) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/msf/core/modules/external/shim.rb', line 4 def self.generate(module_path, framework) mod = Msf::Modules::External.new(module_path, framework: framework) # first check if meta exists and raise an issue if not, #14281 # raise instead of returning nil to avoid confusion unless mod. raise LoadError, " Try running file manually to check for errors or dependency issues." end case mod.['type'] when 'remote_exploit' remote_exploit(mod) when 'remote_exploit_cmd_stager' remote_exploit_cmd_stager(mod) when 'capture_server' capture_server(mod) when 'dos' dos(mod) when 'single_scanner' single_scanner(mod) when 'single_host_login_scanner' single_host_login_scanner(mod) when 'multi_scanner' multi_scanner(mod) when 'evasion' evasion(mod) else nil end end |
.mod_meta_common(mod, meta = {}, ignore_options: []) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/msf/core/modules/external/shim.rb', line 48 def self.(mod, = {}, ignore_options: []) [:path] = mod.path.dump [:name] = mod.['name'].dump [:description] = mod.['description'].dump [:authors] = mod.['authors'].map(&:dump).join(",\n ") [:license] = mod.['license'].nil? ? 'MSF_LICENSE' : mod.['license'] [:options] = (mod, ignore_options: ) [:advanced_options] = (mod, ignore_options: , advanced: true) [:capabilities] = mod.['capabilities'] [:notes] = transform_notes(mod.['notes']) # Additionally check the 'describe_payload_options' key for backwards compatibility [:default_options] = (mod.['default_options'] || mod.['describe_payload_options'] || {}) end |
.mod_meta_common_options(mod, ignore_options: [], advanced: false) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/msf/core/modules/external/shim.rb', line 65 def self.(mod, ignore_options: [], advanced: false) # Set modules without options to have an empty map if mod.['options'].nil? mod.['options'] = {} end = mod.['options'].map do |n, o| next if .include? n next unless o.fetch('advanced', false) == advanced if o['values'] "Opt#{o['type'].camelize}.new(#{n.dump}, [#{o['required']}, #{o['description'].dump}, #{o['default'].inspect}, #{o['values'].inspect}])" else "Opt#{o['type'].camelize}.new(#{n.dump}, [#{o['required']}, #{o['description'].dump}, #{o['default'].inspect}])" end end .compact! .join(",\n ") end |
.mod_meta_exploit(mod, meta = {}) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/msf/core/modules/external/shim.rb', line 87 def self.(mod, = {}) [:rank] = mod.['rank'].nil? ? 'NormalRanking' : "#{mod.['rank'].capitalize}Ranking" [:date] = mod.['date'].dump [:wfsdelay] = mod.['wfsdelay'] || 5 [:privileged] = mod.['privileged'].inspect [:platform] = mod.['targets'].map do |t| t['platform'].dump end.uniq.join(",\n ") [:arch] = mod.['targets'].map do |t| t['arch'].dump end.uniq.join(",\n ") [:references] = mod.['references'].map do |r| "[#{r['type'].upcase.dump}, #{r['ref'].dump}]" end.join(",\n ") [:targets] = mod.['targets'].map do |t| "[#{t['platform'].dump} + ' ' + #{t['arch'].dump}, {'Arch' => ARCH_#{t['arch'].upcase}, 'Platform' => #{t['platform'].dump} }]" end.join(",\n ") end |
.multi_scanner(mod) ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/msf/core/modules/external/shim.rb', line 144 def self.multi_scanner(mod) = (mod) [:date] = mod.['date'].dump [:references] = mod.['references'].map do |r| "[#{r['type'].upcase.dump}, #{r['ref'].dump}]" end.join(",\n ") render_template('multi_scanner.erb', ) end |
.remote_exploit(mod) ⇒ Object
107 108 109 110 111 |
# File 'lib/msf/core/modules/external/shim.rb', line 107 def self.remote_exploit(mod) = (mod) = (mod, ) render_template('remote_exploit.erb', ) end |
.remote_exploit_cmd_stager(mod) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/msf/core/modules/external/shim.rb', line 113 def self.remote_exploit_cmd_stager(mod) = (mod, ignore_options: ['command']) = (mod, ) [:command_stager_flavor] = mod.['payload']['command_stager_flavor'].dump render_template('remote_exploit_cmd_stager.erb', ) end |
.render_template(name, meta = {}) ⇒ Object
33 34 35 36 |
# File 'lib/msf/core/modules/external/shim.rb', line 33 def self.render_template(name, = {}) template = File.join(File.dirname(__FILE__), 'templates', name) ERB.new(File.read(template)).result(binding) end |
.single_host_login_scanner(mod) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/msf/core/modules/external/shim.rb', line 134 def self.single_host_login_scanner(mod) = (mod, ignore_options: ['rhost']) [:date] = mod.['date'].dump [:references] = mod.['references'].map do |r| "[#{r['type'].upcase.dump}, #{r['ref'].dump}]" end.join(",\n ") render_template('single_host_login_scanner.erb', ) end |
.single_scanner(mod) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/msf/core/modules/external/shim.rb', line 125 def self.single_scanner(mod) = (mod, ignore_options: ['rhost']) [:date] = mod.['date'].dump [:references] = mod.['references'].map do |r| "[#{r['type'].upcase.dump}, #{r['ref'].dump}]" end.join(",\n ") render_template('single_scanner.erb', ) end |
.transform_notes(notes) ⇒ Object
In case certain notes are not properly capitalized in the external module definition, ensure that they are properly capitalized before rendering.
189 190 191 192 193 194 195 196 |
# File 'lib/msf/core/modules/external/shim.rb', line 189 def self.transform_notes(notes) return {} unless notes notes.reduce({}) do |acc, (key, val)| acc[key.upcase] = val acc end end |