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