Skip to content

Commit

Permalink
refactor: start main refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MEhrn00 committed Sep 1, 2024
1 parent e6e3e7b commit c3b38a9
Show file tree
Hide file tree
Showing 205 changed files with 5,334 additions and 8,156 deletions.
43 changes: 0 additions & 43 deletions .github/actions/setup-lint/action.yml

This file was deleted.

7 changes: 3 additions & 4 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
name: Build the base container image
name: Test build base container image

on:
pull_request:
branches:
- main

paths:
- Payload_Type/thanatos/thanatos/agent_code
- Payload_Type/thanatos/**.py
- Payload_Type/thanatos/

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build the base container image
name: Build base container image
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down
119 changes: 48 additions & 71 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,84 @@ on:
branches:
- dev
paths:
- Payload_Type/thanatos/thanatos/agent_code
- Payload_Type/thanatos/**.py
- Payload_Type/thanatos/

pull_request:
branches:
- main
- dev
paths:
- Payload_Type/thanatos/thanatos/agent_code
- Payload_Type/thanatos/**.py
- Payload_Type/thanatos/

workflow_call:

env:
THANATOS_PATH: Payload_Type/thanatos
AGENT_CODE: thanatos/agent_code
MYTHIC_CODE: thanatos/mythic/agent_functions
AGENT_CODE_PATH: Payload_Type/thanatos/agent
MYTHIC_CODE_PATH: Payload_Type/thanatos/mythic

jobs:
syntax:
name: Check Syntax
mythic:
name: Mythic code checks
runs-on: ubuntu-latest

defaults:
run:
working-directory: ${{ env.MYTHIC_CODE_PATH }}

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

- name: Setup environment
uses: ./.github/actions/setup-lint
with:
python-requirements: ${{ env.THANATOS_PATH }}/requirements.txt
agent-code: ${{ env.THANATOS_PATH }}/${{ env.AGENT_CODE }}
- name: Install Poetry
run: |
python -m ensurepip
python -m pip install --upgrade pip
python -m pip install poetry
- name: Check Mythic code for errors
working-directory: ${{ env.THANATOS_PATH }}
run: python -m pylint --rcfile pylintrc -f colorized --errors-only main.py ${MYTHIC_CODE}/*.py
- name: Install Python packages
run: poetry install

- name: Check Agent code for errors
working-directory: ${{ env.THANATOS_PATH }}/${{ env.AGENT_CODE }}
run: cargo check --color always --all-targets --all-features
env:
RUSTFLAGS: "--cfg http"
UUID: ""
AESPSK: ""
callback_host: ""
callback_interval: ""
callback_jitter: ""
callback_port: ""
connection_retries: ""
encrypted_exchange_check: ""
get_uri: ""
headers: ""
post_uri: ""
working_hours: ""
- name: Formatting
run: poetry run black --color --diff --check thanatos

- name: Linting
run: poetry run pylint thanatos

format:
name: Check Formatting
agent:
name: Agent code checks
runs-on: ubuntu-latest

defaults:
run:
working-directory: ${{ env.AGENT_CODE_PATH }}

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

- name: Setup environment
uses: ./.github/actions/setup-lint
- name: Setup cargo cache
uses: actions/cache@v4
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles(format('{0}/Cargo.toml', env.AGENT_CODE_PATH)) }}
restore-keys: |
${{ runner.os }}-cargo-${{ hashFiles(format('{0}/Cargo.toml', env.AGENT_CODE_PATH)) }}
${{ runner.os }}-cargo
- name: Setup cargo target cache
uses: actions/cache@v4
with:
python-requirements: ${{ env.THANATOS_PATH }}/requirements.txt
agent-code: ${{ env.THANATOS_PATH }}/${{ env.AGENT_CODE }}
path: ${{ env.AGENT_CODE_PATH }}/target
key: ${{ runner.os }}-cargo-target-${{ hashFiles(format('{0}/Cargo.toml', env.AGENT_CODE_PATH)) }}
restore-keys: |
${{ runner.os }}-cargo-target-${{ hashFiles(format('{0}/Cargo.toml', env.AGENT_CODE_PATH)) }}
${{ runner.os }}-cargo-target
- name: Check Mythic code formatting
working-directory: ${{ env.THANATOS_PATH }}
run: python -m black --color --diff --check main.py ${MYTHIC_CODE}/*.py
- name: Install Clippy
run: rustup component add clippy

- name: Check Agent code formatting
working-directory: ${{ env.THANATOS_PATH }}/${{ env.AGENT_CODE }}
- name: Formatting
run: cargo fmt -- --color always --check
env:
RUSTFLAGS: "--cfg http"
UUID: ""
AESPSK: ""
callback_host: ""
Expand All @@ -96,32 +96,9 @@ jobs:
post_uri: ""
working_hours: ""

lint:
name: Lint Code
runs-on: ubuntu-latest

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

- name: Setup environment
uses: ./.github/actions/setup-lint
with:
python-requirements: ${{ env.THANATOS_PATH }}/requirements.txt
agent-code: ${{ env.THANATOS_PATH }}/${{ env.AGENT_CODE }}

- name: Install Clippy
run: rustup component add clippy

- name: Lint Mythic code with pylint
working-directory: ${{ env.THANATOS_PATH }}
run: python -m pylint --rcfile pylintrc -f colorized main.py ${MYTHIC_CODE}/*.py

- name: Lint Agent code with clippy
working-directory: ${{ env.THANATOS_PATH }}/${{ env.AGENT_CODE }}
- name: Linting
run: cargo clippy --color always --all-features --all-targets -- -D warnings
env:
RUSTFLAGS: "--cfg http"
UUID: ""
AESPSK: ""
callback_host: ""
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ env:
# License for the base container image
CONTAINER_IMAGE_LICENSE: BSD-3-Clause
# Path to the agent code
AGENT_CODE_PATH: Payload_Type/thanatos/thanatos/agent_code
AGENT_CODE_PATH: Payload_Type/thanatos/agent
# Path to the Mythic code
MYTHIC_CODE_PATH: Payload_Type/thanatos/mythic

jobs:
# Get the new release version number
Expand Down Expand Up @@ -88,6 +90,12 @@ jobs:
- name: Lowercase the container image name
run: echo "CONTAINER_IMAGE_NAME=${CONTAINER_IMAGE_NAME,,}" >> ${GITHUB_ENV}

- name: Install Poetry
run: |
python -m ensurepip
python -m pip install --upgrade pip
python -m pip install poetry
- name: Set config.json version number
uses: jossef/[email protected]
with:
Expand All @@ -114,6 +122,12 @@ jobs:
VERSION: ${{ needs.version.outputs.number }}
run: sed -i "0,/^version = .*$/s//version = \"${VERSION}\"/" Cargo.toml

- name: Set Mythic code version number
working-directory: ${{ env.MYTHIC_CODE_PATH }}
env:
VERSION: ${{ needs.version.outputs.number }}
run: poetry version ${VERSION}

- name: Push the updated version number changes
uses: EndBug/add-and-commit@v9
with:
Expand Down
45 changes: 45 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Deploy changes",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}",
},
"command": "ssh",
"args": [
"mythic",
"./redeploy.sh",
],
"group": "build",
"dependsOn": [
"Build base Docker image"
]
},
{
"label": "Build base Docker image",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/Payload_Type/thanatos",
},
"command": "docker",
"args": [
"build",
"-f",
".docker/Dockerfile",
"-t",
"ghcr.io/mythicagents/thanatos:${input:tag}",
"."
],
"group": "build"
}
],
"inputs": [
{
"id": "tag",
"description": "Image tag",
"type": "promptString"
}
]
}
Loading

0 comments on commit c3b38a9

Please sign in to comment.