|
12 | 12 | from struct import pack, unpack
|
13 | 13 |
|
14 | 14 | from sniffle.pcap import PcapBleWriter
|
15 |
| -from sniffle.sniffle_hw import SniffleHW, BLE_ADV_AA, PacketMessage, DebugMessage, StateMessage, \ |
16 |
| - MeasurementMessage, SnifferState |
17 |
| -from sniffle.packet_decoder import DPacketMessage, DataMessage, LlDataContMessage, AdvIndMessage, \ |
18 |
| - AdvDirectIndMessage, ScanRspMessage, ConnectIndMessage, str_mac, LlControlMessage |
19 |
| -from sniffle.relay_protocol import RelayServer, MessageType |
| 15 | +from sniffle.sniffle_hw import SniffleHW, BLE_ADV_AA, PacketMessage, DebugMessage, \ |
| 16 | + StateMessage, MeasurementMessage, SnifferState |
| 17 | +from sniffle.packet_decoder import DPacketMessage, DataMessage, LlDataContMessage, \ |
| 18 | + AdvIndMessage, AdvDirectIndMessage, ScanRspMessage, ConnectIndMessage, \ |
| 19 | + str_mac, LlControlMessage, AdvertMessage |
| 20 | +from sniffle.relay_protocol import RelayServer, MessageType, ErrorCode |
20 | 21 |
|
21 | 22 | """
|
22 | 23 | Relay attack principles:
|
@@ -153,6 +154,10 @@ def main():
|
153 | 154 |
|
154 | 155 | # obtain the target's advertisement and scan response, share it with relay slave
|
155 | 156 | adv, scan_rsp = scan_target(mac_bytes)
|
| 157 | + if not adv or not scan_rsp: |
| 158 | + print("Error: Advertisement type must be ADV_IND. Aborting.") |
| 159 | + conn.send_err(ErrorCode.INVALID_ADV) |
| 160 | + return |
156 | 161 | conn.send_msg(MessageType.ADVERT, adv.body)
|
157 | 162 | conn.send_msg(MessageType.SCAN_RSP, scan_rsp.body)
|
158 | 163 |
|
@@ -351,14 +356,17 @@ def scan_target(mac):
|
351 | 356 | if not isinstance(msg, PacketMessage):
|
352 | 357 | continue
|
353 | 358 | dpkt = DPacketMessage.decode(msg)
|
354 |
| - if isinstance(dpkt, AdvIndMessage) or isinstance(dpkt, AdvDirectIndMessage): |
| 359 | + if isinstance(dpkt, AdvIndMessage): |
355 | 360 | if advPkt is None:
|
356 | 361 | print("Found advertisement.")
|
357 | 362 | advPkt = dpkt
|
358 | 363 | elif isinstance(dpkt, ScanRspMessage):
|
359 | 364 | if scanRspPkt is None:
|
360 | 365 | print("Found scan response.")
|
361 | 366 | scanRspPkt = dpkt
|
| 367 | + elif isinstance(dpkt, AdvertMessage): |
| 368 | + print("Received incompatible advertisement of type %s." % dpkt.pdutype) |
| 369 | + return None, None |
362 | 370 |
|
363 | 371 | print("Target Advertisement:")
|
364 | 372 | print(advPkt)
|
|
0 commit comments