scapy.layers.l2
Classes and functions for layer 2 protocols.
- class scapy.layers.l2.ARP(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- answers(other)
- extract_padding(s)
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | HWTYPE | PTYPE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | HWLEN | PLEN | OP | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | HWSRC | PSRC | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | HWDST | PDST | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. ARP
ARP fields hwtype
1
ptype
2048
hwlen
None
plen
None
op
1
hwsrc
None
psrc
None
hwdst
None
pdst
None
- hashret()
- mysummary()
- route()
- class scapy.layers.l2.ARP_am(**kargs)
Bases:
scapy.ansmachine.AnsweringMachine
Fake ARP Relay Daemon (farpd)
example: To respond to an ARP request for 192.168.100 replying on the ingress interface:
farpd(IP_addr='192.168.1.100',ARP_addr='00:01:02:03:04:05')
To respond on a different interface add the interface parameter:
farpd(IP_addr='192.168.1.100',ARP_addr='00:01:02:03:04:05',iface='eth0')
To respond on ANY arp request on an interface with mac address ARP_addr:
farpd(ARP_addr='00:01:02:03:04:05',iface='eth1')
To respond on ANY arp request with my mac addr on the given interface:
farpd(iface='eth1')
Optional Args:
inter=<n> Interval in seconds between ARP replies being sent
- filter = 'arp'
- function_name = 'farpd'
- is_request(req)
- make_reply(req)
- parse_options(IP_addr=None, ARP_addr=None)
- print_reply(req, reply)
- static send_function(x, inter=0, loop=0, iface=None, iface_hint=None, count=None, verbose=None, realtime=None, return_packets=False, socket=None, *args, **kargs)
Send packets at layer 2
- Parameters
x – the packets
inter – time (in s) between two packets (default 0)
loop – send packet indefinetly (default 0)
count – number of packets to send (default None=1)
verbose – verbose mode (default None=conf.verbose)
realtime – check that a packet was sent before sending the next one
return_packets – return the sent packets
socket – the socket to use (default is conf.L3socket(kargs))
iface – the interface to send the packets on
monitor – (not on linux) send in monitor mode
- Returns
None
- send_reply(reply)
- class scapy.layers.l2.ARPingResult(res=None, name='ARPing', stats=None)
Bases:
scapy.plist.SndRcvList
- show()
Print the list of discovered MAC addresses.
- class scapy.layers.l2.CookedLinux(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | PKTTYPE | LLADDRTYPE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | LLADDRLEN | SRC | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | PROTO | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. CookedLinux
CookedLinux fields pkttype
0
lladdrtype
512
lladdrlen
0
src
b''
proto
2048
- class scapy.layers.l2.DestMACField(name)
Bases:
scapy.fields.MACField
- i2h(pkt, x)
- i2m(pkt, x)
- class scapy.layers.l2.Dot1AD(*args, **kargs)
Bases:
scapy.layers.l2.Dot1Q
- aliastypes
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | PRIO|I| VLAN | TYPE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. Dot1AD
Dot1AD fields prio
BitField
(3 bits)0
id
BitField
(1 bit)0
vlan
BitField
(12 bits)1
type
0
- class scapy.layers.l2.Dot1Q(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- answers(other)
- default_payload_class(pay)
- extract_padding(s)
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | PRIO|I| VLAN | TYPE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. Dot1Q
Dot1Q fields prio
BitField
(3 bits)0
id
BitField
(1 bit)0
vlan
BitField
(12 bits)1
type
0
- mysummary()
- class scapy.layers.l2.Dot3(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- answers(other)
- classmethod dispatch_hook(_pkt=None, *args, **kargs)
- extract_padding(s)
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | DST | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | SRC | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | LEN | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. Dot3
Dot3 fields dst
None
src
None
len
None
- mysummary()
- class scapy.layers.l2.Ether(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- answers(other)
- classmethod dispatch_hook(_pkt=None, *args, **kargs)
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | DST | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | SRC | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | TYPE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. Ether
Ether fields dst
None
src
None
type
36864
- hashret()
- mysummary()
- class scapy.layers.l2.GRE(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- deprecated_fields = {'seqence_number': ('sequence_number', '2.4.4')}
- classmethod dispatch_hook(_pkt=None, *args, **kargs)
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |C|R|K|S|S|RECUR| FLAGS |VERSI| PROTO | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | CHKSUM | OFFSET | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | KEY | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | SEQUENCE NUMBER | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. GRE
GRE fields chksum_present
BitField
(1 bit)0
routing_present
BitField
(1 bit)0
key_present
BitField
(1 bit)0
seqnum_present
BitField
(1 bit)0
strict_route_source
BitField
(1 bit)0
recursion_control
BitField
(3 bits)0
flags
BitField
(5 bits)0
version
BitField
(3 bits)0
proto
0
chksum
XShortField
(Cond)None
offset
XShortField
(Cond)None
key
XIntField
(Cond)None
sequence_number
XIntField
(Cond)None
- payload_guess
Possible sublayers:
ERSPAN_III
,ERSPAN_II
,ERSPAN
,MPLS
,NSH
,EAPOL
,IP
,IPv6
,ARP
,Dot1AD
,Dot1Q
,Ether
,GRErouting
,LLC
- post_build(p, pay)
- class scapy.layers.l2.GRE_PPTP(*args, **kargs)
Bases:
scapy.layers.l2.GRE
Enhanced GRE header used with PPTP RFC 2637
- aliastypes
- deprecated_fields = {'seqence_number': ('sequence_number', '2.4.4')}
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |C|R|K|S|S|RECUR|A| FLAGS |VERSI| PROTO | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | PAYLOAD LEN | CALL ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | SEQUENCE NUMBER | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ACK NUMBER | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. GRE_PPTP
GRE_PPTP fields chksum_present
BitField
(1 bit)0
routing_present
BitField
(1 bit)0
key_present
BitField
(1 bit)1
seqnum_present
BitField
(1 bit)0
strict_route_source
BitField
(1 bit)0
recursion_control
BitField
(3 bits)0
acknum_present
BitField
(1 bit)0
flags
BitField
(4 bits)0
version
BitField
(3 bits)1
proto
34827
payload_len
None
call_id
None
sequence_number
XIntField
(Cond)None
ack_number
XIntField
(Cond)None
- payload_guess
Possible sublayers:
ERSPAN_III
,ERSPAN_II
,ERSPAN
,EAPOL
,IP
,IPv6
,ARP
,Dot1AD
,Dot1Q
,Ether
,GRErouting
,LLC
,PPP
- post_build(p, pay)
- class scapy.layers.l2.GRErouting(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ADDRESS FAMILY | SRE OFFSET | SRE LEN | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ROUTING INFO | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. GRErouting
GRErouting fields address_family
0
SRE_offset
0
SRE_len
None
routing_info
b''
- payload_guess
Possible sublayers:
GRErouting
,Raw
- class scapy.layers.l2.LLC(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- class scapy.layers.l2.LoIntEnumField(name, default, enum)
Bases:
scapy.fields.IntEnumField
- i2m(pkt, x)
- m2i(pkt, x)
- class scapy.layers.l2.Loopback(*args, **kargs)
Bases:
scapy.packet.Packet
*BSD loopback layer
- aliastypes
- class scapy.layers.l2.MPacketPreamble(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | PREAMBLE | FCS | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. MPacketPreamble
MPacketPreamble fields preamble
b''
fcs
0
- class scapy.layers.l2.Neighbor
Bases:
object
- register_l3(l2, l3, resolve_method)
- resolve(l2inst, l3inst)
- class scapy.layers.l2.SNAP(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | OUI | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | CODE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. SNAP
SNAP fields OUI
0
code
0
- class scapy.layers.l2.STP(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- fields_desc
Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | PROTO | VERSION | BPDUTYPE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | BPDUFLAGS | ROOTID | ROOTMAC | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | PATHCOST | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | BRIDGEID | BRIDGEMAC | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | PORTID | AGE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | MAXAGE | HELLOTIME | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | FWDDELAY | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. STP
STP fields proto
0
version
0
bpdutype
0
bpduflags
0
rootid
0
rootmac
'00:00:00:00:00:00'
pathcost
0
bridgeid
0
bridgemac
'00:00:00:00:00:00'
portid
0
age
1
maxage
20
hellotime
2
fwddelay
15
- class scapy.layers.l2.SourceMACField(name, getif=None)
Bases:
scapy.fields.MACField
- getif
- i2h(pkt, x)
- i2m(pkt, x)
- scapy.layers.l2.arpcachepoison(target, victim, interval=60)
Poison target’s cache with (your MAC,victim’s IP) couple arpcachepoison(target, victim, [interval=60]) -> None
- scapy.layers.l2.arping(net, timeout=2, cache=0, verbose=None, **kargs)
Send ARP who-has requests to determine which hosts are up arping(net, [cache=0,] [iface=conf.iface,] [verbose=conf.verb]) -> None Set cache=True if you want arping to modify internal ARP-Cache
- scapy.layers.l2.arpleak(target, plen=255, hwlen=255, **kargs)
Exploit ARP leak flaws, like NetBSD-SA2017-002.
https://ftp.netbsd.org/pub/NetBSD/security/advisories/NetBSD-SA2017-002.txt.asc
- scapy.layers.l2.etherleak(target, **kargs)
Exploit Etherleak flaw
- scapy.layers.l2.getmacbyip(ip, chainCC=0)
Return MAC address corresponding to a given IP address
- scapy.layers.l2.is_promisc(ip, fake_bcast='ff:ff:00:00:00:00', **kargs)
Try to guess if target is in Promisc mode. The target is provided by its ip.
- scapy.layers.l2.l2_register_l3(l2, l3)
- scapy.layers.l2.l2_register_l3_arp(l2, l3)
- scapy.layers.l2.promiscping(net, timeout=2, fake_bcast='ff:ff:ff:ff:ff:fe', **kargs)
Send ARP who-has requests to determine which hosts are in promiscuous mode promiscping(net, iface=conf.iface)