# modules/features/pentest/boxes.nix — one directory and one box.json per box.## htbbox new Sauna 10.10.10.175 windows easy positional, any order# htbbox new Sauna 10.10.10.175 win easy sauna.htb dc01.sauna.htb# htbbox new prompt for everything (gum)# htbbox use <box> | ls | info | path | json switch and look around# htbbox set | host | cred | flag | note | ports record what you find## The CLI itself is _htbbox.py (stdlib python, its docstring is the manual).# It used to be ~200 lines of bash in this file plus a separate renderer; one# python file is easier to read, test and extend than either.## The layout is the CPTS vocabulary, not the HTB website's:## box.json the manifest: ip, os, difficulty, hostnames, domain, status,# flags, creds, ports, notes. Every other tool reads it.# writeup.md the post, rendered once from the vault's Templater template# recon/ enum/ creds/ loot/ exploit/ serve/ casts/## `serve/` rather than `payloads/`: the global arsenal is ~/pentesting# ($PAYLOADS, paths.nix), and a per-box `payloads/` would read as the same thing.## `new` and `use` write $STATE/{box,target,host} and call htb-hosts, so $BOX, $BOXDIR,# $TARGET and /etc/hosts all follow the box in every terminal (htb.nix).{ lib, ... }:
{
flake.nixosModules.pentest-boxes= { config, pkgs, lib, ... }:
leton= config.daemon.pentest.enable;
htbbox= pkgs.runCommand "htbbox" {
nativeBuildInputs= [ pkgs.makeWrapper pkgs.python3 ];
meta.mainProgram="htbbox";
}
'' install -Dm0644 ${./_htbbox.py} $out/libexec/htbbox.py # A syntax error should fail the build, not the first `htbbox new`. python3 -m py_compile $out/libexec/htbbox.py rm -rf $out/libexec/__pycache__ makeWrapper ${pkgs.python3}/bin/python3 $out/bin/htbbox \ --add-flags "-I $out/libexec/htbbox.py" \ --prefix PATH : ${lib.makeBinPath [ pkgs.gum ]} install -Dm0644 ${./_completions/_htbbox} $out/share/zsh/site-functions/_htbbox '';
in {
config= lib.mkIf on {
environment.systemPackages= [ htbbox ];
};
};
}