Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/core/module/compatibility.rb
Views: 11784
module Msf::Module::Compatibility1#2# Returns the hash that describes this module's compatibilities.3#4def compat5module_info['Compat'] || {}6end78#9# Returns whether or not this module is compatible with the supplied10# module.11#12def compatible?(mod)13ch = nil1415# Invalid module? Shoot, we can't compare that.16return true if (mod == nil)1718# Determine which hash to used based on the supplied module type19if (mod.type == Msf::MODULE_ENCODER)20ch = self.compat['Encoder']21elsif (mod.type == Msf::MODULE_NOP)22ch = self.compat['Nop']23elsif (mod.type == Msf::MODULE_PAYLOAD)24ch = self.compat['Payload']25if self.respond_to?("target") and self.target and self.target['Payload'] and self.target['Payload']['Compat']26ch = ch.merge(self.target['Payload']['Compat'])27end28else29return true30end3132# Enumerate each compatibility item in our hash to find out33# if we're compatible with this sucker.34ch.each_pair do |k,v|3536# Get the value of the current key from the module, such as37# the ConnectionType for a stager (ws2ord, for instance).38mval = mod.module_info[k]3940# Reject a filled compat item on one side, but not the other41if (v and not mval)42dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{v}")43return false44end4546# Track how many of our values matched the module47mcnt = 04849# Values are whitespace separated50sv = v.split(/\s+/)51mv = mval.split(/\s+/)5253sv.each do |x|5455dlog("Checking compat [#{mod.refname} with #{self.refname}]: #{x} to #{mv.join(", ")}", 'core', LEV_3)5657# Verify that any negate values are not matched58if (x[0,1] == '-' and mv.include?(x[1, x.length-1]))59dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{x}, value was #{mval}", 'core', LEV_1)60return false61end6263mcnt += 1 if mv.include?(x)64end6566# No values matched, reject this module67if (mcnt == 0)68dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{v}, value was #{mval}", 'core', LEV_1)69return false70end7172end7374dlog("Module #{mod.refname} is compatible with #{self.refname}", "core", LEV_1)757677# If we get here, we're compatible.78return true79end8081protected8283#84# This method initializes the module's compatibility hashes by normalizing85# them into one single hash. As it stands, modules can define86# compatibility in their supplied info hash through:87#88# Compat:: direct compat definitions89# PayloadCompat:: payload compatibilities90# EncoderCompat:: encoder compatibilities91# NopCompat:: nop compatibilities92# MeterpreterCompat:: meterpreter compatibilities93#94# In the end, the module specific compatibilities are merged as sub-hashes95# of the primary Compat hash key to make checks more uniform.96#97def init_compat98c = module_info['Compat']99100if (c == nil)101c = module_info['Compat'] = Hash.new102end103104105%w{ Encoder Meterpreter Nop Payload }.each do |key|106# Initialize the module sub compatibilities107c[key] = Hash.new if c[key].nil?108# Update the compat-derived module specific compatibilities from109# the specific ones to make a uniform view of compatibilities110c[key].update(module_info["#{key}Compat"] || {})111end112end113end114115116