Skip to content

Commit 84c0504

Browse files
author
HD Moore
committed
MSI sections actually need to be signed after all
1 parent c9b6c05 commit 84c0504

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/msf/util/exe.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,16 @@ def self.replace_msi_buffer(pe, opts)
655655
}
656656

657657
section_size = 2**(msi[30..31].unpack('v')[0])
658-
sector_allocation_table = msi[section_size..section_size*2].unpack('V*')
658+
659+
# This table is one of the few cases where signed values are needed
660+
sector_allocation_table = msi[section_size..section_size*2].unpack('l<*')
659661

660662
buffer_chain = []
661-
current_secid = 5 # This is closely coupled with the template provided and ideally
662-
# would be calculated from the dir stream?
663+
664+
# This is closely coupled with the template provided and ideally
665+
# would be calculated from the dir stream?
666+
current_secid = 5
667+
663668

664669
until current_secid == -2
665670
buffer_chain << current_secid
@@ -827,16 +832,16 @@ def self.to_exe_elf(framework, opts, template, code, big_endian=false)
827832

828833
# Check EI_CLASS to determine if the header is 32 or 64 bit
829834
# Use the proper offsets and pack size
830-
case elf[4]
831-
when 1, "\x01" # ELFCLASS32 - 32 bit (ruby 1.8 and 1.9)
835+
case elf[4,1].unpack("C").first
836+
when 1 # ELFCLASS32 - 32 bit (ruby 1.9+)
832837
if big_endian
833838
elf[0x44,4] = [elf.length].pack('N') #p_filesz
834839
elf[0x48,4] = [elf.length + code.length].pack('N') #p_memsz
835840
else # little endian
836841
elf[0x44,4] = [elf.length].pack('V') #p_filesz
837842
elf[0x48,4] = [elf.length + code.length].pack('V') #p_memsz
838843
end
839-
when 2, "\x02" # ELFCLASS64 - 64 bit (ruby 1.8 and 1.9)
844+
when 2 # ELFCLASS64 - 64 bit (ruby 1.9+)
840845
if big_endian
841846
elf[0x60,8] = [elf.length].pack('Q>') #p_filesz
842847
elf[0x68,8] = [elf.length + code.length].pack('Q>') #p_memsz

0 commit comments

Comments
 (0)