-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsniff.py
40 lines (39 loc) · 1.96 KB
/
sniff.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
39
#!/usr/bin/env python
import os
# The previous line ensures that this script is run under the context
# of the Python interpreter. Next, import the Scapy functions:
from scapy.all import *
# Define the interface name that we will be sniffing from, you can
# change this if needed.
interface = "mon0"
# Next, declare a Python list to keep track of client MAC addresses
# that we have already seen so we only print the address once per client.
observedclients = []
# The sniffmgmt() function is called each time Scapy receives a packet
# (we'll tell Scapy to use this function below with the sniff() function).
# The packet that was sniffed is passed as the function argument, "p".
def sniffmgmt(p):
# Define our tuple (an immutable list) of the 3 management frame
# subtypes sent exclusively by clients. I got this list from Wireshark.
stamgmtstypes = (0, 2, 4)
# Make sure the packet has the Scapy Dot11 layer present
if p.haslayer(Dot11):
# Check to make sure this is a management frame (type=0) and that
# the subtype is one of our management frame subtypes indicating a
# a wireless client
if p.type == 0 and p.subtype in stamgmtstypes:
# We only want to print the MAC address of the client if it
# hasn't already been observed. Check our list and if the
# client address isn't present, print the address and then add
# it to our list.
if p.addr2 not in observedclients:
print p.addr2
observedclients.append(p.addr2)
# f8:8f:ca:24 is the start of the MAC of Google Glass
if 'f8:8f:ca:24' in p.addr2:
print "WARNING! GOOGLE GLASS DETECTED!"
os.system("sudo hologram send -t twitter dangerousDeviceName")
# With the sniffmgmt() function complete, we can invoke the Scapy sniff()
# function, pointing to the monitor mode interface, and telling Scapy to call
# the sniffmgmt() function for each packet received. Easy!
sniff(iface=interface, prn=sniffmgmt)