diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index b5175a87..f0d923db 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -259,6 +259,12 @@ github = "silmarp"; githubID = 67292496; }; + soratenshi = { + email = "dream@neoncity.dev"; + github = "soratenshi"; + githubId = 13474089; + name = "Sora"; + }; fendse = { email = "46252070+Fendse@users.noreply.github.com"; github = "Fendse"; diff --git a/modules/modules.nix b/modules/modules.nix index 4e1f0e20..eb034ea4 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -194,6 +194,7 @@ let ./programs/powerline-go.nix ./programs/pqiv.nix ./programs/pubs.nix + ./programs/pwninit.nix ./programs/pyenv.nix ./programs/pylint.nix ./programs/qcal.nix diff --git a/modules/programs/pwninit.nix b/modules/programs/pwninit.nix new file mode 100644 index 00000000..23376b3e --- /dev/null +++ b/modules/programs/pwninit.nix @@ -0,0 +1,76 @@ +{ pkgs, lib, config, ... }: +let + inherit (lib) mkEnableOption mkPackageOption mkOption mkIf types; + cfg = config.programs.pwninit; +in { + meta.maintainers = [ lib.hm.maintainer.soratenshi ]; + + options = { + programs.pwninit = { + enable = mkEnableOption + "A tool for automating starting binary exploit challenges"; + package = mkPackageOption pkgs "pwninit" { }; + + template = mkOption { + type = types.nullOr types.str; + default = null; + description = "The pwninit template."; + example = '' + #!/usr/bin/env python3 + from pwn import * + import warnings + + warnings.filterwarnings(action='ignore', category=BytesWarning) + + {bindings} + + context.binary = {bin_name} + + IP, PORT = "address", 12345 + + gdbscript = ''' + tbreak main + continue + ''' + + def start(): + if args.GDB: + return gdb.debug([elf.path], gdbscript) + elif args.REMOTE: + return remote(IP, PORT) + else: + return elf.process() + + p = start() + + # ----- Exploit ----- # + + p.interactive() + ''; + }; + + templateAlias = mkOption { + type = types.bool; + default = false; + description = + "Creates an alias for 'pwninit --template-path {template}' as 'pwninit'."; + }; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + assertions = mkIf cfg.templateAlias [{ + assertion = cfg.template != null; + message = + "The 'programs.pwninit.template' option must be set when 'programs.pwninit.templateAlias' is true."; + }]; + + home.shellAliases = mkIf (cfg.templateAlias && cfg.template != null) { + pwninit = "${cfg.package}/bin/pwninit --template-path ${ + (pkgs.writeText "template.py" cfg.template) + }"; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 4d8d49d4..fa1805f9 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -126,6 +126,7 @@ in import nmtSrc { ./modules/programs/poetry ./modules/programs/powerline-go ./modules/programs/pubs + ./modules/programs/pwninit ./modules/programs/pyenv ./modules/programs/qcal ./modules/programs/qutebrowser diff --git a/tests/modules/programs/pwninit/basic-configuration.nix b/tests/modules/programs/pwninit/basic-configuration.nix new file mode 100644 index 00000000..f381e41f --- /dev/null +++ b/tests/modules/programs/pwninit/basic-configuration.nix @@ -0,0 +1,17 @@ +{ config, ... }: { + config = { + programs.bash.enable = true; + + programs.pwninit = { + enable = true; + package = config.lib.test.mkStubPackage { }; + template = "A simple test"; + templateAlias = true; + }; + + nmt.script = '' + assertFileRegex home-files/.bashrc \ + 'pwninit --template-path.*template.py' + ''; + }; +} diff --git a/tests/modules/programs/pwninit/default.nix b/tests/modules/programs/pwninit/default.nix new file mode 100644 index 00000000..f1a2006a --- /dev/null +++ b/tests/modules/programs/pwninit/default.nix @@ -0,0 +1 @@ +{ pwninit-basic-configuration = ./basic-configuration.nix; }