MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / start_beacon_tracking

Method start_beacon_tracking

actions/ble_pentest.py:69–144  ·  view source on GitHub ↗

Track Bluetooth beacons (iBeacon, Eddystone, AltBeacon) Useful for tracking people/devices via beacon advertisements Args: duration: How long to track in seconds Returns: Dictionary of discovered beacons with their data

(self, duration: int = 60)

Source from the content-addressed store, hash-verified

67 # ============================================================================
68
69 def start_beacon_tracking(self, duration: int = 60) -> Dict[str, Any]:
70 """
71 Track Bluetooth beacons (iBeacon, Eddystone, AltBeacon)
72 Useful for tracking people/devices via beacon advertisements
73
74 Args:
75 duration: How long to track in seconds
76
77 Returns:
78 Dictionary of discovered beacons with their data
79 """
80 self.logger.info(f"Starting beacon tracking for {duration} seconds...")
81
82 beacons = {}
83 start_time = time.time()
84
85 try:
86 # Use hcitool and hcidump to capture BLE advertisements
87 # This requires root/sudo privileges
88
89 # Start hcidump in background to capture advertisements
90 hcidump_cmd = ['hcidump', '--raw']
91 proc = subprocess.Popen(
92 hcidump_cmd,
93 stdout=subprocess.PIPE,
94 stderr=subprocess.PIPE,
95 text=True
96 )
97
98 self.logger.info("Capturing BLE advertisements...")
99
100 # Parse hcidump output for beacon data
101 while time.time() - start_time < duration:
102 line = proc.stdout.readline()
103 if not line:
104 break
105
106 # Parse beacon advertisements
107 beacon_data = self._parse_beacon_advertisement(line)
108 if beacon_data:
109 beacon_id = beacon_data.get('uuid') or beacon_data.get('address')
110 if beacon_id:
111 if beacon_id not in beacons:
112 beacons[beacon_id] = {
113 'first_seen': time.time(),
114 'last_seen': time.time(),
115 'count': 1,
116 'data': beacon_data
117 }
118 else:
119 beacons[beacon_id]['last_seen'] = time.time()
120 beacons[beacon_id]['count'] += 1
121 # Update RSSI if available
122 if 'rssi' in beacon_data:
123 beacons[beacon_id]['data']['rssi'] = beacon_data['rssi']
124
125 # Clean up
126 proc.terminate()

Callers 3

pentest_beacon_trackFunction · 0.80
executeMethod · 0.80
ble_pentest.pyFile · 0.80

Calls 5

infoMethod · 0.80
errorMethod · 0.80
getMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected