-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpwndroid.py
188 lines (173 loc) · 7.32 KB
/
pwndroid.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
176
177
178
179
180
181
182
183
184
185
186
187
188
import json
import logging
import asyncio
import websockets
import pwnagotchi.plugins as plugins
import pwnagotchi.ui.fonts as fonts
from pwnagotchi.ui.components import LabeledValue
from pwnagotchi.ui.view import BLACK
class PwnDroid(plugins.Plugin):
__author__ = "Jayofelony"
__version__ = "1.1.002"
__license__ = "GPL3"
__description__ = "Plugin for the companion app PwnDroid to display GPS data on the Pwnagotchi screen."
LINE_SPACING = 10
LABEL_SPACING = 0
def __init__(self):
self.running = False
self.coordinates = dict()
self.options = dict()
self.websocket = None
def on_loaded(self):
self.running = True
logging.info("[PwnDroid] Plugin loaded")
asyncio.run(self.start_fetching_location_data())
if self.message == "Connection established":
logging.info("[PwnDroid] Connection established")
async def start_fetching_location_data(self):
uri = "ws://192.168.44.1:8080" # Replace with your WebSocket server URI
while True:
try:
async with websockets.connect(uri) as websocket:
self.websocket = websocket
while True:
try:
self.message = await websocket.recv()
if self.message != "": # Check if the message is not empty
try:
self.coordinates = json.loads(self.message)
except json.JSONDecodeError as e:
await asyncio.sleep(5) # Retry after 5 seconds
self.coordinates = {}
else:
logging.error("Received empty message from WebSocket")
await asyncio.sleep(5) # Retry after 5 seconds
except websockets.ConnectionClosed:
break
except Exception as e:
logging.error(f"Connection error: {e}")
await asyncio.sleep(5) # Retry after 5 seconds
async def close_websocket(self):
if self.websocket:
await self.websocket.close()
logging.info("[PwnDroid] WebSocket connection closed")
def on_unload(self, ui):
self.running = False
asyncio.run(self.close_websocket())
with ui._lock:
ui.remove_element('latitude')
ui.remove_element('longitude')
if self.options['display_altitude']:
ui.remove_element('altitude')
def on_handshake(self, agent, filename, access_point, client_station):
if self.coordinates:
logging.info("Location Data:")
logging.info(f"Latitude: {self.coordinates['Latitude']}")
logging.info(f"Longitude: {self.coordinates['Longitude']}")
logging.info(f"Altitude: {self.coordinates['Altitude']}")
logging.info(f"Speed: {self.coordinates['Speed']}")
logging.info(f"Accuracy: {self.coordinates['Accuracy']}")
logging.info(f"Bearing: {self.coordinates['Bearing']}")
gps_filename = filename.replace(".pcap", ".gps.json")
# avoid 0.000... measurements
if all([self.coordinates.get("Latitude"), self.coordinates.get("Longitude")]):
logging.info(f"saving GPS to {gps_filename} ({self.coordinates})")
with open(gps_filename, "w+t") as fp:
json.dump(self.coordinates, fp)
else:
logging.info("[PwnDroid] not saving GPS. Couldn't find location.")
def on_ui_setup(self, ui):
try:
# Configure line_spacing
line_spacing = int(self.options['linespacing'])
except Exception as e:
# Set default value
logging.debug(f"[PwnDroid] Error on_ui_setup: {e}")
line_spacing = self.LINE_SPACING
try:
# Configure position
pos = self.options['position'].split(',')
pos = [int(x.strip()) for x in pos]
lat_pos = (pos[0] + 5, pos[1])
lon_pos = (pos[0], pos[1] + line_spacing)
alt_pos = (pos[0] + 5, pos[1] + (2 * line_spacing))
except Exception as e:
# Set default value based on display type
logging.debug(f"[PwnDroid] Error on_ui_setup: {e}")
lat_pos = (127, 64)
lon_pos = (127, 74)
alt_pos = (127, 84)
if self.options['display']:
if self.options['display_altitude']:
ui.add_element(
"latitude",
LabeledValue(
color=BLACK,
label="lat:",
value="",
position=lat_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
ui.add_element(
"longitude",
LabeledValue(
color=BLACK,
label="long:",
value="",
position=lon_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
ui.add_element(
"altitude",
LabeledValue(
color=BLACK,
label="alt:",
value="",
position=alt_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
else:
ui.add_element(
"latitude",
LabeledValue(
color=BLACK,
label="lat:",
value="",
position=lon_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
ui.add_element(
"longitude",
LabeledValue(
color=BLACK,
label="long:",
value="",
position=alt_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
def on_ui_update(self, ui):
if self.options['display']:
with ui._lock:
if self.coordinates and all([
# avoid 0.000... measurements
self.coordinates["Latitude"], self.coordinates["Longitude"]
]):
ui.set("latitude", f"{self.coordinates['Latitude']} ")
ui.set("longitude", f"{self.coordinates['Longitude']} ")
if self.options['display_altitude']:
ui.set("altitude", f"{self.coordinates['Altitude']:.1f}m ")