Skip to main content

CLI tool for CTF management

Project description

pwnv: A CTF Workspace Management Tool ๐Ÿ› ๏ธ

pwnv is a Command-Line Interface (CLI) utility designed to optimize and organize CTF workflows. It facilitates challenge management, environment setup, and integration with remote CTF platforms, providing a structured approach to CTF participation.


๐ŸŽฏ Overview

pwnv addresses common challenges in CTF participation, such as disorganized challenge files and manual platform interaction. It provides a standardized framework to structure CTF events, automate setup procedures, and interface with platforms like CTFd, enabling participants to concentrate on problem-solving and enhancing overall efficiency.


โœจ Key Features

Feature Description
๐Ÿ—‚๏ธ Structured Workspace Establishes a consistent and organized directory structure for CTFs and their associated challenges.
๐Ÿ“ฆ Virtual Environments Manages isolated Python virtual environments for CTF workspaces, utilizing uv for rapid setup.
๐Ÿ”„ Remote Synchronization Enables fetching challenges, descriptions, and attachments from CTFd instances using the ctfbridge library.
๐Ÿš€ Remote Flag Submission Allows direct submission of flags to remote CTF platforms via the command line.
๐Ÿ”Œ Plugin Architecture Supports custom Python plugins for automating challenge setup based on predefined categories (e.g., pwn, web).
๐Ÿท๏ธ Challenge Tagging Provides functionality to tag solved challenges with relevant keywords for efficient searching and retrieval.
โœจ Interactive Interface Employs fuzzy finders and interactive prompts for intuitive navigation and user input.

๐Ÿ—๏ธ Installation Guide

Prerequisites

  • Python 3.12 or higher.
  • uv: Ensure uv is installed and accessible via the system PATH.

Option 1: Via pip

pip install pwnv

Option 2: From Source (Development)

git clone https://github.com/CarixoHD/pwnv
cd pwnv
pip install --editable .

๐Ÿš€ Quickstart Guide

  1. Initialize the workspace:
    pwnv init --ctfs-folder ~/CTFs
    source ~/CTFs/.pwnvenv/bin/activate
    
  2. Add a CTF event:
    # Add a local event
    pwnv ctf add ExampleCTF_Local
    
    # Add a remote event (prompts for URL and credentials)
    pwnv ctf add ExampleCTF_Remote
    
  3. Add a challenge:
    pwnv challenge add RopMaster # Select category when prompted
    
  4. Navigate to the challenge directory and begin work:
    cd ~/CTFs/ExampleCTF_Local/pwn/RopMaster/
    # Begin solving the challenge.
    
  5. Mark the challenge as solved:
    pwnv solve --flag "FLAG{example_flag}"
    # Enter tags when prompted (e.g., "buffer-overflow, ROP").
    

๐Ÿงฐ Devcontainer (Zed)

This repo includes a devcontainer configuration that isolates pwnv state inside the workspace. Open the folder in Zed and it will build the container and install dev dependencies.

Inside the container, run:

source .venv/bin/activate
pwnv init --ctfs-folder .pwnv/CTF

This keeps config and CTF data under .pwnv/ (already gitignored).


๐Ÿง  Core Concepts

Workspace Organization

pwnv enforces a hierarchical directory structure. A primary CTF folder contains individual CTF event directories, which in turn contain challenges categorized by type:

~/CTFs/
โ”œโ”€โ”€ .pwnvenv/
โ”œโ”€โ”€ ExampleCTF_Local/
โ”‚   โ”œโ”€โ”€ pwn/
โ”‚   โ”‚   โ””โ”€โ”€ RopMaster/
โ”‚   โ”‚       โ””โ”€โ”€ solve.py
โ”‚   โ””โ”€โ”€ web/
โ”‚       โ””โ”€โ”€ WebChallenge/
โ””โ”€โ”€ ExampleCTF_Remote/
    โ”œโ”€โ”€ .env
    โ”œโ”€โ”€ .session
    โ”œโ”€โ”€ crypto/
    โ”‚   โ””โ”€โ”€ CryptoChallenge/
    โ””โ”€โ”€ ...

Remote Platform Integration

Leveraging ctfbridge, pwnv interacts with remote CTF platforms to:

  • Retrieve challenge data (descriptions, values, categories, tags).
  • Download associated attachments.
  • Handle authentication via credentials or API tokens.
  • Maintain session state.
  • Submit flags programmatically via pwnv solve.

Plugin System

The plugin system allows for the execution of category-specific Python scripts during challenge creation, automating setup tasks like generating boilerplate solver scripts or setting up tools.


๐Ÿงฉ Plugin Architecture

pwnv features an extensible plugin system that allows users to define custom actions executed automatically during challenge creation (pwnv challenge add). This enables the automation of boilerplate setup, tool integration, and other category-specific tasks.

Plugin Location

  • Plugin Scripts: Reside within the plugins folder in your pwnv configuration directory (typically ~/.config/pwnv/plugins/). Each .py file represents a potential plugin.
  • Template Files: Associated template files (e.g., solve.py skeletons) are stored in the templates folder, organized by category (e.g., ~/.config/pwnv/templates/pwn/).

Plugin Structure

A pwnv plugin is a Python class that inherits from pwnv.plugins.ChallengePlugin. It must be decorated with @register_plugin to be discoverable.

Key components include:

  • @register_plugin: Decorator that makes the plugin available to pwnv.
  • category(self) -> Category:: Abstract method that must return the pwnv.models.challenge.Category for which this plugin should be considered.
  • logic(self, challenge: Challenge) -> None:: Abstract method containing the core custom logic to be executed.
  • templates_to_copy: Dict[str, str | None]: A class attribute specifying which files from the templates directory should be copied into the new challenge directory.
  • Template placeholders: Any {{placeholder}} tokens in template files are replaced with challenge metadata. Examples: {{service.host}}, {{service.port}}, {{service.url}}, {{challenge.name}}, {{challenge.points}}. Missing values keep the placeholder unchanged.

Example Plugin (pwn_plugin.py)

from pwnv.core import register_plugin
from pwnv.models.challenge import Category
from pwnv.plugins.plugin import ChallengePlugin
from pwnv.models import Challenge
from pwnv.utils.ui import info

@register_plugin
class BasicPwnPlugin(ChallengePlugin):
    # Copy 'solve.py' and 'gdbinit' from templates/pwn/ to the challenge dir.
    templates_to_copy = {
        "solve.py": None,
        "gdbinit": "gdbinit_rop" # save as gdbinit_rop
    }

    def category(self) -> Category:
        return Category.pwn

    def logic(self, challenge: Challenge) -> None:
        # Custom logic for pwn challenges
        info(f"Set up basic pwn environment for {challenge.name}")

โŒจ๏ธ Command Reference

The following table summarizes the available commands. For detailed usage, append --help to any command or subcommand.

Command Description
pwnv init Initializes the pwnv environment and workspace.
pwnv reset Removes all pwnv configurations and CTF data (exercise caution).
pwnv ctf add <name> Adds a new CTF event (local or remote).
pwnv ctf remove Deletes a CTF event and its challenges.
pwnv ctf info Displays metadata for a selected CTF.
pwnv ctf sync Fetches new challenges from a remote CTF.
pwnv ctf start Sets a CTF's status to 'running'.
pwnv ctf stop Sets a CTF's status to 'stopped'.
pwnv challenge add <name> Adds a new challenge, triggering relevant plugins.
pwnv challenge remove Deletes a specific challenge.
pwnv challenge info Displays metadata for a selected challenge.
pwnv challenge filter Lists solved challenges based on specified tags.
pwnv solve Marks a challenge as solved and handles flag submission/tagging.
pwnv plugin add <name> Creates a new plugin and its associated template.
pwnv plugin remove Deletes an existing plugin file.
pwnv plugin info Displays information about registered plugins.
pwnv plugin select Assigns a specific plugin to a challenge category.

๐Ÿค Contributing

Contributions to pwnv are welcome. Please refer to the GitHub repository to report issues, propose features, or submit pull requests.


๐Ÿ“„ License

pwnv is distributed under the MIT License. See the LICENSE file for further details.

MIT ยฉ Shayan Alinejad

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pwnv-0.4.5.tar.gz (64.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pwnv-0.4.5-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file pwnv-0.4.5.tar.gz.

File metadata

  • Download URL: pwnv-0.4.5.tar.gz
  • Upload date:
  • Size: 64.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for pwnv-0.4.5.tar.gz
Algorithm Hash digest
SHA256 4d945f3d85203e534fdf03d0536cbbea51c6eb597e16f6e3bc5e8e7dfb337af3
MD5 49a66f6b5cbe8f353a40bbcec170edb3
BLAKE2b-256 b184843f88087d9025ad1ac0bdbfe548015328038ea20487bc70242eae8001d2

See more details on using hashes here.

File details

Details for the file pwnv-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: pwnv-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for pwnv-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6596fc963fd65f7b4d50f44da358b6ae4e07b90613ca5c202d9f7fb97d94552b
MD5 8acbeeff3913a538c59ac479228afadb
BLAKE2b-256 8b390d5b9075e6df5049c219c1b1ae76505d6f1e16532dd9b5f4610cc90be248

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page