From 76b0bc5c4797c79180b5de1f0e29b1b82905d330 Mon Sep 17 00:00:00 2001 From: cgranleese-r7 Date: Wed, 28 Aug 2024 15:33:57 +0100 Subject: [PATCH] Renames Acceptance::Meterpreter module to Acceptance::Session --- .github/workflows/meterpreter_acceptance.yml | 4 +- spec/acceptance/README.md | 12 +++-- spec/acceptance/ldap_spec.rb | 12 ++--- spec/acceptance/meterpreter_spec.rb | 50 +++++++++---------- spec/acceptance/mssql_spec.rb | 12 ++--- spec/acceptance/mysql_spec.rb | 12 ++--- spec/acceptance/postgres_spec.rb | 12 ++--- spec/acceptance/smb_spec.rb | 12 ++--- spec/allure_config.rb | 12 ++--- spec/support/acceptance/line_validation.rb | 4 +- .../acceptance/{meterpreter.rb => session.rb} | 35 +++++++++---- .../{meterpreter => session}/java.rb | 2 +- .../{meterpreter => session}/mettle.rb | 2 +- .../{meterpreter => session}/php.rb | 2 +- .../{meterpreter => session}/python.rb | 2 +- .../windows_meterpreter.rb | 2 +- 16 files changed, 104 insertions(+), 83 deletions(-) rename spec/support/acceptance/{meterpreter.rb => session.rb} (73%) rename spec/support/acceptance/{meterpreter => session}/java.rb (99%) rename spec/support/acceptance/{meterpreter => session}/mettle.rb (99%) rename spec/support/acceptance/{meterpreter => session}/php.rb (99%) rename spec/support/acceptance/{meterpreter => session}/python.rb (99%) rename spec/support/acceptance/{meterpreter => session}/windows_meterpreter.rb (99%) diff --git a/.github/workflows/meterpreter_acceptance.yml b/.github/workflows/meterpreter_acceptance.yml index e0ab2b2d7e58..93035b7c33a6 100644 --- a/.github/workflows/meterpreter_acceptance.yml +++ b/.github/workflows/meterpreter_acceptance.yml @@ -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: 'meterpreter/${{ matrix.meterpreter.name }}' + SESSION_RUNTIME_VERSION: ${{ matrix.meterpreter.runtime_version }} BUNDLE_WITHOUT: "coverage development" name: ${{ matrix.meterpreter.name }} ${{ matrix.meterpreter.runtime_version }} ${{ matrix.os }} diff --git a/spec/acceptance/README.md b/spec/acceptance/README.md index 4ae2011466ff..e9921500fadf 100644 --- a/spec/acceptance/README.md +++ b/spec/acceptance/README.md @@ -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: @@ -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: diff --git a/spec/acceptance/ldap_spec.rb b/spec/acceptance/ldap_spec.rb index 206ffb92e795..74773dff6985 100644 --- a/spec/acceptance/ldap_spec.rb +++ b/spec/acceptance/ldap_spec.rb @@ -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 @@ -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 @@ -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]) } @@ -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 @@ -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]}" diff --git a/spec/acceptance/meterpreter_spec.rb b/spec/acceptance/meterpreter_spec.rb index a65435836e71..e595c67f291b 100644 --- a/spec/acceptance/meterpreter_spec.rb +++ b/spec/acceptance/meterpreter_spec.rb @@ -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] @@ -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) } @@ -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 @@ -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] @@ -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 diff --git a/spec/acceptance/mssql_spec.rb b/spec/acceptance/mssql_spec.rb index 232d468190cb..3f8c44199d95 100644 --- a/spec/acceptance/mssql_spec.rb +++ b/spec/acceptance/mssql_spec.rb @@ -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 @@ -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 @@ -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]) } @@ -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 @@ -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]}" diff --git a/spec/acceptance/mysql_spec.rb b/spec/acceptance/mysql_spec.rb index be1ff4231c6d..c080596e4b5b 100644 --- a/spec/acceptance/mysql_spec.rb +++ b/spec/acceptance/mysql_spec.rb @@ -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 @@ -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 @@ -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]) } @@ -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 @@ -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]}" diff --git a/spec/acceptance/postgres_spec.rb b/spec/acceptance/postgres_spec.rb index 785d51894355..75dfda056b80 100644 --- a/spec/acceptance/postgres_spec.rb +++ b/spec/acceptance/postgres_spec.rb @@ -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 @@ -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 @@ -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]) } @@ -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 @@ -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]}" diff --git a/spec/acceptance/smb_spec.rb b/spec/acceptance/smb_spec.rb index 92a82943d806..85bed98ccecd 100644 --- a/spec/acceptance/smb_spec.rb +++ b/spec/acceptance/smb_spec.rb @@ -94,7 +94,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 @@ -169,7 +169,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 @@ -262,12 +262,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]) } @@ -330,7 +330,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 @@ -355,7 +355,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]}" diff --git a/spec/allure_config.rb b/spec/allure_config.rb index dfe140bc3977..97b9a34df4d5 100644 --- a/spec/allure_config.rb +++ b/spec/allure_config.rb @@ -13,12 +13,12 @@ ruby_version: RUBY_VERSION, host_runner_image: ENV['HOST_RUNNER_IMAGE'], }.compact - meterpreter_name = ENV['METERPRETER'] - meterpreter_runtime_version = ENV['METERPRETER_RUNTIME_VERSION'] - if meterpreter_name.present? - environment_properties[:meterpreter_name] = meterpreter_name - if meterpreter_runtime_version.present? - environment_properties[:meterpreter_runtime_version] = "#{meterpreter_name}#{meterpreter_runtime_version}" + session_name = ENV['SESSION'] + session_runtime_version = ENV['SESSION_RUNTIME_VERSION'] + if session_name.present? + environment_properties[:session_name] = session_name + if session_runtime_version.present? + environment_properties[:session_runtime_version] = "#{session_name}#{session_runtime_version}" end end environment_properties[:runtime_version] = ENV['RUNTIME_VERSION'] diff --git a/spec/support/acceptance/line_validation.rb b/spec/support/acceptance/line_validation.rb index 3c6819fd3be2..148bd3b1acec 100644 --- a/spec/support/acceptance/line_validation.rb +++ b/spec/support/acceptance/line_validation.rb @@ -47,9 +47,9 @@ def to_h private - # (see Acceptance::Meterpreter#eval_predicate) + # (see Acceptance::Session#eval_predicate) def evaluate_predicate(value, environment) - Acceptance::Meterpreter.eval_predicate(value, environment) + Acceptance::Session.eval_predicate(value, environment) end end end diff --git a/spec/support/acceptance/meterpreter.rb b/spec/support/acceptance/session.rb similarity index 73% rename from spec/support/acceptance/meterpreter.rb rename to spec/support/acceptance/session.rb index 6d20de39e7e7..1578945b0782 100644 --- a/spec/support/acceptance/meterpreter.rb +++ b/spec/support/acceptance/session.rb @@ -1,4 +1,4 @@ -module Acceptance::Meterpreter +module Acceptance::Session # @return [Symbol] The current platform def self.current_platform host_os = RbConfig::CONFIG['host_os'] @@ -17,18 +17,35 @@ def self.current_platform # Allows restricting the tests of a specific Meterpreter's test suite with the METERPRETER environment variable # @return [TrueClass, FalseClass] True if the given Meterpreter should be run, false otherwise. def self.run_meterpreter?(meterpreter_config) - return true if ENV['METERPRETER'].blank? + return true if ENV['SESSION'].blank? name = meterpreter_config[:name].to_s - ENV['METERPRETER'].include?(name) + ENV['SESSION'].include?(name) end # Allows restricting the tests of a specific Meterpreter's test suite with the METERPRETER environment variable # @return [TrueClass, FalseClass] True if the given Meterpreter should be run, false otherwise. def self.run_meterpreter_module_test?(module_test) - return true if ENV['METERPRETER_MODULE_TEST'].blank? + return true if ENV['SESSION_MODULE_TEST'].blank? - ENV['METERPRETER_MODULE_TEST'].include?(module_test) + ENV['SESSION_MODULE_TEST'].include?(module_test) + end + + # Allows restricting the tests of a specific session's test suite with the SESSION environment variable + # @return [TrueClass, FalseClass] True if the given session should be run, false otherwise. + def self.run_session?(session_config) + return true if ENV['SESSION'].blank? + + name = session_config[:name].to_s + ENV['SESSION'].include?("command_shell/#{name}") + end + + # Allows restricting the tests of a specific session's test suite with the SESSION environment variable + # @return [TrueClass, FalseClass] True if the given session should be run, false otherwise. + def self.run_session_module_test?(module_test) + return true if ENV['SESSION_MODULE_TEST'].blank? + + ENV['SESSION_MODULE_TEST'].include?(module_test) end # @param [String] string A console string with ANSI escape codes present @@ -54,8 +71,8 @@ def self.skipped_module_test?(module_test, test_environment) # @param [Hash] payload_config # @return [String] The human readable name for the given payload configuration def self.human_name_for_payload(payload_config) - is_stageless = payload_config[:name].include?('meterpreter_reverse_tcp') - is_staged = payload_config[:name].include?('meterpreter/reverse_tcp') + is_stageless = payload_config[:name].include?('_reverse_tcp') + is_staged = payload_config[:name].include?('/reverse_tcp') details = [] details << 'stageless' if is_stageless @@ -67,7 +84,7 @@ def self.human_name_for_payload(payload_config) # @param [Object] hash A hash of key => hash # @return [Object] Returns a new hash with the 'key' merged into hash value and all payloads - def self.with_meterpreter_name_merged(hash) + def self.with_session_name_merged(hash) hash.each_with_object({}) do |(name, config), acc| acc[name] = config.merge({ name: name }) end @@ -81,7 +98,7 @@ def self.eval_predicate(value, environment) case value when Array left_operand, operator, right_operand = value - # Map values such as `:meterpreter_name` to the runtime value + # Map values such as `:session_name` to the runtime value left_operand = environment[left_operand] if environment.key?(left_operand) right_operand = environment[right_operand] if environment.key?(right_operand) diff --git a/spec/support/acceptance/meterpreter/java.rb b/spec/support/acceptance/session/java.rb similarity index 99% rename from spec/support/acceptance/meterpreter/java.rb rename to spec/support/acceptance/session/java.rb index 3c8ae38fe3f4..99ca708eda06 100644 --- a/spec/support/acceptance/meterpreter/java.rb +++ b/spec/support/acceptance/session/java.rb @@ -1,4 +1,4 @@ -module Acceptance::Meterpreter +module Acceptance::Session JAVA_METERPRETER = { payloads: [ { diff --git a/spec/support/acceptance/meterpreter/mettle.rb b/spec/support/acceptance/session/mettle.rb similarity index 99% rename from spec/support/acceptance/meterpreter/mettle.rb rename to spec/support/acceptance/session/mettle.rb index 264cf2a601c7..182a0d370610 100644 --- a/spec/support/acceptance/meterpreter/mettle.rb +++ b/spec/support/acceptance/session/mettle.rb @@ -1,4 +1,4 @@ -module Acceptance::Meterpreter +module Acceptance::Session METTLE_METERPRETER = { payloads: [ { diff --git a/spec/support/acceptance/meterpreter/php.rb b/spec/support/acceptance/session/php.rb similarity index 99% rename from spec/support/acceptance/meterpreter/php.rb rename to spec/support/acceptance/session/php.rb index 0c4d9d81eade..6d314dfec948 100644 --- a/spec/support/acceptance/meterpreter/php.rb +++ b/spec/support/acceptance/session/php.rb @@ -1,4 +1,4 @@ -module Acceptance::Meterpreter +module Acceptance::Session PHP_METERPRETER = { payloads: [ { diff --git a/spec/support/acceptance/meterpreter/python.rb b/spec/support/acceptance/session/python.rb similarity index 99% rename from spec/support/acceptance/meterpreter/python.rb rename to spec/support/acceptance/session/python.rb index 007274a2ac9b..f14b5f289c94 100644 --- a/spec/support/acceptance/meterpreter/python.rb +++ b/spec/support/acceptance/session/python.rb @@ -1,4 +1,4 @@ -module Acceptance::Meterpreter +module Acceptance::Session PYTHON_METERPRETER = { payloads: [ { diff --git a/spec/support/acceptance/meterpreter/windows_meterpreter.rb b/spec/support/acceptance/session/windows_meterpreter.rb similarity index 99% rename from spec/support/acceptance/meterpreter/windows_meterpreter.rb rename to spec/support/acceptance/session/windows_meterpreter.rb index c5363434b308..7784ab66d2fa 100644 --- a/spec/support/acceptance/meterpreter/windows_meterpreter.rb +++ b/spec/support/acceptance/session/windows_meterpreter.rb @@ -1,4 +1,4 @@ -module Acceptance::Meterpreter +module Acceptance::Session WINDOWS_METERPRETER = { payloads: [ {