-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path082-handshake-capture.py
38 lines (32 loc) · 1.44 KB
/
082-handshake-capture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from scapy.all import *
# set the wireless interface to capture packets from
iface = "wlan0"
# set the BSSID (MAC address of the access point) to filter on
bssid = "00:11:22:33:44:55"
# set the ESSID (network name) to filter on
essid = "MyWiFiNetwork"
# set the number of packets to capture
num_packets = 1000
# create a function to handle captured packets
def packet_handler(pkt):
global handshake
# check if the packet is a wireless management frame
if pkt.haslayer(Dot11):
if pkt.type == 0 and pkt.subtype == 8: # management frame, beacon
# check if the packet matches the BSSID and ESSID filters
if pkt.addr3 == bssid and pkt.info == essid:
# check if the packet is part of a handshake
if pkt.haslayer(Dot11Elt) and pkt[Dot11Elt].ID == 48:
if not handshake:
handshake = [pkt]
else:
handshake.append(pkt)
if len(handshake) == 4:
print("Valid handshake captured!")
print("".join([pkt[Dot11Elt].info.decode() for pkt in handshake]))
# you can save the handshake to a file or process it further
# reset the handshake list
handshake = []
# start capturing packets on the wireless interface
handshake = []
sniff(iface=iface, prn=packet_handler, count=num_packets)