CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/tools/egghunter_spec.rb
Views: 1904
1
load Metasploit::Framework.root.join('tools/exploit/egghunter.rb').to_path
2
require 'spec_helper'
3
4
RSpec.describe Egghunter do
5
6
describe Egghunter::Driver do
7
8
subject do
9
Egghunter::Driver.new
10
end
11
12
let(:egg) {
13
'W00T'
14
}
15
16
describe '#run' do
17
18
let(:default_opts) {
19
{ :platform => 'windows', :format => 'c', :eggtag => egg, :arch => 'x86' }
20
}
21
22
before(:example) do
23
allow(Egghunter::OptsConsole).to receive(:parse).with(any_args).and_return(options)
24
end
25
26
context 'when the platform is windows' do
27
let(:options) { default_opts }
28
29
it 'returns a windows egghunter' do
30
output = get_stdout { subject.run }
31
expect(output).to include("\\x66\\x81\\xca\\xff")
32
end
33
end
34
35
context 'when the platform is linux' do
36
let(:options) do
37
{ :platform => 'linux', :format => 'c', :eggtag => egg, :arch => 'x86' }
38
end
39
40
it 'returns a linux egghunter' do
41
output = get_stdout { subject.run }
42
expect(output).to include("\\xfc\\x66\\x81\\xc9\\xff")
43
end
44
end
45
46
context 'when the egg is WOOT' do
47
let(:options) { default_opts }
48
49
it 'includes W00T in the egghunter' do
50
output = get_stdout { subject.run }
51
expect(output).to include("\\x57\\x30\\x30\\x54")
52
end
53
end
54
end
55
end
56
57
58
describe Egghunter::OptsConsole do
59
subject do
60
Egghunter::OptsConsole
61
end
62
63
context 'when no options are given' do
64
it 'raises OptionParser::MissingArgument' do
65
expect{subject.parse([])}.to raise_error(OptionParser::MissingArgument)
66
end
67
end
68
69
context 'when no format is specified and --list-formats isn\'t used' do
70
it 'raises OptionParser::MissingArgument' do
71
args = '-e AAAA'.split
72
expect{subject.parse(args)}.to raise_error(OptionParser::MissingArgument)
73
end
74
end
75
76
context 'when no egg is specified and --list-formats isn\'t used' do
77
it 'raises OptionParser::MissingArgument' do
78
args = '-f python'.split
79
expect{subject.parse(args)}.to raise_error(OptionParser::MissingArgument)
80
end
81
end
82
83
context 'when :depsize is a string' do
84
it 'raises OptionParser::InvalidOption' do
85
args = '-e AAAA -f c --depsize STRING'.split
86
expect{subject.parse(args)}.to raise_error(OptionParser::InvalidOption)
87
end
88
end
89
end
90
91
end
92
93