scapy.layers.l2
Classes and functions for layer 2 protocols.
- class scapy.layers.l2.ARP(_pkt, /, *, hwtype=1, ptype=2048, hwlen=None, plen=None, op=1, hwsrc=None, psrc=None, hwdst=None, pdst=None)[source]
Bases:
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | HWTYPE | PTYPE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | HWLEN | PLEN | OP | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | HWSRC | PSRC | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | HWDST | PDST | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. ARP
ARP fields hwtype
1
ptype
2048
hwlen
None
plen
None
op
1
hwsrc
MultipleTypeField
(SourceMACField, StrFixedLenField)None
psrc
MultipleTypeField
(SourceIPField, SourceIP6Field, StrFixedLenField)None
hwdst
MultipleTypeField
(MACField, StrFixedLenField)None
pdst
MultipleTypeField
(IPField, IP6Field, StrFixedLenField)None
- class scapy.layers.l2.ARP_am(self, IP_addr=None, ARP_addr=None, from_ip=None)[source]
Bases:
AnsweringMachine
[Packet
]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: str | None = 'arp'
- function_name = 'farpd'
- optam0: Dict[str, Any]
- optam1: Dict[str, Any]
- optam2: Dict[str, Any]
- optsend: Dict[str, Any]
- optsniff: Dict[str, Any]
- parse_options(IP_addr: str | None = None, ARP_addr: str | None = None, from_ip: str | None = None) None [source]
- static send_function(x: Sequence[Packet] | Packet | SetGen[Packet] | _PacketList[Packet], iface: NetworkInterface | str | None = None, iface_hint: str | None = None, socket: SuperSocket | None = None, **kargs: Any) PacketList | None [source]
Send packets at layer 2
- Parameters:
x – the packets
inter – time (in s) between two packets (default 0)
loop – send packet indefinitely (default 0)
count – number of packets to send (default None=1)
verbose – verbose mode (default None=conf.verb)
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
- class scapy.layers.l2.ARPingResult(res=None, name='ARPing', stats=None)[source]
Bases:
SndRcvList
- class scapy.layers.l2.CookedLinux(_pkt, /, *, pkttype=0, lladdrtype=512, lladdrlen=0, src=b'', proto=2048)[source]
Bases:
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.CookedLinuxV2(_pkt, /, *, proto=2048, reserved=0, ifindex=0, lladdrtype=512, pkttype=0, lladdrlen=0, src=b'')[source]
Bases:
CookedLinux
- 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 | RESERVED | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | IFINDEX | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | LLADDRTYPE | PKTTYPE | LLADDRLEN | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | SRC | + + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. CookedLinuxV2
CookedLinuxV2 fields proto
2048
reserved
0
ifindex
0
lladdrtype
512
pkttype
0
lladdrlen
0
src
b''
- class scapy.layers.l2.Dot1AD(_pkt, /, *, prio=0, dei=0, vlan=1, type=0)[source]
Bases:
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|D| VLAN | TYPE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. Dot1AD
Dot1AD fields prio
BitField
(3 bits)0
dei
BitField
(1 bit)0
vlan
BitField
(12 bits)1
type
0
- class scapy.layers.l2.Dot1AH(_pkt, /, *, prio=0, dei=0, nca=0, res1=0, res2=0, isid=0)[source]
Bases:
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | PRIO|D|N|R|RES| ISID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | +-+-+-+-+-+-+-+-+ Fig. Dot1AH
Dot1AH fields prio
BitField
(3 bits)0
dei
BitField
(1 bit)0
nca
BitField
(1 bit)0
res1
BitField
(1 bit)0
res2
BitField
(2 bits)0
isid
0
- class scapy.layers.l2.Dot1Q(_pkt, /, *, prio=0, dei=0, vlan=1, type=0)[source]
Bases:
Packet
- aliastypes
- deprecated_fields: Dict[str, Tuple[str, str]] = {'id': ('dei', '2.5.0')}
- 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|D| VLAN | TYPE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. Dot1Q
Dot1Q fields prio
BitField
(3 bits)0
dei
BitField
(1 bit)0
vlan
BitField
(12 bits)1
type
0
- class scapy.layers.l2.Dot3(_pkt, /, *, dst=None, src=None, len=None)[source]
Bases:
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | DST | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | SRC | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | LEN | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. Dot3
Dot3 fields dst
None
src
None
len
None
- class scapy.layers.l2.Ether(_pkt, /, *, dst=None, src=None, type=36864)[source]
Bases:
Packet
- aliastypes
- classmethod dispatch_hook(_pkt: bytes | None = None, *args: Any, **kargs: Any) Type[Packet] [source]
- 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
- class scapy.layers.l2.GRE(_pkt, /, *, chksum_present=0, routing_present=0, key_present=0, seqnum_present=0, strict_route_source=0, recursion_control=0, flags=0, version=0, proto=0, chksum=None, offset=None, key=None, sequence_number=None)[source]
Bases:
Packet
- aliastypes
- deprecated_fields: Dict[str, Tuple[str, str]] = {'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| 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
- class scapy.layers.l2.GRE_PPTP(_pkt, /, *, chksum_present=0, routing_present=0, key_present=1, seqnum_present=0, strict_route_source=0, recursion_control=0, acknum_present=0, flags=0, version=1, proto=34827, payload_len=None, call_id=None, sequence_number=None, ack_number=None)[source]
Bases:
GRE
Enhanced GRE header used with PPTP RFC 2637
- aliastypes
- deprecated_fields: Dict[str, Tuple[str, str]] = {'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
- class scapy.layers.l2.GRErouting(_pkt, /, *, address_family=0, SRE_offset=0, SRE_len=None, routing_info=b'')[source]
Bases:
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(_pkt, /, *, dsap=0, ssap=0, ctrl=0)[source]
Bases:
Packet
- aliastypes
- class scapy.layers.l2.LoIntEnumField(name: str, default: int | None, enum: Dict[int, str])[source]
Bases:
IntEnumField
- class scapy.layers.l2.Loopback(_pkt, /, *, type=2)[source]
Bases:
Packet
*BSD loopback layer
- aliastypes
- class scapy.layers.l2.LoopbackOpenBSD(_pkt, /, *, type=2)[source]
Bases:
Loopback
- 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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | TYPE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. LoopbackOpenBSD
LoopbackOpenBSD fields type
2
- class scapy.layers.l2.MPacketPreamble(_pkt, /, *, preamble=b'', fcs=0)[source]
Bases:
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[source]
Bases:
object
- class scapy.layers.l2.SNAP(_pkt, /, *, OUI=0, code=0)[source]
Bases:
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(_pkt, /, *, 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)[source]
Bases:
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: str, getif: Any | None = None)[source]
Bases:
MACField
- getif
- scapy.layers.l2.arp_mitm(ip1: str, ip2: str, mac1: List[str] | str | None = None, mac2: List[str] | str | None = None, broadcast: bool = False, target_mac: str | None = None, iface: NetworkInterface | str | None = None, inter: int = 3) None [source]
ARP MitM: poison 2 target’s ARP cache
- Parameters:
ip1 – IPv4 of the first machine
ip2 – IPv4 of the second machine
mac1 – MAC of the first machine (optional: will ARP otherwise)
mac2 – MAC of the second machine (optional: will ARP otherwise)
broadcast – if True, will use broadcast mac for MitM by default
target_mac – MAC of the attacker (optional: default to the interface’s one)
iface – the network interface. (optional: default, route for ip1)
Example usage:
$ sysctl net.ipv4.conf.virbr0.send_redirects=0 # virbr0 = interface $ sysctl net.ipv4.ip_forward=1 $ sudo iptables -t mangle -A PREROUTING -j TTL --ttl-inc 1 $ sudo scapy >>> arp_mitm("192.168.122.156", "192.168.122.17")
- Alternative usages:
>>> arp_mitm("10.0.0.1", "10.1.1.0/21", iface="eth1") >>> arp_mitm("10.0.0.1", "10.1.1.2", ... target_mac="aa:aa:aa:aa:aa:aa", ... mac2="00:1e:eb:bf:c1:ab")
Warning
If using a subnet, this will first perform an arping, unless broadcast is on!
Remember to change the sysctl settings back..
- scapy.layers.l2.arpcachepoison(target: str | List[str], addresses: str | Tuple[str, str] | List[Tuple[str, str]], broadcast: bool = False, count: int | None = None, interval: int = 15, **kwargs: Any) None [source]
Poison targets’ ARP cache
- Parameters:
target – Can be an IP, subnet (string) or a list of IPs. This lists the IPs or the subnet that will be poisoned.
addresses – Can be either a string, a tuple of a list of tuples. If it’s a string, it’s the IP to advertise to the victim, with the local interface’s MAC. If it’s a tuple, it’s (“IP”, “MAC”). It it’s a list, it’s [(“IP”, “MAC”)]. “IP” can be a subnet of course.
broadcast – Use broadcast ethernet
Examples for target “192.168.0.2”:
>>> arpcachepoison("192.168.0.2", "192.168.0.1") >>> arpcachepoison("192.168.0.1/24", "192.168.0.1") >>> arpcachepoison(["192.168.0.2", "192.168.0.3"], "192.168.0.1") >>> arpcachepoison("192.168.0.2", ("192.168.0.1", get_if_hwaddr("virbr0"))) >>> arpcachepoison("192.168.0.2", [("192.168.0.1", get_if_hwaddr("virbr0"), ... ("192.168.0.2", "aa:aa:aa:aa:aa:aa")])
- scapy.layers.l2.arping(net: str, timeout: int = 2, cache: int = 0, verbose: int | None = None, threaded: bool = True, **kargs: Any) Tuple[ARPingResult, PacketList] [source]
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: str, plen: int = 255, hwlen: int = 255, **kargs: Any) Tuple[SndRcvList, PacketList] [source]
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: str, **kargs: Any) Tuple[SndRcvList, PacketList] [source]
Exploit Etherleak flaw
- scapy.layers.l2.getmacbyip(ip: str, chainCC: int = 0) str | None [source]
Returns the destination MAC address used to reach a given IP address.
This will follow the routing table and will issue an ARP request if necessary. Special cases (multicast, etc.) are also handled.
See also
getmacbyip6()
for IPv6.
- scapy.layers.l2.is_promisc(ip: str, fake_bcast: str = 'ff:ff:00:00:00:00', **kargs: Any) bool [source]
Try to guess if target is in Promisc mode. The target is provided by its ip.
- scapy.layers.l2.l2_register_l3(l2: Packet, l3: Packet) str | None [source]
Delegates resolving the default L2 destination address to the payload of L3.
- scapy.layers.l2.l2_register_l3_arp(l2: Packet, l3: Packet) str | None [source]
Resolves the default L2 destination address when ARP is used.
- scapy.layers.l2.promiscping(net: str, timeout: int = 2, fake_bcast: str = 'ff:ff:ff:ff:ff:fe', **kargs: Any) Tuple[ARPingResult, PacketList] [source]
Send ARP who-has requests to determine which hosts are in promiscuous mode promiscping(net, iface=conf.iface)