Skip to content

Commit

Permalink
Debug powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 committed Aug 21, 2024
1 parent dd04557 commit 831e042
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,43 +64,43 @@ jobs:
fail-fast: false
matrix:
os:
# - macos-12
- macos-12
- windows-2019
# - ubuntu-20.04
- ubuntu-20.04
ruby:
- 3.0.2
# meterpreter:
meterpreter:
# Python
# - { name: python, runtime_version: 3.6 }
# - { name: python, runtime_version: 3.11 }
- { name: python, runtime_version: 3.6 }
- { name: python, runtime_version: 3.11 }

# Java
# - { name: java, runtime_version: 8 }
# - { name: java, runtime_version: 21 }
- { name: java, runtime_version: 8 }
- { name: java, runtime_version: 21 }

# PHP
# - { name: php, runtime_version: 5.3 }
# - { name: php, runtime_version: 7.4 }
# - { name: php, runtime_version: 8.3 }
- { name: php, runtime_version: 5.3 }
- { name: php, runtime_version: 7.4 }
- { name: php, runtime_version: 8.3 }
include:
# Windows Meterpreter
# - { meterpreter: { name: windows_meterpreter }, os: windows-2019 }
# - { meterpreter: { name: windows_meterpreter }, os: windows-2022 }
- { meterpreter: { name: windows_meterpreter }, os: windows-2019 }
- { meterpreter: { name: windows_meterpreter }, os: windows-2022 }

# Powershell
- { meterpreter: { name: powershell }, os: windows-2019 }
- { meterpreter: { name: powershell }, os: windows-2022 }

# Linux
# - { meterpreter: { name: linux }, os: ubuntu-20.04 }
- { meterpreter: { name: linux }, os: ubuntu-20.04 }

# CMD
# - { meterpreter: { name: cmd }, os: windows-2019 }
# - { meterpreter: { name: cmd }, os: windows-2022 }
- { meterpreter: { name: cmd }, os: windows-2019 }
- { meterpreter: { name: cmd }, os: windows-2022 }

# Mettle
# - { meterpreter: { name: mettle }, os: macos-12 }
# - { meterpreter: { name: mettle }, os: ubuntu-20.04 }
- { meterpreter: { name: mettle }, os: macos-12 }
- { meterpreter: { name: mettle }, os: ubuntu-20.04 }

runs-on: ${{ matrix.os }}

Expand Down
5 changes: 3 additions & 2 deletions spec/acceptance/non_meterpreter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,15 @@ def initialize(path)
session_id = nil

# Wait for the session to open, or break early if the payload is detected as dead
wait_for_expect do
larger_retry_count_for_powershell = 600
wait_for_expect(larger_retry_count_for_powershell) do
unless payload_process.alive?
break
end

# TODO: Was strictly for Meterpreter sessions, now more generic
# - can be reverted if we decide to move these new tests
session_opened_matcher = /\w.* session (\d+) opened[^\n]*\n/
session_opened_matcher = /session (\d+) opened[^\n]*\n/
session_message = ''
begin
session_message = console.recvuntil(session_opened_matcher, timeout: 1)
Expand Down
8 changes: 4 additions & 4 deletions spec/support/acceptance/non_meterpreter/powershell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module Acceptance::NonMeterpreter
POWERSHELL = {
payloads: [
{
name: 'windows/x64/powershell_reverse_tcp',
extension: '.exe',
name: 'cmd/windows/powershell_reverse_tcp',
extension: '.ps1',
platforms: [:windows],
execute_cmd: ['${payload_path}'],
execute_cmd: ['powershell ${payload_path}'],
executable: true,
generate_options: {
'-f': 'exe'
'-f': 'raw'
},
datastore: {
global: {},
Expand Down
11 changes: 9 additions & 2 deletions test/lib/module_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,15 @@ def push_test_directory
@directory_stack.push(_file_system.pwd)

# Find the temp directory
tmp = _file_system.get_env("TMP").strip.presence || _file_system.get_env("TMPDIR").strip.presence
# tmp = _file_system.get_env("TMP") || _file_system.get_env("TMPDIR")

# TODO: This caused issue with random jobs, will add some logic below to unblock for now
# tmp = _file_system.get_env("TMP")&.strip&.presence || _file_system&.get_env("TMPDIR").strip&.presence
if session.platform == 'unix'
tmp = _file_system.get_env("TMP").strip.presence || _file_system.get_env("TMPDIR").strip.presence
else
tmp = _file_system.get_env("TMP") || _file_system.get_env("TMPDIR")
end

# mettle fallback
tmp = '/tmp' if tmp.nil? && _file_system.directory?('/tmp')
raise "Could not find tmp directory" if tmp == nil || !_file_system.directory?(tmp)
Expand Down

0 comments on commit 831e042

Please sign in to comment.