1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
|
.. highlight:: sh
*************************
Download and Installation
*************************
Overview
========
0. Install *Python 2*.
1. Download and install *Scapy*.
2. (For non-Linux platforms): Install *libpcap and libdnet* and their Python wrappers.
3. (Optional): Install *additional software* for special features.
4. Run Scapy with root privileges.
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.
At the moment, there are two different versions of Scapy:
* **Scapy v1.x**. It consists of only one file and works on Python 2.4, so it might be easier to install.
Moreover, your OS may already have a specially prepared packages or ports for it. Last version is v1.2.2.
* **Scapy v2.x**. The current development version adds several features (e.g. IPv6). It consists of several
files packaged in the standard distutils way. Scapy v2 needs Python 2.5.
.. note::
In Scapy v2 use ``from scapy.all import *`` instead of ``from scapy import *``.
Installing Scapy v2.x
=====================
The following steps describe how to install (or update) Scapy itself.
Dependent on your platform, some additional libraries might have to be installed to make it actually work.
So please also have a look at the platform specific chapters on how to install those requirements.
.. note::
The following steps apply to Unix-like operating systems (Linux, BSD, Mac OS X).
For Windows, see the special chapter below.
Make sure you have Python installed before you go on.
Latest release
--------------
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::
$ cd /tmp
$ wget scapy.net
$ unzip scapy-latest.zip
$ cd scapy-2.*
$ sudo python setup.py install
Alternatively, you can execute the zip file::
$ chmod +x scapy-latest.zip
$ sudo ./scapy-latest.zip
or::
$ sudo sh scapy-latest.zip
or::
$ mv scapy-latest.zip /usr/local/bin/scapy
$ sudo scapy
.. note::
To make a zip executable, some bytes have been added before the zip header.
Most zip programs handle this, but not all. If your zip program complains
about the zip file to be corrupted, either change it, or download a
non-executable zip at https://github.com/secdev/scapy/archive/master.zip
Current development version
----------------------------
.. index::
single: Git, repository
If you always want the latest version with all new features and bugfixes, use Scapy's Git repository:
1. Install the Git version control system. For example, on Debian/Ubuntu use::
$ sudo apt-get install git
or on OpenBSD::
$ pkg_add git
2. Check out a clone of Scapy's repository::
$ git clone https://github.com/secdev/scapy
3. Install Scapy in the standard distutils way::
$ cd scapy
$ sudo python setup.py install
Then you can always update to the latest version::
$ git pull
$ sudo python setup.py install
Installing Scapy v1.2
=====================
As Scapy v1 consists only of one single Python file, installation is easy:
Just download the last version and run it with your Python interpreter::
$ wget https://raw.githubusercontent.com/secdev/scapy/v1.2.0.2/scapy.py
$ sudo python scapy.py
.. index::
single: scapy-bpf
On BSD systems, you can also try the latest version of `Scapy-bpf <http://hg.natisbad.org/scapy-bpf/raw-file/tip/scapy.py>`_ (`development repository <http://hg.natisbad.org/scapy-bpf/>`_). It doesn't need libpcap or libdnet.
Optional software for special features
======================================
For some special features you have to install more software.
Platform-specific instructions on how to install those packages can be found in the next chapter.
Here are the topics involved and some examples that you can use to try if your installation was successful.
.. index::
single: plot()
* Plotting. ``plot()`` needs `Gnuplot-py <http://gnuplot-py.sourceforge.net/>`_ which needs `GnuPlot <http://www.gnuplot.info/>`_ and `NumPy <http://numpy.scipy.org/>`_.
.. code-block:: python
>>> p=sniff(count=50)
>>> p.plot(lambda x:len(x))
* 2D graphics. ``psdump()`` and ``pdfdump()`` need `PyX <http://pyx.sourceforge.net/>`_ which in turn needs a `LaTeX distribution <http://www.tug.org/texlive/>`_. 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``).
.. code-block:: python
>>> p=IP()/ICMP()
>>> p.pdfdump("test.pdf")
* Graphs. ``conversations()`` needs `Graphviz <http://www.graphviz.org/>`_ and `ImageMagick <http://www.imagemagick.org/>`_.
.. code-block:: python
>>> p=readpcap("myfile.pcap")
>>> p.conversations(type="jpg", target="> test.jpg")
* 3D graphics. ``trace3D()`` needs `VPython <http://www.vpython.org/>`_.
.. code-block:: python
>>> a,u=traceroute(["www.python.org", "google.com","slashdot.org"])
>>> a.trace3D()
.. index::
single: WEP, unwep()
* WEP decryption. ``unwep()`` needs `PyCrypto <http://www.dlitz.net/software/pycrypto/>`_. Example using a `Weplap test file <http://weplab.sourceforge.net/caps/weplab-64bit-AA-managed.pcap>`_:
.. code-block:: python
>>> enc=rdpcap("weplab-64bit-AA-managed.pcap")
>>> enc.show()
>>> enc[0]
>>> conf.wepkey="AA\x00\x00\x00"
>>> dec=Dot11PacketList(enc).toEthernet()
>>> dec.show()
>>> dec[0]
* 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.
.. code-block:: python
>>> load_module("nmap")
>>> nmap_fp("192.168.0.1")
Begin emission:
Finished to send 8 packets.
Received 19 packets, got 4 answers, remaining 4 packets
(0.88749999999999996, ['Draytek Vigor 2000 ISDN router'])
.. index::
single: VOIP
* VOIP. ``voip_play()`` needs `SoX <http://sox.sourceforge.net/>`_.
Platform-specific instructions
==============================
Linux native
------------
Scapy can run natively on Linux, without libdnet and libpcap.
* Install `Python 2.5 <http://www.python.org>`_.
* Install `tcpdump <http://www.tcpdump.org>`_ and make sure it is in the $PATH. (It's only used to compile BPF filters (``-ddd option``))
* Make sure your kernel has Packet sockets selected (``CONFIG_PACKET``)
* If your kernel is < 2.6, make sure that Socket filtering is selected ``CONFIG_FILTER``)
Debian/Ubuntu
-------------
Just use the standard packages::
$ sudo apt-get install tcpdump graphviz imagemagick python-gnuplot python-crypto python-pyx
Fedora
------
Here's how to install Scapy on Fedora 9:
.. code-block:: text
# yum install git python-devel
# cd /tmp
# git clone https://github.com/secdev/scapy
# cd scapy
# python setup.py install
Some optional packages:
.. code-block:: text
# yum install graphviz python-crypto sox PyX gnuplot numpy
# cd /tmp
# wget http://heanet.dl.sourceforge.net/sourceforge/gnuplot-py/gnuplot-py-1.8.tar.gz
# tar xvfz gnuplot-py-1.8.tar.gz
# cd gnuplot-py-1.8
# python setup.py install
Mac OS X
--------
On Mac OS X, Scapy does not work natively. You need to install Python bindings
to use libdnet and libpcap. You can choose to install using either Homebrew or
MacPorts. They both work fine, yet Homebrew is used to run unit tests with
`Travis CI <https://travis-ci.org>`_.
Install using Homebrew
^^^^^^^^^^^^^^^^^^^^^^
1. Update Homebrew::
$ sudo brew update
2. Install Python bindings::
$ sudo brew install --with-python libdnet
$ sudo brew install https://raw.githubusercontent.com/secdev/scapy/master/.travis/pylibpcap.r
Install using MacPorts
^^^^^^^^^^^^^^^^^^^^^^
1. Update MacPorts::
$ sudo port -d selfupdate
2. Install Python bindings::
$ sudo port install py-libdnet py-pylibpcap
OpenBSD
-------
Here's how to install Scapy on OpenBSD 4.3.
.. code-block:: text
# export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.3/packages/i386/
# pkg_add py-libpcap py-libdnet git
# ln -sf /usr/local/bin/python2.5 /usr/local/bin/python
# cd /tmp
# git clone http://github.com/secdev/scapy
# cd scapy
# python setup.py install
Optional packages
^^^^^^^^^^^^^^^^^
py-crypto
.. code-block:: text
# pkg_add py-crypto
gnuplot and its Python binding:
.. code-block:: text
# pkg_add gnuplot py-gnuplot
Graphviz (large download, will install several GNOME libraries)
.. code-block:: text
# pkg_add graphviz
ImageMagick (takes long to compile)
.. code-block:: text
# cd /tmp
# ftp ftp://ftp.openbsd.org/pub/OpenBSD/4.3/ports.tar.gz
# cd /usr
# tar xvfz /tmp/ports.tar.gz
# cd /usr/ports/graphics/ImageMagick/
# make install
PyX (very large download, will install texlive etc.)
.. code-block:: text
# pkg_add py-pyx
/etc/ethertypes
.. code-block:: text
# wget http://git.netfilter.org/ebtables/plain/ethertypes -O /etc/ethertypes
python-bz2 (for UTscapy)
.. code-block:: text
# pkg_add python-bz2
.. _windows_installation:
Windows
-------
.. sectionauthor:: Dirk Loss <mail at dirk-loss.de>
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.
.. note::
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 *``.
.. image:: graphics/scapy-win-screenshot1.png
:scale: 80
:align: center
You need the following software packages in order to install Scapy on Windows:
* `Python <http://www.python.org>`_: `python-2.5.4.msi <http://www.python.org/ftp/python/2.5.4/python-2.5.4.msi>`_. `python-2.6.3.msi <http://www.python.org/ftp/python/2.6.3/python-2.6.3.msi>`_. After installation, add the Python installation directory and its \Scripts subdirectory to your PATH. Depending on your Python version, the defaults would be ``C:\Python25`` and ``C:\Python25\Scripts`` or ``C:\Python26`` and ``C:\Python26\Scripts`` respectively.
* `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".
* `pywin32 <http://python.net/crew/mhammond/win32/Downloads.html>`_: `pywin32-214.win32-py2.5.exe <http://surfnet.dl.sourceforge.net/sourceforge/pywin32/pywin32-214.win32-py2.5.exe>`_ `pywin32-214.win32-py2.6.exe <http://downloads.sourceforge.net/project/pywin32/pywin32/Build%20214/pywin32-214.win32-py2.6.exe>`_
* `WinPcap <http://www.winpcap.org/>`_: `WinPcap_4_1_1.exe <http://www.winpcap.org/install/bin/WinPcap_4_1_1.exe>`_. You might want to choose "[x] Automatically start the WinPcap driver at boot time", so that non-privileged users can sniff, especially under Vista and Windows 7. If you want to use the ethernet vendor database to resolve MAC addresses or use the ``wireshark()`` command, download `Wireshark <http://www.wireshark.org/>`_ which already includes WinPcap.
* `pypcap <http://code.google.com/p/pypcap/>`_: `pcap-1.1-scapy-20090720.win32-py25.exe <http://www.secdev.org/projects/scapy/files/pcap-1.1-scapy-20090720.win32-py2.5.exe>`_ `pcap-1.1-scapy-20090720.win32-py2.6.exe <http://www.secdev.org/projects/scapy/files/pcap-1.1-scapy-20090720.win32-py2.6.exe>`_. This is a *special version for Scapy*, as the original leads to some timing problems. Now works on Vista and Windows 7, too. Under Vista/Win7 please right-click on the installer and choose "Run as administrator".
* `libdnet <http://code.google.com/p/libdnet/>`_: `dnet-1.12.win32-py2.5.exe <http://libdnet.googlecode.com/files/dnet-1.12.win32-py2.5.exe>`_ `dnet-1.12.win32-py2.6.exe <http://www.secdev.org/projects/scapy/files/dnet-1.12.win32-py2.6.exe>`_. Under Vista/Win7 please right-click on the installer and choose "Run as administrator"
* `pyreadline <http://ipython.scipy.org/moin/PyReadline/Intro>`_: `pyreadline-1.5-win32-setup.exe <http://ipython.scipy.org/dist/pyreadline-1.5-win32-setup.exe>`_
Just download the files and run the setup program. Choosing the default installation options should be safe.
For your convenience direct links are given to the versions I used (for Python 2.5 and Python 2.6). If these links do not work or if you are using a different Python version, just visit the homepage of the respective package and look for a Windows binary. As a last resort, search the web for the filename.
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:\Python26\Scripts`` directory and instruct the Python interpreter to load Scapy.
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``.
Optional packages
^^^^^^^^^^^^^^^^^
Plotting (``plot``)
* `GnuPlot <http://www.gnuplot.info/>`_: `gp420win32.zip <http://downloads.sourceforge.net/gnuplot/gp420win32.zip>`_. Extract the zip file (e.g. to ``c:\gnuplot``) and add the ``gnuplot\bin`` directory to your PATH.
* `NumPy <http://numpy.scipy.org/>`_: `numpy-1.3.0-win32-superpack-python2.5.exe <http://downloads.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0-win32-superpack-python2.5.exe>`_ `numpy-1.3.0-win32-superpack-python2.6.exe <http://downloads.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0-win32-superpack-python2.6.exe>`_. Gnuplot-py 1.8 needs NumPy.
* `Gnuplot-py <http://gnuplot-py.sourceforge.net/>`_: `gnuplot-py-1.8.zip <http://downloads.sourceforge.net/project/gnuplot-py/Gnuplot-py/1.8/gnuplot-py-1.8.zip>`_. Extract to temp dir, open command prompt, change to tempdir and type ``python setup.py install``.
2D Graphics (``psdump``, ``pdfdump``)
* `PyX <http://pyx.sourceforge.net/>`_: `PyX-0.10.tar.gz <http://mesh.dl.sourceforge.net/sourceforge/pyx/PyX-0.10.tar.gz>`_. Extract to temp dir, open command prompt, change to tempdir and type ``python setup.py install``
* `MikTeX <http://miktex.org/>`_: `Basic MiKTeX 2.8 Installer <http://miktex.org/2.8/setup>`_. PyX needs a LaTeX installation. Choose an installation directory WITHOUT spaces (e.g. ``C:\MikTex2.8`` and add the ``(INSTALLDIR)\miktex\bin`` subdirectory to your PATH.
Graphs (conversations)
* `Graphviz <http://www.graphviz.org/>`_: `graphviz-2.24.exe <http://www.graphviz.org/pub/graphviz/stable/windows/graphviz-2.24.msi>`_. Add ``(INSTALLDIR)\ATT\Graphviz\bin`` to your PATH.
3D Graphics (trace3d)
* `VPython <http://www.vpython.org/>`_: `VPython-Win-Py2.5-3.2.11.exe <http://www.vpython.org/download/VPython-Win-Py2.5-3.2.11.exe>`_. No binary installer for Python 2.6 seems to be available yet.
WEP decryption
* `PyCrypto <http://www.dlitz.net/software/pycrypto/>`_: `pycrypto-2.1.0.win32-py2.5.zip <http://www.voidspace.org.uk/downloads/pycrypto-2.1.0.win32-py2.5.zip>`_ `pycrypto-2.1.0.win32-py2.6.zip <http://www.voidspace.org.uk/downloads/pycrypto-2.1.0.win32-py2.6.zip>`_
Fingerprinting
* `Nmap <http://nmap.org>`_. `nmap-4.20-setup.exe <http://download.insecure.org/nmap/dist-old/nmap-4.20-setup.exe>`_. If you use the default installation directory, Scapy should automatically find the fingerprints file.
* Queso: `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
Screenshot
^^^^^^^^^^
.. image:: graphics/scapy-win-screenshot2.png
:scale: 80
:align: center
Known bugs
^^^^^^^^^^
* 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``.
* Packets cannot be sent to localhost (or local IP addresses on your own host).
* The ``voip_play()`` functions do not work because they output the sound via ``/dev/dsp`` which is not available on Windows.
Build the documentation offline
===============================
The Scapy project's documentation is written using reStructuredText (files \*.rst) and can be built using
the `Sphinx <http://www.sphinx-doc.org/>`_ python library. The official online version is available
on `readthedocs <http://scapy.readthedocs.io/>`_.
HTML version
------------
The instructions to build the HTML version are: ::
(activate a virtualenv)
pip install sphinx
cd doc/scapy
make html
You can now open the resulting HTML file ``_build/html/index.html`` in your favorite web browser.
To use the ReadTheDocs' template, you will have to install the corresponding theme with: ::
pip install sphinx_rtd_theme
and edit the doc/scapy/conf.py file to have: ::
import sphinx_rtd_theme
#html_style = 'default.css'
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
Note: make sure you commented out the ``html_style`` variable.
UML diagram
-----------
Using ``pyreverse`` you can build an UML representation of the Scapy source code's object hierarchy. Here is an
example on how to build the inheritence graph for the Fields objects : ::
(activate a virtualenv)
pip install pylint
cd scapy/
pyreverse -o png -p fields scapy/fields.py
This will generate a ``classes_fields.png`` picture containing the inheritance hierarchy. Note that you can provide as many
modules or packages as you want, but the result will quickly get unreadable.
To see the dependencies between the DHCP layer and the ansmachine module, you can run: ::
pyreverse -o png -p dhcp_ans scapy/ansmachine.py scapy/layers/dhcp.py scapy/packet.py
In this case, Pyreverse will also generate a ``packages_dhcp_ans.png`` showing the link between the different python modules provided.
|