You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scapy optionally uses python-cryptography v1.7 or later. It has not been packaged for ``apt`` in less recent OS versions (e.g. Debian Jessie). If you need the cryptography-related methods, you may install the library with:
The "send'n'receive" functions family is the heart of scapy. They return a couple of two lists. The first element is a list of couples (packet sent, answer), and the second element is the list of unanswered packets. These two elements are lists, but they are wrapped by an object to present them better, and to provide them with some methods that do most frequently needed actions::
329
+
The "send'n'receive" functions family is the heart of Scapy. They return a couple of two lists. The first element is a list of couples (packet sent, answer), and the second element is the list of unanswered packets. These two elements are lists, but they are wrapped by an object to present them better, and to provide them with some methods that do most frequently needed actions::
Received 6 packets, got 3 answers, remaining 0 packets
@@ -337,7 +337,7 @@ The "send'n'receive" functions family is the heart of scapy. They return a coupl
337
337
IP / TCP 192.168.8.14:20 > 192.168.8.1:22 S ==> Ether / IP / TCP 192.168.8.1:22 > 192.168.8.14:20 RA / Padding
338
338
IP / TCP 192.168.8.14:20 > 192.168.8.1:23 S ==> Ether / IP / TCP 192.168.8.1:23 > 192.168.8.14:20 RA / Padding
339
339
340
-
If there is a limited rate of answers, you can specify a time interval to wait between two packets with the inter parameter. If some packets are lost or if specifying an interval is not enough, you can resend all the unanswered packets, either by calling the function again, directly with the unanswered list, or by specifying a retry parameter. If retry is 3, scapy will try to resend unanswered packets 3 times. If retry is -3, scapy will resend unanswered packets until no more answer is given for the same set of unanswered packets 3 times in a row. The timeout parameter specify the time to wait after the last packet has been sent::
340
+
If there is a limited rate of answers, you can specify a time interval to wait between two packets with the inter parameter. If some packets are lost or if specifying an interval is not enough, you can resend all the unanswered packets, either by calling the function again, directly with the unanswered list, or by specifying a retry parameter. If retry is 3, Scapy will try to resend unanswered packets 3 times. If retry is -3, Scapy will resend unanswered packets until no more answer is given for the same set of unanswered packets 3 times in a row. The timeout parameter specify the time to wait after the last packet has been sent::
The process of sending packets and receiving is quite complicated. As I wanted to use the PF_PACKET interface to go through netfilter, I also needed to implement an ARP stack and ARP cache, and a LL stack. Well it seems to work, on ethernet and PPP interfaces, but I don't guarantee anything. Anyway, the fact I used a kind of super-socket for that mean that you can switch your IO layer very easily, and use PF_INET/SOCK_RAW, or use PF_PACKET at level 2 (giving the LL header (ethernet,...) and giving yourself mac addresses, ...). I've just added a super socket which use libdnet and libpcap, so that it should be portable::
537
+
Different super sockets are available in Scapy: the native ones, and the ones that use a libpcap provider (that go through libpcap to send/receive packets).
538
+
By default, Scapy will try to use the native ones (except on Windows, where the winpcap/npcap ones are preferred). To manually use the libpcap ones, you must:
538
539
539
-
>>> conf.L3socket=L3dnetSocket
540
-
>>> conf.L3listen=L3pcapListenSocket
540
+
* On Unix/OSX: be sure to have libpcap installed, and one of the following as libpcap python wrapper: `pcapy` or `pypcap`
541
+
* On Windows: have Npcap/Winpcap installed. (default)
542
+
543
+
Then use:
544
+
545
+
>>> conf.use_pcap =True
546
+
547
+
This will automatically update the sockets pointing to `conf.L2socket` and `conf.L3socket`.
548
+
549
+
If you want to manually set them, you have a bunch of sockets available, depending on your platform. For instance, you might want to use:
550
+
551
+
>>> conf.L3socket=L3pcapSocket # Receive/send L3 packets through libpcap
552
+
>>> conf.L2listen=L2ListenTcpdump # Receive L2 packets through TCPDump
541
553
542
554
Sniffing
543
555
--------
@@ -878,7 +890,7 @@ Making tables
878
890
879
891
Now we have a demonstration of the ``make_table()`` presentation function. It takes a list as parameter, and a function who returns a 3-uple. The first element is the value on the x axis from an element of the list, the second is about the y value and the third is the value that we want to see at coordinates (x,y). The result is a table. This function has 2 variants, ``make_lined_table()`` and ``make_tex_table()`` to copy/paste into your LaTeX pentest report. Those functions are available as methods of a result object :
880
892
881
-
Here we can see a multi-parallel traceroute (scapy already has a multi TCP traceroute function. See later)::
893
+
Here we can see a multi-parallel traceroute (Scapy already has a multi TCP traceroute function. See later)::
882
894
883
895
>>> ans, unans = sr(IP(dst="www.test.fr/30", ttl=(1,6))/TCP())
884
896
Received 49 packets, got 24 answers, remaining 0 packets
@@ -914,7 +926,7 @@ Routing
914
926
.. index::
915
927
single: Routing, conf.route
916
928
917
-
Now scapy has its own routing table, so that you can have your packets routed differently than the system::
929
+
Now Scapy has its own routing table, so that you can have your packets routed differently than the system::
918
930
919
931
>>> conf.route
920
932
Network Netmask Gateway Iface
@@ -937,18 +949,18 @@ Now scapy has its own routing table, so that you can have your packets routed di
937
949
192.168.8.0 255.255.255.0 0.0.0.0 eth0
938
950
0.0.0.0 0.0.0.0 192.168.8.1 eth0
939
951
940
-
Gnuplot
941
-
-------
952
+
Matplotlib
953
+
----------
942
954
943
955
.. index::
944
-
single: Gnuplot, plot()
956
+
single: Matplotlib, plot()
945
957
946
-
We can easily plot some harvested values using Gnuplot. (Make sure that you have Gnuplot-py and Gnuplot installed.)
958
+
We can easily plot some harvested values using Matplotlib. (Make sure that you have matplotlib installed.)
947
959
For example, we can observe the IP ID patterns to know how many distinct IP stacks are used behind a load balancer::
948
960
949
961
>>> a, b = sr(IP(dst="www.target.com")/TCP(sport=[RandShort()]*1000))
950
962
>>> a.plot(lambda x:x[1].id)
951
-
<Gnuplot._Gnuplot.Gnuplot instance at 0xb7d6a74c>
963
+
[<matplotlib.lines.Line2D at 0x2367b80d6a0>]
952
964
953
965
.. image:: graphics/ipid.png
954
966
@@ -959,7 +971,7 @@ TCP traceroute (2)
959
971
.. index::
960
972
single: traceroute(), Traceroute
961
973
962
-
Scapy also has a powerful TCP traceroute function. Unlike other traceroute programs that wait for each node to reply before going to the next, scapy sends all the packets at the same time. This has the disadvantage that it can't know when to stop (thus the maxttl parameter) but the great advantage that it took less than 3 seconds to get this multi-target traceroute result::
974
+
Scapy also has a powerful TCP traceroute function. Unlike other traceroute programs that wait for each node to reply before going to the next, Scapy sends all the packets at the same time. This has the disadvantage that it can't know when to stop (thus the maxttl parameter) but the great advantage that it took less than 3 seconds to get this multi-target traceroute result::
Note the `monitor=True` argument, which only work from scapy>2.4.0 (2.4.0dev+), that is cross-platform. It will in work in most cases (Windows, OSX), but might require you to manually toggle monitor mode.
1363
1377
1364
1378
The above command will produce output similar to the one below::
0 commit comments