C0deH4cker / PwnableHarness

Manage building and deploying exploitation challenges with ease
MIT License
57 stars 4 forks source link

Allow repos of challenges to mark their root directory with a workspace file #20

Open C0deH4cker opened 1 year ago

C0deH4cker commented 1 year ago

It's common for CTFs to be organized in a repo with a bunch of challenges in the subdirectories. As an example, check out SunshineCTF 2022.

I would like to be able to run a command like pwnmake docker-start from within the Pwn/CTFSim directory (for example), and have it act like pwnmake docker-start[ctfsim] from the root of that repo clone. That is, build products will go in the top-level .build directory, files will be published to the top-level publish directory, any parent Build.mk or After.mk files will still be parsed (so they can define variables that are used by CTFSim's Build.mk), and any prebuild.sh scripts are applied to the pwnmake environment. So effectively, when the pwnmake command is run, each directory from the current directory upwards will be checked until the pwnmake workspace marker file is found.

Perhaps this file will be called .pwnmake and just needs to exist. Or maybe its content can be useful? Maybe the existing prebuild.sh file can be named pwnmake-workspace.sh or something, so if an upwards directory search for that file finds a result, that directory will be considered the pwnmake root. The pwnmake script would then need to pass some variable to make to set the current directory, perhaps PWNMAKE_CURRENT_DIRECTORY or PWNMAKE_CWD. The various makefile targets like docker-start and even all will need to respect that variable in filtering down which specific rules the top-level targets list as dependencies.

C0deH4cker commented 1 year ago

As an aside, I think it would be nice for pwnmake or pwnmake . to build the current directory's project, but pwnmake all would still build all projects. This means that the . target would now be the default target in PwnableHarness's Makefile, and it would delegate to either all or all[project] if PWNMAKE_CWD is defined.