Skip to content

Commit

Permalink
Renames Acceptance::Meterpreter module to Acceptance::Session
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 committed Sep 16, 2024
1 parent 370f0f4 commit ceffede
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/meterpreter_acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ jobs:
metasploitPayloadsCommit: ${{ github.event.inputs.metasploitPayloadsCommit || 'master' }}
mettleCommit: ${{ github.event.inputs.mettleCommit|| 'master' }}
HOST_RUNNER_IMAGE: ${{ matrix.os }}
METERPRETER: ${{ matrix.meterpreter.name }}
METERPRETER_RUNTIME_VERSION: ${{ matrix.meterpreter.runtime_version }}
SESSION: ${{ matrix.meterpreter.name }}
SESSION_RUNTIME_VERSION: ${{ matrix.meterpreter.runtime_version }}
BUNDLE_WITHOUT: "coverage development"

name: ${{ matrix.meterpreter.name }} ${{ matrix.meterpreter.runtime_version }} ${{ matrix.os }}
Expand Down
12 changes: 8 additions & 4 deletions spec/acceptance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ There is no remote host support currently.
### Meterpreter

Useful environment variables:
- `METERPRETER` - Filter the test suite for specific Meterpreter instances, example: `METERPRETER=java`
- `METERPRETER_MODULE_TEST` - Filter the post modules to run, example: `METERPRETER_MODULE_TEST=test/meterpreter`
- `SESSION` - Filter the test suite for specific Meterpreter instances, example: `SESSION=meterpreter/java`
- `SESSION_MODULE_TEST` - Filter the post modules to run, example: `SESSION_MODULE_TEST=test/meterpreter`
- `SPEC_HELPER_LOAD_METASPLOIT` - Skip RSpec from loading Metasploit framework and requiring a connected msfdb instance, example: `SPEC_HELPER_LOAD_METASPLOIT=false`

Running Meterpreter test suite:
Expand All @@ -30,14 +30,18 @@ Run a specific Meterpreter/module test Unix / Windows:

Bash command:
```
SPEC_OPTS='--tag acceptance' METERPRETER=php METERPRETER_MODULE_TEST=post/test/unix bundle exec rspec './spec/acceptance/meterpreter_spec.rb'
SPEC_OPTS='--tag acceptance' SESSION=meterpreter/php SESSION_MODULE_TEST=post/test/unix bundle exec rspec './spec/acceptance/meterpreter_spec.rb'
```

Powershell command:
```
$env:SPEC_OPTS='--tag acceptance'; $env:SPEC_HELPER_LOAD_METASPLOIT=$false; $env:METERPRETER = 'php'; bundle exec rspec './spec/acceptance/meterpreter_spec.rb'
$env:SPEC_OPTS='--tag acceptance'; $env:SPEC_HELPER_LOAD_METASPLOIT=$false; $env:SESSION = 'meterpreter/php'; bundle exec rspec './spec/acceptance/meterpreter_spec.rb'
```

Session types can be specified via the `SESSION` argument. Meterpreter and command shell are support and use the following notation:
- SESSION=meterpreter/php
- SESSION=command_shell/php

### Postgres

Run a target:
Expand Down
12 changes: 6 additions & 6 deletions spec/acceptance/ldap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

allure_test_environment = AllureRspec.configuration.environment_properties

let_it_be(:current_platform) { Acceptance::Meterpreter.current_platform }
let_it_be(:current_platform) { Acceptance::Session.current_platform }

# Driver instance, keeps track of all open processes/payloads/etc, so they can be closed cleanly
let_it_be(:driver) do
Expand Down Expand Up @@ -196,7 +196,7 @@ def with_test_harness(module_test)
end

validated_lines.each do |test_line|
test_line = Acceptance::Meterpreter.uncolorize(test_line)
test_line = Acceptance::Session.uncolorize(test_line)
expect(test_line).to_not include('FAILED', '[-] FAILED', '[-] Exception', '[-] '), "Unexpected error: #{test_line}"
end

Expand Down Expand Up @@ -286,12 +286,12 @@ def with_test_harness(module_test)
tests.each do |runtime_name, test_config|
runtime_name = "#{runtime_name}#{ENV.fetch('RUNTIME_VERSION', '')}"

describe "#{Acceptance::Meterpreter.current_platform}/#{runtime_name}", focus: test_config[:focus] do
describe "#{Acceptance::Session.current_platform}/#{runtime_name}", focus: test_config[:focus] do
test_config[:module_tests].each do |module_test|
describe(
module_test[:name],
if:
Acceptance::Meterpreter.supported_platform?(module_test)
Acceptance::Session.supported_platform?(module_test)
) do
let(:target) { Acceptance::Target.new(test_config[:target]) }

Expand Down Expand Up @@ -352,7 +352,7 @@ def with_test_harness(module_test)

context 'when targeting a session', if: module_test[:targets].include?(:session) do
it(
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
"#{Acceptance::Session.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
) do
with_test_harness(module_test) do |replication_commands|
# Ensure we have a valid session id; We intentionally omit this from a `before(:each)` to ensure the allure attachments are generated if the session dies
Expand All @@ -379,7 +379,7 @@ def with_test_harness(module_test)

context 'when targeting an rhost', if: module_test[:targets].include?(:rhost) do
it(
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
"#{Acceptance::Session.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
) do
with_test_harness(module_test) do |replication_commands|
use_module = "use #{module_test[:name]}"
Expand Down
50 changes: 25 additions & 25 deletions spec/acceptance/meterpreter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
include_context 'wait_for_expect'

# Tests to ensure that Meterpreter is consistent across all implementations/operation systems
METERPRETER_PAYLOADS = Acceptance::Meterpreter.with_meterpreter_name_merged(
METERPRETER_PAYLOADS = Acceptance::Session.with_session_name_merged(
{
python: Acceptance::Meterpreter::PYTHON_METERPRETER,
php: Acceptance::Meterpreter::PHP_METERPRETER,
java: Acceptance::Meterpreter::JAVA_METERPRETER,
mettle: Acceptance::Meterpreter::METTLE_METERPRETER,
windows_meterpreter: Acceptance::Meterpreter::WINDOWS_METERPRETER
python: Acceptance::Session::PYTHON_METERPRETER,
php: Acceptance::Session::PHP_METERPRETER,
java: Acceptance::Session::JAVA_METERPRETER,
mettle: Acceptance::Session::METTLE_METERPRETER,
windows_meterpreter: Acceptance::Session::WINDOWS_METERPRETER
}
)

allure_test_environment = AllureRspec.configuration.environment_properties

let_it_be(:current_platform) { Acceptance::Meterpreter::current_platform }
let_it_be(:current_platform) { Acceptance::Session::current_platform }

# @!attribute [r] port_allocator
# @return [Acceptance::PortAllocator]
Expand Down Expand Up @@ -55,10 +55,10 @@
describe meterpreter_runtime_name, focus: meterpreter_config[:focus] do
meterpreter_config[:payloads].each.with_index do |payload_config, payload_config_index|
describe(
Acceptance::Meterpreter.human_name_for_payload(payload_config).to_s,
Acceptance::Session.human_name_for_payload(payload_config).to_s,
if: (
Acceptance::Meterpreter.run_meterpreter?(meterpreter_config) &&
Acceptance::Meterpreter.supported_platform?(payload_config)
Acceptance::Session.run_meterpreter?(meterpreter_config) &&
Acceptance::Session.supported_platform?(payload_config)
)
) do
let(:payload) { Acceptance::Payload.new(payload_config) }
Expand Down Expand Up @@ -183,18 +183,18 @@ def get_file_attachment_contents(path)
console.reset
end

context "#{Acceptance::Meterpreter.current_platform}" do
describe "#{Acceptance::Meterpreter.current_platform}/#{meterpreter_runtime_name} Meterpreter successfully opens a session for the #{payload_config[:name].inspect} payload" do
context "#{Acceptance::Session.current_platform}" do
describe "#{Acceptance::Session.current_platform}/#{meterpreter_runtime_name} Meterpreter successfully opens a session for the #{payload_config[:name].inspect} payload" do
it(
"exposes available metasploit commands",
if: (
# Assume that regardless of payload, staged/unstaged/etc, the Meterpreter will have the same commands available
# So only run this test when config_index == 0
payload_config_index == 0 && Acceptance::Meterpreter.supported_platform?(payload_config)
# Run if ENV['METERPRETER'] = 'java php' etc
Acceptance::Meterpreter.run_meterpreter?(meterpreter_config) &&
payload_config_index == 0 && Acceptance::Session.supported_platform?(payload_config)
# Run if ENV['SESSION'] = 'java php' etc
Acceptance::Session.run_meterpreter?(meterpreter_config) &&
# Only run payloads / tests, if the host machine can run them
Acceptance::Meterpreter.supported_platform?(payload_config)
Acceptance::Session.supported_platform?(payload_config)
)
) do
begin
Expand Down Expand Up @@ -332,17 +332,17 @@ def get_file_attachment_contents(path)
meterpreter_config[:module_tests].each do |module_test|
describe module_test[:name].to_s, focus: module_test[:focus] do
it(
"#{Acceptance::Meterpreter.current_platform}/#{meterpreter_runtime_name} meterpreter successfully opens a session for the #{payload_config[:name].inspect} payload and passes the #{module_test[:name].inspect} tests",
"#{Acceptance::Session.current_platform}/#{meterpreter_runtime_name} meterpreter successfully opens a session for the #{payload_config[:name].inspect} payload and passes the #{module_test[:name].inspect} tests",
if: (
# Run if ENV['METERPRETER'] = 'java php' etc
Acceptance::Meterpreter.run_meterpreter?(meterpreter_config) &&
# Run if ENV['METERPRETER_MODULE_TEST'] = 'test/cmd_exec' etc
Acceptance::Meterpreter.run_meterpreter_module_test?(module_test[:name]) &&
# Run if ENV['SESSION'] = 'java php' etc
Acceptance::Session.run_meterpreter?(meterpreter_config) &&
# Run if ENV['SESSION_MODULE_TEST'] = 'test/cmd_exec' etc
Acceptance::Session.run_meterpreter_module_test?(module_test[:name]) &&
# Only run payloads / tests, if the host machine can run them
Acceptance::Meterpreter.supported_platform?(payload_config) &&
Acceptance::Meterpreter.supported_platform?(module_test) &&
Acceptance::Session.supported_platform?(payload_config) &&
Acceptance::Session.supported_platform?(module_test) &&
# Skip tests that are explicitly skipped, or won't pass in the current environment
!Acceptance::Meterpreter.skipped_module_test?(module_test, allure_test_environment)
!Acceptance::Session.skipped_module_test?(module_test, allure_test_environment)
),
# test metadata - will appear in allure report
module_test: module_test[:name]
Expand Down Expand Up @@ -406,7 +406,7 @@ def get_file_attachment_contents(path)
end

validated_lines.each do |test_line|
test_line = Acceptance::Meterpreter.uncolorize(test_line)
test_line = Acceptance::Session.uncolorize(test_line)
expect(test_line).to_not include('FAILED', '[-] FAILED', '[-] Exception', '[-] '), "Unexpected error: #{test_line}"
end

Expand Down
12 changes: 6 additions & 6 deletions spec/acceptance/mssql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

allure_test_environment = AllureRspec.configuration.environment_properties

let_it_be(:current_platform) { Acceptance::Meterpreter::current_platform }
let_it_be(:current_platform) { Acceptance::Session::current_platform }

# Driver instance, keeps track of all open processes/payloads/etc, so they can be closed cleanly
let_it_be(:driver) do
Expand Down Expand Up @@ -183,7 +183,7 @@ def with_test_harness(module_test)
end

validated_lines.each do |test_line|
test_line = Acceptance::Meterpreter.uncolorize(test_line)
test_line = Acceptance::Session.uncolorize(test_line)
expect(test_line).to_not include('FAILED', '[-] FAILED', '[-] Exception', '[-] '), "Unexpected error: #{test_line}"
end

Expand Down Expand Up @@ -272,12 +272,12 @@ def with_test_harness(module_test)
tests.each do |runtime_name, test_config|
runtime_name = "#{runtime_name}#{ENV.fetch('RUNTIME_VERSION', '')}"

describe "#{Acceptance::Meterpreter.current_platform}/#{runtime_name}", focus: test_config[:focus] do
describe "#{Acceptance::Session.current_platform}/#{runtime_name}", focus: test_config[:focus] do
test_config[:module_tests].each do |module_test|
describe(
module_test[:name],
if: (
Acceptance::Meterpreter.supported_platform?(module_test)
Acceptance::Session.supported_platform?(module_test)
)
) do
let(:target) { Acceptance::Target.new(test_config[:target]) }
Expand Down Expand Up @@ -340,7 +340,7 @@ def with_test_harness(module_test)

context "when targeting a session", if: module_test[:targets].include?(:session) do
it(
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
"#{Acceptance::Session.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
) do
with_test_harness(module_test) do |replication_commands|
# Ensure we have a valid session id; We intentionally omit this from a `before(:each)` to ensure the allure attachments are generated if the session dies
Expand All @@ -365,7 +365,7 @@ def with_test_harness(module_test)

context "when targeting an rhost", if: module_test[:targets].include?(:rhost) do
it(
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
"#{Acceptance::Session.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
) do
with_test_harness(module_test) do |replication_commands|
use_module = "use #{module_test[:name]}"
Expand Down
12 changes: 6 additions & 6 deletions spec/acceptance/mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

allure_test_environment = AllureRspec.configuration.environment_properties

let_it_be(:current_platform) { Acceptance::Meterpreter::current_platform }
let_it_be(:current_platform) { Acceptance::Session::current_platform }

# Driver instance, keeps track of all open processes/payloads/etc, so they can be closed cleanly
let_it_be(:driver) do
Expand Down Expand Up @@ -161,7 +161,7 @@ def with_test_harness(module_test)
end

validated_lines.each do |test_line|
test_line = Acceptance::Meterpreter.uncolorize(test_line)
test_line = Acceptance::Session.uncolorize(test_line)
expect(test_line).to_not include('FAILED', '[-] FAILED', '[-] Exception', '[-] '), "Unexpected error: #{test_line}"
end

Expand Down Expand Up @@ -250,12 +250,12 @@ def with_test_harness(module_test)
tests.each do |runtime_name, test_config|
runtime_name = "#{runtime_name}#{ENV.fetch('RUNTIME_VERSION', '')}"

describe "#{Acceptance::Meterpreter.current_platform}/#{runtime_name}", focus: test_config[:focus] do
describe "#{Acceptance::Session.current_platform}/#{runtime_name}", focus: test_config[:focus] do
test_config[:module_tests].each do |module_test|
describe(
module_test[:name],
if: (
Acceptance::Meterpreter.supported_platform?(module_test)
Acceptance::Session.supported_platform?(module_test)
)
) do
let(:target) { Acceptance::Target.new(test_config[:target]) }
Expand Down Expand Up @@ -318,7 +318,7 @@ def with_test_harness(module_test)

context "when targeting a session", if: module_test[:targets].include?(:session) do
it(
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
"#{Acceptance::Session.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
) do
with_test_harness(module_test) do |replication_commands|
# Ensure we have a valid session id; We intentionally omit this from a `before(:each)` to ensure the allure attachments are generated if the session dies
Expand All @@ -343,7 +343,7 @@ def with_test_harness(module_test)

context "when targeting an rhost", if: module_test[:targets].include?(:rhost) do
it(
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
"#{Acceptance::Session.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
) do
with_test_harness(module_test) do |replication_commands|
use_module = "use #{module_test[:name]}"
Expand Down
12 changes: 6 additions & 6 deletions spec/acceptance/postgres_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

allure_test_environment = AllureRspec.configuration.environment_properties

let_it_be(:current_platform) { Acceptance::Meterpreter::current_platform }
let_it_be(:current_platform) { Acceptance::Session::current_platform }

# Driver instance, keeps track of all open processes/payloads/etc, so they can be closed cleanly
let_it_be(:driver) do
Expand Down Expand Up @@ -167,7 +167,7 @@ def with_test_harness(module_test)
end

validated_lines.each do |test_line|
test_line = Acceptance::Meterpreter.uncolorize(test_line)
test_line = Acceptance::Session.uncolorize(test_line)
expect(test_line).to_not include('FAILED', '[-] FAILED', '[-] Exception', '[-] '), "Unexpected error: #{test_line}"
end

Expand Down Expand Up @@ -256,12 +256,12 @@ def with_test_harness(module_test)
tests.each do |runtime_name, test_config|
runtime_name = "#{runtime_name}#{ENV.fetch('RUNTIME_VERSION', '')}"

describe "#{Acceptance::Meterpreter.current_platform}/#{runtime_name}", focus: test_config[:focus] do
describe "#{Acceptance::Session.current_platform}/#{runtime_name}", focus: test_config[:focus] do
test_config[:module_tests].each do |module_test|
describe(
module_test[:name],
if: (
Acceptance::Meterpreter.supported_platform?(module_test)
Acceptance::Session.supported_platform?(module_test)
)
) do
let(:target) { Acceptance::Target.new(test_config[:target]) }
Expand Down Expand Up @@ -324,7 +324,7 @@ def with_test_harness(module_test)

context "when targeting a session", if: module_test[:targets].include?(:session) do
it(
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
"#{Acceptance::Session.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
) do
with_test_harness(module_test) do |replication_commands|
# Ensure we have a valid session id; We intentionally omit this from a `before(:each)` to ensure the allure attachments are generated if the session dies
Expand All @@ -349,7 +349,7 @@ def with_test_harness(module_test)

context "when targeting an rhost", if: module_test[:targets].include?(:rhost) do
it(
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
"#{Acceptance::Session.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
) do
with_test_harness(module_test) do |replication_commands|
use_module = "use #{module_test[:name]}"
Expand Down
Loading

0 comments on commit ceffede

Please sign in to comment.