Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/lib/maintainers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@
github = "silmarp";
githubID = 67292496;
};
soratenshi = {
email = "[email protected]";
github = "soratenshi";
githubId = 13474089;
name = "Sora";
};
fendse = {
email = "[email protected]";
github = "Fendse";
Expand Down
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 76 additions & 0 deletions modules/programs/pwninit.nix
Original file line number Diff line number Diff line change
@@ -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)
}";
};
};
}
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/modules/programs/pwninit/basic-configuration.nix
Original file line number Diff line number Diff line change
@@ -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'
'';
};
}
1 change: 1 addition & 0 deletions tests/modules/programs/pwninit/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ pwninit-basic-configuration = ./basic-configuration.nix; }