2005-12-17 07:46:23 +01:00
|
|
|
#!/usr/bin/env ruby
|
2005-10-01 11:10:41 +02:00
|
|
|
|
2005-12-06 04:34:58 +01:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
2005-10-01 11:10:41 +02: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 07:44:15 +02:00
|
|
|
'Header' => "Framework Payloads (#{$framework.stats.num_payloads} total)",
|
2005-10-01 11:10:41 +02:00
|
|
|
'Columns' =>
|
|
|
|
[
|
|
|
|
"Name",
|
|
|
|
"Description"
|
|
|
|
])
|
|
|
|
|
|
|
|
$framework.payloads.each_module { |name, mod|
|
|
|
|
tbl << [ name, mod.new.description ]
|
|
|
|
}
|
|
|
|
|
|
|
|
"\n" + tbl.to_s + "\n"
|
|
|
|
end
|
|
|
|
|
2005-10-01 23:26:17 +02:00
|
|
|
# Initialize the simplified framework instance.
|
|
|
|
$framework = Msf::Simple::Framework.create
|
2005-10-01 11:10:41 +02:00
|
|
|
|
|
|
|
if (ARGV.length <= 1)
|
2006-07-31 06:05:20 +02:00
|
|
|
puts "\n" + " Usage: #{$0} <payload> [var=val] <S[ummary]|C|P[erl]|R[aw]|J[avascript]|e[X]ecutable>\n"
|
2005-10-01 11:10:41 +02:00
|
|
|
puts dump_payloads
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get the payload name we'll be using
|
|
|
|
payload_name = ARGV.shift
|
|
|
|
payload = $framework.payloads.create(payload_name)
|
|
|
|
|
|
|
|
if (payload == nil)
|
|
|
|
puts "Invalid payload: #{payload_name}"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
# Evalulate the command
|
|
|
|
cmd = ARGV.pop.downcase
|
|
|
|
|
|
|
|
# Populate the framework datastore
|
|
|
|
options = ARGV.join(',')
|
|
|
|
|
2006-07-31 06:05:20 +02:00
|
|
|
if (cmd =~ /^(p|r|c|j|x)/)
|
|
|
|
fmt = 'perl' if (cmd =~ /^p/)
|
|
|
|
fmt = 'raw' if (cmd =~ /^(r|x)/)
|
|
|
|
fmt = 'js_be' if (cmd =~ /^j/ and Rex::Arch.endian(payload.arch) == ENDIAN_BIG)
|
|
|
|
fmt = 'js_le' if (cmd =~ /^j/ and ! fmt)
|
|
|
|
|
2005-10-01 11:10:41 +02:00
|
|
|
begin
|
|
|
|
buf = payload.generate_simple(
|
2006-07-31 06:05:20 +02:00
|
|
|
'Format' => fmt,
|
2005-10-01 11:10:41 +02:00
|
|
|
'OptionStr' => options)
|
|
|
|
rescue
|
|
|
|
puts "Error generating payload: #{$!}"
|
|
|
|
exit
|
|
|
|
end
|
2006-07-31 06:05:20 +02: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
|
|
|
|
|
|
|
|
if (plat.index(Msf::Module::Platform::Windows) and arch.index("x86"))
|
|
|
|
buf = Rex::Text.to_win32pe(buf, note)
|
|
|
|
$stderr.puts(note)
|
|
|
|
$stdout.write(buf)
|
|
|
|
exit(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
$stderr.puts "No executable format support for this arch/platform"
|
|
|
|
exit(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
puts buf
|
|
|
|
|
2005-10-01 11:10:41 +02:00
|
|
|
elsif (cmd =~ /^s/)
|
|
|
|
puts Msf::Serializer::ReadableText.dump_module(payload)
|
|
|
|
end
|