2011-03-22 22:59:01 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# ## This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2011-03-22 22:59:01 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/core/post/common'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
include Msf::Post::Common
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2011-04-27 16:25:15 +00:00
|
|
|
'Name' => 'Multi Gather Run Shell Command Resource File',
|
2011-03-22 22:59:01 +00:00
|
|
|
'Description' => %q{ This module will read shell commands from a resource file and
|
2011-07-27 02:39:49 +00:00
|
|
|
execute the commands in the specified Meterpreter or shell session.},
|
2011-03-22 22:59:01 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Platform' => [ 'windows', 'linux', 'bsd', 'unix', 'osx' ],
|
|
|
|
'SessionTypes' => [ 'meterpreter','shell' ]
|
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('RESOURCE', [true, 'Full path to resource file to read commands from.', nil])
|
|
|
|
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Run Method for when run command is issued
|
|
|
|
def run
|
|
|
|
session_type = session.type
|
|
|
|
print_status("Running module against #{sysinfo['Computer']}")
|
|
|
|
if not ::File.exists?(datastore['RESOURCE'])
|
2011-06-10 03:36:48 +00:00
|
|
|
raise "Resource File does not exists!"
|
|
|
|
else
|
2011-12-16 05:13:06 +00:00
|
|
|
::File.open(datastore['RESOURCE'], "rb").each_line do |cmd|
|
2011-06-10 03:36:48 +00:00
|
|
|
next if cmd.strip.length < 1
|
2011-03-22 22:59:01 +00:00
|
|
|
next if cmd[0,1] == "#"
|
|
|
|
begin
|
|
|
|
tmpout = "\n"
|
|
|
|
tmpout << "*****************************************\n"
|
|
|
|
tmpout << " Output of #{cmd}\n"
|
|
|
|
tmpout << "*****************************************\n"
|
|
|
|
print_status "Running command #{cmd.chomp}"
|
|
|
|
if session_type =~ /meterpreter/
|
|
|
|
tmpout << cmd_exec(cmd.chomp)
|
|
|
|
elsif session_type =~ /shell/
|
2011-03-26 02:56:19 +00:00
|
|
|
tmpout << session.shell_command_token(cmd.chomp).chomp
|
2011-03-22 22:59:01 +00:00
|
|
|
end
|
2011-07-15 15:33:35 +00:00
|
|
|
vprint_status tmpout
|
2011-03-23 02:59:51 +00:00
|
|
|
command_log = store_loot("host.command", "text/plain", session,tmpout ,
|
2011-03-22 22:59:01 +00:00
|
|
|
"#{cmd.gsub(/\.|\/|\s/,"_")}.txt", "Command Output \'#{cmd.chomp}\'")
|
|
|
|
print_status("Command output saved to: #{command_log}")
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error Running Command #{cmd.chomp}: #{e.class} #{e}")
|
|
|
|
end
|
2011-06-10 03:36:48 +00:00
|
|
|
end
|
|
|
|
end
|
2011-03-22 22:59:01 +00:00
|
|
|
end
|
2011-07-15 15:33:35 +00:00
|
|
|
end
|