Skip to content

Commit 0221d2d

Browse files
committed
Land rapid7#7735, make assigning payloads fast again!
2 parents cc293f0 + f95136c commit 0221d2d

File tree

1 file changed

+26
-32
lines changed

1 file changed

+26
-32
lines changed

lib/msf/core/exploit.rb

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,12 @@ def target_arch
698698
(target and target.arch) ? target.arch : (arch == []) ? nil : arch
699699
end
700700

701+
def normalize_platform_arch
702+
c_platform = (target && target.platform) ? target.platform : platform
703+
c_arch = (target && target.arch) ? target.arch : (arch == []) ? nil : arch
704+
c_arch ||= [ ARCH_X86 ]
705+
return c_platform, c_arch
706+
end
701707

702708
#
703709
# Returns whether the requested payload is compatible with the module.
@@ -706,10 +712,23 @@ def target_arch
706712
# @return [TrueClass] Payload is compatible.
707713
# @return [FalseClass] Payload is not compatible.
708714
#
709-
def is_payload_compatible?(payload_name)
710-
payload_names = compatible_payloads.collect { |entry| entry[0] }
715+
def is_payload_compatible?(name)
716+
p = framework.payloads[name]
717+
718+
# Skip over payloads that are too big
719+
return false if payload_space && p.cached_size && p.cached_size > payload_space
720+
721+
pi = p.new
711722

712-
payload_names.include?(payload_name)
723+
# Are we compatible in terms of conventions and connections and
724+
# what not?
725+
return false if !compatible?(pi)
726+
727+
# If the payload is privileged but the exploit does not give
728+
# privileged access, then fail it.
729+
return false if !self.privileged && pi.privileged
730+
731+
return true
713732
end
714733

715734
#
@@ -719,34 +738,11 @@ def is_payload_compatible?(payload_name)
719738
def compatible_payloads
720739
payloads = []
721740

722-
723-
c_platform = (target and target.platform) ? target.platform : platform
724-
c_arch = (target and target.arch) ? target.arch : (arch == []) ? nil : arch
725-
c_arch ||= [ ARCH_X86 ]
741+
c_platform, c_arch = normalize_platform_arch
726742

727743
framework.payloads.each_module(
728-
'Platform' => c_platform,
729-
'Arch' => c_arch ) { |name, mod|
730-
731-
# Skip over payloads that are too big
732-
if ((payload_space) and
733-
(framework.payloads.sizes[name]) and
734-
(framework.payloads.sizes[name] > payload_space))
735-
dlog("#{refname}: Skipping payload #{name} for being too large", 'core',
736-
LEV_1)
737-
next
738-
end
739-
740-
# Are we compatible in terms of conventions and connections and
741-
# what not?
742-
next if (compatible?(framework.payloads.instance(name)) == false)
743-
744-
# If the payload is privileged but the exploit does not give
745-
# privileged access, then fail it.
746-
next if (self.privileged == false and framework.payloads.instance(name).privileged == true)
747-
748-
# This one be compatible!
749-
payloads << [ name, mod ]
744+
'Arch' => c_arch, 'Platform' => c_platform) { |name, mod|
745+
payloads << [ name, mod ] if is_payload_compatible?(name)
750746
}
751747

752748
return payloads;
@@ -758,12 +754,10 @@ def compatible_payloads
758754
def compatible_encoders
759755
encoders = []
760756

761-
c_platform = (target and target.platform) ? target.platform : platform
762-
c_arch = (target and target.arch) ? target.arch : (arch == []) ? nil : arch
757+
c_platform, c_arch = normalize_platform_arch
763758

764759
framework.encoders.each_module_ranked(
765760
'Arch' => c_arch, 'Platform' => c_platform) { |name, mod|
766-
767761
encoders << [ name, mod ]
768762
}
769763

0 commit comments

Comments
 (0)