Skip to content

Commit d311059

Browse files
committed
Fix DYNAMIC_BASE templates
1 parent 24dbc28 commit d311059

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/msf/util/exe.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ def self.to_win32pe(framework, code, opts = {})
168168
# Create a new PE object and run through sanity checks
169169
fsize = File.size(opts[:template])
170170
pe = Rex::PeParsey::Pe.new_from_file(opts[:template], true)
171+
172+
# DYNAMIC_BASE modification
173+
original_dllcharacteristics = pe.hdr.opt.DllCharacteristics
174+
c_bits = ("%32d" %original_dllcharacteristics.to_s(2)).split('').map { |e| e.to_i }.reverse
175+
c_bits[6] = 0 # DYNAMIC_BASE
176+
new_dllcharacteristics = c_bits.reverse.join.to_i(2)
177+
171178
text = nil
172179
pe.sections.each {|sec| text = sec if sec.name == ".text"}
173180

@@ -277,6 +284,10 @@ def self.to_win32pe(framework, code, opts = {})
277284
tds = pe.hdr.file.TimeDateStamp
278285
exe[exe.index([tds].pack('V')), 4] = [tds - rand(0x1000000)].pack("V")
279286

287+
# Patch dll characteristics
288+
dll_ch_offset = exe[60, 4].unpack('h4')[0].reverse.hex + 94
289+
exe[dll_ch_offset, 2] = [ new_dllcharacteristics ].pack("v")
290+
280291
cks = pe.hdr.opt.CheckSum
281292
unless cks == 0
282293
exe[exe.index([cks].pack('V')), 4] = [0].pack("V")

0 commit comments

Comments
 (0)