Skip to content

Commit ccf967f

Browse files
committed
added support to msfpayload to use elf so payload target
1 parent 1c5cfee commit ccf967f

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

lib/msf/util/exe.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,12 @@ def self.to_linux_x64_elf(framework, code, opts={})
911911
return elf
912912
end
913913

914+
# Create a 64-bit Linux ELF_DYN containing the payload provided in +code+
915+
def self.to_linux_x64_elf_dll(framework, code, opts={})
916+
elf = to_exe_elf(framework, opts, "template_x64_linux_dll.bin", code)
917+
return elf
918+
end
919+
914920
def self.to_linux_armle_elf(framework, code, opts={})
915921
elf = to_exe_elf(framework, opts, "template_armle_linux.bin", code)
916922
return elf
@@ -1896,6 +1902,13 @@ def self.to_executable_fmt(framework, arch, plat, code, fmt, exeopts)
18961902
end
18971903
end
18981904

1905+
when 'elf-so'
1906+
if (not plat or (plat.index(Msf::Module::Platform::Linux)))
1907+
output = case arch
1908+
when ARCH_X86_64 then to_linux_x64_elf_dll(framework, code, exeopts)
1909+
end
1910+
end
1911+
18991912
when 'macho', 'osx-app'
19001913
output = case arch
19011914
when ARCH_X86,nil then to_osx_x86_macho(framework, code, exeopts)
@@ -1949,6 +1962,7 @@ def self.to_executable_fmt_formats
19491962
"aspx-exe",
19501963
"dll",
19511964
"elf",
1965+
"elf-so",
19521966
"exe",
19531967
"exe-only",
19541968
"exe-service",

msfpayload

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $args = Rex::Parser::Arguments.new(
3030
#
3131
def usage
3232
$stderr.puts("\n" +
33-
" Usage: #{$0} [<options>] <payload> [var=val] <[S]ummary|C|Cs[H]arp|[P]erl|Rub[Y]|[R]aw|[J]s|e[X]e|[D]ll|[V]BA|[W]ar|Pytho[N]>\n" +
33+
" Usage: #{$0} [<options>] <payload> [var=val] <[S]ummary|C|Cs[H]arp|[P]erl|Rub[Y]|[R]aw|[J]s|e[X]e|[D]ll|[V]BA|[W]ar|Pytho[N]|s[O]>\n" +
3434
$args.usage)
3535
exit
3636
end
@@ -125,10 +125,10 @@ end
125125

126126
payload.datastore.merge! options
127127

128-
if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n)$/)
128+
if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n|o)$/)
129129
fmt = 'perl' if (cmd =~ /^p$/)
130130
fmt = 'ruby' if (cmd =~ /^y$/)
131-
fmt = 'raw' if (cmd =~ /^(r|x|d)$/)
131+
fmt = 'raw' if (cmd =~ /^(r|x|d|o)$/)
132132
fmt = 'raw' if (cmd =~ /^v$/)
133133
fmt = 'c' if (cmd =~ /^c$/)
134134
fmt = 'csharp' if (cmd =~ /^h$/)
@@ -208,6 +208,24 @@ if (cmd =~ /^(p|y|r|d|c|h|j|x|b|v|w|n)$/)
208208
exit(-1)
209209
end
210210

211+
if (cmd =~ /^o$/)
212+
so = Msf::Util::EXE.to_linux_x64_elf_dll($framework, buf)
213+
note =
214+
"Created by msfpayload (http://www.metasploit.com).\r\n" +
215+
"Payload: " + payload.refname + "\r\n" +
216+
" Length: " + buf.length.to_s + "\r\n" +
217+
"Options: " + options.inspect + "\r\n"
218+
219+
if(so)
220+
$stderr.puts(note)
221+
$stdout.write(so)
222+
exit(0)
223+
end
224+
225+
$stderr.puts "Failed to build dll"
226+
exit(-1)
227+
end
228+
211229
if(cmd =~ /^w$/)
212230
note =
213231
"Created by msfpayload (http://www.metasploit.com).\n" +

spec/support/shared/contexts/msf/util/exe.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"linux" => [
4949
{ :format => "elf", :arch => "x86", :file_fp => /ELF 32.*SYSV/ },
5050
{ :format => "elf", :arch => "x64", :file_fp => /ELF 64.*SYSV/ },
51+
{ :format => "elf-so", :arch => "x64", :file_fp => /ELF 64.*SYSV/ },
5152
{ :format => "elf", :arch => "armle", :file_fp => /ELF 32.*ARM/ },
5253
{ :format => "elf", :arch => "mipsbe", :file_fp => /ELF 32-bit MSB executable, MIPS/ },
5354
{ :format => "elf", :arch => "mipsle", :file_fp => /ELF 32-bit LSB executable, MIPS/ },

0 commit comments

Comments
 (0)