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/spec/lib/msf/exploit/local_spec.rb
Views: 11704
1
require 'spec_helper'
2
require 'rex/post/meterpreter/extensions/stdapi/sys/config'
3
4
RSpec.describe Msf::Exploit::Local do
5
describe '#exploit_type' do
6
it 'indicates that the exploit is local' do
7
expect(subject.exploit_type).to eq 'local'
8
end
9
end
10
11
describe '#sysinfo' do
12
before(:each) do
13
allow(subject).to receive(:session).and_return(session)
14
end
15
16
context 'when the session is nil' do
17
let(:session) { nil }
18
19
it 'returns nil' do
20
expect(subject.sysinfo).to eq nil
21
end
22
end
23
24
context 'when the session is not Meterpreter' do
25
let(:session) do
26
connection = nil
27
Msf::Sessions::CommandShell.new(connection)
28
end
29
30
it 'returns nil' do
31
expect(subject.sysinfo).to eq nil
32
end
33
end
34
35
context 'when the session is Meterpreter' do
36
let(:session) do
37
connection = nil
38
session = Msf::Sessions::Meterpreter_x86_Win.new(connection)
39
session.register_extension_alias(
40
'sys',
41
Rex::Post::Meterpreter::ObjectAliases.new(
42
'config' => instance_double(
43
::Rex::Post::Meterpreter::Extensions::Stdapi::Sys::Config,
44
sysinfo: { 'Computer' => 'FooComputer' }
45
)
46
)
47
)
48
session
49
end
50
51
it 'returns the sysinfo object' do
52
expect(subject.sysinfo).to eq({ 'Computer' => 'FooComputer' })
53
end
54
end
55
end
56
end
57
58