Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Virtual environments
**/.venv
**/venv
**/.virtualenv

# Python cache
**/__pycache__
**/*.pyc
**/*.pyo
**/*.pyd
**/.Python

# Test and coverage
**/.pytest_cache
**/.coverage
**/htmlcov
**/.tox
**/.nox

# IDE and editor
**/.idea
**/.vscode
**/*.swp
**/*.swo
*~

# Git
.git
.gitignore
.gitattributes

# Documentation
*.md
!README.md
docs/

# Build artifacts
**/*.egg-info
**/dist
**/build
**/.eggs

# OS files
.DS_Store
Thumbs.db

# Local environment files
.env
.env.local
.env.*.local

# Misc development files
**/.mypy_cache
**/.ruff_cache
2 changes: 1 addition & 1 deletion .github/scripts/generate_api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def mock_get_secret(store_name, key):
return app.openapi()
except ImportError as e:
print(f"Error importing web_api.main: {e}")
print("Make sure to run: cd projects/web_api && poetry install")
print("Make sure to run: cd projects/web_api && uv sync")
sys.exit(1)
except Exception as e:
import traceback
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python virtualenv
- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Install dependencies
run: |
pip install --upgrade pip
python -m venv env
source env/bin/activate
pip install -r docs/requirements.txt
uv pip install --system -r docs/requirements.txt

- name: Build documentation
run: |
source env/bin/activate
mkdocs build
python -m mkdocs build

- name: Setup Github pages
uses: actions/configure-pages@v4
Expand Down
26 changes: 10 additions & 16 deletions .github/workflows/generate-api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,21 @@ jobs:
with:
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
run: uv python install 3.12

- name: Setup Python virtualenv
- name: Install dependencies
run: |
pip install --upgrade pip
python -m venv env
source env/bin/activate
cd projects/web_api
pip install poetry
poetry install
uv sync --frozen

- name: Generate API documentation
run: |
source env/bin/activate
cd projects/web_api
poetry run python ../../.github/scripts/generate_api_docs.py
uv run python ../../.github/scripts/generate_api_docs.py

- name: Commit documentation changes
uses: stefanzweifel/git-auto-commit-action@v5
Expand All @@ -57,13 +53,11 @@ jobs:

- name: Install mkdocs dependencies
run: |
source env/bin/activate
pip install -r docs/requirements.txt
uv pip install --system -r docs/requirements.txt

- name: Build documentation
run: |
source env/bin/activate
mkdocs build
python -m mkdocs build

- name: Setup Github pages
uses: actions/configure-pages@v4
Expand All @@ -74,4 +68,4 @@ jobs:
path: site

- name: Deploy documentation to Github pages
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v4
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ ipython_config.py
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
Expand Down
30 changes: 30 additions & 0 deletions compose.override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ services:
- ./libs/:/src/libs/
- ./projects/web_api/web_api:/src/projects/web_api/web_api
- /src/projects/web_api/.venv
# Shadow libs .venv directories to prevent file watcher from scanning them
- /src/libs/chromium/.venv
- /src/libs/common/.venv
- /src/libs/file_enrichment_modules/.venv
- /src/libs/file_linking/.venv
- /src/libs/nemesis_dpapi/.venv
environment:
- LOG_LEVEL=${LOG_LEVEL:-DEBUG}

Expand Down Expand Up @@ -48,6 +54,12 @@ services:
- ./projects/file_enrichment/file_enrichment:/src/projects/file_enrichment/file_enrichment
- /src/projects/file_enrichment/.venv
- ./libs/file_enrichment_modules/yara_rules/dev/:/yara_rules/:ro
# Shadow libs .venv directories to prevent file watcher from scanning them
- /src/libs/chromium/.venv
- /src/libs/common/.venv
- /src/libs/file_enrichment_modules/.venv
- /src/libs/file_linking/.venv
- /src/libs/nemesis_dpapi/.venv

frontend:
image: !reset null
Expand Down Expand Up @@ -103,6 +115,12 @@ services:
- ./libs/:/src/libs/
- ./projects/agents/agents:/src/projects/agents/agents
- /src/projects/agents/.venv
# Shadow libs .venv directories to prevent file watcher from scanning them
- /src/libs/chromium/.venv
- /src/libs/common/.venv
- /src/libs/file_enrichment_modules/.venv
- /src/libs/file_linking/.venv
- /src/libs/nemesis_dpapi/.venv

housekeeping:
image: !reset null
Expand All @@ -114,6 +132,12 @@ services:
- ./libs/:/src/libs/
- ./projects/housekeeping/housekeeping:/src/projects/housekeeping/housekeeping
- /src/projects/housekeeping/.venv
# Shadow libs .venv directories to prevent file watcher from scanning them
- /src/libs/chromium/.venv
- /src/libs/common/.venv
- /src/libs/file_enrichment_modules/.venv
- /src/libs/file_linking/.venv
- /src/libs/nemesis_dpapi/.venv
environment:
- CLEANUP_SCHEDULE=*/3 * * * * # Test every 3 minutes
- LOG_LEVEL=${LOG_LEVEL:-DEBUG}
Expand All @@ -130,6 +154,12 @@ services:
- ./libs/:/src/libs/
- ./projects/document_conversion/document_conversion:/src/projects/document_conversion/document_conversion
- /src/projects/document_conversion/.venv
# Shadow libs .venv directories to prevent file watcher from scanning them
- /src/libs/chromium/.venv
- /src/libs/common/.venv
- /src/libs/file_enrichment_modules/.venv
- /src/libs/file_linking/.venv
- /src/libs/nemesis_dpapi/.venv
environment:
- LOG_LEVEL=${LOG_LEVEL:-DEBUG}

Expand Down
22 changes: 11 additions & 11 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ The helper scripts `./tools/submit.sh`, `./tools/monitor_folder.sh`, and `./tool

If you want to manually build the docker images, see [the Nemesis CLI project's README](https://github.com/SpecterOps/Nemesis/blob/main/projects/cli/README.md).

### Poetry Method (Local Usage or Development)
To use the Nemesis CLI locally or for development, install at least Python 3.12.8 and [install Poetry](https://python-poetry.org/docs/#installation). Then, run the following:
### Local Method (Development)
To use the Nemesis CLI locally or for development, install at least Python 3.12.8 and [install uv](https://docs.astral.sh/uv/getting-started/installation/). Then, run the following:

```bash
cd Nemesis/projects/cli
poetry install
poetry run python -m cli <command>
uv sync
uv run python -m cli <command>
```

## File Submission
Expand Down Expand Up @@ -79,11 +79,11 @@ The `./tools/submit.sh` script wraps the docker syntax automatically.
--debug
```

**Poetry :**
**Local (uv) :**
```bash
# Submit a single file w/ Poetry env
# Submit a single file w/ local env
cd Nemesis/projects/cli
poetry run python -m cli submit /data/file
uv run python -m cli submit /data/file
```

### Options Reference
Expand Down Expand Up @@ -182,12 +182,12 @@ docker run \
--debug
```

**Poetry :**
**Local (uv) :**
```bash
# Monitor a directory w/ Poetry env
# Monitor a directory w/ local env
cd Nemesis/projects/cli
poetry install
poetry run python -m cli monitor /path/to/directory
uv sync
uv run python -m cli monitor /path/to/directory
```

### Options Reference
Expand Down
18 changes: 8 additions & 10 deletions docs/file_enrichment_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@ To add a new module, create a new folder matching Python's [PEP8 naming conventi

Create a main `analyzer.py` file with your enrichment logic. The easiest method for this (and enrichment modules are fairly small) is to find an example module, and use it as a base with a LLM to help draft your code.

If your module needs additional dependencies, you have two options. Before either, first [install Poetry](https://python-poetry.org/). To prevent version issues, we recommend installing version 2.0.1 of Poetry with `pipx install poetry==2.0.1`
If your module needs additional dependencies, you have two options. First, [install uv](https://docs.astral.sh/uv/getting-started/installation/).

For the first option, you can `cd` to `projects/file_enrichment` or `libs/file_enrichment_modules/` and run `poetry add X` for the needed library.
For the first option, you can `cd` to `projects/file_enrichment` or `libs/file_enrichment_modules/` and run `uv add X` for the needed library.

Alternatively (and easier) you can create a `pyproject.yaml` in the new module module folder. An example is:
Alternatively (and easier) you can create a `pyproject.toml` in the new module folder. An example is:

```toml
[tool.poetry]
[project]
name = "module"
version = "0.1.0"
description = "Enriches things"
authors = ["harmj0y <will@harmj0y.net>"]
package-mode = false

[tool.poetry.dependencies]
python = "^3.9"
authors = [{name = "harmj0y", email = "will@harmj0y.net"}]
requires-python = ">=3.9"
dependencies = []
```

Then in this folder, run `poetry add X` to add a new library. The dynamic module loader will install the necessary dependencies in a Poetry env for just that module.
Then in this folder, run `uv add X` to add a new library. The dynamic module loader will install the necessary dependencies in a virtual env for just that module.

## Tips / Tricks

Expand Down
16 changes: 11 additions & 5 deletions infra/docker/python_base/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# This is the development image for python projects
# It is a slim image with dev tools/programs installed
FROM python:3.12.3-slim

RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes \
pipx wget curl procps net-tools htop jq iputils-ping
ENV PATH="/root/.local/bin:${PATH}"
RUN pipx install poetry==2.0.1
RUN pipx inject poetry poetry-plugin-bundle
wget curl procps net-tools htop jq iputils-ping git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install uv from official image
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1

WORKDIR /src
WORKDIR /src
Loading