This repository has been archived by the owner on Dec 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcaptureclients.py
executable file
·175 lines (142 loc) · 4.33 KB
/
captureclients.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# +++++++++++++++++++++++++++++++++++++++++
#
# WLAN Capture Client Script
# +++++++++++++++++++++++++++++++++++++++++
#
#
# Author : SSB
# http://bitforestinfo.blogspot.com
# github.com/surajsinghbisht054
#
#
# This Script Is Created For Educational And Practise Purpose Only
#
#
import scapy.all as scapy
import sys
#
# Class For Storing/Handling Client And Station Informations
#
class HandleClients:
'''
This Class Provides Simple But Effective Way To Store
Client And Station MAC Address.
'''
def __init__(self):
self.records = [None,]
self.lastpacket = None
def save(self, data):
'''
Save Data In Records If its Not Already Exist.
'''
if data not in self.records:
self.records.append(data)
self.lastpacket = data
return self.lastpackets()
def getall(self):
'''
Return All Saved Records
'''
self.records.remove(None)
return self.records
def lastpackets(self):
if not self.lastpacket:
return
f1 = self.lastpacket[3]
f = self.lastpacket
if f1=='association_request':
form = '< Station : {} | Client : {} | StationInfo : {} | Layer : {} >'.format(f[0], f[1], f[2], f[3])
elif f1=='association_response':
form = '< Station : {} | Client : {} | ClientInfo : {} | Layer : {} >'.format(f[1], f[0], f[2], f[3])
elif f1=='authentication':
form = '< DeviceOne : {} | DeviceTwo : {} | DeviceInfo : {} | Layer : {} >'.format(f[0], f[1], f[2], f[3])
elif f1=='probe_request':
form = '< Station : {} | Client : {} | ClientInfo : {} | Layer : {} >'.format(f[0], f[1], f[2], f[3])
elif f1=='probe_answer':
form = '< Station : {} | Client : {} | StationInfo : {} | Layer : {} >'.format(f[1], f[0], f[2], f[3])
else:
form = str(f)
self.lastpacket = None
return form
#
# Main Class For Sniffing And Packets Extracting
#
class GetClients:
def __init__(self, **kwargs):
'''
Function For Automatic Packet Sniffing And Handling.
'''
self.kwargs = kwargs
self.handler = HandleClients()
self.CapturePackets()
self.showresults()
def showresults(self):
'''
Show All Captured Packets With MAC Address Details.
'''
print "\n\t\tFinal Result"
print " ==> [{}] | [{}] | [{}] | [{}] <==".format(" Station "," Client ", " Info ", " Layer ")
for a,b,c,d in self.handler.getall():
print " ==> [{}] | [{}] | [{}] | [{}] <==".format(a,b,c.ljust(18),d.ljust(18))
return
def CapturePackets(self):
'''
Scapy Sniff Function
'''
scapy.sniff(prn = self.GetAcessClient, **self.kwargs)
return
def GetAcessClient(self, pkt):
'''
Function For Extracting Various Layers From Captured Packet.
Supported Layers For Extracting Client And Station MAC Address
scapy.Dot11AssoReq = Association Request
scapy.Dot11AssoResp = Association Response
scapy.Dot11Auth = Authentication
scapy.Dot11ProbeReq = Probe Request
scapy.Dot11ProbeResp = Probe Answer
'''
if pkt.haslayer(scapy.Dot11AssoReq):
# Association Request
# print " [*] Association Request."
data = (station, client, stationinfo, packet) = (pkt.addr1, pkt.addr2, pkt.info, 'association_request')
get = self.handler.save(data)
if get:
print get
if pkt.haslayer(scapy.Dot11AssoResp):
# Association Response
# print " [*] Association Response."
data = (client, station, clientinfo, packet) = (pkt.addr1, pkt.addr2, pkt.info, 'association_response')
get = self.handler.save(data)
if get:
print get
if pkt.haslayer(scapy.Dot11Auth):
# Authentication
# print " [*] Authentication. "
data = (device1, device2, info, packet)=(pkt.addr1, pkt.addr2, pkt.info, 'authentication')
get = self.handler.save(data)
if get:
print get
if pkt.haslayer(scapy.Dot11ProbeReq):
# Probe Request
# print " [*] Probe Request."
data = (station, client, clientinfo, packet)=(pkt.addr1, pkt.addr2, pkt.info, 'probe_request')
get = self.handler.save(data)
if get:
print get
if pkt.haslayer(scapy.Dot11ProbeResp):
# Probe Answer
# print " [*] Probe Answer."
data = (client, station, stationinfo, packet)=(pkt.addr1, pkt.addr2, pkt.info, 'probe_answer')
get = self.handler.save(data)
if get:
print get
return
# Main Trigger
if __name__=="__main__":
if sys.argv:
acp=sys.argv[1]
GetClients(iface="mon0",timeout=60)