-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathejemplo20.py
executable file
·89 lines (74 loc) · 2.42 KB
/
ejemplo20.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os,time, datetime
from datetime import timedelta
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
import scapy_ex
from netaddr import *
from netaddr.core import NotRegisteredError
intfmon='mon0'
workdir='/root' ## directory where the captures pcap are stored
verbose=1
pcounter=0
# Parse information inside beacon frame
def ParsePacket(pkt):
capability = pkt.sprintf("{Dot11Beacon:%Dot11Beacon.cap%}{Dot11ProbeResp:%Dot11ProbeResp.cap%}")
elt = pkt[Dot11Elt]
crypto = set()
channel=uptime=interval=timestamp=''
if pkt.haslayer(Dot11Beacon):
type='Beacon'
interval = float(pkt.beacon_interval) / 1000 ## Get beacon interval value
uptime=str(timedelta(microseconds=pkt.timestamp)) ## AP uptime
elif pkt.haslayer(Dot11ProbeReq):
type='Probe Request'
# Get date of captured beacon frame
capturetime=datetime.datetime.fromtimestamp(float(pkt.time)).strftime('%d-%m-%Y %H:%M:%S')
while isinstance(elt, Dot11Elt):
if elt.ID == 0:
essid = elt.info
elif elt.ID == 3:
channel = int(ord(elt.info))
elif elt.ID == 48:
crypto.add("WPA2")
elif elt.ID == 221 and elt.info.startswith('\x00P\xf2\x01\x01\x00'):
crypto.add("WPA")
elt = elt.payload
if not channel: channel=pkt[RadioTap].Channel
if not crypto:
if 'privacy' in capability:
crypto.add("WEP")
else:
crypto.add("OPN")
# Get packet BSSID and calculate manufacturer
bssid = pkt.addr2
mac = EUI(bssid)
try:
manuf = mac.oui.registration().org
except NotRegisteredError:
manuf = "Not available"
print "\n%s: BSSID: %s(%s) SSID:%s ENC:%s in Channel:%s captured:[%s] uptime:[%s] Intval: %s" \
%(type, bssid, manuf, essid, ' / '.join(crypto), channel,capturetime,uptime,interval)
# Select AP to use
caplist=[] ; i=0
for file in os.listdir(workdir):
if file.endswith(".cap"):
caplist.append(file)
print "%s. %s" %(i,file)
i+=1
selected = input("\nSelect file number to use: ")
if not selected in range(0,i):
print "Sorry wrong index number..."
exit()
pcapfile = workdir + '/' + caplist[selected]
pktreader = PcapReader(pcapfile)
print pcapfile
# Walk through the PCAP file packets
for pkt in pktreader:
if pkt.haslayer(Dot11Beacon) or pkt.haslayer(Dot11ProbeReq):
ParsePacket(pkt)
if verbose >=1: print "Packet structuret:\n" + pkt.command()
pcounter +=1
print "\nTotal packets in PCAP file: %d\n" % pcounter