Add select_cmdstager

bug/bundler_fix
jvazquez-r7 2014-02-08 19:13:48 -06:00 committed by Spencer McIntyre
parent 35d035fa4e
commit 68938e3d7a
1 changed files with 58 additions and 27 deletions

View File

@ -15,14 +15,38 @@ module Exploit::CmdStager
include Msf::Exploit::EXE
STAGERS = {
:bourne => Rex::Exploitation::CmdStagerBourne,
:debug_asm => Rex::Exploitation::CmdStagerDebugAsm,
:debug_write => Rex::Exploitation::CmdStagerDebugWrite,
:echo => Rex::Exploitation::CmdStagerEcho,
:printf => Rex::Exploitation::CmdStagerPrintf,
:vbs => Rex::Exploitation::CmdStagerVBS,
:vbs_adodb => Rex::Exploitation::CmdStagerVBS,
:tftp => Rex::Exploitation::CmdStagerTFTP
:bourne => {
:klass => Rex::Exploitation::CmdStagerBourne,
:decoder => false
},
:debug_asm => {
:klass => Rex::Exploitation::CmdStagerDebugAsm,
:decoder => true
},
:debug_write => {
:klass => Rex::Exploitation::CmdStagerDebugWrite,
:decoder => true
},
:echo => {
:klass => Rex::Exploitation::CmdStagerEcho,
:decoder => false
},
:printf => {
:klass => Rex::Exploitation::CmdStagerPrintf,
:decoder => false
},
:vbs => {
:klass => Rex::Exploitation::CmdStagerVBS,
:decoder => true
},
:vbs_adodb => {
:klass => Rex::Exploitation::CmdStagerVBS,
:decoder => true
},
:tftp => {
:klass => Rex::Exploitation::CmdStagerTFTP,
:decoder => false
}
}
STUBS = {
@ -54,7 +78,8 @@ module Exploit::CmdStager
end
# Executes the command stager while showing the progress
# Executes the command stager while showing the progress. This method should
# be called from exploits using this mixin.
#
# @param opts [Hash] Hash containing configuration options. Also allow to
# send opts to the Rex::Exploitation::CmdStagerBase constructor.
@ -63,28 +88,14 @@ module Exploit::CmdStager
# @option opts :delay [Float] Delay between command executions.
# @option opts :code [String] Payload to embed into the resultant executable.
# @return [void]
# @raise [ArgumentError] raised if a valid CMD Stager can not be found or
# it isn't compatible with the target.
def execute_cmdstager(opts = {})
# Select the correct flavor
select_flavor(opts)
raise ArgumentError, "Unable to select CMD Stager" if flavor.nil?
raise ArgumentError, "The CMD Stager selected isn't compatible with the target" unless compatible_flavor?
# Select the correct decoder
select_decoder_stub(opts)
# Generate the CMD stager list of commands
self.cmd_list = generate_cmdstager(opts)
# If the stager needs to do additional setup...
stager_instance.setup(self)
# Execute it... ensuring the stager gets a chance to cleanup
begin
execute_cmdstager_begin(opts)
sent = 0
total_bytes = 0
cmd_list.each { |cmd| total_bytes += cmd.length }
@ -114,13 +125,12 @@ module Exploit::CmdStager
# and platform.
#
def generate_cmdstager(opts = {}, pl = nil)
opts[:decoder] = decoder_stub unless opts.include?(:decoder)
select_cmdstager(opts)
self.exe = generate_payload_exe(:code => pl)
self.stager_instance = create_stager
cmd_list = stager_instance.generate(opts)
cmd_list = stager_instance.generate(opts_with_decoder(opts))
if (cmd_list.nil? or cmd_list.length < 1)
print_error("The command stager could not be generated")
@ -130,6 +140,21 @@ module Exploit::CmdStager
cmd_list
end
def select_cmdstager(opts = {})
select_flavor(opts)
raise ArgumentError, "Unable to select CMD Stager" if flavor.nil?
raise ArgumentError, "The CMD Stager selected isn't compatible with the target" unless compatible_flavor?
select_decoder_stub(opts)
raise ArgumentError, "Unable to select decoder stub" if decoder_stub.nil? and stub_required?
end
def opts_with_decoder(opts = {})
return opts if opts.include?(:decoder)
return opts.merge(:decoder => decoder_stub) if decoder_stub
opts
end
#
# Show the progress of the upload
@ -144,7 +169,7 @@ module Exploit::CmdStager
# Create an instance of the flavored stager
#
def create_stager
STAGERS[flavor].new(exe)
STAGERS[flavor][:klass].new(exe)
end
#
@ -157,6 +182,10 @@ module Exploit::CmdStager
STUBS[flavor]
end
def stub_required?
STAGERS[flavor][:decoder]
end
#
# 1 - Use the decoder provided by the module source
# 2 - Use the decoder by the user through datastore
@ -233,6 +262,8 @@ module Exploit::CmdStager
end
def execute_cmdstager_end(opts)
end
def execute_command(cmd, opts)
end
end