Skip to content

Commit 1ec7474

Browse files
committed
Don't embed ELFs in ELF templates
1 parent 66363f1 commit 1ec7474

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/msf/util/exe.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def self.to_zip(files)
107107
# @return [String]
108108
# @return [NilClass]
109109
def self.to_executable(framework, arch, plat, code = '', opts = {})
110+
if elf? code
111+
return code
112+
end
113+
110114
if arch.index(ARCH_X86)
111115

112116
if plat.index(Msf::Module::Platform::Windows)
@@ -959,6 +963,9 @@ def self.to_osx_app(exe, opts = {})
959963
# @param big_endian [Boolean] Set to "false" by default
960964
# @return [String]
961965
def self.to_exe_elf(framework, opts, template, code, big_endian=false)
966+
if elf? code
967+
return code
968+
end
962969

963970
# Allow the user to specify their own template
964971
set_template_default(opts, template)
@@ -2127,6 +2134,9 @@ def self.to_executable_fmt(framework, arch, plat, code, fmt, exeopts)
21272134
exeopts[:uac] = true
21282135
Msf::Util::EXE.to_exe_msi(framework, exe, exeopts)
21292136
when 'elf'
2137+
if elf? code
2138+
return code
2139+
end
21302140
if !plat || plat.index(Msf::Module::Platform::Linux)
21312141
case arch
21322142
when ARCH_X86,nil
@@ -2154,6 +2164,9 @@ def self.to_executable_fmt(framework, arch, plat, code, fmt, exeopts)
21542164
end
21552165
end
21562166
when 'elf-so'
2167+
if elf? code
2168+
return code
2169+
end
21572170
if !plat || plat.index(Msf::Module::Platform::Linux)
21582171
case arch
21592172
when ARCH_X64
@@ -2293,6 +2306,10 @@ def self.find_payload_tag(mo, err_msg)
22932306
bo
22942307
end
22952308

2309+
def self.elf?(code)
2310+
code[0..3] == "\x7FELF"
2311+
end
2312+
22962313
end
22972314
end
22982315
end

0 commit comments

Comments
 (0)