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