@@ -698,6 +698,12 @@ def target_arch
698
698
( target and target . arch ) ? target . arch : ( arch == [ ] ) ? nil : arch
699
699
end
700
700
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
701
707
702
708
#
703
709
# Returns whether the requested payload is compatible with the module.
@@ -706,10 +712,23 @@ def target_arch
706
712
# @return [TrueClass] Payload is compatible.
707
713
# @return [FalseClass] Payload is not compatible.
708
714
#
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
711
722
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
713
732
end
714
733
715
734
#
@@ -719,34 +738,11 @@ def is_payload_compatible?(payload_name)
719
738
def compatible_payloads
720
739
payloads = [ ]
721
740
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
726
742
727
743
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 )
750
746
}
751
747
752
748
return payloads ;
@@ -758,12 +754,10 @@ def compatible_payloads
758
754
def compatible_encoders
759
755
encoders = [ ]
760
756
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
763
758
764
759
framework . encoders . each_module_ranked (
765
760
'Arch' => c_arch , 'Platform' => c_platform ) { |name , mod |
766
-
767
761
encoders << [ name , mod ]
768
762
}
769
763
0 commit comments