Skip to content

Commit adcf45b

Browse files
committed
Fix the arch in #handle_connection too
This fixes an issue with the adated peinject stage which supported both x86 and x64 via a library that checked its own #arch.
1 parent 886f031 commit adcf45b

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

lib/msf/core/payload/windows/pe_inject.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ def valid?(value, check_empty: nil)
6767
module Payload::Windows::PEInject
6868
def initialize(info = {})
6969
super
70+
7071
register_options([
71-
OptInjectablePE.new('PE', [ true, 'The local path to the PE file to upload' ], arch: arch.first)
72+
OptInjectablePE.new('PE', [ true, 'The local path to the PE file to upload' ], arch: info.fetch('AdaptedArch', arch.first))
7273
], self.class)
7374
end
7475

@@ -83,7 +84,7 @@ def pe_path
8384
# Transmits the reflective PE payload to the remote
8485
# computer so that it can be loaded into memory.
8586
#
86-
def handle_connection(conn, _opts = {})
87+
def handle_connection(conn, opts = {})
8788
data = ''
8889
begin
8990
File.open(pe_path, 'rb') do |f|
@@ -96,7 +97,7 @@ def handle_connection(conn, _opts = {})
9697
end
9798

9899
print_status('Premapping PE file...')
99-
pe_map = create_pe_memory_map(data)
100+
pe_map = create_pe_memory_map(data, opts)
100101
print_status("Mapped PE size #{pe_map[:bytes].length}")
101102
opts = {}
102103
opts[:is_dll] = pe_map[:is_dll]
@@ -113,10 +114,10 @@ def handle_connection(conn, _opts = {})
113114
conn.close
114115
end
115116

116-
def create_pe_memory_map(file)
117+
def create_pe_memory_map(file, opts = {})
117118
pe = Rex::PeParsey::Pe.new(Rex::ImageSource::Memory.new(file))
118119
begin
119-
OptInjectablePE.assert_compatible(pe, arch.first)
120+
OptInjectablePE.assert_compatible(pe, opts.fetch(:arch, arch.first))
120121
rescue Msf::ValidationError => e
121122
print_error("PE validation error: #{e.message}")
122123
raise

modules/payloads/adapters/cmd/windows/powershell.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ def generate_payload_uuid(conf = {})
5151
conf[:platform] ||= module_info['AdaptedPlatform']
5252
super
5353
end
54+
55+
def handle_connection(conn, opts = {})
56+
opts[:arch] ||= module_info['AdaptedArch']
57+
super
58+
end
5459
end

modules/payloads/adapters/cmd/windows/powershell/x64.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ def generate_payload_uuid(conf = {})
5151
conf[:platform] ||= module_info['AdaptedPlatform']
5252
super
5353
end
54+
55+
def handle_connection(conn, opts = {})
56+
opts[:arch] ||= module_info['AdaptedArch']
57+
super
58+
end
5459
end

0 commit comments

Comments
 (0)