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