Skip to content

Commit

Permalink
Land #19066, Add smb acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adfoster-r7 authored Apr 19, 2024
2 parents aeafa4a + bf50da5 commit 7e25088
Show file tree
Hide file tree
Showing 12 changed files with 891 additions and 2 deletions.
166 changes: 166 additions & 0 deletions .github/workflows/smb_acceptance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: Acceptance

# Optional, enabling concurrency limits: https://docs.github.com/en/actions/using-jobs/using-concurrency
#concurrency:
# group: ${{ github.ref }}-${{ github.workflow }}
# cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
permissions:
actions: none
checks: none
contents: none
deployments: none
id-token: none
issues: none
discussions: none
packages: none
pages: none
pull-requests: none
repository-projects: none
security-events: none
statuses: none

on:
push:
branches-ignore:
- gh-pages
- metakitty
pull_request:
branches:
- '*'
paths:
- 'metsploit-framework.gemspec'
- 'Gemfile.lock'
- '**/**smb**'
- 'spec/acceptance/**'
- 'spec/support/acceptance/**'
- 'spec/acceptance_spec_helper.rb'
# Example of running as a cron, to weed out flaky tests
# schedule:
# - cron: '*/15 * * * *'

jobs:
smb:
runs-on: ${{ matrix.os }}
timeout-minutes: 40

strategy:
fail-fast: true
matrix:
ruby:
- '3.2'
os:
- ubuntu-latest

env:
RAILS_ENV: test
SMB_USERNAME: acceptance_tests_user
SMB_PASSWORD: acceptance_tests_password

name: SMB Acceptance - ${{ matrix.os }} - Ruby ${{ matrix.ruby }}
steps:
- name: Install system dependencies
run: sudo apt-get install -y --no-install-recommends libpcap-dev graphviz

- name: Checkout code
uses: actions/checkout@v4

- name: Run docker container
working-directory: 'test/smb'
run: |
docker compose build
docker compose up --wait -d
- name: Setup Ruby
env:
BUNDLE_WITHOUT: "coverage development pcap"
# Nokogiri doesn't release pre-compiled binaries for preview versions of Ruby; So force compilation with BUNDLE_FORCE_RUBY_PLATFORM
BUNDLE_FORCE_RUBY_PLATFORM: "${{ contains(matrix.ruby, 'preview') && 'true' || 'false' }}"
uses: ruby/setup-ruby@v1
with:
ruby-version: '${{ matrix.ruby }}'
bundler-cache: true

- name: acceptance
env:
SPEC_HELPER_LOAD_METASPLOIT: false
SPEC_OPTS: "--tag acceptance --require acceptance_spec_helper.rb --color --format documentation --format AllureRspec::RSpecFormatter"
RUNTIME_VERSION: 'latest'
# Unix run command:
# SPEC_HELPER_LOAD_METASPLOIT=false bundle exec ./spec/acceptance
# Windows cmd command:
# set SPEC_HELPER_LOAD_METASPLOIT=false
# bundle exec rspec .\spec\acceptance
# Note: rspec retry is intentionally not used, as it can cause issues with allure's reporting
# Additionally - flakey tests should be fixed or marked as flakey instead of silently retried
run: |
bundle exec rspec spec/acceptance/smb_spec.rb
- name: Archive results
if: always()
uses: actions/upload-artifact@v4
with:
# Provide a unique artifact for each matrix os, otherwise race conditions can lead to corrupt zips
name: smb_acceptance-${{ matrix.os }}
path: tmp/allure-raw-data

# Generate a final report from the previous test results
report:
name: Generate report
needs:
- smb
runs-on: ubuntu-latest
if: always()

steps:
- name: Checkout code
uses: actions/checkout@v4
if: always()

- name: Install system dependencies (Linux)
if: always()
run: sudo apt-get -y --no-install-recommends install libpcap-dev graphviz

- name: Setup Ruby
if: always()
env:
BUNDLE_WITHOUT: "coverage development"
BUNDLE_FORCE_RUBY_PLATFORM: true
uses: ruby/setup-ruby@v1
with:
ruby-version: '${{ matrix.ruby }}'
bundler-cache: true
cache-version: 4
# Github actions with Ruby requires Bundler 2.2.18+
# https://github.com/ruby/setup-ruby/tree/d2b39ad0b52eca07d23f3aa14fdf2a3fcc1f411c#windows
bundler: 2.2.33

- uses: actions/download-artifact@v4
id: download
if: always()
with:
# Note: Not specifying a name will download all artifacts from the previous workflow jobs
path: raw-data

- name: allure generate
if: always()
run: |
export VERSION=2.22.1
curl -o allure-$VERSION.tgz -Ls https://github.com/allure-framework/allure2/releases/download/$VERSION/allure-$VERSION.tgz
tar -zxvf allure-$VERSION.tgz -C .
ls -la ${{steps.download.outputs.download-path}}
./allure-$VERSION/bin/allure generate ${{steps.download.outputs.download-path}}/* -o ./allure-report
find ${{steps.download.outputs.download-path}}
bundle exec ruby tools/dev/report_generation/support_matrix/generate.rb --allure-data ${{steps.download.outputs.download-path}} > ./allure-report/support_matrix.html
- name: archive results
if: always()
uses: actions/upload-artifact@v4
with:
name: final-report-${{ github.run_id }}
path: |
./allure-report
11 changes: 9 additions & 2 deletions lib/rex/post/smb/ui/console/command_dispatcher/shares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def cmd_shares(*args)
# Perform action
case method
when :list
@share_search_results = client.net_share_enum_all(session.address)
@valid_share_names = @share_search_results.map { |result| result[:name] }
populate_shares

table = Rex::Text::Table.new(
'Header' => 'Shares',
Expand All @@ -139,6 +138,7 @@ def cmd_shares(*args)

print_line table.to_s
when :interact
populate_shares if @valid_share_names.nil?
# Share names can be comprised only of digits so prioritise a share name over the share index
if share_name.match?(/\A\d+\z/) && !@valid_share_names.include?(share_name)
share_name = (@share_search_results[share_name.to_i] || {})[:name]
Expand Down Expand Up @@ -626,6 +626,13 @@ def download_file(dest_file, src_file)
dst_fd.close unless dst_fd.nil?
end
end

private

def populate_shares
@share_search_results = client.net_share_enum_all(session.address)
@valid_share_names = @share_search_results.map { |result| result[:name] }
end
end
end
end
Expand Down
25 changes: 25 additions & 0 deletions spec/acceptance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ Run the test suite:
MSSQL_RPORT=1433 SPEC_OPTS='--tag acceptance' SPEC_HELPER_LOAD_METASPLOIT=false bundle exec rspec ./spec/acceptance/mssql_spec.rb
```

### SMB

Build the Docker image:

```
docker compose build
```

Run a target:

```
docker compose up -d --wait
```

Run the test suite:

```
SMB_USERNAME=acceptance_tests_user SMB_PASSWORD=acceptance_tests_password SPEC_OPTS='--tag acceptance' SPEC_HELPER_LOAD_METASPLOIT=false bundle exec rspec ./spec/acceptance/smb_spec.rb
```

Shut down the container:
```
docker compose down
```

#### Allure reports

Generate allure reports locally:
Expand Down
Loading

0 comments on commit 7e25088

Please sign in to comment.