Add rspec for Msf::Core::Exploit::SMB::*Paths
parent
6634fb3583
commit
c11741b7c4
|
@ -0,0 +1,63 @@
|
|||
# -*- coding:binary -*-
|
||||
require 'spec_helper'
|
||||
|
||||
require 'msf/core'
|
||||
require 'msf/core/data_store'
|
||||
#require 'msf/core/exploit/smb'
|
||||
#require 'msf/core/exploit/smb/local_paths'
|
||||
|
||||
describe Msf::Exploit::Remote::SMB::LocalPaths do
|
||||
subject do
|
||||
mod = ::Msf::Module.new
|
||||
mod.extend described_class
|
||||
mod
|
||||
end
|
||||
|
||||
before(:all) do
|
||||
prefix = "local_#{Rex::Text.rand_text_alpha(10)}"
|
||||
# create a single random file to be used for LPATH
|
||||
@lpath = prefix
|
||||
# create file containing several random file names to be used for FILE_LPATHS
|
||||
@indices = Array(0..(1 + rand(5))).map(&:to_s)
|
||||
@file_lpaths = Tempfile.new(prefix)
|
||||
|
||||
File.open(@file_lpaths, 'wb') do |f|
|
||||
@indices.map do |i|
|
||||
f.puts(i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#setup' do
|
||||
context 'when PATH and FILE_LPATHS are not set correctly' do
|
||||
it 'should raise if both are set' do
|
||||
subject.datastore['LPATH'] = @lpath
|
||||
subject.datastore['FILE_LPATHS'] = @file_lpaths
|
||||
expect{subject.setup}.to raise_error(RuntimeError, /bad-config/)
|
||||
end
|
||||
|
||||
it 'should raise if neither are set' do
|
||||
expect{subject.setup}.to raise_error(RuntimeError, /bad-config/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#local_paths' do
|
||||
context 'when LPATH and FILE_LPATHS are set correctly' do
|
||||
it 'should return just one remote file if LPATH is set' do
|
||||
subject.datastore['LPATH'] = @lpath
|
||||
expect(subject.local_paths).to eql([@lpath])
|
||||
end
|
||||
|
||||
it 'should return all files if FILE_LPATHS is set' do
|
||||
subject.datastore['FILE_LPATHS'] = @file_lpaths
|
||||
expect(subject.local_paths).to eql(@indices)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@file_lpaths.unlink
|
||||
end
|
||||
end
|
|
@ -0,0 +1,61 @@
|
|||
# -*- coding:binary -*-
|
||||
require 'spec_helper'
|
||||
|
||||
require 'msf/core'
|
||||
require 'msf/core/data_store'
|
||||
|
||||
describe Msf::Exploit::Remote::SMB::RemotePaths do
|
||||
subject do
|
||||
mod = ::Msf::Module.new
|
||||
mod.extend described_class
|
||||
mod
|
||||
end
|
||||
|
||||
before(:all) do
|
||||
prefix = "remote_#{Rex::Text.rand_text_alpha(10)}"
|
||||
# create a single random file to be used for RPATH
|
||||
@rpath = prefix
|
||||
# create file containing several random file names to be used for FILE_RPATHS
|
||||
@indices = Array(0..(1 + rand(5))).map(&:to_s)
|
||||
@file_rpaths = Tempfile.new(prefix)
|
||||
|
||||
File.open(@file_rpaths, 'wb') do |f|
|
||||
@indices.map do |i|
|
||||
f.puts(i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#setup' do
|
||||
context 'when RPATH and FILE_RPATHS are not set correctly' do
|
||||
it 'should raise if both are set' do
|
||||
subject.datastore['RPATH'] = @rpath
|
||||
subject.datastore['FILE_RPATHS'] = @file_rpaths
|
||||
expect{subject.setup}.to raise_error(RuntimeError, /bad-config/)
|
||||
end
|
||||
|
||||
it 'should raise if neither are set' do
|
||||
expect{subject.setup}.to raise_error(RuntimeError, /bad-config/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#remote_paths' do
|
||||
context 'when RPATH and FILE_RPATHS are set correctly' do
|
||||
it 'should return just one remote file if rpath is set' do
|
||||
subject.datastore['RPATH'] = @rpath
|
||||
expect(subject.remote_paths).to eql([@rpath])
|
||||
end
|
||||
|
||||
it 'should return all files if FILE_RPATHS is set' do
|
||||
subject.datastore['FILE_RPATHS'] = @file_rpaths
|
||||
expect(subject.remote_paths).to eql(@indices)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@file_rpaths.unlink
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue