-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcrack
executable file
·783 lines (742 loc) · 39.3 KB
/
crack
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
#!/usr/bin/env bash
# Script: crack
# Version 2.20
# Date: 22 oct 2020
# Modified: 26 oct 2022 (added grep -E in place of egrep)
# Revision: 09 mar 2023 v 2.30
# - removed hashcat --hwmon-temp-abort 80 parameter
# - code verified using shellcheck and some bugs fixed
# - added vendor OUI name
# Author: mnemonic AKA semeion
# Description: Automate the handshake cracking process
# dependencies: john (with jumbo rules), aircrack-ng, less, hcxtools, hashcat
# Ref: https://miloserdov.org/?p=1047&PageSpeed=noscript
# https://stackoverflow.com/questions/32042997/bash-until-loop-true-when-condition-returns-anything
# john --wordlist=wordlists/carros.txt --rules=single --stdout:63 | hashcat --hash-type 22000 handshakes/94\:46\:96\:80\:5A\:64.22000 --outfile outfile.test --workload-profile 4 --hwmon-temp-abort 80
shopt -s extglob
# Check dependencies
# hcxpcaptool
dependencies=(john aircrack-ng hcxpcapngtool hashcat less xterm grep sha1sum wc cut tr awk sudo)
for c in "${dependencies[@]}"; do
if ! type "$c" &>/dev/null; then
echo "${c}: command not found"
exit 1
fi
done
# Check CUDA/OpenCL
# hashcat -I &>/dev/null
# c=$?
# if [[ $c != 0 ]]; then
# echo "Hashcat Error ${c}: No OpenCL-compatible or CUDA-compatible platform found."
# exit $c
# fi
home="$(eval echo ~"${SUDO_USER}")"
[[ ! -d "$home/.john" ]] && mkdir -p "$home/.john" &>/dev/null
if [ -f "/etc/john/john.conf.custom" ]; then
if [ ! -f "$home/.john/john.conf.backup" ]; then
if cp "$home/.john/john.conf" "$home/.john/john.conf.backup" &>/dev/null; then
echo "$home/.john/john.conf saved to $home/.john/john.conf.backup"
fi
cp "/etc/john/john.conf.custom" "$home/.john/john.conf" &>/dev/null
fi
else
echo "/etc/john/john.conf.custom not found"
exit 1
fi
[[ "$PATH" =~ $PWD ]] || export PATH=$PATH:$PWD
configdir="${home}/.config/handshake-cracker"
[[ ! -d "$configdir" ]] && mkdir -p "$configdir" &>/dev/null
configfile="$configdir/scripts.conf"
if [ ! -f "$configfile" ]; then
echo "\
handshakes_dir=${configdir}/handshakes # Handshakes directory - used by crack
sessions_dir=${configdir}/crack-sessions # Script work directory - used by crack
wordlist_dir=${configdir}/wordlists # Directory to save wordlists - used by wordlist
wordlist=${configdir}/wordlists/wordlist.dic # Password file - used by crack/wordlist
maxlength=63 # Max length (63) of words to be used from wordlist - used by crack
john_incr=Digits8 # John incremental mode to be used - used by crack
john_rules=(Wordlist Single Extra MyCustom MyCustom1 MyCustom2 MyExtra MyExtra2 MyExtra3 NT OldOffice) # John rules to be used - used by crack
deauth_time=3 # Tries to Deauth Clients Quickly - used by handshake" >"$configfile"
fi
# check if the file contains something we don't want
configfile_secured='/tmp/handshake-cracker-secured-scripts.conf'
if grep -E -q -v '^#|^[^ ]*=[^;]*' "$configfile"; then
echo "Config file is unclean, cleaning it..." >&2
# filter the original to a new file
grep -E '^#|^[^ ]*=[^;&]*' "$configfile" > "$configfile_secured"
configfile="$configfile_secured"
fi
# now source it, either the original or the filtered variant
# shellcheck source=/dev/null # to ignore the error
source "$configfile"
shopt -s nullglob
handshake_files=("$handshakes_dir"/*)
shopt -u nullglob
cpus=$(grep -c ^processor /proc/cpuinfo)
# shellcheck disable=SC2034
tempdir="/tmp"
#white="\033[1;37m"
#grey="\033[0;37m"
red="\033[1;31m"
green="\033[1;32m"
yellow="\033[1;33m"
#blue="\033[1;34m"
cyan="\033[0;36m"
#cafe="\033[0;33m"
#fiuscha="\033[0;35m"
transparent="\e[0m"
#VENTSCAN="-geometry 95x56-0+0"
#VENTHAND="-geometry 95x20-0+0"
#VENTDEAU="-geometry 80x20-0-30"
#WINDOWCRACK="-geometry 80x21-0+0"
# shellcheck disable=SC2154
if [ ! -d "$sessions_dir" ]; then mkdir -p "$sessions_dir" &>/dev/null; fi # Create script work directory
# Usage: if confirm "Are you sure? "; then ...
confirm() { local ans IFS=; while read -rp "$1" -n1 ans; do printf '\n'; case $ans in [Yy]) return 0;; ''|[Nn]) return 1;; esac; done; };
function top {
#~ echo -en "\e[3J"
echo
echo -e "##########################################################"
echo -e "# #"
echo -e "# PASSWORD CRACKER 2.30 by mnemonic #"
echo -e "# #"
echo -e "##########################################################"
echo
}
function show_time {
local secs="$1"
echo "$secs" | awk '{printf "%d:%02d:%02d:%02d\n",$0/86400,$0%86400/3600,$0%3600/60,$0%60}'
}
function get_rule {
local i
if [ -f "${sessions_dir}/${bssid}.rule" ]; then
i=$(<"${sessions_dir}/${bssid}.rule")
else
i=0
fi
# shellcheck disable=SC2154
if ((i<${#john_rules[@]})); then
echo "${john_rules[$i]}"
fi
}
function hex2string () {
I=0
while [ $I -lt ${#1} ];
do
echo -en "\x""${1:$I:2}"
((I += 2))
done
}
function session {
local fname="$1"
local ext="$2"
local rule bssid essid aircrack_output encryption workload cracked status cores msg_opt john_status total tested elapsed_porcent elapsed_time elapsed_secs necessary_secs remaining_secs
if [[ "${ext}" =~ ^(22000)$ ]]; then
aircrack_output=$(aircrack-ng "${handshakes_dir}/${fname}.cap" 2>&1)
bssid=$(echo "${aircrack_output}" | grep -P "([A-F0-9]{2}:){5}[A-F0-9]{2}" | grep -e "WPA ([0-9] handshake" | awk -F ' ' '{print $2}')
essid=$(echo "${aircrack_output}" | grep -e "${bssid}" | grep -e "WPA ([0-9] handshake" | grep -Po "(?<=(${bssid} )).*(?= WPA \()")
encryption="WPA-PBKDF2-PMKID+EAPOL"
fi
if [[ "${ext}" =~ ^(cap|hccapx)$ ]]; then
aircrack_output=$(aircrack-ng "${handshakes_dir}/${fname}.${ext}" 2>&1)
bssid=$(echo "${aircrack_output}" | grep -P "([A-F0-9]{2}:){5}[A-F0-9]{2}" | grep -e "WPA ([0-9] handshake" | awk -F ' ' '{print $2}')
essid=$(echo "${aircrack_output}" | grep -e "${bssid}" | grep -e "WPA ([0-9] handshake" | grep -Po "(?<=(${bssid} )).*(?= WPA \()")
encryption=$(echo "${aircrack_output}" | grep -P "([A-F0-9]{2}:){5}[A-F0-9]{2}" | grep -oe "WPA (.*)$")
fi
if [[ "${ext}" =~ ^(PMKID|pmkid)$ ]]; then
bssid=$(awk -F '*' 'NR==1 {print $2}' "${handshakes_dir}/${fname}.${ext}" | sed -e 's/\([0-9A-Fa-f]\{2\}\)/\1:/g' -e 's/\(.*\):$/\1/' | tr '[:lower:]' '[:upper:]')
essid=$(awk -F '*' 'NR==1 {print $4}' "${handshakes_dir}/${fname}.${ext}" | tr '[:lower:]' '[:upper:]')
essid=$(hex2string "${essid}")
encryption="$(< "${handshakes_dir}/${fname}.${ext}" wc -l) PMKID(s)"
fi
if [[ "${ext}" =~ ^(JOHN|john)$ ]]; then
bssid=$(awk -F ':' 'NR==1 {print $5}' "${handshakes_dir}/${fname}.${ext}" | sed -e 's/\([0-9A-Fa-f]\{2\}\)/\1:/g' -e 's/\(.*\):$/\1/' | tr '[:lower:]' '[:upper:]')
essid=$(awk -F ':' 'NR==1 {print $1}' "${handshakes_dir}/${fname}.${ext}")
encryption=$(awk -F ':' 'NR==1 {print $7,$8}' "${handshakes_dir}/${fname}.${ext}")
fi
while true; do
clear
top
rule=$(get_rule)
if [ -f "${sessions_dir}/${bssid}.cracked" ]; then
cracked="[ ${green}$(<"${sessions_dir}/${bssid}.cracked")${transparent} ]"
else
cracked="${red}NO${transparent}"
fi
if is_running "${bssid}"; then
# shellcheck disable=2009
cores=$(ps -ef | grep -Ev 'sh -c|grep|xterm' | grep "[0-9][0-9]:[0-9][0-9]:[0-9][0-9] aircrack-ng -p .*${bssid}.cap$" | awk '{ print $10 }')
if [ -z "$cores" ]; then
cores=$(nvidia-smi -i 0 --query-gpu=utilization.gpu --format=csv,noheader | tr -d ' ')
cores="GPU ${cores}"
else
cores="CPU ${cores} cores"
fi
status="${green}RUNNING${transparent} (${cores})"
msg_opt="top"
else
status="${red}STOPPED${transparent}"
cores="0"
msg_opt="tart"
fi
# shellcheck disable=SC2154
rule="$john_incr"
if [ -f "${sessions_dir}/${bssid}.rule" ]; then
n=$(<"${sessions_dir}/${bssid}.rule")
if ((n<${#john_rules[@]})); then
rule="${john_rules[$n]}"
fi
fi
total=0
if [ -f "${sessions_dir}/${bssid}.rec" ]; then
john_status="$(john --status="${sessions_dir}/${bssid}" 2>&1)"
tested=$(echo "$john_status" | cut -d'p' -f1)
if [ -f "${sessions_dir}/${bssid}.rule" ]; then
if [ -f "${sessions_dir}/${bssid}.dic.total" ]; then
total="$(<"${sessions_dir}/${bssid}.dic.total")"
else
total=0
fi
else
rule="$john_incr"
case "$rule" in
Digits8) total=100000000 ;;
Digits9) total=1100000000 ;;
Digits10) total=11000000000 ;;
esac
fi
if [ "$total" -gt 0 ]; then
elapsed_porcent=$(echo -e "${tested}\t${total}" | awk '{print $1 / $2 * 100}' 2>&1)
elapsed_time=$(echo "${john_status}" | awk '{ print $2 }')
IFS=: read -r _dd _hh _mm _ss<<<"$elapsed_time"
elapsed_secs=$(echo "$elapsed_time" | awk -F: '{print 86400*$1+3600*$2+60*$3+$4}' 2>&1)
necessary_secs=$(echo "$elapsed_secs $elapsed_porcent" | awk '{ print $1/$2*100 }' 2>&1)
remaining_secs=$(echo "$necessary_secs $elapsed_secs" | awk '{ print $1-$2 }' 2>&1)
fi
fi
# Check if wordlist was modified
# shellcheck disable=SC2154
if [ -f "${wordlist}" ]; then
wlst="$(basename "${wordlist}")"
[ -f "${sessions_dir}/${bssid}.sha1sum" ] && saved_hash=$(<"${sessions_dir}/${bssid}.sha1sum") || saved_hash=0
dict_hash=$(sha1sum "${wordlist}")
if [ "$saved_hash" != "$dict_hash" ]; then
wlst="$(basename "${wordlist}") (${green}NEW WORDS FOUND${transparent})"
fi
else
wlst="${red}NONE${transparent} (update or set a wordlist)"
fi
if [ ! "$fname" == "$bssid" ]; then
echo -e " ${cyan}Filename${transparent} : ${fname}.${ext}"
fi
echo -e " ${cyan}BSSID${transparent} : ${bssid}"
[ -e "${configdir}"/oui.txt ] && \
echo -e " ${cyan}Vendor${transparent} : $(grep -Fi "${bssid:0:8}" "${configdir}"/oui.txt | cut -c 11- | tr -d '\n\r')"
echo -e " ${cyan}ESSID${transparent} : ${essid}"
echo -e " ${cyan}ESSID${transparent} : ${essid}"
echo -e " ${cyan}Format${transparent} : ${ext}"
echo -e " ${cyan}Encryption${transparent} : ${encryption}"
echo -e " ${cyan}Status${transparent} : ${status}"
echo -e " ${cyan}Cracked${transparent} : ${cracked}"
echo -e " ${cyan}John Rule${transparent} : ${rule}"
if [ "$total" -gt 0 ]; then
if [ "$rule" == "$john_incr" ]; then
echo -e " ${cyan}Wordlist${transparent} : Incremental"
else
echo -e " ${cyan}Wordlist${transparent} : ${wlst}"
echo -e " ${cyan}Max length${transparent} : ${yellow}${maxlength}${transparent}"
fi
echo -e " ${cyan}Session total words${transparent} : $(printf "%'.f\n" "${total}")"
echo -e " ${cyan}Session tested words${transparent} : $(printf "%'.f\n" "${tested}") ( ${yellow}${elapsed_porcent}%${transparent} )"
echo -e " ${cyan}Session total (D:H:M:S)${transparent} : $(show_time "${necessary_secs}")"
echo -e "${cyan}Time remaining (D:H:M:S)${transparent} : ${yellow}$(show_time "${remaining_secs}")${transparent}"
fi
if [ -f "${sessions_dir}/${bssid}.rec" ]; then
echo -e " ${cyan}Time spent (D:H:M:S)${transparent} : $(echo "${john_status}" | awk '{ print $2 }')"
fi
echo
if [[ "${ext}" == "cap" ]]; then
echo -ne "[${yellow}H${transparent}]ashcat (22000) "
fi
echo -e "[${yellow}D${transparent}]elete file"
echo -e "[${yellow}S${transparent}]${msg_opt} session [${yellow}N${transparent}]ext session [${yellow}R${transparent}]eset session"
echo -ne "[${yellow}V${transparent}]iew current [${yellow}C${transparent}]ompleted s[${yellow}T${transparent}]atistics [${yellow}B${transparent}]ack): "
read -r -n 1 choice
echo
case "$choice" in
h|H)
if [ ! -f "${handshakes_dir}/${bssid}.22000" ] || confirm "The file already exist. OVERWRITE? (y/N): "; then
rm -f "${handshakes_dir}/${bssid}.22000"
hcxpcapngtool -E essidlist -I identitylist -U usernamelist -o "${handshakes_dir}/${bssid}.22000" "${handshakes_dir}/${bssid}.cap"
shopt -s nullglob
handshake_files=("$handshakes_dir"/*)
shopt -u nullglob
fi
;;
d|D)
if confirm "DELETE this BSSID and all related files? (y/N): "; then
rm -f "${handshakes_dir:?}/${bssid:?}.*"
rm -f "${sessions_dir:?}/${bssid:?}.*"
shopt -s nullglob
handshake_files=("$handshakes_dir"/*)
shopt -u nullglob
break
fi
;;
s|S)
if is_running "${bssid}"; then
stop "${bssid}"
else
if [ -f "${sessions_dir}/${bssid}.cracked" ]; then
echo -ne "The handshake was cracked in last process. Password found: ${cracked} "
read -r -n1 choice
else
if [ -f "${wordlist}" ]; then
case "${ext}" in
22000|hccapx|PMKID|pmkid)
workload=0
while (( workload < 1 || workload > 4 )); do
echo -ne "${yellow}Hashcat workload-profile to use (${transparent}${yellow}1${transparent}-${yellow}4${transparent}): "
read -r -n 1 workload
echo
done
crack_handshake "${bssid}" "${ext}" "${workload}" &
sleep 3
;;
cap)
cores=0
while (( cores < 1 || cores > cpus )); do
echo -ne "${yellow}Number of CPU cores to use (${transparent}${yellow}1${transparent}-${yellow}${cpus}${transparent}): "
read -r -n 1 cores
echo
done
crack_handshake "${bssid}" "${ext}" "${cores}" &
sleep 3
;;
john)
cores=1
crack_handshake "${bssid}" "${ext}" "${cores}" &
sleep 3
;;
esac
#~ if [[ "${ext}" =~ ^(hccapx|PMKID|pmkid)$ ]]; then
#~ workload=0
#~ while (( workload < 1 || workload > 4 )); do
#~ echo -ne "${yellow}Hashcat workload-profile to use (${transparent}${yellow}1${transparent}-${yellow}4${transparent}): "
#~ read -n 1 workload
#~ echo
#~ done
#~ crack_handshake "${bssid}" "${ext}" "${workload}" &
#~ sleep 3
#~ else
#~ cores=0
#~ while (( cores < 1 || cores > cpus )); do
#~ echo -ne "${yellow}Number of CPU cores to use (${transparent}${yellow}1${transparent}-${yellow}${cpus}${transparent}): "
#~ read -n 1 cores
#~ echo
#~ done
#~ crack_handshake "${bssid}" "${ext}" "${cores}" &
#~ sleep 3
#~ fi
else
echo
echo "[U]pdate your wordlist first! The cracking process need a wordlist!"
echo "${wordlist} informed does not exist!"
echo "If you want to use a specific wordlist, set this in:"
echo "${configfile}"
echo
echo -ne "Press a key to return "
read -r -n1 choice
fi
fi
fi
;;
v|V)
if [ -f "${sessions_dir}/${bssid}.dic" ]; then
less "${sessions_dir}/${bssid}.dic"
else
echo
echo "No wordlist session was started."
echo
echo -ne "Press a key to return "
read -r -n1 choice
fi
;;
c|C)
for i in "${john_rules[@]}"; do
if [ -f "${sessions_dir}/${bssid}.${i}.tested" ]; then
echo "------------------------------------ Rule: $i"
cat "${sessions_dir}/${bssid}.${i}.tested"
fi
done | less
;;
n|N)
if is_running "${bssid}"; then
if confirm "Do you want to cancel the current session and go to the next one? (y/N): "; then
if confirm "You will lose the current time spent. Are you sure? (y/N): "; then
# shellcheck disable=2009
cores=$(ps -ef | grep -Ev 'sh -c|grep|xterm' | grep "[0-9][0-9]:[0-9][0-9]:[0-9][0-9] aircrack-ng -p .*${bssid}.cap$" | awk '{ print $10 }')
stop "${bssid}"
rm -f "${sessions_dir}/${bssid}.rec"
rm -f "${sessions_dir}/${bssid}.dic"
rm -f "${sessions_dir}/${bssid}.dic.total"
case "${ext}" in
22000|hccapx|PMKID|pmkid)
workload=0
while (( workload < 1 || workload > 4 )); do
echo -ne "${yellow}Hashcat workload-profile to use (${transparent}${yellow}1${transparent}-${yellow}4${transparent}): "
read -r -n 1 workload
echo
done
crack_handshake "${bssid}" "${ext}" "${workload}" &
sleep 3
;;
cap)
crack_handshake "${bssid}" "${ext}" "${cores}" &
sleep 3
;;
john)
cores=1
crack_handshake "${bssid}" "${ext}" "${cores}" &
sleep 3
esac
#~ if [[ "${ext}" =~ ^(hccapx|PMKID|pmkid)$ ]]; then
#~ workload=0
#~ while (( workload < 1 || workload > 4 )); do
#~ echo -ne "${yellow}Hashcat workload-profile to use (${transparent}${yellow}1${transparent}-${yellow}4${transparent}): "
#~ read -n 1 workload
#~ echo
#~ done
#~ crack_handshake "${bssid}" "${ext}" "${workload}" &
#~ sleep 3
#~ else
#~ crack_handshake "${bssid}" "${cores}" &
#~ sleep 3
#~ fi
fi
fi
else
echo
echo "No session started yet."
echo
echo -ne "Press a key to return "
read -r -n1 choice
fi
;;
r|R)
if [ -f "${sessions_dir}/${bssid}.rec" ]; then
if confirm "Do you want to cancel current session and restart to incremental mode? (y/N): "; then
if confirm "You will lose the current session time spent. Are you sure? (y/N): "; then
if is_running "${bssid}"; then
stop "${bssid}"
fi
rm -f "${sessions_dir}/${bssid}.${john_incr}.tested"
rm -f "${sessions_dir}/${bssid}.rec"
rm -f "${sessions_dir}/${bssid}.dic"
rm -f "${sessions_dir}/${bssid}.dic.total"
rm -f "${sessions_dir}/${bssid}.session"
rm -f "${sessions_dir}/${bssid}.rule"
fi
fi
else
rm -f "${sessions_dir}/${bssid}.${john_incr}.tested"
rm -f "${sessions_dir}/${bssid}.rec"
rm -f "${sessions_dir}/${bssid}.dic"
rm -f "${sessions_dir}/${bssid}.dic.total"
rm -f "${sessions_dir}/${bssid}.session"
rm -f "${sessions_dir}/${bssid}.rule"
echo
echo "Sessions restarted."
echo
echo -ne "Press a key to return "
read -r -n1 choice
fi
;;
t|T)
if [ ! -f "${sessions_dir}/${bssid}.dic.total" ]; then
statistics "${bssid}"
else
echo "Statistics is already being performed for this session!"
echo "Press a key to return"
read -r -n1 choice
fi
;;
b|B|q|Q)
break
;;
esac
done
}
function print {
local size=$1
local length=${#2}
[ "$length" -gt "$size" ] && length="${size}"
local spaces=$(( "$size" - "$length" ))
printf "%.${size}s" "${2}"
# shellcheck disable=SC2046
printf " %.0s" $(eval "echo {0.."$((spaces))"}");
}
function select_handshake {
local status n rule cracked cores
while true; do
clear
top
echo "NR. BSSID FORMAT STATUS JOHN RULE CRAKED ESSID ENCRYPTION/CONTENT"
echo "---- ----------------- ------ ------- --------------- ------ ----------------- ------------------------------"
for ((i=0; i<${#handshake_files[@]}; i++)); do
# load handshakes
extension[i]="${handshake_files[$i]##*.}"
filename[i]="${handshake_files[$i]##*/}"
filename[i]="${filename[$i]%.*}"
if [[ "${extension[$i]}" =~ ^(cap|hccapx)$ ]]; then
aircrack_output=$(aircrack-ng "${handshake_files[$i]}" 2>&1)
bssid[i]=$(echo "${aircrack_output}" | grep -P "([A-F0-9]{2}:){5}[A-F0-9]{2}" | grep -e "WPA ([0-9] handshake" | awk -F ' ' '{print $2}')
essid[i]=$(echo "${aircrack_output}" | grep -e "${bssid[$i]}" | grep -e "WPA ([0-9] handshake" | grep -Po "(?<=(${bssid[$i]} )).*(?= WPA \()")
encryption[i]=$(echo "${aircrack_output}" | grep -P "([A-F0-9]{2}:){5}[A-F0-9]{2}" | grep -oe "WPA (.*)$")
fi
if [[ "${extension[$i]}" =~ ^(22000)$ ]]; then
aircrack_output=$(aircrack-ng "${handshakes_dir}/${filename[$i]}.cap" 2>&1)
bssid[i]=$(echo "${aircrack_output}" | grep -P "([A-F0-9]{2}:){5}[A-F0-9]{2}" | grep -e "WPA ([0-9] handshake" | awk -F ' ' '{print $2}')
essid[i]=$(echo "${aircrack_output}" | grep -e "${bssid[$i]}" | grep -e "WPA ([0-9] handshake" | grep -Po "(?<=(${bssid[$i]} )).*(?= WPA \()")
encryption[i]="WPA-PBKDF2-PMKID+EAPOL"
fi
if [[ "${extension[$i]}" =~ ^(PMKID|pmkid)$ ]]; then
bssid[i]=$(awk -F '*' 'NR==1 {print $2}' "${handshake_files[$i]}" | sed -e 's/\([0-9A-Fa-f]\{2\}\)/\1:/g' -e 's/\(.*\):$/\1/' | tr '[:lower:]' '[:upper:]')
essid[i]=$(awk -F '*' 'NR==1 {print $4}' "${handshake_files[$i]}" | tr '[:lower:]' '[:upper:]')
essid[i]=$(hex2string "${essid[$i]}")
encryption[i]="$(<"${handshake_files[$i]}" wc -l) PMKID(s)"
fi
if [[ "${extension[$i]}" =~ ^(JOHN|john)$ ]]; then
bssid[i]=$(awk -F ':' 'NR==1 {print $5}' "${handshake_files[$i]}" | sed -e 's/\([0-9A-Fa-f]\{2\}\)/\1:/g' -e 's/\(.*\):$/\1/' | tr '[:lower:]' '[:upper:]')
essid[i]=$(awk -F ':' 'NR==1 {print $1}' "${handshake_files[$i]}")
encryption[i]=$(awk -F ':' 'NR==1 {print $7,$8}' "${handshake_files[$i]}")
fi
if [[ "${extension[$i]}" =~ ^(cap|22000|hccapx|PMKID|pmkid|JOHN|john)$ ]]; then
rule="$john_incr"
if [ -f "${sessions_dir}/${bssid[$i]}.rule" ]; then
n=$(<"${sessions_dir}/${bssid[$i]}.rule")
if ((n<${#john_rules[@]})); then
rule="${john_rules[$n]}"
fi
fi
if [ -f "${sessions_dir}/${bssid[$i]}.cracked" ]; then
cracked="YES"
else
cracked="NO"
fi
if is_running "${bssid[$i]}"; then
status="RUNNING"
else
status="STOPPED"
fi
print 4 "[$((i+1))]"
print 17 "${bssid[$i]}"
echo -ne " "
print 6 "${extension[$i]}"
echo -ne " "
print 7 "${status}"
echo -ne " "
print 15 "${rule}"
print 3 "${cracked}"
echo -ne " "
print 17 "${essid[$i]}"
print 29 "${encryption[$i]}"
echo
fi
done
echo
echo -ne "[${yellow}C${transparent}]apture handshake [${yellow}U${transparent}]pdate wordlist [${yellow}Q${transparent}]uit): "
read -r choice
case "$choice" in
+([0-9]))
if (( choice > 0 && choice <= ${#handshake_files[@]} )); then
choice=$((choice-1))
session "${filename[$choice]}" "${extension[$choice]}"
else
select_handshake
fi
;;
c|C)
echo -n " "
sudo handshake
shopt -s nullglob
handshake_files=("$handshakes_dir"/*)
shopt -u nullglob
;;
u|U)
wordlist --get
wordlist --makediff
if confirm "Want to see the new words? (y/N): "; then
less "${wordlist}.diff"
fi
if confirm "Want to add to the wordlist? (y/N): "; then
wordlist --add
fi
echo "Press a key to return"
read -r -n1 choice
;;
q|Q)
exit
;;
esac
done
}
function is_running {
local bssid john_pid
bssid="$1"
# shellcheck disable=2009
john_pid=$(ps -ef | grep -Ev 'sh -c|grep|xterm' | grep "[0-9][0-9]:[0-9][0-9]:[0-9][0-9] john --.*${bssid}" | awk '{ print $2 }')
if [ "${john_pid}" ]; then
return 0
else
return 1
fi
}
function stop {
local bssid john_pid
bssid="$1"
# shellcheck disable=2009
john_pid=$(ps -ef | grep -Ev 'sh -c|grep|xterm' | grep "[0-9][0-9]:[0-9][0-9]:[0-9][0-9] john --.*${bssid}" | awk '{ print $2 }')
while [ "${john_pid}" ]; do
rm -f "${sessions_dir}/${bssid}.run"
kill -INT "${john_pid}"
sleep 1
# shellcheck disable=2009
john_pid=$(ps -ef | grep -Ev 'sh -c|grep|xterm' | grep "[0-9][0-9]:[0-9][0-9]:[0-9][0-9] john --.*${bssid}" | awk '{ print $2 }')
done
}
function crack_handshake {
local bssid="$1"
local ext="$2"
local cores="$3"
local i=-1
local rule dic
if [[ "${ext}" =~ ^(22000|hccapx|PMKID|pmkid)$ ]]; then
if pgrep -x hashcat; then
exit 1
fi
fi
# Verify BSSID consistence, number of CPU cores, and if the process already running
if [[ ! "$bssid" =~ ^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$ ]] || (( cores < 1 || cores > cpus )) || is_running "${bssid}"; then
exit 1
fi
local biggest
biggest=$(wc -L "${wordlist}" | cut -d' ' -f1) # biggest word in wordlist
if (( maxlength > biggest )); then
maxlength="${biggest}"
fi
rule=$(get_rule)
echo -n >"${sessions_dir}/${bssid}.run"
while ((i<${#john_rules[@]})) && [ ! -f "${sessions_dir}/${bssid}.cracked" ] && [ -f "${sessions_dir}/${bssid}.run" ]; do
#~ xterm_pid=$(wmctrl -lp | grep "Cracking ${bssid}" | awk '{ print $3 }')
if ! is_running "${bssid}"; then
# if .rec exist resume previous john crack session
# (hashcat option --advice-disable can be added)
if [ -f "${sessions_dir}/${bssid}.rec" ]; then
case "${ext}" in
cap ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --restore=${sessions_dir}/${bssid} | aircrack-ng -p ${cores} -w - -b ${bssid} -l ${sessions_dir}/${bssid}.cracked ${handshakes_dir}/${bssid}.cap" ;;
22000 ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --restore=${sessions_dir}/${bssid} | hashcat --hash-type 22000 ${handshakes_dir}/${bssid}.22000 --outfile ${sessions_dir}/${bssid}.cracked --workload-profile ${cores}" ;;
hccapx ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --restore=${sessions_dir}/${bssid} | hashcat --hash-type 2500 ${handshakes_dir}/${bssid}.hccapx --outfile ${sessions_dir}/${bssid}.cracked --workload-profile ${cores}" ;;
PMKID|pmkid ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --restore=${sessions_dir}/${bssid} | hashcat --hash-type 16800 ${handshakes_dir}/${bssid}.PMKID --outfile ${sessions_dir}/${bssid}.cracked --workload-profile ${cores}" ;;
JOHN|john ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --restore=${sessions_dir}/${bssid}" ;;
esac
else
# if ${john_incr}.tested exist incremental is completed
if [ -f "${sessions_dir}/${bssid}.${john_incr}.tested" ]; then
# Add tested words to *.tested file, Create new dictionary, Step to next rule/crack session
if [ -f "${sessions_dir}/${bssid}.dic" ]; then
cat "${sessions_dir}/${bssid}.dic" >>"${sessions_dir}/${bssid}.${rule}.tested" # Add tested passwords to *.tested file
rm -f "${sessions_dir}/${bssid}.dic"
rm -f "${sessions_dir}/${bssid}.dic.total"
fi
# Get wordlist sha1sum
if [ ! -f "${sessions_dir}/${bssid}.sha1sum" ]; then
sha1sum "${wordlist}" >"${sessions_dir}/${bssid}.sha1sum"
fi
# if wordlist was modified restart from the first rule
saved_hash=$(<"${sessions_dir}/${bssid}.sha1sum")
dict_hash=$(sha1sum "${wordlist}")
if [ "$saved_hash" != "$dict_hash" ]; then
sha1sum "${wordlist}" >"${sessions_dir}/${bssid}.sha1sum"
rm -f "${sessions_dir}/${bssid}.rule"
fi
# Go to next rule
if [ -f "${sessions_dir}/${bssid}.rule" ]; then
i=$(<"${sessions_dir}/${bssid}.rule")
else
i=-1
fi
i=$((i+1))
if ((i<${#john_rules[@]})); then
echo "$i" >"${sessions_dir}/${bssid}.rule"
fi
# End of Rules?
if ((i<${#john_rules[@]})); then
# No. Proccess the rule starting new session
rule="${john_rules[$i]}" # get rule name
[ ! -f "${sessions_dir}/${bssid}.${rule}.tested" ] && echo -n >"${sessions_dir}/${bssid}.${rule}.tested" # if *.tested don´t exist, create
grep -E "^.{1,$maxlength}$" "${wordlist}" | grep -vxF -f "${sessions_dir}/${bssid}.${rule}.tested" >"${sessions_dir}/${bssid}.dic" # Create a dictionary excluding .tested words
sync
dic="${sessions_dir}/${bssid}.dic"
case "${ext}" in
cap ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --session=${sessions_dir}/${bssid} --wordlist=${dic} --rules=${rule} --stdout:63 | aircrack-ng -p ${cores} -w - -b ${bssid} -l ${sessions_dir}/${bssid}.cracked ${handshakes_dir}/${bssid}.cap" ;;
22000 ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --session=${sessions_dir}/${bssid} --wordlist=${dic} --rules=${rule} --stdout:63 | hashcat --hash-type 22000 ${handshakes_dir}/${bssid}.22000 --outfile ${sessions_dir}/${bssid}.cracked --workload-profile ${cores}" ;;
hccapx ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --session=${sessions_dir}/${bssid} --wordlist=${dic} --rules=${rule} --stdout:63 | hashcat --hash-type 2500 ${handshakes_dir}/${bssid}.hccapx --outfile ${sessions_dir}/${bssid}.cracked --workload-profile ${cores}" ;;
PMKID|pmkid ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --session=${sessions_dir}/${bssid} --wordlist=${dic} --rules=${rule} --stdout:63 | hashcat --hash-type 16800 ${handshakes_dir}/${bssid}.PMKID --outfile ${sessions_dir}/${bssid}.cracked --workload-profile ${cores}" ;;
JOHN|john ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --session=${sessions_dir}/${bssid} --wordlist=${dic} --rules=${rule} --format=wpapsk-opencl ${handshakes_dir}/${bssid}.john" ;;
esac
else
# Yes. finish
echo "End of Rules"
sleep 3
fi
else
# Starting from john incremental mode (create *.rec)
case "${ext}" in
cap ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --session=${sessions_dir}/${bssid} --incremental:${john_incr} --stdout:63 | aircrack-ng -p ${cores} -w - -b ${bssid} -l ${sessions_dir}/${bssid}.cracked ${handshakes_dir}/${bssid}.cap" ;;
22000 ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --session=${sessions_dir}/${bssid} --incremental:${john_incr} --stdout:63 | hashcat --hash-type 22000 ${handshakes_dir}/${bssid}.22000 --outfile ${sessions_dir}/${bssid}.cracked --workload-profile ${cores}" ;;
hccapx ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --session=${sessions_dir}/${bssid} --incremental:${john_incr} --stdout:63 | hashcat --hash-type 2500 ${handshakes_dir}/${bssid}.hccapx --outfile ${sessions_dir}/${bssid}.cracked --workload-profile ${cores}" ;;
PMKID|pmkid ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --session=${sessions_dir}/${bssid} --incremental:${john_incr} --stdout:63 | hashcat --hash-type 16800 ${handshakes_dir}/${bssid}.PMKID --outfile ${sessions_dir}/${bssid}.cracked --workload-profile ${cores}" ;;
JOHN|john ) xterm -title "Cracking ${bssid}" -geometry 80x21-0+0 -bg "#000000" -fg "#FFFFFF" -e sh -c "john --session=${sessions_dir}/${bssid} --incremental:${john_incr} --format=wpapsk-opencl ${handshakes_dir}/${bssid}.john" ;;
esac
[ ! -f "${sessions_dir}/${bssid}.${john_incr}.tested" ] && echo -n >"${sessions_dir}/${bssid}.${john_incr}.tested" # if .tested file don´t exist, create
fi
fi
fi
# john --show=LEFT sabrina.john 2>/dev/null | wc -l
if [[ "${ext}" =~ ^(JOHN|john)$ ]]; then
if ! john --show "${handshakes_dir}/${bssid}.john" | grep '0 password hashes cracked, 1 left' ; then
john --show "${handshakes_dir}/${bssid}.john" >"${sessions_dir}/${bssid}.cracked"
fi
fi
sleep 5
done
if is_running "${bssid}"; then
stop "${bssid}"
fi
rm -f "${sessions_dir}/${bssid}.run"
}
function statistics {
local bssid dict total rule
bssid="$1"
rule=$(get_rule)
if [[ ! $rule == "$john_incr" ]]; then
if [ -f "${sessions_dir}/${bssid}.rec" ]; then
echo "Processing, please wait..."
dict="${sessions_dir}/${bssid}.dic"
total="$(john --wordlist="${dict}" --stdout --rules="${rule}" 2>&1 | wc -l)"
echo "$total" >"${sessions_dir}/${bssid}.dic.total"
fi
fi
}
# Commandline parameters?
if [ "$#" -eq 3 ]; then
bssid="$1"
ext="$2"
cores="$3"
if [[ "$bssid" =~ ^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$ ]]; then # Valid BSSID?
crack_handshake "$bssid" "${ext}" "$cores" &
fi
else
select_handshake
fi