Questions tagged [scapy]

Scapy is a network packet manipulation tool for use with Python.

What is Scapy?

Scapy is a network packet manipulation program for use with Python. It is able to:

  • forge or decode packets of a wide number of protocols
  • send them on the wire, capture them, match requests and replies, and much more. It can easily handle most classical tasks like scanning, tracerouting, probing, unit tests, attacks or network discovery. (it can replace hping, 85% of nmap, arpspoof, arp-sk, arping, tcpdump, tethereal, p0f, etc.)

What makes scapy different from most other networking tools?

  • You can build whatever packets you want, stack ARP on top of 802.11, use double 802.1q encapsulation or send an ICMP packet with padding, and send them over the wire.

  • Scapy does not interpret answers: unlike most tools, it won't say “this port is open” instead of “I received a SYN-ACK”. You are free to interpret the packets as you want

  • It reports everything: you see the padding, the reserved fields... Nothing is dismissed


Useful links:

2198 questions
10
votes
1 answer

TCP Traceroute in python

I am writing a python script to perform 'TCP Traceroute'. I learned scapy is a useful library to do this but I`m not getting the results I need. Can anyone help me resolve this? I want the python script to generate similar results as command…
Hussain ali
  • 491
  • 3
  • 7
  • 21
10
votes
1 answer

Python Scapy / operator, | pipe in types

With scapy we can to this : p = Ether() / IP() What kind of operation does '/' really do ? What kind of object does it return ? If I type p in a python interpreter it returns this What does '|' mean in this case ? I was…
x4rkz
  • 513
  • 4
  • 19
10
votes
5 answers

the filter of sniff function in scapy does not work properly

It seems that the filter of sniff function does not work properly. I m executing the sniff with the following filter a=sniff(count=1,filter="tcp and host 192.168.10.55 and port 14010") But some time the sniff catch an UDP packet like this: >>>…
MOHAMED
  • 41,599
  • 58
  • 163
  • 268
10
votes
4 answers

scapy: Operation not permitted when sending packets

I'm trying to learn a bit of packet generation with scapy. It looks pretty cool. Following some documentation I'm doing this: l3=IP(dst="192.168.0.1", src="192.168.0.2", tos=(46 << 2)) But only to get the error message of: Traceback (most recent…
lang2
  • 11,433
  • 18
  • 83
  • 133
10
votes
2 answers

C/Python Socket Performance?

my question simply relates to the difference in performance between a socket in C and in Python. Since my Python build is CPython, I assume it's similar, but I'm curious if someone actually has "real" benchmarks, or at least an opinion that's…
Kevin
  • 2,361
  • 2
  • 20
  • 20
10
votes
3 answers

Scapy - get my own MAC address

How do I get the MAC address of the interface I am sending packets with? I am trying to create a custom ARP packet, and I need to include my own MAC in it. I can not seem to find a way to get it.
Aviran
  • 5,160
  • 7
  • 44
  • 76
10
votes
4 answers

Get all the layers in a packet

How can I get a list of all the layers in scapy? Eg: Ether/IP/UDP/DNS or Ether/IP/TCP/HTTP. The only thing I can think of is to do a packet.summary() and parse the output, which seems very crude. I think there should be a method built-in, but cannot…
krish7919
  • 892
  • 2
  • 13
  • 30
9
votes
3 answers

Pinging an IP range with Scapy

I'm attempting to write a Python script which uses the Scapy module to ping an internal IP range to determine which IP's are online. I've got this so far: #!/usr/bin/python from scapy.all import * conf.verb = 0 for ip in range(0, 256): packet =…
user961124
  • 111
  • 1
  • 1
  • 3
9
votes
1 answer

PermissionError: [Errno 1] Operation not permitted

I am completely new to python, linux RPI and scapy. I am trying to send some packets using scapy. On Command Line (only if super user privileges are given to scapy) send(IP(dst="1.2.3.4")/ICMP()) This works perfectly, while running on python…
Kashif Ahmad
  • 426
  • 3
  • 8
  • 22
9
votes
2 answers

Send packet and change its source IP

Lets say I have an application written in python to send a ping or e-mail. How can I change the source IP address of the sent packet to a fake one, using, e.g., Scapy? Consider that that the IP address assigned to my eth0 is 192.168.0.100. My e-mail…
Jay
  • 347
  • 2
  • 5
  • 10
9
votes
2 answers

Three-way handshake in Scapy

I’m trying to build a three-way handshake in Scapy. Using the following code, #!/usr/local/bin/python from scapy.all import * sport = random.randint(1024, 65535) # SYN ip = IP(src='172.16.120.5', dst='172.16.100.101') SYN = TCP(sport=sport,…
felix001
  • 15,341
  • 32
  • 94
  • 121
9
votes
1 answer

sending ICMP packets in scapy and choosing the correct interface

Can we use the srp() function for a Layer 3 ICMP packet? I see that when we craft an ICMP echo-request packet and use the sr() to send/receive, we do NOT see it getting sent out of the interface , hence no response from the destination. But the same…
Pradeep
  • 619
  • 2
  • 10
  • 22
9
votes
1 answer

Scapy In A Script

I have used scapy as a session in python, but I want to use it in a script. Why so? I want to be able to use sys.argv to specify an IP address to use as well as use other modules. How can this be accomplished?
James Parsons
  • 6,097
  • 12
  • 68
  • 108
9
votes
2 answers

Scapy packet sent cannot be received

I'm trying to send UDP Packets with scapy with the following command: >> send(IP(dst="127.0.0.1",src="111.111.111.111")/UDP(dport=5005)/"Hello") . Sent 1 packets. And from tcpdump I can see: 22:02:58.384730 IP 111.111.111.111.domain >…
ethanjyx
  • 1,970
  • 7
  • 28
  • 50
9
votes
1 answer

Scapy fails to sniff packets when using multiple threads

I'll try to demonstrate my problem with a simplified example. Following is a very simple (single threaded) packet sniffer (ICMP): from scapy.all import * m_iface = "wlan0" m_dst = "192.168.0.1" def print_summary(pkt): print pkt.summary() def…
Asiri Rathnayake
  • 1,138
  • 1
  • 11
  • 27