Files
metasploit-gs/test/functional/meterpreter/meterpreter_java_spec.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
2.3 KiB
Ruby
Raw Normal View History

2011-03-09 03:04:12 +00:00
$:.unshift(File.join(File.dirname(__FILE__)))
2011-01-06 20:48:56 +00:00
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib'))
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'test', 'lib'))
require 'fileutils'
require 'meterpreter_spec_helper'
require 'meterpreter_specs'
module MsfTest
describe "JavaMeterpreter" do
2013-09-30 13:47:53 -05:00
# This include brings in all the spec helper methods
include MsfTest::MeterpreterSpecHelper
2011-01-06 20:48:56 +00:00
2013-09-30 13:47:53 -05:00
# This include brings in all the specs that are generic across the
# meterpreter platforms
include MsfTest::MeterpreterSpecs
# This include brings in all the specs that are specific to the java
# meterpreter
include MsfTest::JavaMeterpreterSpecs
before :all do
@verbose = true
@meterpreter_type = "java"
## Set up an outupt directory
@output_directory = File.join(File.dirname(__FILE__), "test_output_#{@meterpreter_type}")
if File.directory? @output_directory
FileUtils.rm_rf(@output_directory)
2022-04-28 15:06:43 +01:00
end
2013-09-30 13:47:53 -05:00
Dir.mkdir(@output_directory)
@default_file = "#{@output_directory}/default"
2022-04-28 15:06:43 +01:00
2013-09-30 13:47:53 -05:00
create_session_java
end
before :each do
2022-04-28 15:06:43 +01:00
end
2013-09-30 13:47:53 -05:00
after :each do
@session.init_ui(@input, @output)
2022-04-28 15:06:43 +01:00
end
2013-09-30 13:47:53 -05:00
after :all do
# FileUtils.rm_rf("*.jpeg")
# FileUtils.rm_rf("payload.jar")
FileUtils.rm_rf(@output_directory)
2022-04-28 15:06:43 +01:00
end
2013-09-30 13:47:53 -05:00
def create_session_java
## Setup for win32
@framework = Msf::Simple::Framework.create
2022-04-28 15:06:43 +01:00
2013-09-30 13:47:53 -05:00
test_modules_path = File.join(File.dirname(__FILE__), '..', '..', 'modules')
@framework.modules.add_module_path(test_modules_path)
2022-04-28 15:06:43 +01:00
2013-09-30 13:47:53 -05:00
@exploit_name = 'test/java_tester'
@payload_name = 'java/meterpreter/bind_tcp'
@input = Rex::Ui::Text::Input::Stdio.new
@output = Rex::Ui::Text::Output::File.new(@default_file)
2022-04-28 15:06:43 +01:00
2013-09-30 13:47:53 -05:00
# Initialize the exploit instance
exploit = @framework.exploits.create(@exploit_name)
2022-04-28 15:06:43 +01:00
2013-09-30 13:47:53 -05:00
## Fire it off against a known-vulnerable host
@session = exploit.exploit_simple(
'Options' => {},
'Payload' => @payload_name,
'LocalInput' => @input,
'LocalOutput' => @output
)
2022-04-28 15:06:43 +01:00
2013-09-30 13:47:53 -05:00
puts @session.inspect
2022-04-28 15:06:43 +01:00
2013-09-30 13:47:53 -05:00
## If a session came back, try to interact with it.
if @session
@session.load_stdapi
else
raise Exception "Couldn't get a session!"
2022-04-28 15:06:43 +01:00
end
2013-09-30 13:47:53 -05:00
end
end
2011-01-06 20:48:56 +00:00
end