scapy/doc/scapy.1

202 lines
4.9 KiB
Groff
Raw Normal View History

2018-05-08 10:04:21 +00:00
.TH SCAPY 1 "May 8, 2018"
2018-05-07 15:21:32 +00:00
.SH NAME
scapy \- Interactive packet manipulation tool
.SH SYNOPSIS
.B scapy
.RI [ options ]
.SH DESCRIPTION
This manual page documents briefly the
2018-05-08 10:04:21 +00:00
.B Scapy
2018-05-07 15:21:32 +00:00
tool.
.PP
2018-05-08 10:04:21 +00:00
\fBScapy\fP is a powerful interactive packet manipulation tool,
2018-05-07 15:21:32 +00:00
packet generator, network scanner, network discovery, packet sniffer,
etc. It can for the moment replace hping, parts of nmap, arpspoof, arp-sk,
arping, tcpdump, tshark, p0f, ...
.PP
2018-05-08 10:04:21 +00:00
\fBScapy\fP uses the Python interpreter as a command board. That means that
you can use directly Python language (assign variables, use loops,
define functions, etc.) If you give a file a parameter when you run
\fBScapy\fP, your session (variables, functions, instances, ...) will be saved
when you leave the interpreter and restored the next time you launch
\fBScapy\fP.
2018-05-07 15:21:32 +00:00
.PP
2018-05-08 10:04:21 +00:00
The idea is simple. Those kinds of tools do two things : sending packets
and receiving answers. That's what \fBScapy\fP does : you define a set of
2018-05-07 15:21:32 +00:00
packets, it sends them, receives answers, matches requests with answers
and returns a list of packet couples (request, answer) and a list of
unmatched packets. This has the big advantage over tools like nmap or
hping that an answer is not reduced to (open/closed/filtered), but is
the whole packet.
.PP
2018-05-08 10:04:21 +00:00
On top of this can be used to build more high-level functions, for example, one
2018-05-07 15:21:32 +00:00
that does traceroutes and give as a result only the start TTL of the
request and the source IP of the answer. One that pings a whole network
and gives the list of machines answering. One that does a portscan and
returns a LaTeX report.
.SH OPTIONS
2018-05-08 10:04:21 +00:00
Options for Scapy are:
2018-05-07 15:21:32 +00:00
.TP
\fB\-h\fR
display usage
.TP
\fB\-d\fR
increase log verbosity. Can be used many times.
.TP
\fB\-s\fR FILE
2018-05-08 10:04:21 +00:00
use FILE to save/load session values (variables, functions, instances, ...)
2018-05-07 15:21:32 +00:00
.TP
\fB\-p\fR PRESTART_FILE
use PRESTART_FILE instead of $HOME/.scapy_prestart.py as pre-startup file
.TP
\fB\-P\fR
do not run prestart file
.TP
\fB\-c\fR STARTUP_FILE
use STARTUP_FILE instead of $HOME/.scapy_startup.py as startup file
.TP
\fB\-C\fR
do not run startup file
.SH COMMANDS
Only the vital commands to begin are listed here for the moment.
.TP
\fBls()\fR
2018-07-17 19:37:29 +00:00
lists supported protocol layers.
If a protocol layer is given as parameter, lists its fields and types of fields.
If a string is given as parameter, it is used to filter the layers.
2018-05-07 15:21:32 +00:00
.TP
\fBlsc()\fR
2018-07-17 19:37:29 +00:00
lists scapy's main user commands.
2018-05-07 15:21:32 +00:00
.TP
\fBconf\fR
this object contains the configuration.
.SH FILES
\fB$HOME/.scapy_prestart.py\fR
2018-07-17 19:37:29 +00:00
This file is run before Scapy core is loaded. Only the \fBconf\fP object
2018-05-07 15:21:32 +00:00
is available. This file can be used to manipulate \fBconf.load_layers\fP
list to choose which layers will be loaded:
.nf
conf.load_layers.remove("bluetooth")
conf.load_layers.append("new_layer")
.fi
\fB$HOME/.scapy_startup.py\fR
2018-05-08 10:04:21 +00:00
This file is run after Scapy is loaded. It can be used to configure
some of the Scapy behaviors:
2018-05-07 15:21:32 +00:00
.nf
2018-07-17 19:37:29 +00:00
conf.prog.pdfreader = "xpdf"
2018-05-07 15:21:32 +00:00
split_layers(UDP,DNS)
.fi
.SH EXAMPLES
More verbose examples are available at
2018-07-17 19:37:29 +00:00
https://scapy.net/demo/
2018-05-07 15:21:32 +00:00
Just run \fBscapy\fP and try the following commands in the interpreter.
.LP
Test the robustness of a network stack with invalid packets:
.nf
2018-07-17 19:37:29 +00:00
sr(IP(dst="172.16.1.1", ihl=2, options="\everb$\ex02$", version=3)/ICMP())
2018-05-07 15:21:32 +00:00
.fi
.LP
2018-05-08 10:04:21 +00:00
Packet sniffing and dissection (with a bpf filter or tshark-like output):
2018-05-07 15:21:32 +00:00
.nf
a=sniff(filter="tcp port 110")
a=sniff(prn = lambda x: x.display)
.fi
.LP
2018-05-08 10:04:21 +00:00
Sniffed packet re-emission:
2018-05-07 15:21:32 +00:00
.nf
a=sniff(filter="tcp port 110")
sendp(a)
.fi
.LP
2018-05-08 10:04:21 +00:00
Pcap file packet re-emission:
2018-05-07 15:21:32 +00:00
.nf
sendp(rdpcap("file.cap"))
.fi
.LP
Manual TCP traceroute:
.nf
sr(IP(dst="www.google.com", ttl=(1,30))/TCP(seq=RandInt(), sport=RandShort(), dport=dport)
.fi
.LP
Protocol scan:
.nf
sr(IP(dst="172.16.1.28", proto=(1,254)))
.fi
.LP
ARP ping:
.nf
srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="172.16.1.1/24"))
.fi
.LP
ACK scan:
.nf
sr(IP(dst="172.16.1.28")/TCP(dport=(1,1024), flags="A"))
.fi
.LP
Passive OS fingerprinting:
.nf
sniff(prn=prnp0f)
.fi
.LP
Active OS fingerprinting:
.nf
nmap_fp("172.16.1.232")
.fi
.LP
2018-05-08 10:04:21 +00:00
ARP cache poisoning:
2018-05-07 15:21:32 +00:00
.nf
sendp(Ether(dst=tmac)/ARP(op="who-has", psrc=victim, pdst=target))
.fi
.LP
Reporting:
.nf
report_ports("192.168.2.34", (20,30))
.fi
.SH SEE ALSO
.nf
2018-07-17 19:37:29 +00:00
The official website: \fIhttps://scapy.net/\fP
The GitHub Development repository: \fIhttps://github.com/secdev/scapy/\fP
The official documentation: \fIhttps://scapy.readthedocs.io/en/latest/\fP
2018-05-07 15:21:32 +00:00
.fi
.SH BUGS
Does not give the right source IP for routes that use interface aliases.
2018-07-17 19:37:29 +00:00
May miss packets under heavy load. This is a restriction from python itself
2018-05-07 15:21:32 +00:00
Session saving is limited by Python ability to marshal objects. As a
consequence, lambda functions and generators can't be saved, which seriously
2018-05-08 10:04:21 +00:00
reduce the usefulness of this feature.
2018-05-07 15:21:32 +00:00
BPF filters don't work on Point-to-point interfaces.
.SH AUTHOR
Philippe Biondi <phil@secdev.org>
.PP
This manual page was written by Alberto Gonzalez Iniesta <agi@agi.as>
and Philippe Biondi.