forked from FluxionNetwork/fluxion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fluxion.sh
executable file
·1960 lines (1563 loc) · 63.1 KB
/
fluxion.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
#!/usr/bin/env bash
# ============================================================ #
# ================== < FLUXION Parameters > ================== #
# ============================================================ #
# Path to directory containing the FLUXION executable script.
readonly FLUXIONPath=$(dirname $(readlink -f "$0"))
# Path to directory containing the FLUXION library (scripts).
readonly FLUXIONLibPath="$FLUXIONPath/lib"
# Path to the temp. directory available to FLUXION & subscripts.
readonly FLUXIONWorkspacePath="/tmp/fluxspace"
readonly FLUXIONIPTablesBackup="$FLUXIONPath/iptables-rules"
# Path to FLUXION's preferences file, to be loaded afterward.
readonly FLUXIONPreferencesFile="$FLUXIONPath/preferences/preferences.conf"
# Constants denoting the reference noise floor & ceiling levels.
# These are used by the the wireless network scanner visualizer.
readonly FLUXIONNoiseFloor=-90
readonly FLUXIONNoiseCeiling=-60
readonly FLUXIONVersion=6
readonly FLUXIONRevision=9
# Declare window ration bigger = smaller windows
FLUXIONWindowRatio=4
# Allow to skip dependencies if required, not recommended
FLUXIONSkipDependencies=1
# Check if there are any missing dependencies
FLUXIONMissingDependencies=0
# Allow to use 5ghz support
FLUXIONEnable5GHZ=0
# ============================================================ #
# ================= < Script Sanity Checks > ================= #
# ============================================================ #
if [ $EUID -ne 0 ]; then # Super User Check
echo -e "\\033[31mAborted, please execute the script as root.\\033[0m"; exit 1
fi
# ===================== < XTerm Checks > ===================== #
# TODO: Run the checks below only if we're not using tmux.
if [ ! "${DISPLAY:-}" ]; then # Assure display is available.
echo -e "\\033[31mAborted, X (graphical) session unavailable.\\033[0m"; exit 2
fi
if ! hash xdpyinfo 2>/dev/null; then # Assure display probe.
echo -e "\\033[31mAborted, xdpyinfo is unavailable.\\033[0m"; exit 3
fi
if ! xdpyinfo &>/dev/null; then # Assure display info available.
echo -e "\\033[31mAborted, xterm test session failed.\\033[0m"; exit 4
fi
# ================ < Parameter Parser Check > ================ #
getopt --test > /dev/null # Assure enhanced getopt (returns 4).
if [ $? -ne 4 ]; then
echo "\\033[31mAborted, enhanced getopt isn't available.\\033[0m"; exit 5
fi
# =============== < Working Directory Check > ================ #
if ! mkdir -p "$FLUXIONWorkspacePath" &> /dev/null; then
echo "\\033[31mAborted, can't generate a workspace directory.\\033[0m"; exit 6
fi
# Once sanity check is passed, we can start to load everything.
# ============================================================ #
# =================== < Library Includes > =================== #
# ============================================================ #
source "$FLUXIONLibPath/installer/InstallerUtils.sh"
source "$FLUXIONLibPath/InterfaceUtils.sh"
source "$FLUXIONLibPath/SandboxUtils.sh"
source "$FLUXIONLibPath/FormatUtils.sh"
source "$FLUXIONLibPath/ColorUtils.sh"
source "$FLUXIONLibPath/IOUtils.sh"
source "$FLUXIONLibPath/HashUtils.sh"
source "$FLUXIONLibPath/HelpUtils.sh"
# NOTE: These are configured after arguments are loaded (later).
# ============================================================ #
# =================== < Parse Parameters > =================== #
# ============================================================ #
if ! FLUXIONCLIArguments=$(
getopt --options="vdk5rinmthb:e:c:l:a:r" \
--longoptions="debug,version,killer,5ghz,installer,reloader,help,airmon-ng,multiplexer,target,test,auto,bssid:,essid:,channel:,language:,attack:,ratio,skip-dependencies" \
--name="FLUXION V$FLUXIONVersion.$FLUXIONRevision" -- "$@"
); then
echo -e "${CRed}Aborted$CClr, parameter error detected..."; exit 5
fi
AttackCLIArguments=${FLUXIONCLIArguments##* -- }
readonly FLUXIONCLIArguments=${FLUXIONCLIArguments%%-- *}
if [ "$AttackCLIArguments" = "$FLUXIONCLIArguments" ]; then
AttackCLIArguments=""
fi
# ============================================================ #
# ================== < Load Configurables > ================== #
# ============================================================ #
# ============= < Argument Loaded Configurables > ============ #
eval set -- "$FLUXIONCLIArguments" # Set environment parameters.
#[ "$1" != "--" ] && readonly FLUXIONAuto=1 # Auto-mode if using CLI.
while [ "$1" != "" ] && [ "$1" != "--" ]; do
case "$1" in
-v|--version) echo "FLUXION V$FLUXIONVersion.$FLUXIONRevision"; exit;;
-h|--help) fluxion_help; exit;;
-d|--debug) readonly FLUXIONDebug=1;;
-k|--killer) readonly FLUXIONWIKillProcesses=1;;
-5|--5ghz) FLUXIONEnable5GHZ=1;;
-r|--reloader) readonly FLUXIONWIReloadDriver=1;;
-n|--airmon-ng) readonly FLUXIONAirmonNG=1;;
-m|--multiplexer) readonly FLUXIONTMux=1;;
-b|--bssid) FluxionTargetMAC=$2; shift;;
-e|--essid) FluxionTargetSSID=$2;
# TODO: Rearrange declarations to have routines available for use here.
FluxionTargetSSIDClean=$(echo "$FluxionTargetSSID" | sed -r 's/( |\/|\.|\~|\\)+/_/g'); shift;;
-c|--channel) FluxionTargetChannel=$2; shift;;
-l|--language) FluxionLanguage=$2; shift;;
-a|--attack) FluxionAttack=$2; shift;;
-i|--install) FLUXIONSkipDependencies=0; shift;;
--ratio) FLUXIONWindowRatio=$2; shift;;
--auto) readonly FLUXIONAuto=1;;
--skip-dependencies) readonly FLUXIONSkipDependencies=1;;
esac
shift # Shift new parameters
done
shift # Remove "--" to prepare for attacks to read parameters.
# Executable arguments are handled after subroutine definition.
# =================== < User Preferences > =================== #
# Load user-defined preferences if there's an executable script.
# If no script exists, prepare one for the user to store config.
# WARNING: Preferences file must assure no redeclared constants.
if [ -x "$FLUXIONPreferencesFile" ]; then
source "$FLUXIONPreferencesFile"
else
echo '#!/usr/bin/env bash' > "$FLUXIONPreferencesFile"
chmod u+x "$FLUXIONPreferencesFile"
fi
# ================ < Configurable Constants > ================ #
if [ "$FLUXIONAuto" != "1" ]; then # If defined, assure 1.
readonly FLUXIONAuto=${FLUXIONAuto:+1}
fi
if [ "$FLUXIONDebug" != "1" ]; then # If defined, assure 1.
readonly FLUXIONDebug=${FLUXIONDebug:+1}
fi
if [ "$FLUXIONAirmonNG" != "1" ]; then # If defined, assure 1.
readonly FLUXIONAirmonNG=${FLUXIONAirmonNG:+1}
fi
if [ "$FLUXIONWIKillProcesses" != "1" ]; then # If defined, assure 1.
readonly FLUXIONWIKillProcesses=${FLUXIONWIKillProcesses:+1}
fi
if [ "$FLUXIONWIReloadDriver" != "1" ]; then # If defined, assure 1.
readonly FLUXIONWIReloadDriver=${FLUXIONWIReloadDriver:+1}
fi
# FLUXIONDebug [Normal Mode "" / Developer Mode 1]
if [ $FLUXIONDebug ]; then
:> /tmp/fluxion.debug.log
readonly FLUXIONOutputDevice="/tmp/fluxion.debug.log"
readonly FLUXIONHoldXterm="-hold"
else
readonly FLUXIONOutputDevice=/dev/null
readonly FLUXIONHoldXterm=""
fi
# ================ < Configurable Variables > ================ #
readonly FLUXIONPromptDefault="$CRed[${CSBlu}fluxion$CSYel@$CSWht$HOSTNAME$CClr$CRed]-[$CSYel~$CClr$CRed]$CClr "
FLUXIONPrompt=$FLUXIONPromptDefault
readonly FLUXIONVLineDefault="$CRed[$CSYel*$CClr$CRed]$CClr"
FLUXIONVLine=$FLUXIONVLineDefault
# ================== < Library Parameters > ================== #
readonly InterfaceUtilsOutputDevice="$FLUXIONOutputDevice"
readonly SandboxWorkspacePath="$FLUXIONWorkspacePath"
readonly SandboxOutputDevice="$FLUXIONOutputDevice"
readonly InstallerUtilsWorkspacePath="$FLUXIONWorkspacePath"
readonly InstallerUtilsOutputDevice="$FLUXIONOutputDevice"
readonly InstallerUtilsNoticeMark="$FLUXIONVLine"
readonly PackageManagerLog="$InstallerUtilsWorkspacePath/package_manager.log"
declare IOUtilsHeader="fluxion_header"
readonly IOUtilsQueryMark="$FLUXIONVLine"
readonly IOUtilsPrompt="$FLUXIONPrompt"
readonly HashOutputDevice="$FLUXIONOutputDevice"
# ============================================================ #
# =================== < Default Language > =================== #
# ============================================================ #
# Set by default in case fluxion is aborted before setting one.
source "$FLUXIONPath/language/en.sh"
# ============================================================ #
# ================== < Startup & Shutdown > ================== #
# ============================================================ #
fluxion_startup() {
if [ "$FLUXIONDebug" ]; then return 1; fi
# Make sure that we save the iptable files
iptables-save >"$FLUXIONIPTablesBackup"
local banner=()
format_center_literals \
" ⌠▓▒▓▒ ⌠▓╗ ⌠█┐ ┌█ ┌▓\ /▓┐ ⌠▓╖ ⌠◙▒▓▒◙ ⌠█\ ☒┐"
banner+=("$FormatCenterLiterals")
format_center_literals \
" ║▒_ │▒║ │▒║ ║▒ \▒\/▒/ │☢╫ │▒┌╤┐▒ ║▓▒\ ▓║"
banner+=("$FormatCenterLiterals")
format_center_literals \
" ≡◙◙ ║◙║ ║◙║ ║◙ ◙◙ ║¤▒ ║▓║☯║▓ ♜◙\✪\◙♜"
banner+=("$FormatCenterLiterals")
format_center_literals \
" ║▒ │▒║__ │▒└_┘▒ /▒/\▒\ │☢╫ │▒└╧┘▒ ║█ \▒█║"
banner+=("$FormatCenterLiterals")
format_center_literals \
" ⌡▓ ⌡◘▒▓▒ ⌡◘▒▓▒◘ └▓/ \▓┘ ⌡▓╝ ⌡◙▒▓▒◙ ⌡▓ \▓┘"
banner+=("$FormatCenterLiterals")
format_center_literals \
"¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯ ¯¯¯ ¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯"
banner+=("$FormatCenterLiterals")
clear
if [ "$FLUXIONAuto" ]; then echo -e "$CBlu"; else echo -e "$CRed"; fi
for line in "${banner[@]}"; do
echo "$line"; sleep 0.05
done
echo # Do not remove.
sleep 0.1
local -r fluxionRepository="https://github.com/FluxionNetwork/fluxion"
format_center_literals "${CGrn}Site: ${CRed}$fluxionRepository$CClr"
echo -e "$FormatCenterLiterals"
sleep 0.1
local -r versionInfo="${CSRed}FLUXION $FLUXIONVersion$CClr"
local -r revisionInfo="(rev. $CSBlu$FLUXIONRevision$CClr)"
local -r credits="by$CCyn FluxionNetwork$CClr"
format_center_literals "$versionInfo $revisionInfo $credits"
echo -e "$FormatCenterLiterals"
sleep 0.1
local -r fluxionDomain="raw.githubusercontent.com"
local -r fluxionPath="FluxionNetwork/fluxion/master/fluxion.sh"
local -r updateDomain="github.com"
local -r updatePath="FluxionNetwork/fluxion/archive/master.zip"
if installer_utils_check_update "https://$fluxionDomain/$fluxionPath" \
"FLUXIONVersion=" "FLUXIONRevision=" \
$FLUXIONVersion $FLUXIONRevision; then
if installer_utils_run_update "https://$updateDomain/$updatePath" \
"FLUXION-V$FLUXIONVersion.$FLUXIONRevision" "$FLUXIONPath"; then
fluxion_shutdown
fi
fi
echo # Do not remove.
local requiredCLITools=(
"aircrack-ng" "bc" "awk:awk|gawk|mawk"
"curl" "cowpatty" "dhcpd:isc-dhcp-server|dhcp" "7zr:p7zip" "hostapd" "lighttpd"
"iwconfig:wireless-tools" "macchanger" "mdk4" "dsniff" "mdk3" "nmap" "openssl"
"php-cgi" "xterm" "rfkill" "unzip" "route:net-tools"
"fuser:psmisc" "killall:psmisc"
)
while ! installer_utils_check_dependencies requiredCLITools[@]; do
if ! installer_utils_run_dependencies InstallerUtilsCheckDependencies[@]; then
echo
echo -e "${CRed}Dependency installation failed!$CClr"
echo "Press enter to retry, ctrl+c to exit..."
read -r bullshit
fi
done
if [ $FLUXIONMissingDependencies -eq 1 ] && [ $FLUXIONSkipDependencies -eq 1 ];then
echo -e "\n\n"
format_center_literals "[ ${CSRed}Missing dependencies: try to install using ./fluxion.sh -i${CClr} ]"
echo -e "$FormatCenterLiterals"; sleep 3
exit 7
fi
echo -e "\\n\\n" # This echo is for spacing
}
fluxion_shutdown() {
if [ $FLUXIONDebug ]; then return 1; fi
# Show the header if the subroutine has already been loaded.
if type -t fluxion_header &> /dev/null; then
fluxion_header
fi
echo -e "$CWht[$CRed-$CWht]$CRed $FLUXIONCleanupAndClosingNotice$CClr"
# Get running processes we might have to kill before exiting.
local processes
readarray processes < <(ps -A)
# Currently, fluxion is only responsible for killing airodump-ng, since
# fluxion explicitly uses it to scan for candidate target access points.
# NOTICE: Processes started by subscripts, such as an attack script,
# MUST BE TERMINATED BY THAT SCRIPT in the subscript's abort handler.
local -r targets=("airodump-ng")
local targetID # Program identifier/title
for targetID in "${targets[@]}"; do
# Get PIDs of all programs matching targetPID
local targetPID
targetPID=$(
echo "${processes[@]}" | awk '$4~/'"$targetID"'/{print $1}'
)
if [ ! "$targetPID" ]; then continue; fi
echo -e "$CWht[$CRed-$CWht] `io_dynamic_output $FLUXIONKillingProcessNotice`"
kill -s SIGKILL $targetPID &> $FLUXIONOutputDevice
done
kill -s SIGKILL $authService &> $FLUXIONOutputDevice
# Assure changes are reverted if installer was activated.
if [ "$PackageManagerCLT" ]; then
echo -e "$CWht[$CRed-$CWht] "$(
io_dynamic_output "$FLUXIONRestoringPackageManagerNotice"
)"$CClr"
# Notice: The package manager has already been restored at this point.
# InstallerUtils assures the manager is restored after running operations.
fi
# If allocated interfaces exist, deallocate them now.
if [ ${#FluxionInterfaces[@]} -gt 0 ]; then
local interface
for interface in "${!FluxionInterfaces[@]}"; do
# Only deallocate fluxion or airmon-ng created interfaces.
if [[ "$interface" == "flux"* || "$interface" == *"mon"* || "$interface" == "prism"* ]]; then
fluxion_deallocate_interface $interface
fi
done
fi
echo -e "$CWht[$CRed-$CWht] $FLUXIONDisablingCleaningIPTablesNotice$CClr"
if [ -f "$FLUXIONIPTablesBackup" ]; then
iptables-restore <"$FLUXIONIPTablesBackup" \
&> $FLUXIONOutputDevice
else
iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
fi
echo -e "$CWht[$CRed-$CWht] $FLUXIONRestoringTputNotice$CClr"
tput cnorm
if [ ! $FLUXIONDebug ]; then
echo -e "$CWht[$CRed-$CWht] $FLUXIONDeletingFilesNotice$CClr"
sandbox_remove_workfile "$FLUXIONWorkspacePath/*"
fi
if [ $FLUXIONWIKillProcesses ]; then
echo -e "$CWht[$CRed-$CWht] $FLUXIONRestartingNetworkManagerNotice$CClr"
# TODO: Add support for other network managers (wpa_supplicant?).
if [ ! -x "$(command -v systemctl)" ]; then
if [ -x "$(command -v service)" ];then
service network-manager restart &> $FLUXIONOutputDevice &
service networkmanager restart &> $FLUXIONOutputDevice &
service networking restart &> $FLUXIONOutputDevice &
fi
else
systemctl restart network-manager.service &> $FLUXIONOutputDevice &
fi
fi
echo -e "$CWht[$CGrn+$CWht] $CGrn$FLUXIONCleanupSuccessNotice$CClr"
echo -e "$CWht[$CGrn+$CWht] $CGry$FLUXIONThanksSupportersNotice$CClr"
sleep 3
clear
exit 0
}
# ============================================================ #
# ================== < Helper Subroutines > ================== #
# ============================================================ #
# The following will kill the parent proces & all its children.
fluxion_kill_lineage() {
if [ ${#@} -lt 1 ]; then return -1; fi
if [ ! -z "$2" ]; then
local -r options=$1
local match=$2
else
local -r options=""
local match=$1
fi
# Check if the match isn't a number, but a regular expression.
# The following might
if ! [[ "$match" =~ ^[0-9]+$ ]]; then
match=$(pgrep -f $match 2> $FLUXIONOutputDevice)
fi
# Check if we've got something to kill, abort otherwise.
if [ -z "$match" ]; then return -2; fi
kill $options $(pgrep -P $match 2> $FLUXIONOutputDevice) \
&> $FLUXIONOutputDevice
kill $options $match &> $FLUXIONOutputDevice
}
# ============================================================ #
# ================= < Handler Subroutines > ================== #
# ============================================================ #
# Delete log only in Normal Mode !
fluxion_conditional_clear() {
# Clear iff we're not in debug mode
if [ ! $FLUXIONDebug ]; then clear; fi
}
fluxion_conditional_bail() {
echo ${1:-"Something went wrong, whoops! (report this)"}
sleep 5
if [ ! $FLUXIONDebug ]; then
fluxion_handle_exit
return 1
fi
echo "Press any key to continue execution..."
read -r bullshit
}
# ERROR Report only in Developer Mode
if [ $FLUXIONDebug ]; then
fluxion_error_report() {
echo "Exception caught @ line #$1"
}
trap 'fluxion_error_report $LINENO' ERR
fi
fluxion_handle_abort_attack() {
if [ $(type -t stop_attack) ]; then
stop_attack &> $FLUXIONOutputDevice
unprep_attack &> $FLUXIONOutputDevice
else
echo "Attack undefined, can't stop anything..." > $FLUXIONOutputDevice
fi
fluxion_target_tracker_stop
}
# In case of abort signal, abort any attacks currently running.
trap fluxion_handle_abort_attack SIGABRT
fluxion_handle_exit() {
fluxion_handle_abort_attack
fluxion_shutdown
exit 1
}
# In case of unexpected termination, run fluxion_shutdown.
trap fluxion_handle_exit SIGINT SIGHUP
fluxion_handle_target_change() {
echo "Target change signal received!" > $FLUXIONOutputDevice
local targetInfo
readarray -t targetInfo < <(more "$FLUXIONWorkspacePath/target_info.txt")
FluxionTargetMAC=${targetInfo[0]}
FluxionTargetSSID=${targetInfo[1]}
FluxionTargetChannel=${targetInfo[2]}
FluxionTargetSSIDClean=$(fluxion_target_normalize_SSID)
if ! stop_attack; then
fluxion_conditional_bail "Target tracker failed to stop attack."
fi
if ! unprep_attack; then
fluxion_conditional_bail "Target tracker failed to unprep attack."
fi
if ! load_attack "$FLUXIONPath/attacks/$FluxionAttack/attack.conf"; then
fluxion_conditional_bail "Target tracker failed to load attack."
fi
if ! prep_attack; then
fluxion_conditional_bail "Target tracker failed to prep attack."
fi
if ! fluxion_run_attack; then
fluxion_conditional_bail "Target tracker failed to start attack."
fi
}
# If target monitoring enabled, act on changes.
trap fluxion_handle_target_change SIGALRM
# ============================================================ #
# =============== < Resolution & Positioning > =============== #
# ============================================================ #
fluxion_set_resolution() { # Windows + Resolution
# Get dimensions
# Verify this works on Kali before commiting.
# shopt -s checkwinsize; (:;:)
# SCREEN_SIZE_X="$LINES"
# SCREEN_SIZE_Y="$COLUMNS"
SCREEN_SIZE=$(xdpyinfo | grep dimension | awk '{print $4}' | tr -d "(")
SCREEN_SIZE_X=$(printf '%.*f\n' 0 $(echo $SCREEN_SIZE | sed -e s'/x/ /'g | awk '{print $1}'))
SCREEN_SIZE_Y=$(printf '%.*f\n' 0 $(echo $SCREEN_SIZE | sed -e s'/x/ /'g | awk '{print $2}'))
# Calculate proportional windows
if hash bc ;then
PROPOTION=$(echo $(awk "BEGIN {print $SCREEN_SIZE_X/$SCREEN_SIZE_Y}")/1 | bc)
NEW_SCREEN_SIZE_X=$(echo $(awk "BEGIN {print $SCREEN_SIZE_X/$FLUXIONWindowRatio}")/1 | bc)
NEW_SCREEN_SIZE_Y=$(echo $(awk "BEGIN {print $SCREEN_SIZE_Y/$FLUXIONWindowRatio}")/1 | bc)
NEW_SCREEN_SIZE_BIG_X=$(echo $(awk "BEGIN {print 1.5*$SCREEN_SIZE_X/$FLUXIONWindowRatio}")/1 | bc)
NEW_SCREEN_SIZE_BIG_Y=$(echo $(awk "BEGIN {print 1.5*$SCREEN_SIZE_Y/$FLUXIONWindowRatio}")/1 | bc)
SCREEN_SIZE_MID_X=$(echo $(($SCREEN_SIZE_X + ($SCREEN_SIZE_X - 2 * $NEW_SCREEN_SIZE_X) / 2)))
SCREEN_SIZE_MID_Y=$(echo $(($SCREEN_SIZE_Y + ($SCREEN_SIZE_Y - 2 * $NEW_SCREEN_SIZE_Y) / 2)))
# Upper windows
TOPLEFT="-geometry $NEW_SCREEN_SIZE_Xx$NEW_SCREEN_SIZE_Y+0+0"
TOPRIGHT="-geometry $NEW_SCREEN_SIZE_Xx$NEW_SCREEN_SIZE_Y-0+0"
TOP="-geometry $NEW_SCREEN_SIZE_Xx$NEW_SCREEN_SIZE_Y+$SCREEN_SIZE_MID_X+0"
# Lower windows
BOTTOMLEFT="-geometry $NEW_SCREEN_SIZE_Xx$NEW_SCREEN_SIZE_Y+0-0"
BOTTOMRIGHT="-geometry $NEW_SCREEN_SIZE_Xx$NEW_SCREEN_SIZE_Y-0-0"
BOTTOM="-geometry $NEW_SCREEN_SIZE_Xx$NEW_SCREEN_SIZE_Y+$SCREEN_SIZE_MID_X-0"
# Y mid
LEFT="-geometry $NEW_SCREEN_SIZE_Xx$NEW_SCREEN_SIZE_Y+0-$SCREEN_SIZE_MID_Y"
RIGHT="-geometry $NEW_SCREEN_SIZE_Xx$NEW_SCREEN_SIZE_Y-0+$SCREEN_SIZE_MID_Y"
# Big
TOPLEFTBIG="-geometry $NEW_SCREEN_SIZE_BIG_Xx$NEW_SCREEN_SIZE_BIG_Y+0+0"
TOPRIGHTBIG="-geometry $NEW_SCREEN_SIZE_BIG_Xx$NEW_SCREEN_SIZE_BIG_Y-0+0"
fi
}
# ============================================================ #
# ================= < Sequencing Framework > ================= #
# ============================================================ #
# The following lists some problems with the framework's design.
# The list below is a list of DESIGN FLAWS, not framework bugs.
# * Sequenced undo instructions' return value is being ignored.
# * A global is generated for every new namespace being used.
# * It uses eval too much, but it's bash, so that's not so bad.
# TODO: Try to fix this or come up with a better alternative.
declare -rA FLUXIONUndoable=( \
["set"]="unset" \
["prep"]="unprep" \
["run"]="halt" \
["start"]="stop" \
)
# Yes, I know, the identifiers are fucking ugly. If only we had
# some type of mangling with bash identifiers, that'd be great.
fluxion_do() {
if [ ${#@} -lt 2 ]; then return -1; fi
local -r __fluxion_do__namespace=$1
local -r __fluxion_do__identifier=$2
# Notice, the instruction will be adde to the Do Log
# regardless of whether it succeeded or failed to execute.
eval FXDLog_$__fluxion_do__namespace+=\("$__fluxion_do__identifier"\)
eval ${__fluxion_do__namespace}_$__fluxion_do__identifier "${@:3}"
return $?
}
fluxion_undo() {
if [ ${#@} -ne 1 ]; then return -1; fi
local -r __fluxion_undo__namespace=$1
# Removed read-only due to local constant shadowing bug.
# I've reported the bug, we can add it when fixed.
eval local __fluxion_undo__history=\("\${FXDLog_$__fluxion_undo__namespace[@]}"\)
eval echo \$\{FXDLog_$__fluxion_undo__namespace[@]\} \
> $FLUXIONOutputDevice
local __fluxion_undo__i
for (( __fluxion_undo__i=${#__fluxion_undo__history[@]}; \
__fluxion_undo__i > 0; __fluxion_undo__i-- )); do
local __fluxion_undo__instruction=${__fluxion_undo__history[__fluxion_undo__i-1]}
local __fluxion_undo__command=${__fluxion_undo__instruction%%_*}
local __fluxion_undo__identifier=${__fluxion_undo__instruction#*_}
echo "Do ${FLUXIONUndoable["$__fluxion_undo__command"]}_$__fluxion_undo__identifier" \
> $FLUXIONOutputDevice
if eval ${__fluxion_undo__namespace}_${FLUXIONUndoable["$__fluxion_undo__command"]}_$__fluxion_undo__identifier; then
echo "Undo-chain succeded." > $FLUXIONOutputDevice
eval FXDLog_$__fluxion_undo__namespace=\("${__fluxion_undo__history[@]::$__fluxion_undo__i}"\)
eval echo History\: \$\{FXDLog_$__fluxion_undo__namespace[@]\} \
> $FLUXIONOutputDevice
return 0
fi
done
return -2 # The undo-chain failed.
}
fluxion_done() {
if [ ${#@} -ne 1 ]; then return -1; fi
local -r __fluxion_done__namespace=$1
eval "FluxionDone=\${FXDLog_$__fluxion_done__namespace[-1]}"
if [ ! "$FluxionDone" ]; then return 1; fi
}
fluxion_done_reset() {
if [ ${#@} -ne 1 ]; then return -1; fi
local -r __fluxion_done_reset__namespace=$1
eval FXDLog_$__fluxion_done_reset__namespace=\(\)
}
fluxion_do_sequence() {
if [ ${#@} -ne 2 ]; then return 1; fi
# TODO: Implement an alternative, better method of doing
# what this subroutine does, maybe using for-loop iteFLUXIONWindowRation.
# The for-loop implementation must support the subroutines
# defined above, including updating the namespace tracker.
local -r __fluxion_do_sequence__namespace=$1
# Removed read-only due to local constant shadowing bug.
# I've reported the bug, we can add it when fixed.
local __fluxion_do_sequence__sequence=("${!2}")
if [ ${#__fluxion_do_sequence__sequence[@]} -eq 0 ]; then
return -2
fi
local -A __fluxion_do_sequence__index=()
local i
for i in $(seq 0 $((${#__fluxion_do_sequence__sequence[@]} - 1))); do
__fluxion_do_sequence__index["${__fluxion_do_sequence__sequence[i]}"]=$i
done
# Start sequence with the first instruction available.
local __fluxion_do_sequence__instructionIndex=0
local __fluxion_do_sequence__instruction=${__fluxion_do_sequence__sequence[0]}
while [ "$__fluxion_do_sequence__instruction" ]; do
if ! fluxion_do $__fluxion_do_sequence__namespace $__fluxion_do_sequence__instruction; then
if ! fluxion_undo $__fluxion_do_sequence__namespace; then
return -2
fi
# Synchronize the current instruction's index by checking last.
if ! fluxion_done $__fluxion_do_sequence__namespace; then
return -3;
fi
__fluxion_do_sequence__instructionIndex=${__fluxion_do_sequence__index["$FluxionDone"]}
if [ ! "$__fluxion_do_sequence__instructionIndex" ]; then
return -4
fi
else
let __fluxion_do_sequence__instructionIndex++
fi
__fluxion_do_sequence__instruction=${__fluxion_do_sequence__sequence[$__fluxion_do_sequence__instructionIndex]}
echo "Running next: $__fluxion_do_sequence__instruction" \
> $FLUXIONOutputDevice
done
}
# ============================================================ #
# ================= < Load All Subroutines > ================= #
# ============================================================ #
fluxion_header() {
format_apply_autosize "[%*s]\n"
local verticalBorder=$FormatApplyAutosize
format_apply_autosize "[%*s${CSRed}FLUXION $FLUXIONVersion${CSWht}.${CSBlu}$FLUXIONRevision$CSRed <$CIRed F${CIYel}luxion$CIRed I${CIYel}s$CIRed T${CIYel}he$CIRed F${CIYel}uture$CClr$CSYel >%*s$CSBlu]\n"
local headerTextFormat="$FormatApplyAutosize"
fluxion_conditional_clear
echo -e "$(printf "$CSRed$verticalBorder" "" | sed -r "s/ /~/g")"
printf "$CSRed$verticalBorder" ""
printf "$headerTextFormat" "" ""
printf "$CSBlu$verticalBorder" ""
echo -e "$(printf "$CSBlu$verticalBorder" "" | sed -r "s/ /~/g")$CClr"
echo
echo
}
# ======================= < Language > ======================= #
fluxion_unset_language() {
FluxionLanguage=""
if [ "$FLUXIONPreferencesFile" ]; then
sed -i.backup "/FluxionLanguage=.\+/ d" "$FLUXIONPreferencesFile"
fi
}
fluxion_set_language() {
if [ ! "$FluxionLanguage" ]; then
# Get all languages available.
local languageCodes
readarray -t languageCodes < <(ls -1 language | sed -E 's/\.sh//')
local languages
readarray -t languages < <(
head -n 3 language/*.sh |
grep -E "^# native: " |
sed -E 's/# \w+: //'
)
io_query_format_fields "$FLUXIONVLine Select your language" \
"\t$CRed[$CSYel%d$CClr$CRed]$CClr %s / %s\n" \
languageCodes[@] languages[@]
FluxionLanguage=${IOQueryFormatFields[0]}
echo # Do not remove.
fi
# Check if all language files are present for the selected language.
find -type d -name language | while read language_dir; do
if [ ! -e "$language_dir/${FluxionLanguage}.sh" ]; then
echo -e "$FLUXIONVLine ${CYel}Warning${CClr}, missing language file:"
echo -e "\t$language_dir/${FluxionLanguage}.sh"
return 1
fi
done
if [ $? -eq 1 ]; then # If a file is missing, fall back to english.
echo -e "\n\n$FLUXIONVLine Falling back to English..."; sleep 5
FluxionLanguage="en"
fi
source "$FLUXIONPath/language/$FluxionLanguage.sh"
if [ "$FLUXIONPreferencesFile" ]; then
if more $FLUXIONPreferencesFile | \
grep -q "FluxionLanguage=.\+" &> /dev/null; then
sed -r "s/FluxionLanguage=.+/FluxionLanguage=$FluxionLanguage/g" \
-i.backup "$FLUXIONPreferencesFile"
else
echo "FluxionLanguage=$FluxionLanguage" >> "$FLUXIONPreferencesFile"
fi
fi
}
# ====================== < Interfaces > ====================== #
declare -A FluxionInterfaces=() # Global interfaces' registry.
fluxion_deallocate_interface() { # Release interfaces
if [ ! "$1" ] || ! interface_is_real $1; then return 1; fi
local -r oldIdentifier=$1
local -r newIdentifier=${FluxionInterfaces[$oldIdentifier]}
# Assure the interface is in the allocation table.
if [ ! "$newIdentifier" ]; then return 2; fi
local interfaceIdentifier=$newIdentifier
echo -e "$CWht[$CSRed-$CWht] "$(
io_dynamic_output "$FLUXIONDeallocatingInterfaceNotice"
)"$CClr"
if interface_is_wireless $oldIdentifier; then
# If interface was allocated by airmon-ng, deallocate with it.
if [[ "$oldIdentifier" == *"mon"* || "$oldIdentifier" == "prism"* ]]; then
if ! airmon-ng stop $oldIdentifier &> $FLUXIONOutputDevice; then
return 4
fi
else
# Attempt deactivating monitor mode on the interface.
if ! interface_set_mode $oldIdentifier managed; then
return 3
fi
# Attempt to restore the original interface identifier.
if ! interface_reidentify "$oldIdentifier" "$newIdentifier"; then
return 5
fi
fi
fi
# Once successfully renamed, remove from allocation table.
unset FluxionInterfaces[$oldIdentifier]
unset FluxionInterfaces[$newIdentifier]
}
# Parameters: <interface_identifier>
# ------------------------------------------------------------ #
# Return 1: No interface identifier was passed.
# Return 2: Interface identifier given points to no interface.
# Return 3: Unable to determine interface's driver.
# Return 4: Fluxion failed to reidentify interface.
# Return 5: Interface allocation failed (identifier missing).
fluxion_allocate_interface() { # Reserve interfaces
if [ ! "$1" ]; then return 1; fi
local -r identifier=$1
# If the interface is already in allocation table, we're done.
if [ "${FluxionInterfaces[$identifier]+x}" ]; then
return 0
fi
if ! interface_is_real $identifier; then return 2; fi
local interfaceIdentifier=$identifier
echo -e "$CWht[$CSGrn+$CWht] "$(
io_dynamic_output "$FLUXIONAllocatingInterfaceNotice"
)"$CClr"
if interface_is_wireless $identifier; then
# Unblock wireless interfaces to make them available.
echo -e "$FLUXIONVLine $FLUXIONUnblockingWINotice"
rfkill unblock all &> $FLUXIONOutputDevice
if [ "$FLUXIONWIReloadDriver" ]; then
# Get selected interface's driver details/info-descriptor.
echo -e "$FLUXIONVLine $FLUXIONGatheringWIInfoNotice"
if ! interface_driver "$identifier"; then
echo -e "$FLUXIONVLine$CRed $FLUXIONUnknownWIDriverError"
sleep 3
return 3
fi
# Notice: This local is function-scoped, not block-scoped.
local -r driver="$InterfaceDriver"
# Unload the driver module from the kernel.
rmmod -f $driver &> $FLUXIONOutputDevice
# Wait while interface becomes unavailable.
echo -e "$FLUXIONVLine "$(
io_dynamic_output $FLUXIONUnloadingWIDriverNotice
)
while interface_physical "$identifier"; do
sleep 1
done
fi
if [ "$FLUXIONWIKillProcesses" ]; then
# Get list of potentially troublesome programs.
echo -e "$FLUXIONVLine $FLUXIONFindingConflictingProcessesNotice"
# Kill potentially troublesome programs.
echo -e "$FLUXIONVLine $FLUXIONKillingConflictingProcessesNotice"
# TODO: Make the loop below airmon-ng independent.
# Maybe replace it with a list of network-managers?
# WARNING: Version differences could break code below.
for program in "$(airmon-ng check | awk 'NR>6{print $2}')"; do
killall "$program" &> $FLUXIONOutputDevice
done
fi
if [ "$FLUXIONWIReloadDriver" ]; then
# Reload the driver module into the kernel.
modprobe "$driver" &> $FLUXIONOutputDevice
# Wait while interface becomes available.
echo -e "$FLUXIONVLine "$(
io_dynamic_output $FLUXIONLoadingWIDriverNotice
)
while ! interface_physical "$identifier"; do
sleep 1
done
fi
# Set wireless flag to prevent having to re-query.
local -r allocatingWirelessInterface=1
fi
# If we're using the interface library, reidentify now.
# If usuing airmon-ng, let airmon-ng rename the interface.
if [ ! $FLUXIONAirmonNG ]; then
echo -e "$FLUXIONVLine $FLUXIONReidentifyingInterface"
# Prevent interface-snatching by renaming the interface.
if [ $allocatingWirelessInterface ]; then
# Get next wireless interface to add to FluxionInterfaces global.
fluxion_next_assignable_interface fluxwl
else
# Get next ethernet interface to add to FluxionInterfaces global.
fluxion_next_assignable_interface fluxet
fi
interface_reidentify $identifier $FluxionNextAssignableInterface
if [ $? -ne 0 ]; then # If reidentifying failed, abort immediately.
return 4
fi
fi
if [ $allocatingWirelessInterface ]; then
# Activate wireless interface monitor mode and save identifier.
echo -e "$FLUXIONVLine $FLUXIONStartingWIMonitorNotice"
# TODO: Consider the airmon-ng flag is set, monitor mode is
# already enabled on the interface being allocated, and the
# interface identifier is something non-airmon-ng standard.
# The interface could already be in use by something else.
# Snatching or crashing interface issues could occur.
# NOTICE: Conditionals below populate newIdentifier on success.
if [ $FLUXIONAirmonNG ]; then
local -r newIdentifier=$(
airmon-ng start $identifier |
grep "monitor .* enabled" |
grep -oP "wl[a-zA-Z0-9]+mon|mon[0-9]+|prism[0-9]+"
)
else
# Attempt activating monitor mode on the interface.
if interface_set_mode $FluxionNextAssignableInterface monitor; then
# Register the new identifier upon consecutive successes.
local -r newIdentifier=$FluxionNextAssignableInterface
else
# If monitor-mode switch fails, undo rename and abort.
interface_reidentify $FluxionNextAssignableInterface $identifier
fi
fi
fi
# On failure to allocate the interface, we've got to abort.
# Notice: If the interface was already in monitor mode and
# airmon-ng is activated, WE didn't allocate the interface.
if [ ! "$newIdentifier" -o "$newIdentifier" = "$oldIdentifier" ]; then
echo -e "$FLUXIONVLine $FLUXIONInterfaceAllocationFailedError"
sleep 3
return 5
fi
# Register identifiers to allocation hash table.
FluxionInterfaces[$newIdentifier]=$identifier
FluxionInterfaces[$identifier]=$newIdentifier
echo -e "$FLUXIONVLine $FLUXIONInterfaceAllocatedNotice"
sleep 3
# Notice: Interfaces are accessed with their original identifier
# as the key for the global FluxionInterfaces hash/map/dictionary.
}
# Parameters: <interface_prefix>
# Description: Prints next available assignable interface name.
# ------------------------------------------------------------ #
fluxion_next_assignable_interface() {
# Find next available interface by checking global.
local -r prefix=$1
local index=0
while [ "${FluxionInterfaces[$prefix$index]}" ]; do
let index++
done
FluxionNextAssignableInterface="$prefix$index"
}