Skip to content

Commit

Permalink
added spec for rapid7#6915
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Cook committed May 26, 2016
1 parent 96c459c commit c2cf992
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions spec/lib/msf/core/payload_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
reference_name: 'windows/meterpreter/reverse_tcp'
)
}

# let(:shellcode) { "\x50\x51\x58\x59" }

# let(:var_name) { 'buf' }

subject(:payload_generator) {
Expand Down Expand Up @@ -130,7 +130,7 @@
template: File.join(Msf::Config.data_directory, 'templates', 'template_x86_windows.exe')
}
}

it { is_expected.to raise_error(ArgumentError, "Invalid Payload Selected") }
end

Expand Down Expand Up @@ -495,7 +495,7 @@
expect{payload_generator.generate_raw_payload}.to raise_error(Msf::IncompatiblePlatform, "You must select a platform for a custom payload")
end
end

let(:generator_opts) {
{
add_code: false,
Expand Down Expand Up @@ -632,7 +632,7 @@
template: File.join(Msf::Config.data_directory, 'templates', 'template_x86_windows.exe')
}
}

it 'returns the original shellcode' do
expect(payload_generator.add_shellcode(shellcode)).to eq shellcode
end
Expand All @@ -658,7 +658,7 @@
template: File.join(Msf::Config.data_directory, 'templates', 'template_x86_windows.exe')
}
}


it 'returns the original shellcode' do
expect(payload_generator.add_shellcode(shellcode)).to eq shellcode
Expand Down Expand Up @@ -775,7 +775,7 @@
template: File.join(Msf::Config.data_directory, 'templates', 'template_x86_windows.exe')
}
}

before(:example) do
load_and_create_module(
module_type: 'nop',
Expand Down Expand Up @@ -861,7 +861,7 @@
# x86/alpha_mixed
# }
# }

let(:generator_opts) {
{
add_code: false,
Expand Down Expand Up @@ -925,7 +925,7 @@
template: File.join(Msf::Config.data_directory, 'templates', 'template_x86_windows.exe')
}
}

it 'returns an array of all encoders with a compatible arch' do
payload_generator.get_encoders.each do |my_encoder|
expect(my_encoder.arch).to include 'x86'
Expand Down Expand Up @@ -959,7 +959,7 @@
reference_name: 'x86/shikata_ga_nai'
)
}

it 'returns an empty array' do
expect(payload_generator.get_encoders).to be_empty
end
Expand Down Expand Up @@ -1128,7 +1128,7 @@
payload_generator.generate_java_payload
end
end

let(:generator_opts) {
{
add_code: false,
Expand All @@ -1148,7 +1148,7 @@
template: File.join(Msf::Config.data_directory, 'templates', 'template_x86_windows.exe')
}
}

it 'raises an InvalidFormat exception' do
expect{ payload_generator.generate_java_payload }.to raise_error(Msf::InvalidFormat)
end
Expand Down Expand Up @@ -1358,5 +1358,30 @@
expect{payload_generator.generate_payload}.to raise_error(Msf::PayloadSpaceViolation, "The payload exceeds the specified space")
end
end
context 'when the payload format is invalid for the platform' do
let!(:payload_module) {
load_and_create_module(
ancestor_reference_names: %w{
stagers/osx/x86/reverse_tcp
stages/osx/x86/isight
},
module_type: 'payload',
reference_name: 'osx/x86/isight/reverse_tcp'
)
}
let(:generator_opts) {
{
datastore: { 'LHOST' => '192.168.172.1', 'LPORT' => '8443' } ,
format: 'elf',
framework: framework,
keep: false,
payload: 'osx/x86/isight/reverse_tcp',
stdin: nil,
}
}
it 'should raise an error' do
expect{payload_generator.generate_payload}.to raise_error(Msf::PayloadGeneratorError, "The payload could not be generated, check options")
end
end

end

0 comments on commit c2cf992

Please sign in to comment.