xref: /aosp_15_r20/external/scapy/README.md (revision 7dc08ffc4802948ccbc861daaf1e81c405c2c4bd)
1*7dc08ffcSJunyu Lai<p align="center">
2*7dc08ffcSJunyu Lai  <img src="doc/scapy_logo.png" width=200>
3*7dc08ffcSJunyu Lai</p>
4*7dc08ffcSJunyu Lai
5*7dc08ffcSJunyu Lai# Scapy #
6*7dc08ffcSJunyu Lai
7*7dc08ffcSJunyu Lai[![Travis Build Status](https://travis-ci.org/secdev/scapy.svg?branch=master)](https://travis-ci.org/secdev/scapy)
8*7dc08ffcSJunyu Lai[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/secdev/scapy?svg=true)](https://ci.appveyor.com/project/secdev/scapy)
9*7dc08ffcSJunyu Lai[![Codecov Status](https://codecov.io/gh/secdev/scapy/branch/master/graph/badge.svg)](https://codecov.io/gh/secdev/scapy)
10*7dc08ffcSJunyu Lai[![PyPI Version](https://img.shields.io/pypi/v/scapy.svg)](https://pypi.python.org/pypi/scapy/)
11*7dc08ffcSJunyu Lai[![Python Versions](https://img.shields.io/pypi/pyversions/scapy.svg)](https://pypi.python.org/pypi/scapy/)
12*7dc08ffcSJunyu Lai[![License: GPL v2](https://img.shields.io/badge/License-GPL%20v2-blue.svg)](LICENSE)
13*7dc08ffcSJunyu Lai[![Join the chat at https://gitter.im/secdev/scapy](https://badges.gitter.im/secdev/scapy.svg)](https://gitter.im/secdev/scapy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
14*7dc08ffcSJunyu Lai
15*7dc08ffcSJunyu Lai
16*7dc08ffcSJunyu LaiScapy is a powerful Python-based interactive packet manipulation program and
17*7dc08ffcSJunyu Lailibrary.
18*7dc08ffcSJunyu Lai
19*7dc08ffcSJunyu LaiIt is able to forge or decode packets of a wide number of protocols, send them
20*7dc08ffcSJunyu Laion the wire, capture them, store or read them using pcap files, match requests
21*7dc08ffcSJunyu Laiand replies, and much more. It is designed to allow fast packet prototyping by
22*7dc08ffcSJunyu Laiusing default values that work.
23*7dc08ffcSJunyu Lai
24*7dc08ffcSJunyu LaiIt can easily handle most classical tasks like scanning, tracerouting, probing,
25*7dc08ffcSJunyu Laiunit tests, attacks or network discovery (it can replace `hping`, 85% of `nmap`,
26*7dc08ffcSJunyu Lai`arpspoof`, `arp-sk`, `arping`, `tcpdump`, `wireshark`, `p0f`, etc.). It also
27*7dc08ffcSJunyu Laiperforms very well at a lot of other specific tasks that most other tools can't
28*7dc08ffcSJunyu Laihandle, like sending invalid frames, injecting your own 802.11 frames, combining
29*7dc08ffcSJunyu Laitechniques (VLAN hopping+ARP cache poisoning, VoIP decoding on WEP protected
30*7dc08ffcSJunyu Laichannel, ...), etc.
31*7dc08ffcSJunyu Lai
32*7dc08ffcSJunyu LaiScapy supports Python 2.7 and Python 3 (3.3 to 3.6). It's intended to
33*7dc08ffcSJunyu Laibe cross platform, and runs on many different platforms (Linux, OSX,
34*7dc08ffcSJunyu Lai*BSD, and Windows).
35*7dc08ffcSJunyu Lai
36*7dc08ffcSJunyu Lai## Hands-on ##
37*7dc08ffcSJunyu Lai
38*7dc08ffcSJunyu Lai### Interactive shell ###
39*7dc08ffcSJunyu Lai
40*7dc08ffcSJunyu LaiScapy can easily be used as an interactive shell to interact with the network.
41*7dc08ffcSJunyu LaiThe following example shows how to send an ICMP Echo Request message to
42*7dc08ffcSJunyu Lai`github.com`, then display the reply source IP address:
43*7dc08ffcSJunyu Lai
44*7dc08ffcSJunyu Lai```python
45*7dc08ffcSJunyu Laisudo ./run_scapy
46*7dc08ffcSJunyu LaiWelcome to Scapy
47*7dc08ffcSJunyu Lai>>> p = IP(dst="github.com")/ICMP()
48*7dc08ffcSJunyu Lai>>> r = sr1(p)
49*7dc08ffcSJunyu LaiBegin emission:
50*7dc08ffcSJunyu Lai.Finished to send 1 packets.
51*7dc08ffcSJunyu Lai*
52*7dc08ffcSJunyu LaiReceived 2 packets, got 1 answers, remaining 0 packets
53*7dc08ffcSJunyu Lai>>> r[IP].src
54*7dc08ffcSJunyu Lai'192.30.253.113'
55*7dc08ffcSJunyu Lai```
56*7dc08ffcSJunyu Lai
57*7dc08ffcSJunyu Lai### Python module ###
58*7dc08ffcSJunyu Lai
59*7dc08ffcSJunyu LaiIt is straightforward to use Scapy as a regular Python module, for example to
60*7dc08ffcSJunyu Laicheck if a TCP port is opened. First, save the following code in a file names
61*7dc08ffcSJunyu Lai`send_tcp_syn.py`
62*7dc08ffcSJunyu Lai
63*7dc08ffcSJunyu Lai```python
64*7dc08ffcSJunyu Laifrom scapy.all import *
65*7dc08ffcSJunyu Laiconf.verb = 0
66*7dc08ffcSJunyu Lai
67*7dc08ffcSJunyu Laip = IP(dst="github.com")/TCP()
68*7dc08ffcSJunyu Lair = sr1(p)
69*7dc08ffcSJunyu Laiprint(r.summary())
70*7dc08ffcSJunyu Lai```
71*7dc08ffcSJunyu Lai
72*7dc08ffcSJunyu LaiThen, launch the script with:
73*7dc08ffcSJunyu Lai```python
74*7dc08ffcSJunyu Laisudo python send_tcp_syn.py
75*7dc08ffcSJunyu LaiIP / TCP 192.30.253.113:http > 192.168.46.10:ftp_data SA / Padding
76*7dc08ffcSJunyu Lai```
77*7dc08ffcSJunyu Lai
78*7dc08ffcSJunyu Lai### Resources ###
79*7dc08ffcSJunyu Lai
80*7dc08ffcSJunyu LaiTo begin with Scapy, you should check [the notebook
81*7dc08ffcSJunyu Laihands-on](doc/notebooks/Scapy%20in%2015%20minutes.ipynb) and the [interactive
82*7dc08ffcSJunyu Laitutorial](http://scapy.readthedocs.io/en/latest/usage.html#interactive-tutorial).
83*7dc08ffcSJunyu LaiIf you want to learn more, see [the quick demo: an interactive
84*7dc08ffcSJunyu Laisession](http://scapy.readthedocs.io/en/latest/introduction.html#quick-demo)
85*7dc08ffcSJunyu Lai(some examples may be outdated), or play with the
86*7dc08ffcSJunyu Lai[HTTP/2](doc/notebooks/HTTP_2_Tuto.ipynb) and [TLS](doc/notebooks/tls)
87*7dc08ffcSJunyu Lainotebooks.
88*7dc08ffcSJunyu Lai
89*7dc08ffcSJunyu LaiThe [documentation](http://scapy.readthedocs.io/en/latest/) contains more
90*7dc08ffcSJunyu Laiadvanced use cases, and examples.
91*7dc08ffcSJunyu Lai
92*7dc08ffcSJunyu Lai## Installation ##
93*7dc08ffcSJunyu Lai
94*7dc08ffcSJunyu LaiScapy works without any external Python modules on Linux and BSD like operating
95*7dc08ffcSJunyu Laisystems. On Windows, you need to install some mandatory dependencies as
96*7dc08ffcSJunyu Laidescribed in [the
97*7dc08ffcSJunyu Laidocumentation](http://scapy.readthedocs.io/en/latest/installation.html#windows).
98*7dc08ffcSJunyu Lai
99*7dc08ffcSJunyu LaiOn most systems, using Scapy is as simple as running the following commands:
100*7dc08ffcSJunyu Lai```
101*7dc08ffcSJunyu Laigit clone https://github.com/secdev/scapy
102*7dc08ffcSJunyu Laicd scapy
103*7dc08ffcSJunyu Lai./run_scapy
104*7dc08ffcSJunyu Lai>>>
105*7dc08ffcSJunyu Lai```
106*7dc08ffcSJunyu Lai
107*7dc08ffcSJunyu LaiTo benefit from all Scapy features, such as plotting, you might want to install
108*7dc08ffcSJunyu LaiPython modules, such as `matplotlib` or `cryptography`. See the
109*7dc08ffcSJunyu Lai[documentation](http://scapy.readthedocs.io/en/latest/installation.html) and
110*7dc08ffcSJunyu Laifollow the instructions to install them.
111*7dc08ffcSJunyu Lai
112*7dc08ffcSJunyu Lai## Contributing ##
113*7dc08ffcSJunyu Lai
114*7dc08ffcSJunyu LaiWant to contribute? Great! Please take a few minutes to
115*7dc08ffcSJunyu Lai[read this](CONTRIBUTING.md)!
116