From 133507ac7321ebef54667cd441637ab50d68469c Mon Sep 17 00:00:00 2001 From: cgranleese-r7 Date: Thu, 23 Jan 2025 14:11:09 +0000 Subject: [PATCH] Updates meterpreter pipeline to now build the payloads gem --- .../shared_meterpreter_acceptance.yml | 115 ++++++++++-------- .../Payload-Testing.md | 12 +- 2 files changed, 71 insertions(+), 56 deletions(-) diff --git a/.github/workflows/shared_meterpreter_acceptance.yml b/.github/workflows/shared_meterpreter_acceptance.yml index e595308e2652d..b19e40a172f45 100644 --- a/.github/workflows/shared_meterpreter_acceptance.yml +++ b/.github/workflows/shared_meterpreter_acceptance.yml @@ -30,11 +30,11 @@ on: type: boolean jobs: - # Compile Java Meterpreter via docker if required, we can't always do this on the + # Compile the Meterpreter payloads via docker if required, we can't always do this on the # host environment (i.e. for macos). So it instead gets compiled first on a linux # host, then the artifacts are copied back to the host later - java_meterpreter_compilation: - name: Compile Java Meterpreter + meterpreter_compilation: + name: Compile Meterpreter runs-on: ubuntu-latest if: ${{ inputs.build_metasploit_payloads }} @@ -46,21 +46,22 @@ jobs: path: metasploit-payloads ref: ${{ inputs.metasploit_payloads_commit }} - - name: Build Java and Android payloads + - name: Build Meterpreter payloads run: | - mkdir $(pwd)/java-artifacts - docker run --rm -w "$(pwd)" -v "$(pwd):$(pwd)" rapid7/msf-ubuntu-x64-meterpreter:latest /bin/bash -c "set -x && cd metasploit-payloads/java && mvn package -Dandroid.sdk.path=/usr/local/android-sdk -Dandroid.release=true -Ddeploy.path=../../java-artifacts -Dmaven.test.skip=true -P deploy && mvn -Dmaven.test.skip=true -Ddeploy.path=../../java-artifacts -P deploy package" + mkdir $(pwd)/meterpreter-artifacts + docker run --rm -w $(pwd) -v $(pwd):$(pwd) rapid7/msf-ubuntu-x64-meterpreter:latest /bin/bash -c "cd metasploit-payloads/gem && rake create_dir && rake win_copy && rake php_prep && rake java_prep && rake python_prep && rake create_manifest && rake build" + cp $(pwd)/metasploit-payloads/gem/pkg/metasploit-payloads-* $(pwd)/meterpreter-artifacts - - name: Store Java artifacts + - name: Store Meterpreter artifacts uses: actions/upload-artifact@v4 with: - name: java-artifacts - path: java-artifacts + name: meterpreter-artifacts + path: meterpreter-artifacts # Run all test individually, note there is a separate final job for aggregating the test results test: - needs: java_meterpreter_compilation - if: always() && (needs.java_meterpreter_compilation.result == 'success' || needs.java_meterpreter_compilation.result == 'skipped') + needs: meterpreter_compilation + if: always() && (needs.meterpreter_compilation.result == 'success' || needs.meterpreter_compilation.result == 'skipped') strategy: fail-fast: false @@ -208,28 +209,28 @@ jobs: working-directory: metasploit-framework - uses: actions/download-artifact@v4 - name: Download Java meterpreter - id: download_java_meterpreter - if: ${{ matrix.meterpreter.name == 'java' && inputs.build_metasploit_payloads }} + name: Download Meterpreter + id: download_meterpreter + if: ${{ matrix.meterpreter.name != 'mettle' && inputs.build_metasploit_payloads }} with: # Note: Not specifying a name will download all artifacts from the previous workflow jobs path: raw-data - - name: Extract Java Meterpreter (Unix) - if: ${{ matrix.meterpreter.name == 'java' && runner.os != 'Windows' && inputs.build_metasploit_payloads }} + - name: Extract Meterpreter (Unix) + if: ${{ matrix.meterpreter.name != 'mettle' && runner.os != 'Windows' && inputs.build_metasploit_payloads }} shell: bash run: | set -x - download_path=${{steps.download_java_meterpreter.outputs.download-path}} - cp -r $download_path/java-artifacts/data/* ./metasploit-framework/data + download_path=${{steps.download_meterpreter.outputs.download-path}} + cp -r $download_path/meterpreter-artifacts/* ./metasploit-framework - - name: Extract Java Meterpreter (Windows) - if: ${{ matrix.meterpreter.name == 'java' && runner.os == 'Windows' && inputs.build_metasploit_payloads }} + - name: Extract Meterpreter (Windows) + if: ${{ matrix.meterpreter.name != 'mettle' && runner.os == 'Windows' && inputs.build_metasploit_payloads }} shell: bash run: | set -x - download_path=$(cygpath -u '${{steps.download_java_meterpreter.outputs.download-path}}') - cp -r $download_path/java-artifacts/data/* ./metasploit-framework/data + download_path=$(cygpath -u '${{steps.download_meterpreter.outputs.download-path}}') + cp -r $download_path/meterpreter-artifacts/* ./metasploit-framework - name: Install mettle gem if: ${{ matrix.meterpreter.name == 'mettle' && inputs.build_mettle }} @@ -256,49 +257,63 @@ jobs: run: echo "METASPLOIT_PAYLOADS_VERSION=$(ruby -ne "puts Regexp.last_match(1) if /VERSION\s+=\s+'([^']+)'/" gem/lib/metasploit-payloads/version.rb)" | tee -a $GITHUB_ENV working-directory: metasploit-payloads - - name: Build metasploit-payloads gem - if: ${{ inputs.build_metasploit_payloads && matrix.meterpreter.name != 'mettle' }} - run: gem build ./gem/metasploit-payloads.gemspec - working-directory: metasploit-payloads - - - name: Copy metasploit-payloads gem into metasploit-framework - if: ${{ inputs.build_metasploit_payloads && matrix.meterpreter.name != 'mettle' }} - shell: bash - run: cp ../metasploit-payloads/metasploit-payloads-${{ env.METASPLOIT_PAYLOADS_VERSION }}.gem . - working-directory: metasploit-framework - - name: Install metasploit-payloads gem - if: ${{ inputs.build_metasploit_payloads && matrix.meterpreter.name != 'mettle' }} + if: ${{ inputs.build_metasploit_payloads && matrix.meterpreter.name != 'mettle' && runner.os != 'Windows'}} run: | bundle exec gem install metasploit-payloads-${{ env.METASPLOIT_PAYLOADS_VERSION }}.gem + ruby -pi -e "gsub(/metasploit-payloads', '\d+.\d+.\d+/, 'metasploit-payloads')" metasploit-framework.gemspec bundle config unset deployment bundle update metasploit-payloads bundle install working-directory: metasploit-framework - - name: Build Windows payloads via Visual Studio 2019 Build (Windows) + - name: Install metasploit-payloads gem (Windows) + if: ${{ inputs.build_metasploit_payloads && matrix.meterpreter.name != 'mettle' && runner.os == 'Windows' }} shell: cmd - if: ${{ matrix.meterpreter.name == 'windows_meterpreter' && matrix.os == 'windows-2019' && inputs.build_metasploit_payloads }} run: | - cd c/meterpreter - git submodule init && git submodule update - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" && make.bat - working-directory: metasploit-payloads + bundle exec gem install metasploit-payloads-${{ env.METASPLOIT_PAYLOADS_VERSION }}.gem + ruby -pi.bak -e "gsub(/metasploit-payloads', '\d+.\d+.\d+/, 'metasploit-payloads')" metasploit-framework.gemspec + working-directory: metasploit-framework - - name: Build Windows payloads via Visual Studio 2022 Build (Windows) +# # TODO: Test gem installed correctly +# - name: Find and replace (Windows) +# if: ${{ inputs.build_metasploit_payloads && matrix.meterpreter.name != 'mettle' && runner.os == 'Windows' }} +# shell: cmd +# run: | +# ruby -pi.bak -e "gsub(/metasploit-payloads', '\d+.\d+.\d+/, 'metasploit-payloads')" metasploit-framework.gemspec +# working-directory: metasploit-framework + + # TODO: Test gem installed correctly + - name: Bundle config unset deployment (Windows) + if: ${{ inputs.build_metasploit_payloads && matrix.meterpreter.name != 'mettle' && runner.os == 'Windows' }} shell: cmd - if: ${{ matrix.meterpreter.name == 'windows_meterpreter' && matrix.os == 'windows-2022' && inputs.build_metasploit_payloads }} run: | - cd c/meterpreter - git submodule init && git submodule update - make.bat - working-directory: metasploit-payloads + bundle config unset deployment + working-directory: metasploit-framework - - name: Build PHP, Python and Windows payloads - if: ${{ (matrix.meterpreter.name == 'php' || matrix.meterpreter.name == 'python' || runner.os == 'Windows') && inputs.build_metasploit_payloads }} + # TODO: Test gem installed correctly + - name: Bundle update metasploit-payloads gem (Windows) + if: ${{ inputs.build_metasploit_payloads && matrix.meterpreter.name != 'mettle' && runner.os == 'Windows' }} + shell: cmd run: | - make install-php install-python install-windows - working-directory: metasploit-payloads + bundle update metasploit-payloads + working-directory: metasploit-framework + + # TODO: Test gem installed correctly + - name: Bundle install (Windows) + if: ${{ inputs.build_metasploit_payloads && matrix.meterpreter.name != 'mettle' && runner.os == 'Windows' }} + shell: cmd + run: | + bundle install + working-directory: metasploit-framework + + # TODO: Test gem installed correctly + - name: Bundle list (Windows) + if: ${{ inputs.build_metasploit_payloads && matrix.meterpreter.name != 'mettle' && runner.os == 'Windows' }} + shell: cmd + run: | + bundle list + working-directory: metasploit-framework - name: Acceptance env: diff --git a/docs/metasploit-framework.wiki/Payload-Testing.md b/docs/metasploit-framework.wiki/Payload-Testing.md index 46cb5dab3b92e..d24f0b52f40c0 100644 --- a/docs/metasploit-framework.wiki/Payload-Testing.md +++ b/docs/metasploit-framework.wiki/Payload-Testing.md @@ -15,27 +15,27 @@ Once the appropriate repository label is added, you will need to edit the GitHub repository and branch you want to test. Below I will outline some changes that are required to make this work, update the following lines like so: -1. Point at your forked repository - [line to update](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L188): +1. Point at your forked repository - [line to update](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L189): ```yaml repository: foo-r7/metasploit-framework ``` -2. Point at your forked repository branch - [line to update](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L190): +2. Point at your forked repository branch - [line to update](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L191): ```yaml ref: fixes-all-the-bugs ``` -3. Point at your forked repository that contains the payload changes you'd like to test - [line to update](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L249) +3. Point at your forked repository that contains the payload changes you'd like to test - [line to update](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L45) ```yaml repository: foo-r7/metasploit-payloads ``` -4. Point at your forked repository branch that contains the payload changes you'd like to test - [line to update](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L251): +4. Point at your forked repository branch that contains the payload changes you'd like to test - [line to update](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L47): ```yaml ref: fixes-all-the-payload-bugs ``` Steps 3 and 4 outline the steps required when steps testing metasploit-payloads. The same steps apply for Mettle, the following lines would need updated: - - Point at your forked repository that contain the payload changes you'd like to test - [line](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L155). - - Point at your forked repository branch that contains the payload changes you'd like to test - [line](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L157). + - Point at your forked repository that contain the payload changes you'd like to test - [line](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L156). + - Point at your forked repository branch that contains the payload changes you'd like to test - [line](https://github.com/rapid7/metasploit-framework/blob/2355ab546d02bfee99183083b12c6953836c12a1/.github/workflows/shared_meterpreter_acceptance.yml#L158).