forked from itsdarklikehell/pwnagotchi-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheducational-purposes-exclusively.py
391 lines (358 loc) · 13.4 KB
/
educational-purposes-exclusively.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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# educational-purposes-exclusively.py
import os
from pwnagotchi.plugins import Plugin
import logging
import subprocess
import requests
import time
from reportlab.pdfgen import canvas
import datetime
READY = 0
STATUS = ""
NETWORK = ""
CHANNEL = 0
class EducationalPurposesOnly(Plugin):
__GitHub__ = ""
__author__ = "(edited by: itsdarklikehell [email protected]), @nagy_craig , MaliosDark"
__version__ = "1.0.15.2"
__license__ = "GPL3"
__description__ = "A plugin to automatically authenticate to known networks and perform internal network recon"
__name__ = "EducationalPurposesOnly"
__help__ = "A plugin to automatically authenticate to known networks and perform internal network recon"
__dependencies__ = {
"apt": ["none"],
"pip": ["requests"],
}
__defaults__ = {
"enabled": False,
}
def __init__(self):
self.ready = False
logging.debug(f"[{self.__class__.__name__}] plugin init")
self.title = ""
def on_loaded(self):
global READY
logging.info(f"[{self.__class__.__name__}] plugin loaded")
READY = 1
def display_text(self, text):
global STATUS
STATUS = text
def on_ui_update(self, ui):
global STATUS
status_messages = []
if STATUS == "rssi_low":
ui.set("face", "(⊙_☉)")
status_messages.append(
"Signal strength of %s is currently too low to connect ..." % NETWORK
)
status_messages.append(
f'Interface Status: {"Up" if "UP" in os.popen("ifconfig wlan0mon").read() else "Down"}'
)
elif STATUS == "home_detected":
ui.set("face", "(╯°□°)╯︵ ┻━┻")
ui.set("face", "(⚆_⚆)")
status_messages.append("Found home network at %s ..." % NETWORK)
elif STATUS == "switching_mon_off":
ui.set("face", "(◔_◔)")
ui.set("face", "(¬_¬)")
status_messages.append("We're home! Pausing monitor mode ...")
elif STATUS == "scrambling_mac":
ui.set("face", "(¬‿¬)")
status_messages.append(
"Scrambling MAC address before connecting to %s ..." % NETWORK
)
elif STATUS == "associating":
status_messages.append(
"Greeting the AP and asking for an IP via DHCP ...")
ui.set("face", "(¬◡¬ )")
ui.set("face", "( ¬◡¬)")
elif STATUS == "associated":
ui.set("face", "(¬‿¬)")
status_messages.append("Home at last!")
status_messages.append(
f"Connected to {NETWORK} on channel {CHANNEL}.")
current_mac = (
os.popen(
"ifconfig wlan0mon | grep -o -E '([0-9a-fA-F]:?){2,6}'")
.read()
.strip()
)
status_messages.append(f"Current MAC Address: {current_mac}")
status_messages.append("Performing network reconnaissance...")
# Única llamada para actualizar el estado
ui.set("status", "\n".join(status_messages))
def _connect_to_target_network(self, network_name, channel, interface="wlan0mon"):
global READY
global STATUS
global NETWORK
global CHANNEL
NETWORK = network_name
logging.info(
f"sending command to Bettercap to stop using wlan0mon on {interface}..."
)
STATUS = "switching_mon_off"
requests.post(
"http://127.0.0.1:8081/api/session",
data='{"cmd":"wifi.recon off"}',
auth=("pwnagotchi", "pwnagotchi"),
)
logging.info("ensuring all wpa_supplicant processes are terminated...")
subprocess.Popen(
f"systemctl stop wpa_supplicant; killall wpa_supplicant",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(10)
logging.info(f"disabling monitor mode on {interface}...")
subprocess.Popen(
f"modprobe --remove brcmfmac; modprobe brcmfmac",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(10)
# Runs this driver reload command again because sometimes it gets stuck the first time:
subprocess.Popen(
f"modprobe --remove brcmfmac; modprobe brcmfmac",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(10)
logging.info(
f"randomizing {interface} MAC address prior to connecting...")
STATUS = "scrambling_mac"
subprocess.Popen(
f"macchanger -A {interface}",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(10)
logging.info(
f"setting hostname to a ^work dictionary word prior to connecting (for added stealth since their DHCP server will see this name)..."
)
subprocess.Popen(
f'hostnamectl set-hostname $(grep "^work" /usr/share/dict/words | grep -v "s$" | sort -u | shuf -n 1))',
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(5)
logging.info(f"starting up {interface} again...")
subprocess.Popen(
f"ifconfig {interface} up",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(3)
# This command runs multiple times because it sometimes doesn't work the first time:
subprocess.Popen(
f"ifconfig {interface} up",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(10)
logging.info(f"setting {interface} channel to match the target...")
STATUS = "associating"
subprocess.Popen(
f"iwconfig {interface} channel {channel}",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
subprocess.Popen(
f"ifconfig {interface} up",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(10)
logging.info(f"writing to wpa_supplicant.conf file...")
with open("/tmp/wpa_supplicant.conf", "w") as wpa_supplicant_conf:
wpa_supplicant_conf.write(
f'ctrl_interface=DIR=/var/run/wpa_supplicant\nupdate_config=1\ncountry=GB\n\nnetwork={{\n\tssid="%s"\n\tpsk="%s"\n}}\n'
% (network_name, self.options["home-password"])
)
logging.info(
f"starting wpa_supplicant background process on {interface}...")
subprocess.Popen(
f"ifconfig {interface} up",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
subprocess.Popen(
f"wpa_supplicant -u -s -c /tmp/wpa_supplicant.conf -i {interface} &",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(10)
logging.info(f"connecting to wifi on {interface}...")
subprocess.Popen(
f"ifconfig {interface} up",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
subprocess.Popen(
f"wpa_cli -i {interface} reconfigure",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(10)
logging.info(
f"trying to get an IP address on the network via DHCP on {interface}..."
)
subprocess.Popen(
f"dhclient {interface}",
shell=True,
stdin=None,
stdout=open("/dev/null", "w"),
stderr=None,
executable="/bin/bash",
)
time.sleep(10)
# Nueva mejora: Registrar la conexión exitosa
self._log_successful_connection(network_name)
STATUS = "associated"
READY = 1
CHANNEL = channel # Esta línea ya está presente al principio de la función
NETWORK = network_name
logging.info(
f"sending command to Bettercap to stop using wlan0mon on {interface}..."
)
def _restart_monitor_mode(self):
logging.info("Resuming wifi recon and monitor mode...")
# Detener wpa_supplicant
subprocess.run(["systemctl", "stop", "wpa_supplicant"])
subprocess.run(["killall", "wpa_supplicant"])
logging.info("Waiting for wpa_supplicant to stop...")
time.sleep(10)
# Recargar el controlador brcmfmac
subprocess.run(["modprobe", "--remove", "brcmfmac"])
subprocess.run(["modprobe", "brcmfmac"])
logging.info("Reloading brcmfmac driver...")
time.sleep(10)
# Randomizar la dirección MAC de wlan0mon
subprocess.run(["macchanger", "-A", "wlan0mon"])
logging.info("Randomizing MAC address...")
time.sleep(10)
# Activar wlan0mon
subprocess.run(["ifconfig", "wlan0mon", "up"])
logging.info("Activating wlan0mon...")
# Crear la interfaz wlan0mon
subprocess.run(
[
"iw",
"phy",
'$(iw phy | head -1 | cut -d" " -f2)',
"interface",
"add",
"wlan0mon",
"type",
"monitor",
]
)
subprocess.run(["ifconfig", "wlan0mon", "up"])
logging.info("Creating and activating wlan0mon...")
# Resumir wifi recon en Bettercap
requests.post(
"http://127.0.0.1:8081/api/session",
data='{"cmd":"wifi.recon on"}',
auth=("pwnagotchi", "pwnagotchi"),
)
logging.info("Resuming wifi recon in Bettercap...")
logging.info("Wifi recon and monitor mode resumed.")
def on_epoch(self, ui, agent, epoch, total_epochs):
global READY
global STATUS
blinds = epoch["blind"]
# If there are blinds, perform reconnection
if blinds > 0:
logging.info(
f"Detected {blinds} blinds. Reconnecting to wlan0monmon...")
self._restart_monitor_mode()
def on_wifi_update(self, agent, access_points):
global STATUS
home_network = self.options["home-network"]
for network in access_points:
if network["hostname"] == home_network:
signal_strength = network["rssi"]
channel = network["channel"]
logging.info(
"FOUND home network nearby on channel %d (rssi: %d)"
% (channel, signal_strength)
)
if signal_strength >= self.options["minimum-signal-strength"]:
logging.info("Starting association...")
self._connect_to_target_network(
network["hostname"], channel)
else:
logging.info(
"The signal strength is too low (%d) to connect."
% (signal_strength)
)
STATUS = "rssi_low"
def _port_scan(self, target_ip):
open_ports = []
for port in range(1, 1025): # Rango común de puertos
command = f"timeout 1 bash -c 'echo >/dev/tcp/{target_ip}/{port}'"
try:
subprocess.run(command, shell=True, check=True)
open_ports.append(port)
except subprocess.CalledProcessError:
pass
logging.info(f"Open ports on {target_ip}: {open_ports}")
# Función para generar un informe en PDF
def _generate_report(self, file_path, content):
with open(file_path, "w") as pdf_file:
pdf = canvas.Canvas(pdf_file)
pdf.drawString(72, 800, "Informe de Actividades")
pdf.drawString(72, 780, content)
pdf.save()
# Notificaciones avanzadas
def _send_notification(self, message, urgency="normal"):
# Implementa notificaciones avanzadas aquí (por ejemplo, Pushbullet API).
logging.info(f"Sending {urgency} notification: {message}")
# Seguimiento de conexiones exitosas
def _log_successful_connection(self, target_ip):
logging.info(
f"Successfully connected to {target_ip} at {datetime.datetime.now()}"
)
def on_unload(self, ui):
with ui._lock:
logging.info(f"[{self.__class__.__name__}] plugin unloaded")
def on_webhook(self, path, request):
logging.info(f"[{self.__class__.__name__}] webhook pressed")