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").
    

๐Ÿง  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.

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 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.2.tar.gz (89.2 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.2-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pwnv-0.4.2.tar.gz
  • Upload date:
  • Size: 89.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for pwnv-0.4.2.tar.gz
Algorithm Hash digest
SHA256 a5d1f5541e31e2166237f36808408d697d6fd8c9bcf812393ea114eb2b620ad4
MD5 4c57600a842637da0c66a28bd3118d17
BLAKE2b-256 b7a00f30d119459b4b9050d166ffa0587988c5920705e2d926ad2568741b6f36

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pwnv-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for pwnv-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 efc7bb61b93f6551cc0a92da7d8d452ec5dd63b015bd3dfefe5b5e8c41d2f7df
MD5 2d66755e29f90d19dd5370ee79052b5e
BLAKE2b-256 716be890b80d7fcc3ddd79a95e45b1c272dfa238424d58d5749281cfaae53bfb

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