Skip to main content

Python decorator for parallel exploit dispatch in Attack & Defense CTFs using the CookieFarm framework.

Project description

🍪 CookieFarm - Exploiter Manager

Language Keywords License

Python decorator for automating exploit execution in CTF Attack & Defense competitions


📦 What is it?

This package provides a @exploit_manager decorator designed to automate the parallel execution of exploits in CTF (Attack & Defense) settings, specifically for use with the CookieFarm project.

It handles:

  • Authentication with the central server
  • Retrieving team configuration
  • Automatic flag parsing from stdout

⚠️ Note: This package is not standalone. It must be used together with the CookieFarm client. The client provides the required APIs and team configurations.


📦 Installation

To install the package:

pip install --upgrade cookiefarm requests

⚙️ How it works

The @exploit_manager decorator takes care of:

  • Calling your exploit(ip, port, name_service, flag_ids) function
  • Retrieving the CookieFarm server configuration
  • Fetching the full flag IDs JSON at every tick
  • Normalizing competition-specific flag IDs structures into a per-team list
  • Passing only the current team/service flag IDs to each exploit thread
  • Capturing your exploit's stdout
  • Parsing flags via regex
  • Logging the result in JSON format, including: team ID, port, service name, and the flag found

🚀 Example usage

from cookiefarm import exploit_manager
import requests

@exploit_manager
def exploit(ip, port, name_service, flag_ids):
    # flag_ids contains only the IDs for the current team and service
    for flag_id in flag_ids:
        response = requests.get(
            f"http://{ip}:{port}/",
            params={"id": flag_id},
        )

        # Just print the flag to stdout
        print(response.text)

# Run from the command line with arguments from CookieFarm
# python3 myexploit.py -s <server_address> -t <tick_time> -T <thread_number> -p <port> -n <name_service>

For execution, you have to pass the required arguments from the command line, which are provided by the CookieFarm client. The decorator will handle the rest.

python3 myexploit.py -s <server_address> -t <tick_time> -T <thread_number> -p <port> -n <name_service> -x [test mode]
Argument Description
-s or --server_address The address of the CookieFarm server
-t or --tick_time The time interval for the exploit execution
-T or --thread_number The number of threads to use for the exploit
-p or --port_service The port to target for the exploit
-n or --name_service The name of the service to exploit
-x or --test Run in test mode against the configured NOP team

🧩 Flag IDs normalization

Different Attack/Defense infrastructures may expose flag IDs with different JSON layouts. CookieFarm fetches the full flag IDs JSON at every tick and normalizes it locally according to the shared.flagids_format value configured on the server.

The exploit function always receives:

flag_ids: list

This list contains only the flag IDs for the current team and the current service.

Format syntax

The flagids_format path supports dynamic tokens:

  • [service] — the service name passed with -n / --name_service
  • [team] — the team key to iterate over
  • [id] — the terminal node containing the flag IDs

Literal keys can be written directly in the path.

CyberChallenge-style layout

Raw flag IDs:

{
  "Service1": {
    "team_1": {
      "1": ["id-a"],
      "2": ["id-b"]
    }
  }
}

Server configuration:

shared:
  url_flag_ids: "http://10.10.0.1/flagids"
  flagids_format: "[service].[team].[id]"

The exploit running against Service1 and team_1 receives:

["id-a", "id-b"]

Team-first layout

Raw flag IDs:

{
  "team_1": {
    "Service1": ["id-a", "id-b"]
  }
}

Server configuration:

shared:
  url_flag_ids: "http://172.168.1.0/flagids"
  flagids_format: "[team].[service].[id]"

The exploit running against Service1 and team_1 receives:

["id-a", "id-b"]

Nested layout with a literal key

Raw flag IDs:

{
  "teams": [123, 456, 789],
  "flag_ids": {
    "service1": {
      "123": ["abc123", "def456"],
      "789": ["xxx", "yyy"]
    }
  }
}

Server configuration:

shared:
  url_flag_ids: "http://example.local/flagids"
  flagids_format: "flag_ids.[service].[team].[id]"

The exploit running against service1 and team 123 receives:

["abc123", "def456"]

If flagids_format is omitted, CookieFarm uses:

flagids_format: "[service].[team].[id]"

🛠️ Requirements

  • Python ≥ 3.13
  • Working CookieFarm client installed

📝 License

Distributed under the MIT License. Feel free to use, modify, and contribute.


For any questions, suggestions, or issues, feel free to open a GitHub issue!

Created with ❤️ by ByteTheCookies (feat. @0xMatte)

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

cookiefarm-1.3.0.tar.gz (28.2 MB view details)

Uploaded Source

Built Distribution

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

cookiefarm-1.3.0-py3-none-any.whl (28.2 MB view details)

Uploaded Python 3

File details

Details for the file cookiefarm-1.3.0.tar.gz.

File metadata

  • Download URL: cookiefarm-1.3.0.tar.gz
  • Upload date:
  • Size: 28.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for cookiefarm-1.3.0.tar.gz
Algorithm Hash digest
SHA256 d71e9b87c4c4b27c91e157e5dc73d18f1ca0eff00e7c8594ada87575b9b22d95
MD5 6c8b12b61718019174f8942b34047d8a
BLAKE2b-256 34f2be609911904c132c078f303bef806e20ec6a4432f1469ea7c84dbc56ccb9

See more details on using hashes here.

File details

Details for the file cookiefarm-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: cookiefarm-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 28.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for cookiefarm-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9abbf86e1fa0897018e772475dff71e2536d4d192bd3021659d836920419fdd1
MD5 8aecdbdb5bc6a6aa3bb8c230a6c29239
BLAKE2b-256 65eb0540ca71860e3608d149850dba539b77cedbfc2d0fedd5c7934b3f77f934

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