2015-10-06 20:42:31 +00:00
|
|
|
load Metasploit::Framework.root.join('tools/exploit/egghunter.rb').to_path
|
2015-12-24 19:03:11 +00:00
|
|
|
require 'spec_helper'
|
2015-03-20 21:46:09 +00:00
|
|
|
|
2015-10-16 20:57:04 +00:00
|
|
|
RSpec.describe Egghunter do
|
2015-03-20 21:53:42 +00:00
|
|
|
|
2015-03-21 01:53:04 +00:00
|
|
|
describe Egghunter::Driver do
|
|
|
|
|
|
|
|
subject do
|
|
|
|
Egghunter::Driver.new
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:egg) {
|
|
|
|
'W00T'
|
|
|
|
}
|
|
|
|
|
|
|
|
describe '#run' do
|
|
|
|
|
|
|
|
let(:default_opts) {
|
|
|
|
{ :platform => 'windows', :format => 'c', :eggtag => egg, :arch => 'x86' }
|
|
|
|
}
|
|
|
|
|
2015-12-31 22:56:13 +00:00
|
|
|
before(:example) do
|
2015-03-21 01:53:04 +00:00
|
|
|
allow(Egghunter::OptsConsole).to receive(:parse).with(any_args).and_return(options)
|
|
|
|
end
|
2015-03-20 21:46:09 +00:00
|
|
|
|
2015-03-21 01:53:04 +00:00
|
|
|
context 'when the platform is windows' do
|
|
|
|
let(:options) { default_opts }
|
2015-03-20 21:46:09 +00:00
|
|
|
|
2015-03-21 01:53:04 +00:00
|
|
|
it 'returns a windows egghunter' do
|
|
|
|
output = get_stdout { subject.run }
|
|
|
|
expect(output).to include("\\x66\\x81\\xca\\xff")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the platform is linux' do
|
|
|
|
let(:options) do
|
|
|
|
{ :platform => 'linux', :format => 'c', :eggtag => egg, :arch => 'x86' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a linux egghunter' do
|
|
|
|
output = get_stdout { subject.run }
|
|
|
|
expect(output).to include("\\xfc\\x66\\x81\\xc9\\xff")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the egg is WOOT' do
|
|
|
|
let(:options) { default_opts }
|
|
|
|
|
|
|
|
it 'includes W00T in the egghunter' do
|
|
|
|
output = get_stdout { subject.run }
|
|
|
|
expect(output).to include("\\x57\\x30\\x30\\x54")
|
|
|
|
end
|
2015-03-20 21:53:42 +00:00
|
|
|
end
|
|
|
|
end
|
2015-03-21 01:53:04 +00:00
|
|
|
end
|
|
|
|
|
2015-03-20 21:53:42 +00:00
|
|
|
|
2015-03-21 01:53:04 +00:00
|
|
|
describe Egghunter::OptsConsole do
|
|
|
|
subject do
|
|
|
|
Egghunter::OptsConsole
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no options are given' do
|
|
|
|
it 'raises OptionParser::MissingArgument' do
|
|
|
|
expect{subject.parse([])}.to raise_error(OptionParser::MissingArgument)
|
2015-03-20 21:53:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-21 01:53:04 +00:00
|
|
|
context 'when no format is specified and --list-formats isn\'t used' do
|
|
|
|
it 'raises OptionParser::MissingArgument' do
|
|
|
|
args = '-e AAAA'.split
|
|
|
|
expect{subject.parse(args)}.to raise_error(OptionParser::MissingArgument)
|
2015-03-20 21:53:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-21 01:53:04 +00:00
|
|
|
context 'when no egg is specified and --list-formats isn\'t used' do
|
|
|
|
it 'raises OptionParser::MissingArgument' do
|
|
|
|
args = '-f python'.split
|
|
|
|
expect{subject.parse(args)}.to raise_error(OptionParser::MissingArgument)
|
2015-03-20 21:53:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-21 01:53:04 +00:00
|
|
|
context 'when :depsize is a string' do
|
|
|
|
it 'raises OptionParser::InvalidOption' do
|
|
|
|
args = '-e AAAA -f c --depsize STRING'.split
|
|
|
|
expect{subject.parse(args)}.to raise_error(OptionParser::InvalidOption)
|
|
|
|
end
|
|
|
|
end
|
2015-03-20 21:53:42 +00:00
|
|
|
end
|
2015-03-21 01:53:04 +00:00
|
|
|
|
2015-03-24 05:19:27 +00:00
|
|
|
end
|