Class: Msf::OptInjectablePE
- Defined in:
- lib/msf/core/payload/windows/pe_inject.rb
Instance Attribute Summary
Attributes inherited from OptBase
#advanced, #aliases, #conditions, #default, #desc, #enums, #evasion, #fallbacks, #max_length, #name, #owner, #regex, #required
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args, arch:, **kwargs) ⇒ OptInjectablePE
constructor
A new instance of OptInjectablePE.
- #valid?(value, check_empty: nil) ⇒ Boolean
Methods inherited from OptPath
#check_memory_location, #normalize, #type, #validate_on_assignment?
Methods inherited from OptBase
#advanced?, #display_value, #empty_required_value?, #evasion?, #invalid_value_length?, #normalize, #required?, #type?, #validate_on_assignment?
Constructor Details
#initialize(*args, arch:, **kwargs) ⇒ OptInjectablePE
Returns a new instance of OptInjectablePE.
6 7 8 9 |
# File 'lib/msf/core/payload/windows/pe_inject.rb', line 6 def initialize(*args, arch:, **kwargs) @arch = arch super(*args, **kwargs) end |
Class Method Details
.assert_compatible(pe, arch) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/msf/core/payload/windows/pe_inject.rb', line 11 def self.assert_compatible(pe, arch) unless (arch == ARCH_X86 && pe.ptr_32?) || (arch == ARCH_X64 && pe.ptr_64?) raise Msf::ValidationError, "Selected PE file is not #{arch}" end # TODO: Add reflective CLR loading support unless pe.hdr.opt['DataDirectory'][14].v['Size'] == 0 raise Msf::ValidationError, 'PE files with CLR are not currently supported' end unless pe.hdr.opt['DataDirectory'][5].v['Size'] != 0 raise Msf::ValidationError, 'PE file is missing relocation data' end unless pe.hdr.opt['DataDirectory'][11].v['Size'] == 0 raise Msf::ValidationError, 'PE file contains bounded imports' end unless pe.hdr.opt['DataDirectory'][9].v['Size'] == 0 tls_offset = pe.rva_to_file_offset(pe.hdr.opt['DataDirectory'][9].v['VirtualAddress']) unless tls_offset.to_i == 0 tls_callback_table_offset = '' if arch == ARCH_X86 tls_callback_table_offset = pe.read(tls_offset + 4, 4) else tls_callback_table_offset = pe.read(tls_offset + 12, 12) end unless tls_callback_table_offset.to_i == 0 unless pe.read(tls_callback_table_offset, 4).to_i == 0 raise Msf::ValidationError, 'PE file contains TLS callbacks' end end end end end |
Instance Method Details
#valid?(value, check_empty: nil) ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/msf/core/payload/windows/pe_inject.rb', line 47 def valid?(value, check_empty: nil) return false unless super return false unless value && File.file?(File.(value)) # no memory: locations begin self.class.assert_compatible(Rex::PeParsey::Pe.new_from_file(value, true), @arch) rescue Msf::ValidationError return false end true end |