-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPwnagotchi_Master.py
359 lines (246 loc) · 11.9 KB
/
Pwnagotchi_Master.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
#################################################### Pwnagotchi Master #########################################################
###################################################### By - VixelCode ##########################################################
# Simple python3 proggram to make interactions with your pwnagotchi easier. This is the first program I have written so the code itself could probably be improved, but hey I'm learning and this is an accomplishment for me. If you have any suggestions or input on how to improve any of the coding please feel free to reach out to me on github! I'm always trying to learn new things.
## Pwnagotchi's ip - Default is 10.0.0.2 during setup, but if for some reason you changed it, you can change it here
pwn_ip = '10.0.0.2'
## Pwnagotchi's username - root is needed for handshake file trasnfer. Make sure you have root ssh enabledd on your pwnagotchi!
pwn_uname = 'root'
# Importing modules needed for program
import subprocess
import os
import paramiko
import sys
import logging
import time
import logging
from datetime import date
# Fancy things
print(" ____ _ _ _ _ __ ___ _____ ____ ___ _ _ ____ __ __ __ ___ ____ ____ ____ \n"
"( _ ( \/\/ | \( ) /__\ / __| _ |_ _) __| )_( |_ _) ( \/ ) /__\ / __|_ _| ___| _ \ \n"
" )___/) ( ) ( /(__)( (_-.)(_)( )(( (__ ) _ ( _)(_ ) ( /(__)\\__ \ )( )__) ) / \n"
"(__) (__/\__|_)\_|__)(__)___(_____)(__)\___|_) (_|____) (_/\/\_|__)(__|___/(__)(____|_)\_) \n")
# Getting local machine variables
local_user = os.getlogin()
local_path = os.getcwd()
date = date.today()
# Setting bash script variables
seperate_bash = (local_path +'/scripts/seperate.sh')
ssh_bash = (local_path + '/scripts/ssh.sh')
combine_bash = (local_path + '/scripts/combine.sh')
# Setting path directories on local machine
loot_path = (local_path + '/loot/')
hashcat_loot = (loot_path + 'hashcat/')
backups = (local_path + '/backups/')
# Hashcat setting
run_hashcat = f'hashcat -m22000'
wordlist = '/usr/share/wordlists/rockyou.txt'
# Setting default answer
default_answer = 'y'
# Setting path directories on pwnagotchi
pwn_handshake = '/root/handshakes/'
pwn_config = '/etc/pwnagotchi/config.toml'
# Redefining settings
ip = pwn_ip
username = pwn_uname
################################################################################################################################
# Logging information
logging.basicConfig(filename='logs.log', level=logging.INFO)
################################################################################################################################
# Defining pwnagotchi Interactions
def pwnagotchi_interactions():
print("1 - SSH into pwnagotchi \n""2 - Download all pcap files \n" "3 - Erase all handshakes on pwnagotchi \n" "0 - Back")
inter_choice = input("Enter choice : ")
inter_choice = int(inter_choice)
if inter_choice == 1: # SSH into pwnagotchi
subprocess.call(ssh_bash, shell=True)
pwnagotchi_interactions()
if inter_choice == 2: # Download all pcap files
password =input('Please enter your pwnagotchi password : ')
server_path = pwn_handshake
# Creating SSH connection
ssh = paramiko.SSHClient()
ssh.load_host_keys(os.path.expanduser(os.path.join('~', '.ssh', 'known_hosts')))
ssh.connect(ip, username=username, password=password)
print("Connection Successful \n")
# Open sftp and get file in requested folder
sftp = ssh.open_sftp()
files = sftp.listdir(server_path)
print("Downloading handshakes \n")
# Downloading Files
for file in files:
sftp.get(server_path + file, loot_path + file)
print("Download completed \n")
logging.info(f' Handshakes downloaded {date}')
pwnagotchi_interactions()
if inter_choice == 3: # Delete all handshakes on pwnagotchi
password = input('Please enter your pwnagotchi password : ')
server_path = pwn_handshake
print("WARNING YOUR ABOUT TO DELETE ALL HANDSHAKES ON PWNAGOTCHI - Type y to confirm : ")
response = str(input())
if response == default_answer:
# Creating SSH connection
ssh = paramiko.SSHClient()
ssh.load_host_keys(os.path.expanduser(os.path.join('~', '.ssh', 'known_hosts')))
ssh.connect(ip, username=username, password=password)
print("Connection Successful \n")
# Open sftp and get file in requested folder
sftp = ssh.open_sftp()
files = sftp.listdir(server_path)
print("Erasing handshakes \n")
# Erasing Files
for file in files:
sftp.remove(server_path + file)
print("Erased handshakes from pwnagotchi \n")
logging.info(f' Erased handhakes from pwnagotchi {date}')
pwnagotchi_interactions()
if inter_choice == 0:
main()
elif inter_choice != 1-3:
pwnagotchi_interactions()
################################################################################################################################
# Defining Backup Files
def pwnagotchi_backup():
print("1 - Backup brain.nn & brain.json \n" "2 - Backup config.toml \n" "3 - Download pwnagotchi.log \n" "0 - Back")
bkfl_choice = input("Enter choice : ")
bkfl_choice = int(bkfl_choice)
if bkfl_choice == 1: # Backup brain.nn and brain.json
# Creating SSH connection
password =input('Please enter your pwnagotchi password : ')
ssh = paramiko.SSHClient()
ssh.load_host_keys(os.path.expanduser(os.path.join('~', '.ssh', 'known_hosts')))
ssh.connect(ip, username=username, password=password)
print("Connection Succesful \n")
# Download brain.nn file
server_path = str('/' + '/root/brain.nn')
sftp = ssh.open_sftp()
sftp.get(server_path, str(backups) + "brain.nn")
# Download brain.json file
server_path = str('/' + '/root/brain.json')
sftp = ssh.open_sftp()
sftp.get(server_path, str(backups) + "brain.json")
print("brain.nn & brain.json downloaded \n")
logging.info(f' Downloaded brain.nn & brain.josn {date}')
pwnagotchi_backup()
if bkfl_choice == 2: # Download config.toml
server_path = pwn_config
# Creating SSH connection
password =input('Please enter your pwnagotchi password : ')
ssh = paramiko.SSHClient()
ssh.load_host_keys(os.path.expanduser(os.path.join('~', '.ssh', 'known_hosts')))
ssh.connect(ip, username=username, password=password)
print("Connection Succesful \n")
# Download config.toml file
sftp = ssh.open_sftp()
sftp.get(server_path, str(backups) + "config.toml")
print("Downloaded config.toml \n")
logging.info(f' Downoaded config.toml {date}')
pwnagotchi_backup()
if bkfl_choice == 3: # Download pwnagotchi.log
server_path = pwn_config
# Creating SSH connection
password =input('Please enter your pwnagotchi password : ')
ssh = paramiko.SSHClient()
ssh.load_host_keys(os.path.expanduser(os.path.join('~', '.ssh', 'known_hosts')))
ssh.connect(ip, username=username, password=password)
print("Connection Succesful \n")
# Download pwnagotchi file
sftp = ssh.open_sftp()
sftp.get(server_path, str(backups) + "pwnagotchi.log")
print("Downloaded pwnagotchi log \n")
logging.info(f' Pwnagotchi.log downloaded {date}')
pwnagotchi_backup()
if bkfl_choice == 0:
main()
elif bkfl_choice != 1-3:
pwnagotchi_backup()
################################################################################################################################
# Defining pwnagotchi setup
def pwnagotchi_setup():
print("1 - Upload backup config.toml file \n" "0 - Back")
stup_choice = input("Enter your choice : ")
stup_choice = int(stup_choice)
if stup_choice == 1:
server_path = pwn_config
# Creating SSH connection
password =input('Please enter your pwnagotchi password : ')
ssh = paramiko.SSHClient()
ssh.load_host_keys(os.path.expanduser(os.path.join('~', '.ssh', 'known_hosts')))
ssh.connect(ip, username=username, password=password)
print("Connection Succesful \n")
# Uploading config.toml file
config_toml = backups + 'config.toml'
print("\n")
sftp = ssh.open_sftp()
sftp.put(config_toml, server_path)
print("Uploaded config.toml \n")
logging.info(f'config.toml file uploaded {date}')
pwnagotchi_setup()
if stup_choice == 0:
main()
elif stup_choice != 1:
pwnagotchi_setup()
################################################################################################################################
def handshake_interactions():
print("1 - Seperate valid handshakes \n" "2 - Hashcat \n" "3 - Copy and paste to whitelist \n" "0 - Back")
hndske_choice = input("Enter choice : ")
hndske_choice = int(hndske_choice)
if hndske_choice == 1: # Seperating pcap files with good handshakes
subprocess.call(['bash', seperate_bash, loot_path])
subprocess.call(['bash', combine_bash, hashcat_loot])
logging.info(f' Seperated valid handshakes {date}')
print("Seperated valid handshake files \n")
handshake_interactions()
if hndske_choice == 2: # List files in the hashcat folder and asking for user input for which one to run hashcat against
valid_hashcat = os.listdir(hashcat_loot)
hashcat_log = valid_hashcat.index('hashcat.log')
valid_hashcat.pop(hashcat_log)
for handshake in valid_hashcat:
print(f'{valid_hashcat.index(handshake)} : {handshake}')
hashcat_file = int(input("Select a network : "))
hashcat_file_name = valid_hashcat[hashcat_file]
os.system(f'{run_hashcat} {hashcat_loot}{hashcat_file_name} {wordlist}')
if hndske_choice == 3: # Copy and paste for whitelist on pwnagotchi
print("Below network names are all the networks you have a valid handshake for ready to pasted into your config.toml file. \n")
valid_handshakes = os.listdir(hashcat_loot)
if len(valid_handshakes) == 0:
print("No valid handshakes, get out there and capture some! \n")
handshake_interactions()
if "combined.hc22000" in valid_handshakes :
valid_handshakes.remove("combined.hc22000")
if "hashcat.log" in valid_handshakes :
valid_handshakes.remove("hashcat.log")
if valid_handshakes == 0 :
print("No valid handshakes, get out there and capture some! \n")
for file in valid_handshakes :
split_hndske = ()
split_hndske = file.split("_")
if len(split_hndske) ==2:
split_hndske.pop(1)
for file in split_hndske :
print('"' + file + '",')
print("\n")
if hndske_choice == 0:
main()
elif hndske_choice != 1-3:
handshake_interactions()
################################################################################################################################
# Main Menu
def main():
print("1 - Pwnagotchi Interactions \n" "2 - Backup Files \n" "3 - Pwnagotchi Setup \n" "4 - Handshake Interactions \n" "0 - Exit \n")
choice = input("Enter choice : ")
choice = int(choice)
options = [1, 2, 0]
if choice == 1:
pwnagotchi_interactions()
if choice == 2:
pwnagotchi_backup()
if choice == 3:
pwnagotchi_setup()
if choice == 4:
handshake_interactions()
if choice == 0:
print("Happy Hunting! \n")
exit()
elif choice != 1-4:
main()
main()