about summary refs log tree commit diff
path: root/nix/templates/ctf/flake.nix
blob: f185bb71fd0a2aab4995fae1c0b53affe1f77722 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
  description = ''
    One Flake to rule them all^W^Wcommon CTF problems, namely broken infa.

    Usage:
    ; nix flake init -t git+https://github.com/hanemile/hefe\#ctf
  '';
  nixConfig.bash-prompt = "\[ctf\]; ";

  inputs = {
    nixpkgs.url = "git+ssh://git@github.com/nixos/nixpkgs.git?shallow=1&ref=nixos-24.11";
    pwndbg.url = "git+ssh://git@github.com/pwndbg/pwndbg";
  };

  # Flake outputs
  outputs =
    { nixpkgs, pwndbg, ... }@inputs:
    let
      # Systems supported
      allSystems = [
        "x86_64-linux" # 64-bit Intel/AMD Linux
        "aarch64-linux" # 64-bit ARM Linux
        "x86_64-darwin" # 64-bit Intel macOS
        "aarch64-darwin" # 64-bit ARM macOS
      ];

      # Helper to provide system-specific attributes
      nameValuePair = name: value: { inherit name value; };
      genAttrs = names: f: builtins.listToAttrs (map (n: nameValuePair n (f n)) names);
      forAllSystems = f: genAttrs allSystems (system: f {
        pkgs = import nixpkgs { inherit system; };
        pwndbg = inputs.pwndbg.packages.${system}.default;
      });
    in
    {
      # Development environment output
      devShells = forAllSystems (
        { pkgs, pwndbg }:
        {
          default =
            pkgs.mkShell {
              shellHook = ''
                cat << EOF > solve.py
                from pwn import *

                context.gdbinit="${pwndbg}/share/pwndbg/gdbinit.py"

                # exe = ELF("./a.out")

                p = remote("138.199.213.51", 31335)
                #p = gdb.debug(exe.path, gdbscript=''''
                #                break main
                #                c
                #              '''')

                p.sendlineafter(b"> ", b"asd")

                p.interactive()
                EOF
              '';
              packages = [
                  pkgs.gcc
                  pwndbg
                  (pkgs.python311.withPackages ( ps: with ps; [
                    pwntools
                    pwndbg
                    pycryptodome
                  ]))
              ];
            };
        }
      );
    };
}