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. ARPARP fields hwtype
1ptype
2048hwlen
Noneplen
Noneop
1hwsrc
Nonepsrc
Nonehwdst
Nonepdst
None
- hashret()
- mysummary()
- route()
- class scapy.layers.l2.ARP_am(**kargs)
Bases:
scapy.ansmachine.AnsweringMachineFake 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. CookedLinuxCookedLinux fields pkttype
0lladdrtype
512lladdrlen
0src
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. Dot1ADDot1AD fields prio
BitField(3 bits)0id
BitField(1 bit)0vlan
BitField(12 bits)1type
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. Dot1QDot1Q fields prio
BitField(3 bits)0id
BitField(1 bit)0vlan
BitField(12 bits)1type
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. Dot3Dot3 fields dst
Nonesrc
Nonelen
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. EtherEther fields dst
Nonesrc
Nonetype
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. GREGRE fields chksum_present
BitField(1 bit)0routing_present
BitField(1 bit)0key_present
BitField(1 bit)0seqnum_present
BitField(1 bit)0strict_route_source
BitField(1 bit)0recursion_control
BitField(3 bits)0flags
BitField(5 bits)0version
BitField(3 bits)0proto
0chksum
XShortField(Cond)Noneoffset
XShortField(Cond)Nonekey
XIntField(Cond)Nonesequence_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.GREEnhanced 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_PPTPGRE_PPTP fields chksum_present
BitField(1 bit)0routing_present
BitField(1 bit)0key_present
BitField(1 bit)1seqnum_present
BitField(1 bit)0strict_route_source
BitField(1 bit)0recursion_control
BitField(3 bits)0acknum_present
BitField(1 bit)0flags
BitField(4 bits)0version
BitField(3 bits)1proto
34827payload_len
Nonecall_id
Nonesequence_number
XIntField(Cond)Noneack_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. GREroutingGRErouting fields address_family
0SRE_offset
0SRE_len
Nonerouting_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. MPacketPreambleMPacketPreamble 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. SNAPSNAP fields OUI
0code
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. STPSTP fields proto
0version
0bpdutype
0bpduflags
0rootid
0rootmac
'00:00:00:00:00:00'pathcost
0bridgeid
0bridgemac
'00:00:00:00:00:00'portid
0age
1maxage
20hellotime
2fwddelay
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)