Compare commits

..

12 Commits

Author SHA1 Message Date
venus
ab1c520cc2 working on project class and implegmenting tests 2026-04-23 07:05:28 -05:00
venus
13a5603773 changed config to use dict and tomlload 2026-04-23 05:18:46 -05:00
venus
df46501731 going to bed, updated the headers file to consolidate data and config dir, for now. Also began working on parsing user input. need to check out click 2026-04-14 03:46:19 -05:00
venus
be093ed3b3 updated config logic to read from one file 2026-04-14 03:36:14 -05:00
venus
3007d07d62 config testing 2026-04-07 02:06:20 -05:00
venus
97332f7d01 hid config file 2026-04-07 02:04:55 -05:00
venus
09b4947e6e added config class to validate config entries 2026-04-07 02:04:00 -05:00
venus
f0d2f18364 config parsing works with persistance 2026-04-06 15:19:11 -05:00
venus
a74553bd88 added state options as an object with dict storing to disk 2026-04-06 00:26:43 -05:00
venus
b208cc2ddb config works 2026-04-05 23:31:32 -05:00
venus
7e88b51db6 initialized as project working now 2026-04-05 23:21:33 -05:00
venus
a70694dbd5 initialized as project 2026-04-05 23:00:30 -05:00
12 changed files with 281 additions and 26 deletions

4
.gitignore vendored
View File

@@ -8,3 +8,7 @@ wheels/
# Virtual environments # Virtual environments
.venv .venv
#development files
state.json
config.json

17
GEMINI.md Normal file
View File

@@ -0,0 +1,17 @@
# CTF Workflow & Python Learning Project
This project serves as a centralized workspace for Capture The Flag (CTF) challenges and as a practical environment for learning Python.
## Project Intent
The primary goal is to use the context of CTF challenges (forensics, crypto, web, etc.) to explore and explain Python concepts, automation, and tooling.
## Core Mandates for Gemini CLI
1. **No Unsolicited Code:** Do NOT write or modify code unless explicitly issued a **Directive** to do so.
2. **Focus on Explanation:** Prioritize high-signal explanations of Python mechanics, libraries, and documentation.
3. **Summarization:** When directed, summarize documentation (local or web-based) to aid in understanding CTF tools and Python modules.
4. **Educational Context:** Use the existing scripts and tools in this repository (like `psk_crack.py`, `exploit.sh`, or the `tools/` directory) as examples when explaining technical concepts.
## Python Learning Objectives
- Understanding standard library modules relevant to security (e.g., `os`, `sys`, `base64`, `hashlib`).
- Analyzing existing scripts to understand control flow, data structures, and error handling.
- Exploring how Python interacts with the shell and external tools.

View File

@@ -1,8 +1,8 @@
#config [Competition]
#file with global options producer = "testProd"
#key = "val" competition = "testComp"
[CTF-DATA] catagory = "textCat"
current-challenge = "testChal" challenge = "testChal"
current-comp = "testComp"
key-format = "SKY-aaaa-0000" [Enviroment]
#comments ignored ctf_dir = "/home/venus/ctf"

View File

@@ -4,4 +4,25 @@ version = "0.1.0"
description = "An AI enhanced CTF toolchain" description = "An AI enhanced CTF toolchain"
readme = "README.md" readme = "README.md"
requires-python = ">=3.14" requires-python = ">=3.14"
dependencies = [] dependencies = [
"platformdirs>=4.9.4",
"toml>=0.10.2",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project.scripts]
ctf = "ctf.main:main"
[tool.hatch.build.targets.wheel]
packages = ["src/ctf"]
[tool.pyright]
extraPaths = ["src"]
[dependency-groups]
dev = [
"pytest>=9.0.3",
]

View File

@@ -1,9 +0,0 @@
# functions for commands needed
# src/commands.py
import os
# Read variables
# Initialize a challenge
## Copy files into directory
## add section to log

22
src/ctf/commands.py Normal file
View File

@@ -0,0 +1,22 @@
# functions for commands needed
# src/commands.py
import os
from ctf.utils import state
from pathlib import path
def test():
print("hello from test")
def Set_Challenge(comp: str, chal: str, setDirectory: bool):
# set the current challenge and competition from input
if state.current_comp != comp:
state.current_comp=comp
state.comp_dir=pathlib
# TODO archive the old competitions
if state.current_chal != chal:
state.current_chal=chal
print("challenge already set")
# TODO archive the old challenges
# TODO set the directory to challenge directory, with ignore option

48
src/ctf/main.py Normal file
View File

@@ -0,0 +1,48 @@
# src/main.py
# Parses and calls commands
import argparse
from pathlib import Path
from ctf.utils import *
def set_arguments():
parser = argparse.ArgumentParser( #type:ignore
prog="ctf",
description="A collection of cli tools to improve your ctf workflow",
epilog="")
parser.add_argument('action') # positional argument, action to be taken
parser.add_argument('-c', '--count') # option that takes a value
parser.add_argument('-v', '--verbose', action='store_true') # on/off flag
args = parser.parse_args()
return args
# Class for a competition, defining active catagories, challenges completed, etc
# return a list of paths for each catagory in a competition
def active_categories(p: Path) -> list:
cats = []
if not p.exists(): return []
for cat in p.iterdir():
cats.append(cat)
return cats
#return a dictionary of competitions in the base directory
def active_competitions(dir: str) -> dict:
comps = {}
p = Path(dir)
if not p.exists(): return {}
for item in p.iterdir():
if item.name == "tools": continue
comps[item] = active_categories(item)
print(item.name)
print(comps[item.name])
return comps
def main():
active_comps = active_competitions(enviroment["ctf_dir"])
print(active_comps)
if __name__ == "__main__":
main()

27
src/ctf/utils.py Normal file
View File

@@ -0,0 +1,27 @@
# src/ctf/utils.py
# basic utilities
import tomllib
import json
import toml
from pathlib import Path
from platformdirs import user_config_dir
# Parse config file
def load_config(config = f"{user_config_dir()}/ctf-config.toml") -> dict:
p = Path(config)
if p.exists():
return toml.load(p)
return{}
def write_config(data: dict, config = f"{user_config_dir()}/ctf"):
with open(config, "w") as f:
toml.dump(data, f)
config = load_config("/home/venus/code/ctf/config.toml")
competition = config["Competition"]
enviroment = config["Enviroment"]
# base_dir = config["ctf_dir"]

View File

@@ -1,8 +0,0 @@
# src/main.py
# Parses and calls commands
def main():
print("Hello from ctf!")
if __name__ == "__main__":
main()

28
tests/test_utils.py Normal file
View File

@@ -0,0 +1,28 @@
from pathlib import Path
import toml
from ctf.utils import load_config
def test_load_config_valid_file(tmp_path):
# 1. Setup: Create a temporary TOML file
config_file = tmp_path / "test_config.toml"
test_data = {
"Competition": {"name": "TestComp"},
"Environment": {"data_dir": "/tmp/ctf"}
}
with open(config_file, "w") as f:
toml.dump(test_data, f)
# 2. Act: Load the config using our function
loaded_data = load_config(str(config_file))
# 3. Assert: Verify the data matches
assert loaded_data["Competition"]["name"] == "TestComp"
assert loaded_data["Environment"]["data_dir"] == "/tmp/ctf"
def test_load_config_missing_file():
# Act: Try to load a file that doesn't exist
loaded_data = load_config("nonexistent_file.toml")
# Assert: Should return an empty dictionary
assert loaded_data == {}

105
uv.lock generated Normal file
View File

@@ -0,0 +1,105 @@
version = 1
revision = 3
requires-python = ">=3.14"
[[package]]
name = "colorama"
version = "0.4.6"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
]
[[package]]
name = "ctf"
version = "0.1.0"
source = { editable = "." }
dependencies = [
{ name = "platformdirs" },
{ name = "toml" },
]
[package.dev-dependencies]
dev = [
{ name = "pytest" },
]
[package.metadata]
requires-dist = [
{ name = "platformdirs", specifier = ">=4.9.4" },
{ name = "toml", specifier = ">=0.10.2" },
]
[package.metadata.requires-dev]
dev = [{ name = "pytest", specifier = ">=9.0.3" }]
[[package]]
name = "iniconfig"
version = "2.3.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/72/34/14ca021ce8e5dfedc35312d08ba8bf51fdd999c576889fc2c24cb97f4f10/iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730", size = 20503, upload-time = "2025-10-18T21:55:43.219Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/cb/b1/3846dd7f199d53cb17f49cba7e651e9ce294d8497c8c150530ed11865bb8/iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12", size = 7484, upload-time = "2025-10-18T21:55:41.639Z" },
]
[[package]]
name = "packaging"
version = "26.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/df/de/0d2b39fb4af88a0258f3bac87dfcbb48e73fbdea4a2ed0e2213f9a4c2f9a/packaging-26.1.tar.gz", hash = "sha256:f042152b681c4bfac5cae2742a55e103d27ab2ec0f3d88037136b6bfe7c9c5de", size = 215519, upload-time = "2026-04-14T21:12:49.362Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/7a/c2/920ef838e2f0028c8262f16101ec09ebd5969864e5a64c4c05fad0617c56/packaging-26.1-py3-none-any.whl", hash = "sha256:5d9c0669c6285e491e0ced2eee587eaf67b670d94a19e94e3984a481aba6802f", size = 95831, upload-time = "2026-04-14T21:12:47.56Z" },
]
[[package]]
name = "platformdirs"
version = "4.9.6"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/9f/4a/0883b8e3802965322523f0b200ecf33d31f10991d0401162f4b23c698b42/platformdirs-4.9.6.tar.gz", hash = "sha256:3bfa75b0ad0db84096ae777218481852c0ebc6c727b3168c1b9e0118e458cf0a", size = 29400, upload-time = "2026-04-09T00:04:10.812Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/75/a6/a0a304dc33b49145b21f4808d763822111e67d1c3a32b524a1baf947b6e1/platformdirs-4.9.6-py3-none-any.whl", hash = "sha256:e61adb1d5e5cb3441b4b7710bea7e4c12250ca49439228cc1021c00dcfac0917", size = 21348, upload-time = "2026-04-09T00:04:09.463Z" },
]
[[package]]
name = "pluggy"
version = "1.6.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", size = 69412, upload-time = "2025-05-15T12:30:07.975Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", size = 20538, upload-time = "2025-05-15T12:30:06.134Z" },
]
[[package]]
name = "pygments"
version = "2.20.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/c3/b2/bc9c9196916376152d655522fdcebac55e66de6603a76a02bca1b6414f6c/pygments-2.20.0.tar.gz", hash = "sha256:6757cd03768053ff99f3039c1a36d6c0aa0b263438fcab17520b30a303a82b5f", size = 4955991, upload-time = "2026-03-29T13:29:33.898Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/f4/7e/a72dd26f3b0f4f2bf1dd8923c85f7ceb43172af56d63c7383eb62b332364/pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176", size = 1231151, upload-time = "2026-03-29T13:29:30.038Z" },
]
[[package]]
name = "pytest"
version = "9.0.3"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "colorama", marker = "sys_platform == 'win32'" },
{ name = "iniconfig" },
{ name = "packaging" },
{ name = "pluggy" },
{ name = "pygments" },
]
sdist = { url = "https://files.pythonhosted.org/packages/7d/0d/549bd94f1a0a402dc8cf64563a117c0f3765662e2e668477624baeec44d5/pytest-9.0.3.tar.gz", hash = "sha256:b86ada508af81d19edeb213c681b1d48246c1a91d304c6c81a427674c17eb91c", size = 1572165, upload-time = "2026-04-07T17:16:18.027Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/d4/24/a372aaf5c9b7208e7112038812994107bc65a84cd00e0354a88c2c77a617/pytest-9.0.3-py3-none-any.whl", hash = "sha256:2c5efc453d45394fdd706ade797c0a81091eccd1d6e4bccfcd476e2b8e0ab5d9", size = 375249, upload-time = "2026-04-07T17:16:16.13Z" },
]
[[package]]
name = "toml"
version = "0.10.2"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/be/ba/1f744cdc819428fc6b5084ec34d9b30660f6f9daaf70eead706e3203ec3c/toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f", size = 22253, upload-time = "2020-11-01T01:40:22.204Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/44/6f/7120676b6d73228c96e17f1f794d8ab046fc910d781c8d151120c3f1569e/toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b", size = 16588, upload-time = "2020-11-01T01:40:20.672Z" },
]