Compare commits
10 Commits
a79a7ac076
...
df46501731
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df46501731 | ||
|
|
be093ed3b3 | ||
|
|
3007d07d62 | ||
|
|
97332f7d01 | ||
|
|
09b4947e6e | ||
|
|
f0d2f18364 | ||
|
|
a74553bd88 | ||
|
|
b208cc2ddb | ||
|
|
7e88b51db6 | ||
|
|
a70694dbd5 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -8,3 +8,7 @@ wheels/
|
|||||||
|
|
||||||
# Virtual environments
|
# Virtual environments
|
||||||
.venv
|
.venv
|
||||||
|
|
||||||
|
#development files
|
||||||
|
state.json
|
||||||
|
config.json
|
||||||
|
|||||||
14
config.toml
14
config.toml
@@ -1,8 +1,6 @@
|
|||||||
#config
|
[Competition]
|
||||||
#file with global options
|
competition = "mycomp"
|
||||||
#key = "val"
|
catagory = "somecat"
|
||||||
[CTF-DATA]
|
challenge = "somechal"
|
||||||
current-challenge = "testChal"
|
[Enviroment]
|
||||||
current-comp = "testComp"
|
data_dir = "/home/venus/code/ctf/"
|
||||||
key-format = "SKY-aaaa-0000"
|
|
||||||
#comments ignored
|
|
||||||
|
|||||||
@@ -4,4 +4,19 @@ 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",
|
||||||
|
]
|
||||||
|
|
||||||
|
[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"]
|
||||||
|
|||||||
@@ -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
22
src/ctf/commands.py
Normal 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
|
||||||
|
|
||||||
|
|
||||||
34
src/ctf/main.py
Normal file
34
src/ctf/main.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# src/main.py
|
||||||
|
# Parses and calls commands
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
from ctf.utils import state
|
||||||
|
|
||||||
|
def setArguments():
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
state.info = "me"
|
||||||
|
# Parse arguments
|
||||||
|
# Current Ctf
|
||||||
|
# Current Challenge
|
||||||
|
# Validate args
|
||||||
|
# Call library functiions
|
||||||
|
# Set Ctf
|
||||||
|
args = setArguments()
|
||||||
|
if args.action == set:
|
||||||
|
print(f"setting ctf to{args.ctf}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
42
src/ctf/utils.py
Normal file
42
src/ctf/utils.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
class StateManager:
|
||||||
|
_path : Path
|
||||||
|
_data: dict
|
||||||
|
def __init__(self):
|
||||||
|
# Assume data directory exists on install and defined in config
|
||||||
|
# TODO check datadir valid
|
||||||
|
object.__setattr__(self, "_path", "user_config_dir/config.json") # set self._path to data_dir safely
|
||||||
|
object.__setattr__(self, "_data", self._load()) # load objects into self
|
||||||
|
|
||||||
|
def _load(self):
|
||||||
|
if self._path.exists():
|
||||||
|
with open(self._path, "r") as f:
|
||||||
|
return toml.load(f)
|
||||||
|
return{}
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
# use state.challenge to return value for challenge from dictionary
|
||||||
|
return self._data.get(name)
|
||||||
|
|
||||||
|
def __setattr__(self, name, value):
|
||||||
|
# use state.challenge = "run" to set challenge and run to dictionary
|
||||||
|
# writes the whole dict to disk
|
||||||
|
self._data[name] = value
|
||||||
|
with open(self._path, "w",) as f:
|
||||||
|
json.dump(self._data, f, indent=4)
|
||||||
|
def __repr__(self):
|
||||||
|
return f"StateManager({self.__dict__})"
|
||||||
|
|
||||||
|
|
||||||
|
state = StateManager()
|
||||||
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
# src/main.py
|
|
||||||
# Parses and calls commands
|
|
||||||
def main():
|
|
||||||
print("Hello from ctf!")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
Reference in New Issue
Block a user