From 9c69e3c670d5c75985b1204c9307d37646021b1e Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Fri, 20 Aug 2010 19:39:13 +0000 Subject: [PATCH] add payload length tool git-svn-id: file:///home/svn/framework3/trunk@10085 4d416f70-5f16-0410-b530-b9f4589650da --- tools/payload_lengths.rb | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 tools/payload_lengths.rb diff --git a/tools/payload_lengths.rb b/tools/payload_lengths.rb new file mode 100755 index 0000000000..62813f04b1 --- /dev/null +++ b/tools/payload_lengths.rb @@ -0,0 +1,65 @@ +#!/usr/bin/env ruby +# +# $Id$ +# $Revision$ +# +# This script lists each payload module along with its length +# NOTE: No encoding or BadChar handling is performed +# + +msfbase = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ +$:.unshift(File.join(File.dirname(msfbase), '..', 'lib')) + +require 'rex' +require 'msf/ui' +require 'msf/base' + +Indent = ' ' + +# Initialize the simplified framework instance. +$framework = Msf::Simple::Framework.create( + :module_types => [ + Msf::MODULE_PAYLOAD # , Msf::MODULE_ENCODER, Msf::MODULE_NOP + ], + #'DisableDatabase' => true +) + +# Process special var/val pairs... +Msf::Ui::Common.process_cli_arguments($framework, ARGV) + +tbl = Rex::Ui::Text::Table.new( + 'Header' => 'Payload Lengths', + 'Indent' => Indent.length, + 'Columns' => [ 'Payload', 'Length' ] +) + +enc = nil +options = ARGV.join(',') + +$framework.payloads.each_module { |payload_name, mod| + + len = 'Unknown error!' + + begin + # Create the payload instance + payload = $framework.payloads.create(payload_name) + raise "Invalid payload" if not payload + + buf = payload.generate_simple( + 'Format' => 'raw', + 'OptionStr' => options, + 'Encoder' => enc + ) + if buf.length > 0 + len = buf.length.to_s + else + len = "Error: Empty payload" + end + rescue + len = "Error: #{$!}" + end + + tbl << [ payload_name, len ] +} + +puts tbl.to_s