1{ buildPythonPackage, fetchFromGitHub, stdenv, lib, isPyPy
2, pycrypto, ecdsa # TODO
3, mock, can, brotli
4, withOptionalDeps ? true, tcpdump, ipython
5, withCryptography ? true, cryptography
6, withVoipSupport ? true, sox
7, withPlottingSupport ? true, matplotlib
8, withGraphicsSupport ? false, pyx, texlive, graphviz, imagemagick
9, withManufDb ? false, wireshark
10, libpcap
11# 2D/3D graphics and graphs TODO: VPython
12# TODO: nmap, numpy
13}:
14
15buildPythonPackage rec {
16 pname = "scapy";
17 version = "2.5.0";
18
19 disabled = isPyPy;
20
21 src = fetchFromGitHub {
22 owner = "secdev";
23 repo = "scapy";
24 rev = "v${version}";
25 hash = "sha256-xJlovcxUQOQHfOU0Jgin/ayd2T5fOyeN4Jg0DbLHoeU=";
26 };
27
28 patches = [
29 ./find-library.patch
30 ];
31
32 postPatch = ''
33 printf "${version}" > scapy/VERSION
34
35 libpcap_file="${lib.getLib libpcap}/lib/libpcap${stdenv.hostPlatform.extensions.sharedLibrary}"
36 if ! [ -e "$libpcap_file" ]; then
37 echo "error: $libpcap_file not found" >&2
38 exit 1
39 fi
40 substituteInPlace "scapy/libs/winpcapy.py" \
41 --replace "@libpcap_file@" "$libpcap_file"
42 '' + lib.optionalString withManufDb ''
43 substituteInPlace scapy/data.py --replace "/opt/wireshark" "${wireshark}"
44 '';
45
46 propagatedBuildInputs = [ pycrypto ecdsa ]
47 ++ lib.optionals withOptionalDeps [ tcpdump ipython ]
48 ++ lib.optional withCryptography cryptography
49 ++ lib.optional withVoipSupport sox
50 ++ lib.optional withPlottingSupport matplotlib
51 ++ lib.optionals withGraphicsSupport [ pyx texlive.combined.scheme-minimal graphviz imagemagick ];
52
53 # Running the tests seems too complicated:
54 doCheck = false;
55 nativeCheckInputs = [ mock can brotli ];
56 checkPhase = ''
57 # TODO: be more specific about files
58 patchShebangs .
59 .config/ci/test.sh
60 '';
61 pythonImportsCheck = [ "scapy" ];
62
63 meta = with lib; {
64 description = "A Python-based network packet manipulation program and library";
65 longDescription = ''
66 Scapy is a powerful Python-based interactive packet manipulation program
67 and library.
68
69 It is able to forge or decode packets of a wide number of protocols, send
70 them on the wire, capture them, store or read them using pcap files,
71 match requests and replies, and much more. It is designed to allow fast
72 packet prototyping by using default values that work.
73
74 It can easily handle most classical tasks like scanning, tracerouting,
75 probing, unit tests, attacks or network discovery (it can replace hping,
76 85% of nmap, arpspoof, arp-sk, arping, tcpdump, wireshark, p0f, etc.). It
77 also performs very well at a lot of other specific tasks that most other
78 tools can't handle, like sending invalid frames, injecting your own
79 802.11 frames, combining techniques (VLAN hopping+ARP cache poisoning,
80 VoIP decoding on WEP protected channel, ...), etc.
81
82 Scapy supports Python 2.7 and Python 3 (3.4 to 3.8). It's intended to be
83 cross platform, and runs on many different platforms (Linux, OSX, *BSD,
84 and Windows).
85 '';
86 homepage = "https://scapy.net/";
87 changelog = "https://github.com/secdev/scapy/releases/tag/v${version}";
88 license = licenses.gpl2Only;
89 platforms = platforms.unix;
90 maintainers = with maintainers; [ primeos bjornfor ];
91 };
92}