nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 makeWrapper,
6 ruby,
7 bundlerEnv,
8 testers,
9 python3,
10}:
11
12let
13 env = bundlerEnv {
14 inherit ruby;
15 name = "metasploit-bundler-env";
16 gemdir = ./.;
17 };
18in
19stdenv.mkDerivation (finalAttrs: {
20 pname = "metasploit-framework";
21 version = "6.4.53";
22
23 src = fetchFromGitHub {
24 owner = "rapid7";
25 repo = "metasploit-framework";
26 tag = finalAttrs.version;
27 hash = "sha256-yHat9U8EZbUWo4j9ut6K9IPtPFm130pfSmIuhtQhFoQ=";
28 };
29
30 nativeBuildInputs = [
31 makeWrapper
32 ];
33
34 buildInputs = [
35 (python3.withPackages (ps: [ ps.requests ]))
36 ];
37
38 dontPatchELF = true; # stay away from exploit executables
39
40 installPhase = ''
41 runHook preInstall
42
43 mkdir -p $out/{bin,share/msf}
44
45 cp -r * $out/share/msf
46
47 grep -rl "^#\!.*python2$" $out/share/msf | xargs -d '\n' rm
48
49 (
50 cd $out/share/msf/
51 for i in msf*; do
52 makeWrapper ${env}/bin/bundle $out/bin/$i \
53 --add-flags "exec ${ruby}/bin/ruby $out/share/msf/$i"
54 done
55 )
56
57 makeWrapper ${env}/bin/bundle $out/bin/msf-pattern_create \
58 --add-flags "exec ${ruby}/bin/ruby $out/share/msf/tools/exploit/pattern_create.rb"
59
60 makeWrapper ${env}/bin/bundle $out/bin/msf-pattern_offset \
61 --add-flags "exec ${ruby}/bin/ruby $out/share/msf/tools/exploit/pattern_offset.rb"
62
63 runHook postInstall
64 '';
65
66 passthru.tests = {
67 msfconsole-version = testers.testVersion {
68 package = finalAttrs.finalPackage;
69 command = "HOME=/tmp msfconsole -q -x 'version;exit'";
70 };
71 };
72
73 # run with: nix-shell maintainers/scripts/update.nix --argstr path metasploit
74 passthru.updateScript = ./update.sh;
75
76 meta = with lib; {
77 description = "Metasploit Framework - a collection of exploits";
78 homepage = "https://docs.metasploit.com/";
79 platforms = platforms.unix;
80 license = licenses.bsd3;
81 maintainers = with maintainers; [
82 fab
83 makefu
84 ];
85 mainProgram = "msfconsole";
86 };
87})