CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/test/functional/meterpreter/meterpreter_java_spec.rb
Views: 11623
1
$:.unshift(File.join(File.dirname(__FILE__)))
2
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib'))
3
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'test', 'lib'))
4
5
require 'fileutils'
6
require 'meterpreter_spec_helper'
7
require 'meterpreter_specs'
8
9
module MsfTest
10
describe "JavaMeterpreter" do
11
# This include brings in all the spec helper methods
12
include MsfTest::MeterpreterSpecHelper
13
14
# This include brings in all the specs that are generic across the
15
# meterpreter platforms
16
include MsfTest::MeterpreterSpecs
17
18
# This include brings in all the specs that are specific to the java
19
# meterpreter
20
include MsfTest::JavaMeterpreterSpecs
21
22
before :all do
23
@verbose = true
24
25
@meterpreter_type = "java"
26
27
## Set up an outupt directory
28
@output_directory = File.join(File.dirname(__FILE__), "test_output_#{@meterpreter_type}")
29
30
if File.directory? @output_directory
31
FileUtils.rm_rf(@output_directory)
32
end
33
34
Dir.mkdir(@output_directory)
35
@default_file = "#{@output_directory}/default"
36
37
create_session_java
38
end
39
40
before :each do
41
end
42
43
after :each do
44
@session.init_ui(@input, @output)
45
end
46
47
after :all do
48
# FileUtils.rm_rf("*.jpeg")
49
# FileUtils.rm_rf("payload.jar")
50
FileUtils.rm_rf(@output_directory)
51
end
52
53
def create_session_java
54
## Setup for win32
55
@framework = Msf::Simple::Framework.create
56
57
test_modules_path = File.join(File.dirname(__FILE__), '..', '..', 'modules')
58
@framework.modules.add_module_path(test_modules_path)
59
60
@exploit_name = 'test/java_tester'
61
@payload_name = 'java/meterpreter/bind_tcp'
62
@input = Rex::Ui::Text::Input::Stdio.new
63
@output = Rex::Ui::Text::Output::File.new(@default_file)
64
65
# Initialize the exploit instance
66
exploit = @framework.exploits.create(@exploit_name)
67
68
## Fire it off against a known-vulnerable host
69
@session = exploit.exploit_simple(
70
'Options' => {},
71
'Payload' => @payload_name,
72
'LocalInput' => @input,
73
'LocalOutput' => @output
74
)
75
76
puts @session.inspect
77
78
## If a session came back, try to interact with it.
79
if @session
80
@session.load_stdapi
81
else
82
raise Exception "Couldn't get a session!"
83
end
84
end
85
end
86
end
87
88