Skip to content

Commit 3b33b23

Browse files
authored
Land rapid7#19428, Rename Acceptance::Meterpreter module to Acceptance::Session
2 parents 409b1ae + 76b0bc5 commit 3b33b23

File tree

16 files changed

+104
-83
lines changed

16 files changed

+104
-83
lines changed

.github/workflows/meterpreter_acceptance.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ jobs:
9898
metasploitPayloadsCommit: ${{ github.event.inputs.metasploitPayloadsCommit || 'master' }}
9999
mettleCommit: ${{ github.event.inputs.mettleCommit|| 'master' }}
100100
HOST_RUNNER_IMAGE: ${{ matrix.os }}
101-
METERPRETER: ${{ matrix.meterpreter.name }}
102-
METERPRETER_RUNTIME_VERSION: ${{ matrix.meterpreter.runtime_version }}
101+
SESSION: 'meterpreter/${{ matrix.meterpreter.name }}'
102+
SESSION_RUNTIME_VERSION: ${{ matrix.meterpreter.runtime_version }}
103103
BUNDLE_WITHOUT: "coverage development"
104104

105105
name: ${{ matrix.meterpreter.name }} ${{ matrix.meterpreter.runtime_version }} ${{ matrix.os }}

spec/acceptance/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ There is no remote host support currently.
1010
### Meterpreter
1111

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

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

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

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

41+
Session types can be specified via the `SESSION` argument. Meterpreter and command shell are support and use the following notation:
42+
- SESSION=meterpreter/php
43+
- SESSION=command_shell/php
44+
4145
### Postgres
4246

4347
Run a target:

spec/acceptance/ldap_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121

122122
allure_test_environment = AllureRspec.configuration.environment_properties
123123

124-
let_it_be(:current_platform) { Acceptance::Meterpreter.current_platform }
124+
let_it_be(:current_platform) { Acceptance::Session.current_platform }
125125

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

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

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

289-
describe "#{Acceptance::Meterpreter.current_platform}/#{runtime_name}", focus: test_config[:focus] do
289+
describe "#{Acceptance::Session.current_platform}/#{runtime_name}", focus: test_config[:focus] do
290290
test_config[:module_tests].each do |module_test|
291291
describe(
292292
module_test[:name],
293293
if:
294-
Acceptance::Meterpreter.supported_platform?(module_test)
294+
Acceptance::Session.supported_platform?(module_test)
295295
) do
296296
let(:target) { Acceptance::Target.new(test_config[:target]) }
297297

@@ -352,7 +352,7 @@ def with_test_harness(module_test)
352352

353353
context 'when targeting a session', if: module_test[:targets].include?(:session) do
354354
it(
355-
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
355+
"#{Acceptance::Session.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
356356
) do
357357
with_test_harness(module_test) do |replication_commands|
358358
# 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)
379379

380380
context 'when targeting an rhost', if: module_test[:targets].include?(:rhost) do
381381
it(
382-
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
382+
"#{Acceptance::Session.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
383383
) do
384384
with_test_harness(module_test) do |replication_commands|
385385
use_module = "use #{module_test[:name]}"

spec/acceptance/meterpreter_spec.rb

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
include_context 'wait_for_expect'
55

66
# Tests to ensure that Meterpreter is consistent across all implementations/operation systems
7-
METERPRETER_PAYLOADS = Acceptance::Meterpreter.with_meterpreter_name_merged(
7+
METERPRETER_PAYLOADS = Acceptance::Session.with_session_name_merged(
88
{
9-
python: Acceptance::Meterpreter::PYTHON_METERPRETER,
10-
php: Acceptance::Meterpreter::PHP_METERPRETER,
11-
java: Acceptance::Meterpreter::JAVA_METERPRETER,
12-
mettle: Acceptance::Meterpreter::METTLE_METERPRETER,
13-
windows_meterpreter: Acceptance::Meterpreter::WINDOWS_METERPRETER
9+
python: Acceptance::Session::PYTHON_METERPRETER,
10+
php: Acceptance::Session::PHP_METERPRETER,
11+
java: Acceptance::Session::JAVA_METERPRETER,
12+
mettle: Acceptance::Session::METTLE_METERPRETER,
13+
windows_meterpreter: Acceptance::Session::WINDOWS_METERPRETER
1414
}
1515
)
1616

1717
allure_test_environment = AllureRspec.configuration.environment_properties
1818

19-
let_it_be(:current_platform) { Acceptance::Meterpreter::current_platform }
19+
let_it_be(:current_platform) { Acceptance::Session::current_platform }
2020

2121
# @!attribute [r] port_allocator
2222
# @return [Acceptance::PortAllocator]
@@ -55,10 +55,10 @@
5555
describe meterpreter_runtime_name, focus: meterpreter_config[:focus] do
5656
meterpreter_config[:payloads].each.with_index do |payload_config, payload_config_index|
5757
describe(
58-
Acceptance::Meterpreter.human_name_for_payload(payload_config).to_s,
58+
Acceptance::Session.human_name_for_payload(payload_config).to_s,
5959
if: (
60-
Acceptance::Meterpreter.run_meterpreter?(meterpreter_config) &&
61-
Acceptance::Meterpreter.supported_platform?(payload_config)
60+
Acceptance::Session.run_meterpreter?(meterpreter_config) &&
61+
Acceptance::Session.supported_platform?(payload_config)
6262
)
6363
) do
6464
let(:payload) { Acceptance::Payload.new(payload_config) }
@@ -183,18 +183,18 @@ def get_file_attachment_contents(path)
183183
console.reset
184184
end
185185

186-
context "#{Acceptance::Meterpreter.current_platform}" do
187-
describe "#{Acceptance::Meterpreter.current_platform}/#{meterpreter_runtime_name} Meterpreter successfully opens a session for the #{payload_config[:name].inspect} payload" do
186+
context "#{Acceptance::Session.current_platform}" do
187+
describe "#{Acceptance::Session.current_platform}/#{meterpreter_runtime_name} Meterpreter successfully opens a session for the #{payload_config[:name].inspect} payload" do
188188
it(
189189
"exposes available metasploit commands",
190190
if: (
191191
# Assume that regardless of payload, staged/unstaged/etc, the Meterpreter will have the same commands available
192192
# So only run this test when config_index == 0
193-
payload_config_index == 0 && Acceptance::Meterpreter.supported_platform?(payload_config)
194-
# Run if ENV['METERPRETER'] = 'java php' etc
195-
Acceptance::Meterpreter.run_meterpreter?(meterpreter_config) &&
193+
payload_config_index == 0 && Acceptance::Session.supported_platform?(payload_config)
194+
# Run if ENV['SESSION'] = 'java php' etc
195+
Acceptance::Session.run_meterpreter?(meterpreter_config) &&
196196
# Only run payloads / tests, if the host machine can run them
197-
Acceptance::Meterpreter.supported_platform?(payload_config)
197+
Acceptance::Session.supported_platform?(payload_config)
198198
)
199199
) do
200200
begin
@@ -332,17 +332,17 @@ def get_file_attachment_contents(path)
332332
meterpreter_config[:module_tests].each do |module_test|
333333
describe module_test[:name].to_s, focus: module_test[:focus] do
334334
it(
335-
"#{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",
335+
"#{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",
336336
if: (
337-
# Run if ENV['METERPRETER'] = 'java php' etc
338-
Acceptance::Meterpreter.run_meterpreter?(meterpreter_config) &&
339-
# Run if ENV['METERPRETER_MODULE_TEST'] = 'test/cmd_exec' etc
340-
Acceptance::Meterpreter.run_meterpreter_module_test?(module_test[:name]) &&
337+
# Run if ENV['SESSION'] = 'java php' etc
338+
Acceptance::Session.run_meterpreter?(meterpreter_config) &&
339+
# Run if ENV['SESSION_MODULE_TEST'] = 'test/cmd_exec' etc
340+
Acceptance::Session.run_meterpreter_module_test?(module_test[:name]) &&
341341
# Only run payloads / tests, if the host machine can run them
342-
Acceptance::Meterpreter.supported_platform?(payload_config) &&
343-
Acceptance::Meterpreter.supported_platform?(module_test) &&
342+
Acceptance::Session.supported_platform?(payload_config) &&
343+
Acceptance::Session.supported_platform?(module_test) &&
344344
# Skip tests that are explicitly skipped, or won't pass in the current environment
345-
!Acceptance::Meterpreter.skipped_module_test?(module_test, allure_test_environment)
345+
!Acceptance::Session.skipped_module_test?(module_test, allure_test_environment)
346346
),
347347
# test metadata - will appear in allure report
348348
module_test: module_test[:name]
@@ -406,7 +406,7 @@ def get_file_attachment_contents(path)
406406
end
407407

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

spec/acceptance/mssql_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108

109109
allure_test_environment = AllureRspec.configuration.environment_properties
110110

111-
let_it_be(:current_platform) { Acceptance::Meterpreter::current_platform }
111+
let_it_be(:current_platform) { Acceptance::Session::current_platform }
112112

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

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

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

275-
describe "#{Acceptance::Meterpreter.current_platform}/#{runtime_name}", focus: test_config[:focus] do
275+
describe "#{Acceptance::Session.current_platform}/#{runtime_name}", focus: test_config[:focus] do
276276
test_config[:module_tests].each do |module_test|
277277
describe(
278278
module_test[:name],
279279
if: (
280-
Acceptance::Meterpreter.supported_platform?(module_test)
280+
Acceptance::Session.supported_platform?(module_test)
281281
)
282282
) do
283283
let(:target) { Acceptance::Target.new(test_config[:target]) }
@@ -340,7 +340,7 @@ def with_test_harness(module_test)
340340

341341
context "when targeting a session", if: module_test[:targets].include?(:session) do
342342
it(
343-
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
343+
"#{Acceptance::Session.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
344344
) do
345345
with_test_harness(module_test) do |replication_commands|
346346
# 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)
365365

366366
context "when targeting an rhost", if: module_test[:targets].include?(:rhost) do
367367
it(
368-
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
368+
"#{Acceptance::Session.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
369369
) do
370370
with_test_harness(module_test) do |replication_commands|
371371
use_module = "use #{module_test[:name]}"

spec/acceptance/mysql_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686

8787
allure_test_environment = AllureRspec.configuration.environment_properties
8888

89-
let_it_be(:current_platform) { Acceptance::Meterpreter::current_platform }
89+
let_it_be(:current_platform) { Acceptance::Session::current_platform }
9090

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

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

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

253-
describe "#{Acceptance::Meterpreter.current_platform}/#{runtime_name}", focus: test_config[:focus] do
253+
describe "#{Acceptance::Session.current_platform}/#{runtime_name}", focus: test_config[:focus] do
254254
test_config[:module_tests].each do |module_test|
255255
describe(
256256
module_test[:name],
257257
if: (
258-
Acceptance::Meterpreter.supported_platform?(module_test)
258+
Acceptance::Session.supported_platform?(module_test)
259259
)
260260
) do
261261
let(:target) { Acceptance::Target.new(test_config[:target]) }
@@ -318,7 +318,7 @@ def with_test_harness(module_test)
318318

319319
context "when targeting a session", if: module_test[:targets].include?(:session) do
320320
it(
321-
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
321+
"#{Acceptance::Session.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
322322
) do
323323
with_test_harness(module_test) do |replication_commands|
324324
# 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)
343343

344344
context "when targeting an rhost", if: module_test[:targets].include?(:rhost) do
345345
it(
346-
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
346+
"#{Acceptance::Session.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
347347
) do
348348
with_test_harness(module_test) do |replication_commands|
349349
use_module = "use #{module_test[:name]}"

spec/acceptance/postgres_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292

9393
allure_test_environment = AllureRspec.configuration.environment_properties
9494

95-
let_it_be(:current_platform) { Acceptance::Meterpreter::current_platform }
95+
let_it_be(:current_platform) { Acceptance::Session::current_platform }
9696

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

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

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

259-
describe "#{Acceptance::Meterpreter.current_platform}/#{runtime_name}", focus: test_config[:focus] do
259+
describe "#{Acceptance::Session.current_platform}/#{runtime_name}", focus: test_config[:focus] do
260260
test_config[:module_tests].each do |module_test|
261261
describe(
262262
module_test[:name],
263263
if: (
264-
Acceptance::Meterpreter.supported_platform?(module_test)
264+
Acceptance::Session.supported_platform?(module_test)
265265
)
266266
) do
267267
let(:target) { Acceptance::Target.new(test_config[:target]) }
@@ -324,7 +324,7 @@ def with_test_harness(module_test)
324324

325325
context "when targeting a session", if: module_test[:targets].include?(:session) do
326326
it(
327-
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
327+
"#{Acceptance::Session.current_platform}/#{runtime_name} session opens and passes the #{module_test[:name].inspect} tests"
328328
) do
329329
with_test_harness(module_test) do |replication_commands|
330330
# 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)
349349

350350
context "when targeting an rhost", if: module_test[:targets].include?(:rhost) do
351351
it(
352-
"#{Acceptance::Meterpreter.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
352+
"#{Acceptance::Session.current_platform}/#{runtime_name} rhost opens and passes the #{module_test[:name].inspect} tests"
353353
) do
354354
with_test_harness(module_test) do |replication_commands|
355355
use_module = "use #{module_test[:name]}"

0 commit comments

Comments
 (0)