- Install Python 2.5.
- Download and install Scapy.
- (For non-Linux platforms): Install libpcap and libdnet and their Python wrappers.
- (Optional): Install additional software for special features.
- Run Scapy with root priviledges.
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:
In Scapy v2 use from scapy.all import * instead of from scapy import *.
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.
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.
$ 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
$ sudo sh scapy-latest.zip
$ mv scapy-latest.zip /usr/local/bin/scapy $ sudo scapy
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 http://hg.secdev.org/scapy/archive/tip.zip
If you always want the latest version with all new features and bugfixes, use Scapy’s Mercurial repository:
Install the Mercurial version control system. For example, on Debian/Ubuntu use:
$ sudo apt-get install mercurial
or on OpenBSD:
$ pkg_add mercurial
Check out a clone of Scapy’s repository:
$ hg clone http://hg.secdev.org/scapy
Install Scapy in the standard distutils way:
$ cd scapy $ sudo python setup.py install
Then you can always update to the latest version:
$ hg pull $ hg update $ sudo python setup.py install
For more information about Mercurial, have a look at the Mercurial book.
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 http://hg.secdev.org/scapy/raw-file/v188.8.131.52/scapy.py $ sudo python scapy.py
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.
>>> p=sniff(count=50) >>> p.plot(lambda x:len(x))
>>> p=IP()/ICMP() >>> p.pdfdump("test.pdf")
>>> p=readpcap("myfile.pcap") >>> p.conversations(type="jpg", target="> test.jpg")
3D graphics. trace3D() needs VPython.
>>> a,u=traceroute(["www.python.org", "google.com","slashdot.org"]) >>> a.trace3D()
>>> enc=rdpcap("weplab-64bit-AA-managed.pcap") >>> enc.show() >>> enc >>> conf.wepkey="AA\x00\x00\x00" >>> dec=Dot11PacketList(enc).toEthernet() >>> dec.show() >>> dec
>>> 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'])
Scapy can run natively on Linux, without libdnet and libpcap.
Just use the standard packages:
$ sudo apt-get install tcpdump graphviz imagemagick python-gnuplot python-crypto python-pyx
Here’s how to install Scapy on Fedora 9:
# yum install mercurial python-devel # cd /tmp # hg clone http://hg.secdev.org/scapy # cd scapy # python setup.py install
Some optional packages:
# 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
Here’s how to install Scapy on Mac OS 10.4 (Tiger) or 10.5 (Leopard).
Install MacPorts Download the dmg from macports.org and install it.
$ sudo port -d selfupdate
$ sudo port install scapy
You can then update to the latest version as shown in the generic installation above.
Install libdnet and its Python wrapper:
$ wget http://libdnet.googlecode.com/files/libdnet-1.12.tgz $ tar xfz libdnet-1.12.tgz $ ./configure $ make $ sudo make install $ cd python $ python2.5 setup.py install
Install libpcap and its Python wrapper:
$ wget http://dfn.dl.sourceforge.net/sourceforge/pylibpcap/pylibpcap-0.6.2.tar.gz $ tar xfz pylibpcap-0.6.2.tar.gz $ cd pylibpcap-0.6.2 $ python2.5 setup.py install
Optionally: Install readline:
$ python `python -c "import pimp; print pimp.__file__"` -i readline
Here’s how to install Scapy on OpenBSD 4.3.
# export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.3/packages/i386/ # pkg_add py-libpcap py-libdnet mercurial # ln -sf /usr/local/bin/python2.5 /usr/local/bin/python # cd /tmp # hg clone http://hg.secdev.org/scapy # cd scapy # python setup.py install
# pkg_add py-crypto
gnuplot and its Python binding:
# pkg_add gnuplot py-gnuplot
Graphviz (large download, will install several GNOME libraries)
# pkg_add graphviz
ImageMagick (takes long to compile)
# 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.)
# pkg_add py-pyx
# wget http://www.secdev.org/projects/scapy/files/ethertypes -O /etc/ethertypes
python-bz2 (for UTscapy)
# pkg_add python-bz2
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.
If you update from Scapy-win v184.108.40.206 to Scapy v2 remember to use from scapy.all import * instead of from scapy import *.
You need the following software packages in order to install Scapy on Windows:
- Python: python-2.5.4.msi. 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: latest development version from the Mercurial repository. Unzip the archive, open a command prompt in that directory and run “python setup.py install”.
- pywin32: pywin32-214.win32-py2.5.exe pywin32-214.win32-py2.6.exe
- WinPcap: 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 which already includes WinPcap.
- pypcap: pcap-1.1-scapy-20090720.win32-py25.exe 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: dnet-1.12.win32-py2.5.exe dnet-1.12.win32-py2.6.exe. Under Vista/Win7 please right-click on the installer and choose “Run as administrator”
- pyreadline: 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 lastest Scapy version by typing cd /tmp && wget scapy.net.
- GnuPlot: gp420win32.zip. Extract the zip file (e.g. to c:\gnuplot) and add the gnuplot\bin directory to your PATH.
- NumPy: numpy-1.3.0-win32-superpack-python2.5.exe numpy-1.3.0-win32-superpack-python2.6.exe. Gnuplot-py 1.8 needs NumPy.
- Gnuplot-py: 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: PyX-0.10.tar.gz. Extract to temp dir, open command prompt, change to tempdir and type python setup.py install
- MikTeX: Basic MiKTeX 2.8 Installer. 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.
3D Graphics (trace3d)
- 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.