lib/msf/core/module_manager.rb
#
# Loads a module from the supplied archive path
#
Loads a module from the supplied archive path
Loads a module from the supplied archive path
def load_module_from_archive(path, file, loaded, recalc, counts, demand = false)
		if not ( demand or has_archive_module_file_changed?(file))
			dlog("Cached module from file #{file} has not changed.", 'core', LEV_2)
			return false
		end
		name = file.match(/^(.+?)#{File::SEPARATOR}(.*)(.rb?)$/)[2]
		base = file.sub(/(.+)(#{File::SEPARATOR}.+)(.rb?)$/, '\1')
		if (m = base.match(/^(.+?)#{File::SEPARATOR}+?/))
			type = m[1]
		else
			type = base
		end
		type.sub!(/s$/, '')
		added = nil
		begin
			wrap = ::Module.new
			wrap.module_eval( ::FastLib.load(path, file), file )
			if(wrap.const_defined?(:RequiredVersions))
				mins = wrap.const_get(:RequiredVersions)
				if( mins[0] > ::Msf::Framework::VersionCore or
				    mins[1] > ::Msf::Framework::VersionAPI
				  )
					errmsg = "Failed to load module from #{path}::#{file} due to version check (requires Core:#{mins[0]} API:#{mins[1]})"
					elog(errmsg)
					self.module_failed[file] = errmsg
					return false
				end
			end
		rescue ::Interrupt
			raise $!
		rescue ::Exception => e
			if(wrap.const_defined?(:RequiredVersions))
				mins = wrap.const_get(:RequiredVersions)
				if( mins[0] > ::Msf::Framework::VersionCore or
				    mins[1] > ::Msf::Framework::VersionAPI
				  )
					errmsg = "Failed to load module from #{path}::#{file}due to error and failed version check (requires Core:#{mins[0]} API:#{mins[1]})"
					elog(errmsg)
					self.module_failed[file] = errmsg
					return false
				end
			end
			errmsg = "#{e.class} #{e}"
			self.module_failed[file] = errmsg
			elog(errmsg)
			return false
		end
		::Msf::Framework::Major.downto(1) do |major|
			if wrap.const_defined?("Metasploit#{major}")
				added = wrap.const_get("Metasploit#{major}")
				break
			end
		end
		if not added
			errmsg = "Missing Metasploit class constant"
			self.module_failed[file] = errmsg
			elog(errmsg)
			return false
		end
		usable = false
		begin
			usable = respond_to?(:is_usable) ? added.is_usable : true
		rescue
			elog("Exception caught during is_usable check: #{$!}")
		end
		if (usable == false)
			ilog("Skipping module in #{path}::#{file} because is_usable returned false.", 'core', LEV_1)
			return false
		end
		ilog("Loaded #{type} module #{added} from #{path}::#{file}.", 'core', LEV_2)
		self.module_failed.delete(file)
		on_module_load(added, type, name, {
			'files' => [ file ],
			'paths' => [ path ],
			'type'  => type })
		recalc[type] = true if (recalc)
		loaded[file] = added if (loaded)
		if (counts)
			counts[type] = (counts[type]) ? (counts[type] + 1) : 1
		end
		return true
	end
def load_module_from_archive ( path , file , loaded , recalc , counts , demand = false ) if not ( demand or has_archive_module_file_changed? ( file ) ) dlog ( "Cached module from file #{file} has not changed." , 'core' , LEV_2 ) return false end name = file . match ( / ^(.+?) #{ File :: SEPARATOR } (.*)(.rb?)$ / ) [ 2 ] base = file . sub ( / (.+)( #{ File :: SEPARATOR } .+)(.rb?)$ / , '\1' ) if ( m = base . match ( / ^(.+?) #{ File :: SEPARATOR } +? / ) ) type = m [ 1 ] else type = base end type . sub! ( / s$ / , '' ) added = nil begin wrap = :: Module . new wrap . module_eval ( :: FastLib . load ( path , file ) , file ) if ( wrap . const_defined? ( :RequiredVersions ) ) mins = wrap . const_get ( :RequiredVersions ) if ( mins [ 0 ] > :: Msf :: Framework :: VersionCore or mins [ 1 ] > :: Msf :: Framework :: VersionAPI ) errmsg = "Failed to load module from #{path}::#{file} due to version check (requires Core:#{mins[0]} API:#{mins[1]})" elog ( errmsg ) self . module_failed [ file ] = errmsg return false end end rescue :: Interrupt raise $! rescue :: Exception => e if ( wrap . const_defined? ( :RequiredVersions ) ) mins = wrap . const_get ( :RequiredVersions ) if ( mins [ 0 ] > :: Msf :: Framework :: VersionCore or mins [ 1 ] > :: Msf :: Framework :: VersionAPI ) errmsg = "Failed to load module from #{path}::#{file}due to error and failed version check (requires Core:#{mins[0]} API:#{mins[1]})" elog ( errmsg ) self . module_failed [ file ] = errmsg return false end end errmsg = "#{e.class} #{e}" self . module_failed [ file ] = errmsg elog ( errmsg ) return false end :: Msf :: Framework :: Major . downto ( 1 ) do | major | if wrap . const_defined? ( "Metasploit#{major}" ) added = wrap . const_get ( "Metasploit#{major}" ) break end end if not added errmsg = "Missing Metasploit class constant" self . module_failed [ file ] = errmsg elog ( errmsg ) return false end usable = false begin usable = respond_to? ( :is_usable ) ? added . is_usable : true rescue elog ( "Exception caught during is_usable check: #{$!}" ) end if ( usable == false ) ilog ( "Skipping module in #{path}::#{file} because is_usable returned false." , 'core' , LEV_1 ) return false end ilog ( "Loaded #{type} module #{added} from #{path}::#{file}." , 'core' , LEV_2 ) self . module_failed . delete ( file ) on_module_load ( added , type , name , { 'files' => [ file ] , 'paths' => [ path ] , 'type' => type } ) recalc [ type ] = true if ( recalc ) loaded [ file ] = added if ( loaded ) if ( counts ) counts [ type ] = ( counts [ type ] ) ? ( counts [ type ] + 1 ) : 1 end return true end
Loads a module from the supplied archive path
Loads a module from the supplied archive path
# Derive the name from the path with the exclusion of the .rb # Chop off the file name # Hide eval errors when the module version is not compatible # If the module indicates that it is not usable on this system, then we # will not try to use it. # Do some processing on the loaded module to get it into the # right associations # Set this module type as needing recalculation # Append the added module to the hash of file->module # The number of loaded modules this round
path
<not_specific>
file
<not_specific>
loaded
<not_specific>
recalc
<not_specific>
counts
<not_specific>
demand
<not_specific>