Skip to content

Commit

Permalink
Pls work
Browse files Browse the repository at this point in the history
  • Loading branch information
MEhrn00 committed Feb 25, 2024
1 parent fc7baa2 commit cde8edc
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ RUN grep -qxF '. "$HOME/.cargo/env"' /home/${username}/.profile \
RUN rm -f rustup.sh

# Install nightly
RUN $HOME/.cargo/bin/rustup install nightly
RUN $HOME/.cargo/bin/rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu

# Install rustfmt, clippy and llvm tools
RUN $HOME/.cargo/bin/rustup component add rustfmt clippy llvm-tools-preview
Expand Down
52 changes: 52 additions & 0 deletions .github/scripts/sanitizers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

REPO_BASE=""
AGENT_CODE="Payload_Type/thanatos/agent"

# Populates the 'REPO_BASE' to the base of the repo
repo_base() {
# Get the path to the directory containing this script
local _script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# Traverse up to the base of the git repository
local _repo_base_dir=${_script_dir}/../..

# Ensure that the repo base contains the '.git' directory
if [ ! -d "${_repo_base_dir}/.git" ]; then
echo "Could not find git repository base"
exit 1
fi

# Set the REPO_BASE variable to the base of the repo
REPO_BASE="$(realpath ${_repo_base_dir})"
}

sanitizers() {
pushd $AGENT_CODE &> /dev/null
local _cmd="cargo build -p genconfig"
echo "current directory: $PWD"
echo "command: $_cmd"
eval $_cmd

local _cmd="RUSTFLAGS='-Zsanitizer=address' cargo +nightly test -Zbuild-std --color always -p ffiwrappers --all-features --target x86_64-unknown-linux-gnu"
echo "current directory: $PWD"
echo "command: $_cmd"
eval $_cmd

local _cmd="RUSTFLAGS='-Zsanitizer=memory' cargo +nightly test -Zbuild-std --color always -p ffiwrappers --all-features --target x86_64-unknown-linux-gnu"
echo "current directory: $PWD"
echo "command: $_cmd"
eval $_cmd

local _cmd="RUSTFLAGS='-Zsanitizer=leak' cargo +nightly test -Zbuild-std --color always -p ffiwrappers --all-features --target x86_64-unknown-linux-gnu"
echo "current directory: $PWD"
echo "command: $_cmd"
eval $_cmd
popd &> /dev/null
}

set -e
repo_base
pushd $REPO_BASE &> /dev/null
sanitizers
popd &> /dev/null
5 changes: 4 additions & 1 deletion .github/workflows/dev-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
- Payload_Type/thanatos/mythic/**
- .github/**


env:
AGENT_CODE: Payload_Type/thanatos/agent
MYTHIC_CODE: Payload_Type/thanatos/mythic
Expand All @@ -24,3 +23,7 @@ jobs:
test-workflow:
name: Test
uses: ./.github/workflows/test.yml

sanitizer-workflow:
name: Sanitizers
uses: ./.github/workflows/sanitizers.yml
81 changes: 81 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,87 @@ jobs:
name: Mythic Code Coverage
path: mythic.gocov

sanitizers:
name: Sanitizer Tests
strategy:
fail-fast: false
matrix:
os:
- platform: ubuntu-latest
target: x86_64-unknown-linux-gnu
- platform: windows-latest
target: x86_64-pc-windows-msvc
sanitizer: [address]
include:
- os:
platform: ubuntu-latest
sanitizer: [memory, leak]

runs-on: ${{ matrix.os.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup cargo cache
uses: actions/cache@v4
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles(format('{0}/Cargo.lock', env.AGENT_CODE)) }}
restore-keys: |
${{ runner.os }}-cargo-${{ hashFiles(format('{0}/Cargo.lock', env.AGENT_CODE)) }}
${{ runner.os }}-cargo
- name: Setup cargo target cache
uses: actions/cache@v4
with:
path: ${{ env.AGENT_CODE }}/target
key: ${{ runner.os }}-cargo-target-${{ hashFiles(format('{0}/Cargo.lock', env.AGENT_CODE)) }}
restore-keys: |
${{ runner.os }}-cargo-target-${{ hashFiles(format('{0}/Cargo.lock', env.AGENT_CODE)) }}
${{ runner.os }}-cargo-target
- name: Install protoc (Linux)
if: ${{ runner.os == 'Linux' }}
run: |
mkdir -p /tmp/protoc
pushd /tmp/protoc
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v25.3/protoc-25.3-linux-x86_64.zip -o protoc.zip
unzip protoc.zip
mv bin/protoc /usr/local/bin
popd
rm -rf /tmp/protoc
- name: Install protoc (Windows)
if: ${{ runner.os == 'Windows' }}
run: |
Invoke-WebRequest -Uri https://github.com/protocolbuffers/protobuf/releases/download/v25.3/protoc-25.3-win64.zip -OutFile protoc.zip
Expand-Archive protoc.zip
Copy-Item -Path .\protoc\bin\protoc.exe -Destination $env:SYSTEMROOT\System32\protoc.exe
Remove-Item -Recurse .\protoc
Remove-Item .\protoc.zip
- name: Install Rust nightly
run: rustup component add rust-src --toolchain nightly-${TARGET}
env:
TARGET: ${{ matrix.os.target }}

- name: Run sanitizer tests for Linux
if: ${{ runner.os == 'Linux' }}
working-directory: ${{ env.AGENT_CODE }}
run: cargo +nightly test -Zbuild-std --color always -p ffiwrappers --all-features --target ${TARGET}
env:
RUSTFLAGS: -Zsanitizer=${{ matrix.sanitizer }}
TARGET: ${{ matrix.os.target }}

- name: Run sanitizer tests for Windows
if: ${{ runner.os == 'Windows' }}
working-directory: ${{ env.AGENT_CODE }}
run: cargo +nightly test --color always -p ffiwrappers --all-features --target $env:TARGET
env:
TARGET: ${{ matrix.os.target }}
RUSTFLAGS: -Zsanitizer=${{ matrix.sanitizer }}
CARGO_INCREMENTAL: 0

coverage:
name: Merge coverage artifacts
needs: [agent, mythic]
Expand Down
9 changes: 9 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
"isDefault": true,
"kind": "test"
}
},
{
"label": "Thanatos: Sanitizer tests",
"type": "shell",
"command": "./.github/scripts/sanitizers.sh",
"group": {
"isDefault": false,
"kind": "test"
}
}
]
}

0 comments on commit cde8edc

Please sign in to comment.