2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2005-10-01 09:10:41 +00:00
|
|
|
|
2006-07-31 15:36:08 +00:00
|
|
|
msfbase = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
|
|
|
$:.unshift(File.join(File.dirname(msfbase), 'lib'))
|
2008-02-02 21:29:46 +00:00
|
|
|
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
2005-10-01 09:10:41 +00:00
|
|
|
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/ui'
|
|
|
|
require 'msf/base'
|
|
|
|
|
|
|
|
#
|
|
|
|
# Dump the list of payloads
|
|
|
|
#
|
|
|
|
def dump_payloads
|
|
|
|
tbl = Rex::Ui::Text::Table.new(
|
|
|
|
'Indent' => 4,
|
2005-10-12 05:44:15 +00:00
|
|
|
'Header' => "Framework Payloads (#{$framework.stats.num_payloads} total)",
|
2005-10-01 09:10:41 +00:00
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
"Name",
|
|
|
|
"Description"
|
|
|
|
])
|
|
|
|
|
|
|
|
$framework.payloads.each_module { |name, mod|
|
|
|
|
tbl << [ name, mod.new.description ]
|
|
|
|
}
|
|
|
|
|
|
|
|
"\n" + tbl.to_s + "\n"
|
|
|
|
end
|
|
|
|
|
2005-10-01 21:26:17 +00:00
|
|
|
# Initialize the simplified framework instance.
|
|
|
|
$framework = Msf::Simple::Framework.create
|
2005-10-01 09:10:41 +00:00
|
|
|
|
|
|
|
if (ARGV.length <= 1)
|
2008-03-05 19:23:01 +00:00
|
|
|
puts "\n" + " Usage: #{$0} <payload> [var=val] <S[ummary]|C|P[erl]|[Rub]y|R[aw]|J[avascript]|e[X]ecutable>\n"
|
2005-10-01 09:10:41 +00:00
|
|
|
puts dump_payloads
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get the payload name we'll be using
|
|
|
|
payload_name = ARGV.shift
|
2007-02-18 12:27:17 +00:00
|
|
|
|
|
|
|
# Process special var/val pairs...
|
|
|
|
Msf::Ui::Common.process_cli_arguments($framework, ARGV)
|
|
|
|
|
|
|
|
# Create the payload instance
|
|
|
|
payload = $framework.payloads.create(payload_name)
|
2005-10-01 09:10:41 +00:00
|
|
|
|
|
|
|
if (payload == nil)
|
|
|
|
puts "Invalid payload: #{payload_name}"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
# Evalulate the command
|
|
|
|
cmd = ARGV.pop.downcase
|
|
|
|
|
|
|
|
# Populate the framework datastore
|
|
|
|
options = ARGV.join(',')
|
|
|
|
|
2008-03-05 19:23:01 +00:00
|
|
|
if (cmd =~ /^(p|y|r|c|j|x|b)/)
|
2006-07-31 04:05:20 +00:00
|
|
|
fmt = 'perl' if (cmd =~ /^p/)
|
2008-03-05 19:23:01 +00:00
|
|
|
fmt = 'ruby' if (cmd =~ /^y/)
|
2006-07-31 04:05:20 +00:00
|
|
|
fmt = 'raw' if (cmd =~ /^(r|x)/)
|
2006-09-25 11:34:04 +00:00
|
|
|
fmt = 'c' if (cmd == 'c')
|
2006-07-31 04:05:20 +00:00
|
|
|
fmt = 'js_be' if (cmd =~ /^j/ and Rex::Arch.endian(payload.arch) == ENDIAN_BIG)
|
|
|
|
fmt = 'js_le' if (cmd =~ /^j/ and ! fmt)
|
2007-05-07 04:42:11 +00:00
|
|
|
fmt = 'java' if (cmd =~ /^b/)
|
2007-06-01 20:29:52 +00:00
|
|
|
enc = options['ENCODER']
|
2006-07-31 04:05:20 +00:00
|
|
|
|
2005-10-01 09:10:41 +00:00
|
|
|
begin
|
|
|
|
buf = payload.generate_simple(
|
2006-07-31 04:05:20 +00:00
|
|
|
'Format' => fmt,
|
2007-06-01 20:29:52 +00:00
|
|
|
'OptionStr' => options,
|
|
|
|
'Encoder' => enc)
|
2005-10-01 09:10:41 +00:00
|
|
|
rescue
|
|
|
|
puts "Error generating payload: #{$!}"
|
|
|
|
exit
|
|
|
|
end
|
2007-06-16 05:16:13 +00:00
|
|
|
|
|
|
|
$stdout.binmode
|
2006-07-31 04:05:20 +00:00
|
|
|
|
|
|
|
if (cmd =~ /^x/)
|
|
|
|
note =
|
|
|
|
"Created by msfpayload (http://www.metasploit.com).\n" +
|
|
|
|
"Payload: " + payload.refname + "\n" +
|
|
|
|
" Length: " + buf.length.to_s + "\n" +
|
|
|
|
"Options: " + options + "\n"
|
|
|
|
|
|
|
|
arch = payload.arch
|
|
|
|
plat = payload.platform.platforms
|
2006-11-15 22:04:36 +00:00
|
|
|
|
2007-09-24 17:54:51 +00:00
|
|
|
|
2006-07-31 04:05:20 +00:00
|
|
|
|
2007-11-26 22:23:51 +00:00
|
|
|
if (arch.index(ARCH_X86))
|
2007-09-24 17:54:51 +00:00
|
|
|
|
|
|
|
# Automatically prepend stack adjustment
|
|
|
|
buf = Rex::Arch.adjust_stack_pointer('x86', -3500) + buf
|
|
|
|
|
|
|
|
if (plat.index(Msf::Module::Platform::Windows))
|
|
|
|
buf = Rex::Text.to_win32pe(buf, note)
|
|
|
|
$stderr.puts(note)
|
|
|
|
$stdout.write(buf)
|
|
|
|
exit(0)
|
|
|
|
end
|
2007-09-25 01:50:05 +00:00
|
|
|
|
|
|
|
if (plat.index(Msf::Module::Platform::Linux))
|
|
|
|
buf = Rex::Text.to_linux_x86_elf(buf, note)
|
|
|
|
$stderr.puts(note)
|
|
|
|
$stdout.write(buf)
|
|
|
|
exit(0)
|
|
|
|
end
|
2007-11-26 22:23:51 +00:00
|
|
|
|
|
|
|
if(plat.index(Msf::Module::Platform::OSX))
|
|
|
|
buf = Rex::Text.to_osx_x86_macho(buf, note)
|
|
|
|
$stderr.puts(note)
|
|
|
|
$stdout.write(buf)
|
|
|
|
exit(0)
|
|
|
|
end
|
2007-09-24 17:54:51 +00:00
|
|
|
end
|
|
|
|
|
2007-11-26 22:23:51 +00:00
|
|
|
if(arch.index(ARCH_ARMLE))
|
2007-09-24 17:54:51 +00:00
|
|
|
if(plat.index(Msf::Module::Platform::OSX))
|
2007-09-25 01:50:05 +00:00
|
|
|
buf = Rex::Text.to_osx_arm_macho(buf, note)
|
2007-09-24 17:54:51 +00:00
|
|
|
$stderr.puts(note)
|
|
|
|
$stdout.write(buf)
|
|
|
|
exit(0)
|
|
|
|
end
|
2006-07-31 04:05:20 +00:00
|
|
|
end
|
2007-09-25 01:50:05 +00:00
|
|
|
|
2007-11-26 22:23:51 +00:00
|
|
|
if(arch.index(ARCH_PPC))
|
2007-09-25 01:50:05 +00:00
|
|
|
if(plat.index(Msf::Module::Platform::OSX))
|
|
|
|
buf = Rex::Text.to_osx_ppc_macho(buf, note)
|
|
|
|
$stderr.puts(note)
|
|
|
|
$stdout.write(buf)
|
|
|
|
exit(0)
|
|
|
|
end
|
|
|
|
end
|
2007-11-26 22:23:51 +00:00
|
|
|
|
2006-07-31 04:05:20 +00:00
|
|
|
$stderr.puts "No executable format support for this arch/platform"
|
|
|
|
exit(-1)
|
|
|
|
end
|
|
|
|
|
2007-06-16 05:16:13 +00:00
|
|
|
$stdout.puts(buf)
|
2006-07-31 04:05:20 +00:00
|
|
|
|
2007-04-28 18:34:33 +00:00
|
|
|
elsif (cmd =~ /^(s|o)/)
|
2005-10-01 09:10:41 +00:00
|
|
|
puts Msf::Serializer::ReadableText.dump_module(payload)
|
|
|
|
end
|