1 .. highlight:: sh 2 3 ************************* 4 Download and Installation 5 ************************* 6 7 Overview 8 ======== 9 10 0. Install `Python 2.7.X or 3.3+ <https://www.python.org/downloads/>`_. 11 1. `Download and install Scapy. <#installing-scapy-v2-x>`_ 12 2. `Follow the platform specific instructions (depedencies) <#platform-specific-instructions>`_. 13 3. (Optional): `Install additional software for special features <#optional-software-for-special-features>`_. 14 4. Run Scapy with root privileges. 15 16 Each of these steps can be done in a different way dependent on your platform and on the version of Scapy you want to use. 17 18 At the moment, there are two different versions of Scapy: 19 20 * **Scapy v2.x**. The current up-to-date version. It consists of several files packaged in the standard distutils way. 21 Scapy v2 <= 2.3.3 needs Python 2.5, Scapy v2 > 2.3.3 needs Python 2.7 or 3.3+. 22 * **Scapy v1.x (deprecated)**. It does not support Python 3. It consists of only one file and works on Python 2.4, so it might be easier to install. 23 Moreover, your OS may already have a specially prepared packages or ports for it. Last version is v1.2.2. 24 25 .. note:: 26 27 In Scapy v2 use ``from scapy.all import *`` instead of ``from scapy import *``. 28 29 30 Installing Scapy v2.x 31 ===================== 32 33 The following steps describe how to install (or update) Scapy itself. 34 Dependent on your platform, some additional libraries might have to be installed to make it actually work. 35 So please also have a look at the platform specific chapters on how to install those requirements. 36 37 .. note:: 38 39 The following steps apply to Unix-like operating systems (Linux, BSD, Mac OS X). 40 For Windows, see the `special chapter <#windows>`_ below. 41 42 Make sure you have Python installed before you go on. 43 44 Latest release 45 -------------- 46 47 .. note:: 48 To get the latest versions, with bugsfixes and new features, but maybe not as stable, see the `development version <#current-development-version>`_. 49 50 Use pip:: 51 52 $ pip install scapy 53 54 55 You can also download the `latest version <http://scapy.net>`_ to a temporary directory and install it in the standard `distutils <http://docs.python.org/inst/inst.html>`_ way:: 56 57 $ cd /tmp 58 $ wget --trust-server-names scapy.net # or wget -O scapy.zip scapy.net 59 $ unzip scapy-x.x.x.zip 60 $ cd scapy 61 $ sudo python setup.py install 62 63 Alternatively, you can execute the zip file:: 64 65 $ chmod +x scapy-x.x.x.zip 66 $ sudo ./scapy-x.x.x.zip 67 68 or:: 69 70 $ sudo sh scapy-x.x.x.zip 71 72 or:: 73 74 $ mv scapy-x.x.x.zip /usr/local/bin/scapy 75 $ sudo scapy 76 77 or:: 78 79 $ chmod +x scapy-x.x.x.zip 80 $ ./scapy-x.x.x.zip 81 82 or download and run in one command:: 83 84 $ sh <(curl -sL scapy.net) 85 86 .. note:: 87 88 To make a zip executable, some bytes have been added before the zip header. 89 Most zip programs handle this, but not all. If your zip program complains 90 about the zip file to be corrupted, either change it, or download a 91 non-executable zip at https://github.com/secdev/scapy/archive/master.zip 92 93 94 Current development version 95 ---------------------------- 96 97 .. index:: 98 single: Git, repository 99 100 If you always want the latest version with all new features and bugfixes, use Scapy's Git repository: 101 102 1. Install the Git version control system. For example, on Debian/Ubuntu use:: 103 104 $ sudo apt-get install git 105 106 or on OpenBSD:: 107 108 $ doas pkg_add git 109 110 2. Check out a clone of Scapy's repository:: 111 112 $ git clone https://github.com/secdev/scapy 113 114 3. Install Scapy in the standard distutils way:: 115 116 $ cd scapy 117 $ sudo python setup.py install 118 119 Then you can always update to the latest version:: 120 121 $ git pull 122 $ sudo python setup.py install 123 124 .. note:: 125 126 You can run scapy without installing it using the ``run_scapy`` (unix) or ``run_scapy.bat`` (Windows) script or running it directly from the executable zip file (see previous section). 127 128 Installing Scapy v1.2 (Deprecated) 129 ================================== 130 131 As Scapy v1 consists only of one single Python file, installation is easy: 132 Just download the last version and run it with your Python interpreter:: 133 134 $ wget https://raw.githubusercontent.com/secdev/scapy/v1.2.0.2/scapy.py 135 $ sudo python scapy.py 136 137 Optional software for special features 138 ====================================== 139 140 For some special features you have to install more software. 141 Most of those softwares are installable via ``pip``. 142 Here are the topics involved and some examples that you can use to try if your installation was successful. 143 144 .. index:: 145 single: plot() 146 147 * Plotting. ``plot()`` needs `Matplotlib <https://matplotlib.org/>`_. It is installable via ``pip install matplotlib`` 148 149 .. code-block:: python 150 151 >>> p=sniff(count=50) 152 >>> p.plot(lambda x:len(x)) 153 154 * 2D graphics. ``psdump()`` and ``pdfdump()`` need `PyX <http://pyx.sourceforge.net/>`_ which in turn needs a LaTeX distribution: `texlive (Unix) <http://www.tug.org/texlive/>`_ or `MikTex (Windows) <https://miktex.org/>`_. For viewing the PDF and PS files interactively, you also need `Adobe Reader <http://www.adobe.com/products/reader/>`_ (``acroread``) and `gv <http://wwwthep.physik.uni-mainz.de/~plass/gv/>`_ (``gv``). 155 156 Note: PyX requires version 0.12 on Python 2.7. This means that on Python 2.7, it needs to be installed via ``pip install pyx==0.12``. Otherwise ``pip install pyx`` 157 158 .. code-block:: python 159 160 >>> p=IP()/ICMP() 161 >>> p.pdfdump("test.pdf") 162 163 * Graphs. ``conversations()`` needs `Graphviz <http://www.graphviz.org/>`_ and `ImageMagick <http://www.imagemagick.org/>`_. 164 165 .. code-block:: python 166 167 >>> p=readpcap("myfile.pcap") 168 >>> p.conversations(type="jpg", target="> test.jpg") 169 170 * 3D graphics. ``trace3D()`` needs `VPython <http://www.vpython.org/>`_. 171 172 .. code-block:: python 173 174 >>> a,u=traceroute(["www.python.org", "google.com","slashdot.org"]) 175 >>> a.trace3D() 176 177 .. index:: 178 single: WEP, unwep() 179 180 * WEP decryption. ``unwep()`` needs `cryptography <https://cryptography.io>`_. Example using a `Weplap test file <http://weplab.sourceforge.net/caps/weplab-64bit-AA-managed.pcap>`_: 181 182 Cryptography is installable via ``pip install cryptography`` 183 184 .. code-block:: python 185 186 >>> enc=rdpcap("weplab-64bit-AA-managed.pcap") 187 >>> enc.show() 188 >>> enc[0] 189 >>> conf.wepkey="AA\x00\x00\x00" 190 >>> dec=Dot11PacketList(enc).toEthernet() 191 >>> dec.show() 192 >>> dec[0] 193 194 * PKI operations and TLS decryption. `cryptography <https://cryptography.io>`_ is also needed. 195 196 * Fingerprinting. ``nmap_fp()`` needs `Nmap <http://nmap.org>`_. You need an `old version <http://nmap.org/dist-old/>`_ (before v4.23) that still supports first generation fingerprinting. 197 198 .. code-block:: python 199 200 >>> load_module("nmap") 201 >>> nmap_fp("192.168.0.1") 202 Begin emission: 203 Finished to send 8 packets. 204 Received 19 packets, got 4 answers, remaining 4 packets 205 (0.88749999999999996, ['Draytek Vigor 2000 ISDN router']) 206 207 * Queso is used withing the queso module: `queso-980922.tar.gz <http://www.packetstormsecurity.org/UNIX/scanners/queso-980922.tar.gz>`_. Extract the tar.gz file (e.g. using `7-Zip <http://www.7-zip.org/>`_) and put ``queso.conf`` into your Scapy directory 208 209 .. index:: 210 single: VOIP 211 212 * VOIP. ``voip_play()`` needs `SoX <http://sox.sourceforge.net/>`_. 213 214 Platform-specific instructions 215 ============================== 216 217 Linux native 218 ------------ 219 220 Scapy can run natively on Linux, without libdnet and libpcap. 221 222 * Install `Python 2.7 or 3.3+ <http://www.python.org>`_. 223 * Install `tcpdump <http://www.tcpdump.org>`_ and make sure it is in the $PATH. (It's only used to compile BPF filters (``-ddd option``)) 224 * Make sure your kernel has Packet sockets selected (``CONFIG_PACKET``) 225 * If your kernel is < 2.6, make sure that Socket filtering is selected ``CONFIG_FILTER``) 226 227 Debian/Ubuntu 228 ------------- 229 230 Just use the standard packages:: 231 232 $ sudo apt-get install tcpdump graphviz imagemagick python-gnuplot python-cryptography python-pyx 233 234 Scapy optionally uses python-cryptography v1.7 or later. It has not been packaged for ``apt`` in less recent OS versions (e.g. Debian Jessie). If you need the cryptography-related methods, you may install the library with: 235 236 .. code-block:: text 237 238 # pip install cryptography 239 240 Fedora 241 ------ 242 243 Here's how to install Scapy on Fedora 9: 244 245 .. code-block:: text 246 247 # yum install git python-devel 248 # cd /tmp 249 # git clone https://github.com/secdev/scapy 250 # cd scapy 251 # python setup.py install 252 253 Some optional packages: 254 255 .. code-block:: text 256 257 # yum install graphviz python-cryptography sox PyX gnuplot numpy 258 # cd /tmp 259 # wget http://heanet.dl.sourceforge.net/sourceforge/gnuplot-py/gnuplot-py-1.8.tar.gz 260 # tar xvfz gnuplot-py-1.8.tar.gz 261 # cd gnuplot-py-1.8 262 # python setup.py install 263 264 265 Mac OS X 266 -------- 267 268 On Mac OS X, Scapy does not work natively. You need to install Python bindings 269 to use libdnet and libpcap. You can choose to install using either Homebrew or 270 MacPorts. They both work fine, yet Homebrew is used to run unit tests with 271 `Travis CI <https://travis-ci.org>`_. 272 273 274 Install using Homebrew 275 ^^^^^^^^^^^^^^^^^^^^^^ 276 277 1. Update Homebrew:: 278 279 $ brew update 280 281 2. Install Python bindings:: 282 283 284 $ brew install --with-python libdnet 285 $ brew install https://raw.githubusercontent.com/secdev/scapy/master/.travis/pylibpcap.rb 286 $ sudo brew install --with-python libdnet 287 $ sudo brew install https://raw.githubusercontent.com/secdev/scapy/master/.travis/pylibpcap.rb 288 289 290 Install using MacPorts 291 ^^^^^^^^^^^^^^^^^^^^^^ 292 293 1. Update MacPorts:: 294 295 $ sudo port -d selfupdate 296 297 2. Install Python bindings:: 298 299 $ sudo port install py-libdnet py-pylibpcap 300 301 302 OpenBSD 303 ------- 304 305 Here's how to install Scapy on OpenBSD 5.9+ 306 307 .. code-block:: text 308 309 $ doas pkg_add py-libpcap py-libdnet git 310 $ cd /tmp 311 $ git clone http://github.com/secdev/scapy 312 $ cd scapy 313 $ doas python2.7 setup.py install 314 315 316 Optional packages (OpenBSD only) 317 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 318 319 py-cryptography 320 321 .. code-block:: text 322 323 # pkg_add py-cryptography 324 325 gnuplot and its Python binding: 326 327 .. code-block:: text 328 329 # pkg_add gnuplot py-gnuplot 330 331 Graphviz (large download, will install several GNOME libraries) 332 333 .. code-block:: text 334 335 # pkg_add graphviz 336 337 338 ImageMagick (takes long to compile) 339 340 .. code-block:: text 341 342 # cd /tmp 343 # ftp ftp://ftp.openbsd.org/pub/OpenBSD/4.3/ports.tar.gz 344 # cd /usr 345 # tar xvfz /tmp/ports.tar.gz 346 # cd /usr/ports/graphics/ImageMagick/ 347 # make install 348 349 PyX (very large download, will install texlive etc.) 350 351 .. code-block:: text 352 353 # pkg_add py-pyx 354 355 /etc/ethertypes 356 357 .. code-block:: text 358 359 # wget http://git.netfilter.org/ebtables/plain/ethertypes -O /etc/ethertypes 360 361 python-bz2 (for UTscapy) 362 363 .. code-block:: text 364 365 # pkg_add python-bz2 366 367 .. _windows_installation: 368 369 Windows 370 ------- 371 372 .. sectionauthor:: Dirk Loss <mail at dirk-loss.de> 373 374 Scapy is primarily being developed for Unix-like systems and works best on those platforms. But the latest version of Scapy supports Windows out-of-the-box. So you can use nearly all of Scapy's features on your Windows machine as well. 375 376 .. note:: 377 If you update from Scapy-win v1.2.0.2 to Scapy v2 remember to use ``from scapy.all import *`` instead of ``from scapy import *``. 378 379 .. image:: graphics/scapy-win-screenshot1.png 380 :scale: 80 381 :align: center 382 383 You need the following software packages in order to install Scapy on Windows: 384 385 * `Python <http://www.python.org>`_: `Python 2.7.X or 3.3+ <https://www.python.org/downloads/>`_. After installation, add the Python installation directory and its \Scripts subdirectory to your PATH. Depending on your Python version, the defaults would be ``C:\Python27`` and ``C:\Python27\Scripts`` respectively. 386 * `Npcap <https://nmap.org/npcap/>`_: `the latest version <https://nmap.org/npcap/#download>`_. Default values are recommanded. Scapy will also work with Winpcap. 387 * `Scapy <http://www.secdev.org/projects/scapy/>`_: `latest development version <https://github.com/secdev/scapy/archive/master.zip>`_ from the `Git repository <https://github.com/secdev/scapy>`_. Unzip the archive, open a command prompt in that directory and run "python setup.py install". 388 389 Just download the files and run the setup program. Choosing the default installation options should be safe. 390 391 For your convenience direct links are given to the version that is supported (Python 2.7 and 3.3+). If these links do not work or if you are using a different Python version (which will surely not work), just visit the homepage of the respective package and look for a Windows binary. As a last resort, search the web for the filename. 392 393 After all packages are installed, open a command prompt (cmd.exe) and run Scapy by typing ``scapy``. If you have set the PATH correctly, this will find a little batch file in your ``C:\Python27\Scripts`` directory and instruct the Python interpreter to load Scapy. 394 395 If really nothing seems to work, consider skipping the Windows version and using Scapy from a Linux Live CD -- either in a virtual machine on your Windows host or by booting from CDROM: An older version of Scapy is already included in grml and BackTrack for example. While using the Live CD you can easily upgrade to the latest Scapy version by typing ``cd /tmp && wget scapy.net``. 396 397 Screenshot 398 ^^^^^^^^^^ 399 400 .. image:: graphics/scapy-win-screenshot2.png 401 :scale: 80 402 :align: center 403 404 Known bugs 405 ^^^^^^^^^^ 406 407 * You may not be able to capture WLAN traffic on Windows. Reasons are explained on the Wireshark wiki and in the WinPcap FAQ. Try switching off promiscuous mode with ``conf.sniff_promisc=False``. 408 * Packets sometimes cannot be sent to localhost (or local IP addresses on your own host). 409 410 Winpcap/Npcap conflicts 411 ^^^^^^^^^^^^^^^^^^^^^^^ 412 413 As Winpcap is becoming old, it's recommanded to use Npcap instead. Npcap is part of the Nmap project. 414 415 1. If you get the message 'Winpcap is installed over Npcap.' it means that you have installed both winpcap and npcap versions, which isn't recommanded. 416 417 You may uninstall winpcap from your Program Files, then you will need to remove: 418 * C:/Windows/System32/wpcap.dll 419 * C:/Windows/System32/Packet.dll 420 421 To use npcap instead. 422 423 2. If you get the message 'The installed Windump version does not work with Npcap' it means that you have installed an old version of Windump. 424 Download the correct one on https://github.com/hsluoyz/WinDump/releases 425 426 Build the documentation offline 427 =============================== 428 The Scapy project's documentation is written using reStructuredText (files \*.rst) and can be built using 429 the `Sphinx <http://www.sphinx-doc.org/>`_ python library. The official online version is available 430 on `readthedocs <http://scapy.readthedocs.io/>`_. 431 432 HTML version 433 ------------ 434 The instructions to build the HTML version are: :: 435 436 (activate a virtualenv) 437 pip install sphinx 438 cd doc/scapy 439 make html 440 441 Or on windows, simply run ``BuildDoc.bat`` 442 443 You can now open the resulting HTML file ``_build/html/index.html`` in your favorite web browser. 444 445 To use the ReadTheDocs' template, you will have to install the corresponding theme with: :: 446 447 pip install sphinx_rtd_theme 448 449 If installed, it will be automatically used, but you may disable it by setting ``auto_rtd`` to ``False`` in ``doc/scapy/conf.py`` 450 451 UML diagram 452 ----------- 453 Using ``pyreverse`` you can build an UML representation of the Scapy source code's object hierarchy. Here is an 454 example on how to build the inheritence graph for the Fields objects : :: 455 456 (activate a virtualenv) 457 pip install pylint 458 cd scapy/ 459 pyreverse -o png -p fields scapy/fields.py 460 461 This will generate a ``classes_fields.png`` picture containing the inheritance hierarchy. Note that you can provide as many 462 modules or packages as you want, but the result will quickly get unreadable. 463 464 To see the dependencies between the DHCP layer and the ansmachine module, you can run: :: 465 466 pyreverse -o png -p dhcp_ans scapy/ansmachine.py scapy/layers/dhcp.py scapy/packet.py 467 468 In this case, Pyreverse will also generate a ``packages_dhcp_ans.png`` showing the link between the different python modules provided. 469