diff --git a/LICENSE b/LICENSE index d8c6657..d1ad71d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2025 Matte23 +Copyright (c) 2025 Matteo Schiff Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index d1bb7d2..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,3 +0,0 @@ -# solvertools - -A bunch of tools to integrate a solver with ctfcli \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a6c687a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,23 @@ +[build-system] +requires = ["hatchling >= 1.26"] +build-backend = "hatchling.build" + +[project] +name = "solvertools" +version = "0.0.1" +authors = [ + { name="Matte23", email="matteo@underdesk.net" }, +] +description = "A bunch of tools to integrate a solver with ctfcli" +readme = "README.md" +requires-python = ">=3.8" +classifiers = [ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", +] +license = "MIT" +license-files = ["LICEN[CS]E*"] + +[project.urls] +Homepage = "https://git.underdesk.net/Matte23/solvertools" +Issues = "https://git.underdesk.net/Matte23/solvertools/issues" \ No newline at end of file diff --git a/src/solvertools/__init__.py b/src/solvertools/__init__.py new file mode 100644 index 0000000..abf4218 --- /dev/null +++ b/src/solvertools/__init__.py @@ -0,0 +1,2 @@ +from .connect import * +from .flags import * diff --git a/src/solvertools/connect.py b/src/solvertools/connect.py new file mode 100644 index 0000000..442e1ce --- /dev/null +++ b/src/solvertools/connect.py @@ -0,0 +1,23 @@ +from pwn import log, remote, process +import sys +from argparse import ArgumentParser + + +def connect_tcp(local_path): + # Argument parsing + parser = ArgumentParser() + parser.add_argument("--connection-info", required=True, help="nc HOST PORT") + parser.add_argument("--local", action="store_true", help="Run locally") + args = parser.parse_args() + + # Parse HOST and PORT + try: + _, HOST, PORT = args.connection_info.split(" ") + PORT = int(PORT) + except ValueError: + log.error("Invalid --connection-info format. Use 'nc HOST PORT'") + sys.exit(1) + + # Connect to process or remote host + conn = process(["python", local_path]) if args.local else remote(HOST, PORT) + return conn diff --git a/src/solvertools/flags.py b/src/solvertools/flags.py new file mode 100644 index 0000000..3416f3c --- /dev/null +++ b/src/solvertools/flags.py @@ -0,0 +1,13 @@ +from pwn import log +import re +import sys + + +def extract_flag(data, regex): + match = re.findall(regex, data) + if match: + log.success(f"Flag found: {match[0]}") + sys.exit(0) + else: + log.failure("Flag not found.") + sys.exit(1)