From ffd7c1e9bb57b12579355137600e92630fc26436 Mon Sep 17 00:00:00 2001 From: deltaxflux Date: Fri, 3 Aug 2018 20:56:15 +0200 Subject: [PATCH] Push latest files --- .gitignore | 2 - attacks/Captive Portal/lib/authenticator.php | 67 ++++ attacks/Captive Portal/lib/check.php | 8 + .../Apple/hotspot-detect.html | 2 + .../connectivity responses/Apple/index.php | 2 + .../connectivity responses/Google/blank.html | 0 .../Google/generate_204.php | 2 + .../connectivity responses/Google/index.html | 0 attacks/Captive Portal/lib/update.php | 9 + fluxion.sh | 4 +- lib/ArrayUtils.sh | 30 ++ lib/ChipsetUtils.sh | 57 ++++ lib/ColorUtils.sh | 69 +++++ lib/FormatUtils.sh | 193 ++++++++++++ lib/HashUtils.sh | 95 ++++++ lib/HelpUtils.sh | 96 ++++++ lib/IOUtils.sh | 149 +++++++++ lib/InterfaceUtils.sh | 182 +++++++++++ lib/SandboxUtils.sh | 37 +++ lib/ap/airbase-ng.sh | 88 ++++++ lib/ap/hostapd.sh | 98 ++++++ lib/installer/InstallerUtils.sh | 293 ++++++++++++++++++ lib/installer/managers/apt.sh | 46 +++ lib/installer/managers/emerge.sh | 23 ++ lib/installer/managers/pacman.sh | 31 ++ lib/installer/managers/yum.sh | 23 ++ lib/installer/managers/zypp.sh | 23 ++ 27 files changed, 1625 insertions(+), 4 deletions(-) create mode 100644 attacks/Captive Portal/lib/authenticator.php create mode 100644 attacks/Captive Portal/lib/check.php create mode 100644 attacks/Captive Portal/lib/connectivity responses/Apple/hotspot-detect.html create mode 100644 attacks/Captive Portal/lib/connectivity responses/Apple/index.php create mode 100644 attacks/Captive Portal/lib/connectivity responses/Google/blank.html create mode 100644 attacks/Captive Portal/lib/connectivity responses/Google/generate_204.php create mode 100644 attacks/Captive Portal/lib/connectivity responses/Google/index.html create mode 100644 attacks/Captive Portal/lib/update.php create mode 100755 lib/ArrayUtils.sh create mode 100755 lib/ChipsetUtils.sh create mode 100755 lib/ColorUtils.sh create mode 100755 lib/FormatUtils.sh create mode 100755 lib/HashUtils.sh create mode 100755 lib/HelpUtils.sh create mode 100755 lib/IOUtils.sh create mode 100755 lib/InterfaceUtils.sh create mode 100755 lib/SandboxUtils.sh create mode 100755 lib/ap/airbase-ng.sh create mode 100755 lib/ap/hostapd.sh create mode 100755 lib/installer/InstallerUtils.sh create mode 100755 lib/installer/managers/apt.sh create mode 100755 lib/installer/managers/emerge.sh create mode 100755 lib/installer/managers/pacman.sh create mode 100755 lib/installer/managers/yum.sh create mode 100755 lib/installer/managers/zypp.sh diff --git a/.gitignore b/.gitignore index 90dc172..6748f33 100644 --- a/.gitignore +++ b/.gitignore @@ -68,8 +68,6 @@ dist/ downloads/ eggs/ .eggs/ -lib/ -lib64/ parts/ sdist/ var/ diff --git a/attacks/Captive Portal/lib/authenticator.php b/attacks/Captive Portal/lib/authenticator.php new file mode 100644 index 0000000..885ae90 --- /dev/null +++ b/attacks/Captive Portal/lib/authenticator.php @@ -0,0 +1,67 @@ +SuccessSuccess + diff --git a/attacks/Captive Portal/lib/connectivity responses/Apple/index.php b/attacks/Captive Portal/lib/connectivity responses/Apple/index.php new file mode 100644 index 0000000..bc86108 --- /dev/null +++ b/attacks/Captive Portal/lib/connectivity responses/Apple/index.php @@ -0,0 +1,2 @@ + ${array[@]} (replaced!) + for __array_contains__item in "${!1}"; do + [[ "$__array_contains__item" == "$2" ]] && return 0 + done + + return 1 # Not found +} + +# FLUXSCRIPT END diff --git a/lib/ChipsetUtils.sh b/lib/ChipsetUtils.sh new file mode 100755 index 0000000..6d2a89a --- /dev/null +++ b/lib/ChipsetUtils.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# ChipsetUtils: check if chipset is supported +check_chipset() { + if [ "$1" == "" ];then printf "\033[31mInvalid input, chipset appears invalid\033[0m\n"; exit 1;fi + + # =================== < CONFIG > =================== + if [ -d "misc" ];then + readonly local CHIPSET_LIST="misc/devices.xml" # chipset file list + elif [ -d "../misc" ];then + readonly local CHIPSET_LIST="../misc/devices.xml" # chipset file list + else + echo -e "\033[31Can't find required ressources\033[0m" + fi + local SUPPORT_AP="" # check if chipset support ap mode + local SUPPORT_MO="" # check if chipset support monitor mode + # =================== < CONFIG > =================== + + if [ ! -f $CHIPSET_LIST ];then + echo "Can't open file" + fi + + local line=$(cat $CHIPSET_LIST | grep -n $1 | cut -d ":" -f1 | head -n 1) # get current position of chipset + local length=$(wc -l $CHIPSET_LIST | awk '{print $1}') + if [ "$line" == "" ];then printf "\033[31mChipset is not in list\033[0m\n";exit 1;fi # Catch if chipset is not present + + local cout=$line + local i=$cout + while true;do + local data=$(cat $CHIPSET_LIST | sed -n -e "${cout}p") + local iden=$(echo $data | cut -d ">" -f1 | cut -d "<" -f2) + local row=$(echo $data | cut -d ">" -f2 | cut -d "<" -f1) + + if [ "$iden" == "AP" ];then + case $row in + y) echo -e "\033[32mChipset support ap mode\033[0m";SUPPORT_AP=true;; + n) echo -e "\033[31mChipset doesn't support ap mode\033[0m";SUPPORT_AP=false;; + ?) echo -e "\033[33mNo information if chipset support ap mode\033[0m";SUPPORT_AP=unknown;; + esac + fi + + if [ "$iden" == "Monitor" ];then + case $row in + y) echo -e "\033[32mChipset support monitor mode\033[0m"; SUPPORT_MO=true;; + n) echo -e "\033[31mChipset doesn't support monitor mode\033[0m";SUPPORT_MO=false;; + ?) echo -e "\033[33mNo information if chipset support monitor mode\033[0m";SUPPORT_MO=unknown; + esac + fi + + if [ "$SUPPORT_MO" == false -a "$SUPPORT_MO" == true ] && [ "$SUPPORT_AP4" == false -a "$SUPPORT_AP" == true ]; then break; fi + + cout=$(echo $(($cout+1))) + if [ $cout -gt $length ] || [ "$cout" -eq $(echo $(($i+10))) ];then echo -e "\033[33mDon't reseve all required information\033[0m";break ;fi # Catch out of range + done + + if [ "$SUPPORT_AP" == true ] && [ "$SUPPORT_MO" == true ]; then return 0; else return 1;fi +} diff --git a/lib/ColorUtils.sh b/lib/ColorUtils.sh new file mode 100755 index 0000000..891bd86 --- /dev/null +++ b/lib/ColorUtils.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +if [ "$ColorUtilsVersion" ]; then return 0; fi +readonly ColorUtilsVersion="1.0" + +################################# < Shell Color Codes > ################################ + +# Regular Text +readonly CRed="\e[0;31m" +readonly CGrn="\e[0;32m" +readonly CYel="\e[0;33m" +readonly CBlu="\e[0;34m" +readonly CPrp="\e[0;35m" +readonly CCyn="\e[0;36m" +readonly CGry="\e[0;37m" +readonly CWht="\e[0;37m" +readonly CClr="\e[0m" + +# [S] - Strong text (bold) +readonly CSRed="\e[1;31m" +readonly CSGrn="\e[1;32m" +readonly CSYel="\e[1;33m" +readonly CSBlu="\e[1;34m" +readonly CSPrp="\e[1;35m" +readonly CSCyn="\e[1;36m" +readonly CSGry="\e[1;37m" +readonly CSWht="\e[1;37m" + +# [D] - Dark text +readonly CDRed="\e[2;31m" +readonly CDGrn="\e[2;32m" +readonly CDYel="\e[2;33m" +readonly CDBlu="\e[2;34m" +readonly CDPrp="\e[2;35m" +readonly CDCyn="\e[2;36m" +readonly CDGry="\e[2;37m" +readonly CDWht="\e[2;37m" + +# [I] Italicized text +readonly CIRed="\e[3;31m" +readonly CIGrn="\e[3;32m" +readonly CIYel="\e[3;33m" +readonly CIBlu="\e[3;34m" +readonly CIPrp="\e[3;35m" +readonly CICyn="\e[3;36m" +readonly CIGry="\e[3;37m" +readonly CIWht="\e[3;37m" + +# [U] - Underlined text +readonly CURed="\e[4;31m" +readonly CUGrn="\e[4;32m" +readonly CUYel="\e[4;33m" +readonly CUBlu="\e[4;34m" +readonly CUPrp="\e[4;35m" +readonly CUCyn="\e[4;36m" +readonly CUGry="\e[4;37m" +readonly CUWht="\e[4;37m" + +# [B] - Blinking text +readonly CBRed="\e[5;31m" +readonly CBGrn="\e[5;32m" +readonly CBYel="\e[5;33m" +readonly CBBlu="\e[5;34m" +readonly CBPrp="\e[5;35m" +readonly CBCyn="\e[5;36m" +readonly CBGry="\e[5;37m" +readonly CBWht="\e[5;37m" + +# FLUXSCRIPT END diff --git a/lib/FormatUtils.sh b/lib/FormatUtils.sh new file mode 100755 index 0000000..9fa2bb3 --- /dev/null +++ b/lib/FormatUtils.sh @@ -0,0 +1,193 @@ +#!/usr/bin/env bash + +if [ "$FormatUtilsVersion" ]; then return 0; fi +readonly FormatUtilsVersion="1.0" + +FormatTabLength=8 +FormatValidSpecifiers='%([+-]?([0-9]+|\*)?(\.([0-9]+|\*))?)?[bqdiouxXfeEgGcsnaA]' + +# This should be relocated (here temporarily) +tabs -$FormatTabLength # Set tab width to var + +# This function strips (some) invisible characters. +# It only strips those needed by fluxion, currently. +# Parameters: $1 - format +function format_strip_invisibles() { + # This function currently only strips the following: + # Color escape sequences, & control characters + FormatStripInvisibles=$(echo "$1" | sed -r 's/\\(e\[([0-9]*;?[0-9]+)m|(t|n))//g') +} + +# This function replaces all invisible characters +# with a specifier of their corresponding length. +# Parameters: $1 - format +function format_expand_invisibles() { + FormatExpandInvisibles=$(echo "$1" | sed -r 's/\\(e\[([0-9]*;?[0-9]+)m|n)/%0s/g; s/\\t/%'"$FormatTabLength"'s/g') +} + +# This function lists all operators in format. +# Parameters: $1 - format +function format_list_specifiers() { + # Special specifier also included (with length value as '*'). + FormatListSpecifiers=($(echo "$1" | grep -oP "$FormatValidSpecifiers")) +} + +# This function calculates the dynamic specifier count in format. +# Parameters: $1 - format [$2 - specifier array] +function format_calculate_dynamics_count() { + local __format_calculate_dynamics_count__specifiers=("${!2}") + + if [ ! "$2" ]; then + format_list_specifiers "$1" + __format_calculate_dynamics_count__specifiers=("${FormatListSpecifiers[@]}") + fi + + FormatCalculateDynamicsCount=0 + local __format_calculate_dynamics_count__specifier + for __format_calculate_dynamics_count__specifier in "${__format_calculate_dynamics_count__specifiers[@]}"; do + if echo "$__format_calculate_dynamics_count__specifier" | grep '\*' >/dev/null 2>&1; then ((FormatCalculateDynamicsCount++)) + fi + done +} + +# This function calculates total length of statics in format. +# Statics are all specifiers in format with a fixed size. +# Parameters: $1 - format [$2 - specifier array] +function format_calculate_statics_length() { + local __format_calculate_statics_length__specifiers=("${!2}") + + if [ ! "$2" ]; then + echo "format_calculate_statics_length missing \$2" + format_list_specifiers "$1" + __format_calculate_statics_length__specifiers=("${FormatListSpecifiers[@]}") + fi + FormatCalculateStaticsLength=$(echo "${__format_calculate_statics_length__specifiers[@]}" | sed -r 's/\.[0-9]+s/s/g' | grep -oP '\d+' | awk 'BEGIN {s=0} {s+=$0} END {print s}') +} + +# This function calculates total length of literals in format. +# Literals are all characters in format printed literally. +# Parameters: $1 - format [$2 - processed format [$3 - specifier array]] +function format_calculate_literals_length() { + local __format_calculate_literals_length__normalizedFormat="$(echo "$2" | sed -r 's/%%|\*\*/X/g')" + local __format_calculate_literals_length__specifiers=("${!3}") + + if [ ! "$2" ]; then + echo "format_calculate_literals_length missing \$2" + format_strip_invisibles "$1" + __format_calculate_literals_length__normalizedFormat="$(echo "$FormatStripInvisibles" | sed -r 's/%%|\*\*/X/g')" + fi + + if [ ! "$3" ]; then + echo "format_calculate_literals_length missing \$3" + format_list_specifiers "$1" + __format_calculate_literals_length__specifiers=("${FormatListSpecifiers[@]}") + fi + + FormatCalculateLiteralsLength=$((${#__format_calculate_literals_length__normalizedFormat} - ($(echo "${__format_calculate_literals_length__specifiers[@]}" | wc -m) - ${#__format_calculate_literals_length__specifiers[@]}))) +} + +# This function calculates the total length of statics & literals in format. +# Parameters: $1 - format [$2 - statics length [$3 - literals length]] +function format_calculate_length() { + local __format_calculate_length__staticsLength=$2 + local __format_calculate_length__literalsLength=$3 + + if [ ! "$2" ]; then + #echo "format_calculate_length missing \$2" + format_expand_invisibles "$1" + format_list_specifiers "$FormatExpandInvisibles" + format_calculate_statics_length X FormatListSpecifiers[@] + __format_calculate_length__staticsLength=$FormatCalculateStaticsLength + fi + + if [ ! "$3" ]; then + if [ "$2" ]; then + format_expand_invisibles "$1" + format_list_specifiers "$FormatExpandInvisibles" + fi + #echo "format_calculate_length missing \$3" + format_calculate_literals_length X "$FormatExpandInvisibles" FormatListSpecifiers[@] + __format_calculate_length__literalsLength=$FormatCalculateLiteralsLength + fi + + FormatCalculateLength=$((__format_calculate_length__staticsLength + __format_calculate_length__literalsLength)) +} + +# This function calculates total length of dynamics in format. +# Dynamics are all asterisk-containing specifiers in format. +# Parameters: $1 - format [$2 - format length ] +function format_calculate_dynamics_length() { + local __format_calculate_dynamics_length__formatLength=$2 + + if [ ! "$2" ]; then + echo "format_calculate_dynamics_length missing \$2" + format_calculate_length "$1" + __format_calculate_dynamics_length__formatLength=$FormatCalculateLength + fi + + FormatCalculateDynamicsLength=$(($(tput cols) - $__format_calculate_dynamics_length__formatLength)) +} + +# This function calculates the size of individual dynamics in format. +# Parameters: $1 - format [$2 - dynamics length [$3 - dynamics count]] +function format_calculate_autosize_length() { + local __format_calculate_autosize_length__dynamicsLength=$2 + local __format_calculate_autosize_length__dynamicsCount=$3 + + if [ ! "$2" ]; then + format_expand_invisibles "$1" + format_list_specifiers "$FormatExpandInvisibles" + format_calculate_statics_length X FormatListSpecifiers[@] + format_calculate_literals_length X "$FormatExpandInvisibles" FormatListSpecifiers[@] + format_calculate_length X "$FormatCalculateStaticsLength" "$FormatCalculateLiteralsLength" + format_calculate_dynamics_length X "$FormatCalculateLength" + __format_calculate_autosize_length__dynamicsLength=$FormatCalculateDynamicsLength + fi + + if [ ! "$3" ]; then + if [ "$2" ]; then format_list_specifiers "$1" + fi + format_calculate_dynamics_count X FormatListSpecifiers[@] + __format_calculate_autosize_length__dynamicsCount=$FormatCalculateDynamicsCount + fi + + if [ $__format_calculate_autosize_length__dynamicsCount -ne 0 -a \ + $__format_calculate_autosize_length__dynamicsLength -ge 0 ]; then FormatCalculateAutosizeLength=$((__format_calculate_autosize_length__dynamicsLength / __format_calculate_autosize_length__dynamicsCount)) + else FormatCalculateAutosizeLength=0 + fi +} + +# This function replaces dynamics' asterisks with their length, in format. +# Parameters: $1 - format [$2 - dynamics length [$3 - dynamics count]] +# Warning: Strings containing '\n' result in undefined behavior (not supported). +# Warning: Strings containing [0-9]+.* result in undefined behavior. +# Notice: Single asterisks are auto-sized, doubles are replaced "**" -> "*". +function format_apply_autosize() { + format_calculate_autosize_length "${@}" # Pass all arguments on. + FormatApplyAutosize=$1 + let format_apply_autosize_overcount=$FormatCalculateDynamicsLength%$FormatCalculateDynamicsCount + if [ $format_apply_autosize_overcount -gt 0 ]; then # If we've got left-over, fill it left-to-right. + let format_apply_autosize_oversize=$FormatCalculateAutosizeLength+1 + FormatApplyAutosize=$(echo "$FormatApplyAutosize" | sed -r 's/(^|[^*])\*(\.\*|[^*]|$)/\1'$format_apply_autosize_oversize'\2/'$format_apply_autosize_overcount'; s/([0-9]+\.)\*/\1'$format_apply_autosize_oversize'/'$format_apply_autosize_overcount) + fi + FormatApplyAutosize=$(echo "$FormatApplyAutosize" | sed -r 's/\*\.\*/'$FormatCalculateAutosizeLength'.'$FormatCalculateAutosizeLength'/g; s/(^|[^*])\*([^*]|$)/\1'$FormatCalculateAutosizeLength'\2/g; s/\*\*/*/g') +} + +# This function centers literal text. +# Parameters: $1 - literals +function format_center_literals() { + format_strip_invisibles "$1" + local __format_center_literals__text_length=${#FormatStripInvisibles} + format_apply_autosize "%*s%${__format_center_literals__text_length}s%*s" + FormatCenterLiterals=$(printf "$FormatApplyAutosize" "" "$1" "") +} + +# This function centers statics in format. +# Parameters: $1 - format +function format_center_dynamic() { + format_calculate_length "$1" + format_calculate_dynamics_length X $FormatCalculateLength + format_apply_autosize "%*s%${FormatCalculateLength}s%*s" $FormatCalculateDynamicsLength 2 + # Temporary, I'll find a better solution later (too tired). + FormatCenterDynamic=$(printf "$(echo "$FormatApplyAutosize" | sed -r 's/%[0-9]+s/%s/2')" "" "$1" "") +} diff --git a/lib/HashUtils.sh b/lib/HashUtils.sh new file mode 100755 index 0000000..a5e94f8 --- /dev/null +++ b/lib/HashUtils.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash + +if [ "$HashUtilsVersion" ]; then return 0; fi +readonly HashUtilsVersion="1.0" + +HashOutputDevice="/dev/stdout" + +function hash_check_handshake() { + local -r handshakeVerifier=$1 + local -r handshakePath=$2 + local -r handshakeAPSSID=$3 + local -r handshakeAPMAC=$4 + + echo "Verifier Parameters: " > $HashOutputDevice + echo " Verifier: $handshakeVerifier" > $HashOutputDevice + echo "Hash Path: $handshakePath" > $HashOutputDevice + echo "Hash SSID: \"$handshakeAPSSID\"" > $HashOutputDevice + echo " Hash MAC: $handshakeAPMAC" > $HashOutputDevice + + local analysis # Since it's being used in all relevant instances. + + case "$handshakeVerifier" in + "pyrit") + readarray analysis < <(pyrit -r "$handshakePath" analyze 2> $HashOutputDevice) + if [ "${#analysis[@]}" -eq 0 -o $? != 0 ]; then + echo "Error: pyrit seems to be broken!" > $HashOutputDevice + return 1 + fi + + local hashMeta=$(echo "${analysis[@]}" | grep -F "AccessPoint ${handshakeAPMAC,,} ('$handshakeAPSSID')") + + if [ "$hashMeta" ]; then + local hashID=$(echo "$hashMeta" | awk -F'[ #:]' '{print $3}') + local hashData=$(echo "${analysis[@]}" | awk "\$0~/#$hashID: HMAC_(SHA[0-9]+_AES|MD5_RC4)/{ print \$0 }") + else + echo "No valid hash meta was found for \"$handshakeAPSSID\"" > $HashOutputDevice + fi + ;; + "aircrack-ng") + readarray analysis < <(aircrack-ng "$handshakePath" 2> $HashOutputDevice) + if [ "${#analysis[@]}" -eq 0 -o $? != 0 ]; then + echo "Error: aircrack-ng seems to be broken!" > $HashOutputDevice + return 1 + fi + + local hashData=$(echo "${analysis[@]}" | grep -E "${handshakeAPMAC^^}\s+" | grep -F "$handshakeAPSSID") + ;; + "cowpatty") + readarray analysis < <(aircrack-ng "$handshakePath" 2> $HashOutputDevice) + if [ "${#analysis[@]}" -eq 0 -o $? != 0 ]; then + echo "Error: cowpatty (aircrack-ng) seems to be broken!" > $HashOutputDevice + return 1 + fi + + if echo "${analysis[@]}" | grep -E "${handshakeAPMAC^^}\s+" | grep -qF "$handshakeAPSSID"; then + local hashData=$(cowpatty -cr "$handshakePath") + fi + ;; + *) + echo "Invalid verifier, quitting!" > $HashOutputDevice + return 1 + ;; + esac + + if [ -z "$hashData" ]; then + echo "Handshake for $handshakeAPSSID ($handshakeAPMAC) is missing!" + return 1 + fi + + case "$handshakeVerifier" in + "pyrit") + if echo "$hashData" | grep -qF "good"; then + local -r hashResult=1 + fi ;; + + "aircrack-ng") + if echo "$hashData" | grep -qE "\([0-9]+ handshake\)"; then + local -r hashResult=1 + fi ;; + + "cowpatty") + if echo "$hashData" | grep -q "Collected all necessary data to mount crack against WPA2/PSK passphrase."; then + local -r hashResult=1 + fi ;; + esac + + if [ -z "$hashResult" ]; then + echo "Invalid hash for $handshakeAPSSID ($handshakeAPMAC)!" > $HashOutputDevice + HASHCheckHandshake="invalid" + return 1 + else + echo "Valid hash for $handshakeAPSSID ($handshakeAPMAC)!" > $HashOutputDevice + HASHCheckHandshake="valid" + fi +} diff --git a/lib/HelpUtils.sh b/lib/HelpUtils.sh new file mode 100755 index 0000000..fb5b36d --- /dev/null +++ b/lib/HelpUtils.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash + +fluxion_help(){ + echo " FLUXION(1) User Manuals FLUXION(1) + + + + NAME + fluxion - Fluxion is a security auditing and social-engineering + research tool + + SYNOPSIS + fluxion [-debug] [-l language ] attack ... + + DESCRIPTION + fluxion is a security auditing and social-engineering research tool. + It is a remake of linset by vk496 with (hopefully) less bugs and more + functionality. The script attempts to retrieve the WPA/WPA2 key from a + target access point by means of a social engineering (phising) attack. + It's compatible with the latest release of Kali (rolling). Fluxion's + attacks' setup is mostly manual, but experimental auto-mode handles + some of the attacks' setup parameters. + + OPTIONS + -v Print version number. + + --help Print help page and exit with 0. + + -m Run fluxion in manual mode instead of auto mode. + + -k Kill wireless connection if it is connected. + + -d Run fluxion in debug mode. + + -x Try to run fluxion with xterm terminals instead of tmux. + + -r Reload driver. + + -l + Define a certain language. + + -e + Select the target network based on the ESSID. + + -c + Indicate the channel(s) to listen to. + + -a + Define a certain attack. + + --ratio + Define the windows size. Bigger ratio -> smaller window size. + Default is 4. + + -b + Select the target network based on the access point MAC address. + + -j + Define a certain jamming interface. + + -a + Define a certain access point interface. + + FILES + /tmp/fluxspace/ + The system wide tmp directory. + $FLUXION/attacks/ + Folder where handshakes and passwords are stored in. + + ENVIRONMENT + FLUXIONAuto + Automatically run fluxion in auto mode if exported. + + FLUXIONDebug + Automatically run fluxion in debug mode if exported. + + FLUXIONWIKillProcesses + Automatically kill any interfering process(es). + + DIAGNOSTICS + Please checkout the other log files or use the debug mode. + + BUGS + Please report any bugs at: https://github.com/FluxionNetwork/flux- + ion/issues + + AUTHOR + Cyberfee, l3op, dlinkproto, vk496, MPX4132 + + SEE ALSO + aircrack-ng(8), + + + Linux MARCH 2018 FLUXION(1)" + +} diff --git a/lib/IOUtils.sh b/lib/IOUtils.sh new file mode 100755 index 0000000..49aad59 --- /dev/null +++ b/lib/IOUtils.sh @@ -0,0 +1,149 @@ +#!/usr/bin/env bash + +if [ "$IOUtilsVersion" ]; then return 0; fi +readonly IOUtilsVersion="1.0" + +if [ ! "$FLUXIONLibPath" ]; then return 1; fi + +IOUtilsHeader="[x] ================================ [x]" +IOUtilsQueryMark="[-] " +IOUtilsPrompt="[$USER@$HOSTNAME]> " + +if [ ! "$ArrayUtilsVersion" ]; then + source "$FLUXIONLibPath/ArrayUtils.sh" +fi + +io_input_choice() { + local __io_input_choice__choice + until [ ! -z "$__io_input_choice__choice" ]; do + echo -ne "$IOUtilsPrompt" + + local __io_input_choice__input + read __io_input_choice__input + + local __io_input_choice__choices + for __io_input_choice__choices in ${@}; do + array_contains $__io_input_choice__choices "$__io_input_choice__input" + if [ $? -eq 0 ]; then + __io_input_choice__choice="$__io_input_choice__input" + break + fi + done + done + + IOInputChoice=$__io_input_choice__choice +} + +io_dynamic_output() { + eval 'echo -ne "'${@}'"' +} + +io_input_enumerated_choice() { + local __io_input_enumerated_choice__choices=("${!1}") + local __io_input_enumerated_choice__indexes=($(seq ${#__io_input_numeric_choice__choices[@]})) + io_input_choice __io_input_enumerated_choice__indexes[@] + IOInputEnumeratedChoice=${__io_input_enumerated_choice__choices[$IOInputChoice]} +} + +# This function outputs formatted lines of fields. +# The function takes an output file (like stdout), +# a "printf format string," and a variable number +# of indirect-expansion passed arrays (reference). +# NOTICE: At least the first array must be passed! +# Example: /dev/stdout "%s is %s." name[@] mood[@] +io_output_format_fields() { + # Determine the amount of arguments passed. + local __io_output_format_fields__argument_count=${#@} + + # Load locally by indirect expansion, ${! ... }, + # and mangle the variable number argument arrays. + local __io_output_format_fields__i + for ((__io_output_format_fields__i = 3; __io_output_format_fields__i <= __io_output_format_fields__argument_count; __io_output_format_fields__i++)); do + eval "local __io_output_format_fields__field$__io_output_format_fields__i=(\"\${!$__io_output_format_fields__i}\")" + done + + # Determine the amount of records/lines to print. + # Notice at least the first array must be passed. + local __io_output_format_fields__record_count=${#__io_output_format_fields__field3[@]} + + for ((__io_output_format_fields__i = 0; __io_output_format_fields__i < __io_output_format_fields__record_count; __io_output_format_fields__i++)); do + local __io_output_format_fields__values="\"\${__io_output_format_fields__field"$( + seq -s "[$__io_output_format_fields__i]}\" \"\${__io_output_format_fields__field" 3 $__io_output_format_fields__argument_count + )"[$__io_output_format_fields__i]}\"" + eval "printf \"$2\" $__io_output_format_fields__values > $1" + done +} + +io_query_format_fields() { + # Assure we've got required parameters. + if [ ${#@} -lt 2 ]; then + return 1 + fi + + local __io_query_format_fields__argument_count=${#@} + + local __io_query_format_fields__query="$1" + local __io_query_format_fields__format="$2" + + # Load locally by indirect expansion, ${! ... }, + # and mangle the variable number argument arrays. + local __io_query_format_fields__i + for ((__io_query_format_fields__i = 3; __io_query_format_fields__i <= __io_query_format_fields__argument_count; __io_query_format_fields__i++)); do + eval "local __io_query_format_fields__f$__io_query_format_fields__i=(\"\${!$__io_query_format_fields__i}\")" + done + + local __io_query_format_fields__record_count=${#__io_query_format_fields__f3[@]} + local __io_query_format_fields__indexes=($(seq $__io_query_format_fields__record_count)) + + if [ ! -z "$1" ]; then + if [ "$(type -t $(echo -e "$IOUtilsHeader" | grep -vE '\s'))" = "function" ]; then $IOUtilsHeader + else echo -e "$IOUtilsHeader"; fi + + echo -e "$__io_query_format_fields__query" + echo + fi + + io_output_format_fields /dev/stdout "$__io_query_format_fields__format" __io_query_format_fields__indexes[@] ${@:3} + + echo + + io_input_choice __io_query_format_fields__indexes[@] + + IOQueryFormatFields=() + for ((__io_query_format_fields__i = 3; __io_query_format_fields__i <= __io_query_format_fields__argument_count; __io_query_format_fields__i++)); do + eval "IOQueryFormatFields[${#IOQueryFormatFields[@]}]=\${__io_query_format_fields__f$__io_query_format_fields__i[IOInputChoice - 1]}" + done +} + +io_query_choice() { + # Assure we've got required parameters. + if [ ${#@} -lt 2 ]; then + return 1 + fi + + __io_query_choice__query=$([ -z "$1" ] && echo -n "" || echo -ne "$FLUXIONVLine $1\n") + io_query_format_fields "$__io_query_choice__query" "\t$CRed[$CSYel%d$CClr$CRed]$CClr %b\n" $2 + + IOQueryChoice="${IOQueryFormatFields[0]}" +} + +io_query_file() { + if [ ${#@} -lt 2 ]; then + return 1 + fi + + local __io_query_file__options + + # List a line per line and redirect output. + # readarray __io_query_file__options < $2 + mapfile __io_query_file__options <$2 + + # Strip newline characters from array elements + __io_query_file__options=("${__io_query_file__options[@]/$'\n'/}") + + io_query_choice "$1" __io_query_file__options[@] + + IOQueryFile=$IOQueryChoice +} + +# FLUXSCRIPT END diff --git a/lib/InterfaceUtils.sh b/lib/InterfaceUtils.sh new file mode 100755 index 0000000..8ed1da8 --- /dev/null +++ b/lib/InterfaceUtils.sh @@ -0,0 +1,182 @@ +#!/usr/bin/env bash + +#if [ "$InterfaceUtilsVersion" ]; then return 0; fi +#readonly InterfaceUtilsVersion="1.0" + +# The methods used in this script are taken from airmon-ng. +# This is all thanks for the airmon-ng authors, thanks guys. +InterfaceUtilsOutputDevice="/dev/stdout" + +if [ -d /sys/bus/usb ] # && hash lsusb; + then InterfaceUSBBus=1 +fi + +if [ -d /sys/bus/pci -o -d /sys/bus/pci_express -o -d /proc/bus/pci ] # && hash lspci; + then InterfacePCIBus=1 +fi + +# Checks if the interface belongs to a physical device. +function interface_is_real() { + test -d /sys/class/net/$1/device + return $? +} + +# Checks if the interface belongs to a wireless device. +function interface_is_wireless() { + grep -qs "DEVTYPE=wlan" /sys/class/net/$1/uevent + return $? +} + +# Returns an array of absolutely all interfaces. +# Notice: That includes interfaces such as the loopback interface. +function interface_list_all() { + InterfaceListAll=(/sys/class/net/*) + InterfaceListAll=("${InterfaceListAll[@]//\/sys\/class\/net\//}") +} + +# Returns an array of interfaces pertaining to a physical device. +function interface_list_real() { + InterfaceListReal=() + interface_list_all + local __interface_list_real__candidate + for __interface_list_real__candidate in "${InterfaceListAll[@]}"; do + if interface_is_real $__interface_list_real__candidate; then InterfaceListReal+=("$__interface_list_real__candidate") + fi + done +} + +# Returns an array of interfaces pertaining to a wireless device. +function interface_list_wireless() { + InterfaceListWireless=() + interface_list_all + local __interface_list_wireless__candidate + for __interface_list_wireless__candidate in "${InterfaceListAll[@]}"; do + if interface_is_wireless $__interface_list_wireless__candidate; then InterfaceListWireless+=("$__interface_list_wireless__candidate") + fi + done +} + +function interface_driver() { + InterfaceDriver=$(basename $(readlink /sys/class/net/$1/device/driver)) +} + +function interface_physical() { + if [ ! "$1" ]; then return 1; fi + + unset InterfacePhysical + + local -r interface_physical_path="/sys/class/net/$1/phy80211" + + if [ -d "$interface_physical_path" ]; then + if [ -r "$interface_physical_path/name" ]; then InterfacePhysical="$(cat "$interface_physical_path/name")" + fi + if [ ! "${InterfacePhysical// /}" ]; then InterfacePhysical="$(ls -l "$interface_physical_path" | sed 's/^.*\/\([a-zA-Z0-9_-]*\)$/\1/')" + fi + fi + + if [ ! "$InterfacePhysical" ]; then return 2; fi +} + +function interface_hardware() { + if [ ! "$1" ]; then return 1; fi + + local __interface_hardware__device="/sys/class/net/$1/device" + local __interface_hardware__hwinfo="$__interface_hardware__device/modalias" + + InterfaceHardwareBus="$(cut -d ":" -f 1 "$__interface_hardware__hwinfo" 2>$InterfaceUtilsOutputDevice)" + + case "$InterfaceHardwareBus" in + "usb") # Wanted to replace the line below with awk, but i'll probably just add complexity & issues (mawk vs gawk). + InterfaceHardwareID="$(cut -d ":" -f 2 $__interface_hardware__hwinfo | cut -b 1-10 | sed 's/^.//;s/p/:/')" + ;; + "pci" | "pcmcia" | "sdio") + InterfaceHardwareID="$(cat "$__interface_hardware__device/vendor" 2>$InterfaceUtilsOutputDevice):$(cat "$__interface_hardware__device/device" 2>$InterfaceUtilsOutputDevice)" + ;; + default) # The following will only work for USB devices. + InterfaceHardwareID="$(cat "$__interface_hardware__device/idVendor" 2>$InterfaceUtilsOutputDevice):$(cat "$__interface_hardware__device/idProduct" 2>$InterfaceUtilsOutputDevice)" + InterfaceHardwareBus="usb" + ;; # This will be reset below if InterfaceHardwareID is invalid. + esac + + # Check for invalid InterfaceHardwareID (starts or ends with :) .. not a happy face, still won't quote it. + if echo "$InterfaceHardwareID" | egrep -q "^:|:$"; then + unset InterfaceHardwareID + unset InterfaceHardwareBus + return 2 + else + # Remove any extraneous hex markers. + InterfaceHardwareID=${InterfaceHardwareID//0x/} + fi +} + +function interface_chipset() { + if [ ! "$1" ]; then return 1; fi + + if ! interface_hardware "$1"; then return 2; fi + + case "$InterfaceHardwareBus" in + "usb") + if [ ! "$InterfaceUSBBus" ]; then return 3; fi + InterfaceChipset="$(lsusb -d "$InterfaceHardwareID" | head -n1 - | cut -f3- -d ":" | sed 's/^....//;s/ Network Connection//g;s/ Wireless Adapter//g;s/^ //')" + ;; + "pci" | "pcmcia") + if [ ! "$InterfacePCIBus" ]; then return 4; fi + InterfaceChipset="$(lspci -d $InterfaceHardwareID | cut -f3- -d ":" | sed 's/Wireless LAN Controller //g;s/ Network Connection//g;s/ Wireless Adapter//;s/^ //')" + ;; + "sdio") + if [[ "${InterfaceHardwareID,,}" == "0x02d0"* ]]; then InterfaceChipset=$(printf "Broadcom %d" ${InterfaceHardwareID:7}) + else InterfaceChipset="Unknown chipset for SDIO device." + fi + ;; + default) + InterfaceChipset="Unknown device chipset & device bus." + ;; + esac +} + +function interface_state() { + if [ ! "$1" ]; then return 1; fi + local __interface_state__stateFile="/sys/class/net/$1/operstate" + + if [ ! -f "$__interface_state__stateFile" ]; then return 2; fi + InterfaceState=$(cat "$__interface_state__stateFile") +} + +function interface_set_state() { + if [ "${#@}" -ne 2 ]; then return 1; fi + # TODO: Add alternatives to 'ip' in case of failure. + ip link set "$1" "$2" + return $? +} + +function interface_set_mode() { + if [ "${#@}" -ne 2 ]; then return 1; fi + if ! interface_set_state "$1" "down"; then return 2; fi + if ! iw dev "$1" set type "$2" &> $InterfaceUtilsOutputDevice; then + if ! iwconfig "$1" mode "$2" &> $InterfaceUtilsOutputDevice + then return 3 + fi + fi + if ! interface_set_state "$1" "up"; then return 4; fi +} + +function interface_reidentify() { + if [ ${#@} -ne 2 ]; then return 1; fi + + local -r __interface_reidentify__oldIdentifier=$1 + local -r __interface_reidentify__newIdentifier=$2 + + if [[ $__interface_reidentify__newIdentifier == *" "* ]] + then return 2 + fi + + if ! interface_set_state $__interface_reidentify__oldIdentifier down + then return 3 + fi + + # TODO: Add alternatives to 'ip' in case of failure. + ip link set $__interface_reidentify__oldIdentifier name $__interface_reidentify__newIdentifier + return $? +} + +# FLUXSCRIPT END diff --git a/lib/SandboxUtils.sh b/lib/SandboxUtils.sh new file mode 100755 index 0000000..e78fb49 --- /dev/null +++ b/lib/SandboxUtils.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +if [ "$SandboxUtilsVersion" ]; then return 0; fi +readonly SandboxUtilsVersion="1.0" + +SandboxWorkspacePath="/tmp/sandbox" +SandboxOutputDevice="/dev/stdout" + +# After changing global identifiers in the main script, +# I forgot to update the identifiers here, leading to a +# horrific accident where the script ended and executed +# the command "rm -rf /*" ... yeah, fuck that... +# Spent an entire day retreiving all my shit back. +function sandbox_remove_workfile() { + # Check we've got the environment variables ready. + if [[ -z "$SandboxWorkspacePath" || -z "$SandboxOutputDevice" ]]; then + echo "The workspace path, or the output device is missing." >$SandboxOutputDevice + return 1 + fi + + # Check we're actually deleting a workfile. + if [[ "$1" != $SandboxWorkspacePath* ]]; then + echo "Stopped an attempt to delete non-workfiles." >$SandboxOutputDevice + return 2 + fi + + # Attempt to remove iff it exists. + #if [ ! -e "$1" -a "$1" != *"/"*"*" ]; then + # echo "Stopped an attempt to delete non-existent files" > $SandboxOutputDevice + # return 3; + #fi + + # Remove the target file (do NOT force it). + eval "rm -r $1 &> $SandboxOutputDevice" +} + +# FLUXSCRIPT END diff --git a/lib/ap/airbase-ng.sh b/lib/ap/airbase-ng.sh new file mode 100755 index 0000000..397fada --- /dev/null +++ b/lib/ap/airbase-ng.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +# ================================================================ +# Configuration Section +# ================================================================ +#APServiceConfigDirectory=$FLUXIONWorkspacePath +# ================================================================ + +#if [ "$APServiceVersion" ]; then return 0; fi +#readonly APServiceVersion="1.0" + +function ap_service_stop() { + if [ "$APServicePID" ]; then + kill $APServicePID &> $FLUXIONOutputDevice + fi + + APServicePID="" +} + +function ap_service_reset() { + ap_service_stop + + APServiceAccessInterface="" + + APServiceChannel="" + APServiceMAC="" + APServiceSSID="" + APServiceInterfaceAddress="" + APServiceInterface="" +} + +function ap_service_route() { + local networkSubnet=${APServiceInterfaceAddress%.*} + local networkAddress=$(( ( ${APServiceInterfaceAddress##*.} + 1 ) % 255 )) + + if [ $hostID -eq 0 ]; then + let hostID++ + fi + + # TODO: Dynamically get the airbase-ng tap interface & use below. + # WARNING: Notice the interface below is STATIC, it'll break eventuajly! + if ! ip addr add "at0" $networkSubnet.$networkAddress/24; then + return 1 + fi + + if ! sysctl net.ipv6.conf.at0.disable_ipv6=1 &> $FLUXIONOutputDevice; then + return 2 + fi +} + +function ap_service_prep() { + if [ ${#@} -lt 5 ]; then return 1; fi + + APServiceInterface=$1 + APServiceInterfaceAddress=$2 + APServiceSSID=$3 + APServiceMAC=$4 + APServiceChannel=$5 + + ap_service_stop + + # Spoof virtual interface MAC address. + # This is done by airbase-ng automatically. + + # airbase-ng uses a monitor-mode virtual interface + # and creates a separate interface, atX, for dhcpd. + APServiceAccessInterface="at0" +} + +function ap_service_start() { + ap_service_stop + + xterm $FLUXIONHoldXterm $TOP -bg "#000000" -fg "#FFFFFF" \ + -title "FLUXION AP Service [airbase-ng]" -e \ + airbase-ng -P -e $APServiceSSID -c $APServiceChannel \ + -a $APServiceMAC $APServiceInterface & + local parentPID=$! + + # Wait till airebase-ng starts and creates the extra virtual interface. + while [ ! "$APServicePID" ]; do + sleep 1 + APServicePID=$(pgrep -P $parentPID) + done + + ap_service_route +} + +# FLUXSCRIPT END diff --git a/lib/ap/hostapd.sh b/lib/ap/hostapd.sh new file mode 100755 index 0000000..fd07f27 --- /dev/null +++ b/lib/ap/hostapd.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash + +# ================================================================ +# Configuration Section +# ================================================================ +APServiceConfigDirectory=$FLUXIONWorkspacePath +# ================================================================ + +#if [ "$APServiceVersion" ]; then return 0; fi +#readonly APServiceVersion="1.0" + +function ap_service_stop() { + if [ "$APServicePID" ]; then + kill $APServicePID &> $FLUXIONOutputDevice + fi + + APServicePID="" +} + +function ap_service_reset() { + ap_service_stop + + # Reset MAC address to original. + ip link set $APServiceInterface down + sleep 0.25 + + macchanger -p $APServiceInterface &> $FLUXIONOutputDevice + sleep 0.25 + + ip link set $APServiceInterface up + sleep 0.25 + + APServiceAccessInterface="" + + APServiceChannel="" + APServiceMAC="" + APServiceSSID="" + APServiceInterfaceAddress="" + APServiceInterface="" + +} + +function ap_service_route() { + echo "APService: No custom routes for hostapd" > $FLUXIONOutputDevice +} + +function ap_service_prep() { + if [ ${#@} -lt 5 ]; then return 1; fi + + APServiceInterface=$1 + APServiceInterfaceAddress=$2 + APServiceSSID=$3 + APServiceMAC=$4 + APServiceChannel=$5 + + ap_service_stop + + # Prepare the hostapd config file. + echo "\ +interface=$APServiceInterface +driver=nl80211 +ssid=$APServiceSSID +channel=$APServiceChannel" \ + > "$APServiceConfigDirectory/$APServiceMAC-hostapd.conf" + + # Spoof virtual interface MAC address. + ip link set $APServiceInterface down + sleep 0.5 + + macchanger --mac=$APServiceMAC $APServiceInterface &> $FLUXIONOutputDevice + sleep 0.5 + + ip link set $APServiceInterface up + sleep 0.5 + + # HostAPD sets the virtual interface mode + # to master, which is supported by dhcpd. + APServiceAccessInterface=$APServiceInterface +} + +function ap_service_start() { + ap_service_stop + + xterm $FLUXIONHoldXterm $TOP -bg "#000000" -fg "#FFFFFF" \ + -title "FLUXION AP Service [hostapd]" -e \ + hostapd "$APServiceConfigDirectory/$APServiceMAC-hostapd.conf" & + local parentPID=$! + + # Wait till hostapd has started and its virtual interface is ready. + while [ ! "$APServicePID" ]; do + sleep 1 + APServicePID=$(pgrep -P $parentPID) + done + + ap_service_route +} + +# FLUXSCRIPT END diff --git a/lib/installer/InstallerUtils.sh b/lib/installer/InstallerUtils.sh new file mode 100755 index 0000000..e3af974 --- /dev/null +++ b/lib/installer/InstallerUtils.sh @@ -0,0 +1,293 @@ +#!/usr/bin/env bash + +if [ "$InstallerUtilsVersion" ]; then return 0; fi +readonly InstallerUtilsVersion="1.0" + +InstallerUtilsWorkspacePath="/tmp/verspace" + +InstallerUtilsOutputDevice="/dev/stdout" + +InstallerUtilsNoticeMark="*" + +PackageManagerLog="$InstallerUtilsWorkspacePath/package_manager.log" + +installer_utils_run_spinner() { + local pid=$1 + local delay=0.15 + local spinstr="|/-\\" + + tput civis + while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do + local temp=${spinstr#?} + printf " [%c] " "$spinstr" + local spinstr=$temp${spinstr%"$temp"} + sleep $delay + printf "\b\b\b\b\b\b" + done + + printf " \b\b\b\b" + tput cnorm +} + +# Pamaters: +# $1 source - Online Info File (text) +# $2 version regex - Online version (regex) +# $3 revision regex - Online version (regex) +installer_utils_check_version() { + if [ ${#@} -ne 3 ]; then return 1; fi + + # Attempt to retrieve versioning information from repository script. + local -r __installer_utils_check_version__info=$(timeout -s SIGTERM 20 curl "$1" 2>/dev/null) + + local -r __installer_utils_check_version__onlineVersion=$( + echo "$__installer_utils_check_version__info" | egrep "$2" | egrep -o "[0-9]+") + local -r __installer_utils_check_version__onlineRevision=$( + echo "$__installer_utils_check_version__info" | egrep "$3" | egrep -o "[0-9]+") + + if [ "$__installer_utils_check_version__onlineVersion" ] && \ + [ "$__installer_utils_check_version__onlineRevision" ]; then + echo "$__installer_utils_check_version__onlineVersion" > \ + "$InstallerUtilsWorkspacePath/latest_version" + echo "$__installer_utils_check_version__onlineRevision" >> \ + "$InstallerUtilsWorkspacePath/latest_version" + fi +} + +# Pamaters: +# $1 source - Online Info File (text) +# $2 version regex - Online version (regex) +# $3 version local - Local version (number) +# $4 revision regex - Online version (regex) +# $5 revision local - Local version (number) +installer_utils_check_update() { + # The following set of statements aren't very generic, need to be refactored. + local versionDialog="Online Version" + local versionDialogOffset=$(($(tput cols) / 2 + ((${#versionDialog} / 2) - 4))) + printf "%${versionDialogOffset}s" "$versionDialog" + + installer_utils_check_version "${@:1:3}" & + installer_utils_run_spinner "$!" # This should be done externally (refactored). + + local __installer_utils_check_update__localVersion=$4 + local __installer_utils_check_update__localRevision=$5 + local __installer_utils_check_update__version="?" + local __installer_utils_check_update__revision="?" + + if [ -f "$InstallerUtilsWorkspacePath/latest_version" -a \ + -s "$InstallerUtilsWorkspacePath/latest_version" ]; then + local __installer_utils_check_update__vInfo + mapfile -tn 2 __installer_utils_check_update__vInfo < \ + "$InstallerUtilsWorkspacePath/latest_version" + + sandbox_remove_workfile "$InstallerUtilsWorkspacePath/latest_version" + + __installer_utils_check_update__version=${__installer_utils_check_update__vInfo[0]} + __installer_utils_check_update__revision=${__installer_utils_check_update__vInfo[1]} + fi + + echo -e "$CClr [$__installer_utils_check_update__version.$__installer_utils_check_update__revision$CClr]" + + if [ \ + "$__installer_utils_check_update__version" != "?" -a \ + "$__installer_utils_check_update__revision" != "?" ]; then + if [ \ + "$__installer_utils_check_update__version" -gt \ + "$__installer_utils_check_update__localVersion" -o \ + "$__installer_utils_check_update__version" -eq \ + "$__installer_utils_check_update__localVersion" -a \ + "$__installer_utils_check_update__revision" -gt \ + "$__installer_utils_check_update__localRevision" ]; then + format_center_literals "[${CBGrn}A newer version has been found!$CClr]" + echo + echo -e "$FormatCenterLiterals" + return 0 + fi + fi + + return 1 # Failure +} + +# Parameters: $1 - Update source (zip) $2 - Backup file name $3 - Update output +installer_utils_run_update() { + if [ ${#@} -ne 3 ]; then return 1; fi + + local __installer_utils_run_update__source="$1" + local __installer_utils_run_update__backup="$2" + local __installer_utils_run_update__output="$3" + + format_center_literals "Press$CYel Y$CClr /$CYel enter$CClr to update, anything else to skip." + echo -e "$FormatCenterLiterals" + + tput civis + local __installer_utils_run_update__option + read -N1 __installer_utils_run_update__option + tput cnorm + + # If the user doesn't want to upgrade, stop this procedure. + if [ \ + "${__installer_utils_run_update__option-}" != $'\n' -a \ + "${__installer_utils_run_update__option^}" != "Y" ]; then + return 1 + fi + + local __installer_utils_run_update__backupFile="$__installer_utils_run_update__backup-$(date +%F_%T)" + local __installer_utils_run_update__backupPath="$(dirname $__installer_utils_run_update__output)/$__installer_utils_run_update__backupFile.7z" + + # If a file with the backup name already exists, abort. + if [ -f "$__installer_utils_run_update__backupPath" ]; then + format_center_literals "[${CRed}Can't overwite existing file!$CClr]" + echo -e "$FormatCenterLiterals" + sleep 3 + return 2 + fi + + format_center_literals "[ ~ Creating Backup ~ ]" + echo -e "$FormatCenterLiterals" + echo + + 7zr a "$__installer_utils_run_update__backupPath" \ + "$__installer_utils_run_update__output" &> $InstallerUtilsOutputDevice + + format_center_literals "[ ~ Downloading Update ~ ]" + echo -e "$FormatCenterLiterals" + echo + if ! curl -L "$__installer_utils_run_update__source" -o "$InstallerUtilsWorkspacePath/update.zip"; then + format_center_literals "[ ~ ${CRed}Download Failed$CClr ~ ]" + echo -e "$FormatCenterLiterals" + echo + sleep 3 + return 3 + fi + + format_center_literals "[ ~ Verifying Download ~ ]" + echo + if ! unzip -t "$InstallerUtilsWorkspacePath/update.zip" &> \ + $InstallerUtilsOutputDevice; then + format_center_literals "[ ~ ${CRed}Download Appears Corrupted$CClr ~ ]" + echo -e "$FormatCenterLiterals" + sleep 3 + return 4 + fi + + format_center_literals "[ ~ Extracting Files ~ ]" + echo -e "$FormatCenterLiterals" + echo + mkdir "$InstallerUtilsWorkspacePath/update_contents" + unzip "$InstallerUtilsWorkspacePath/update.zip" \ + -d "$InstallerUtilsWorkspacePath/update_contents" &> \ + $InstallerUtilsOutputDevice + + if [ ! -d "$__installer_utils_run_update__output" ]; then + if ! mkdir -p "$__installer_utils_run_update__output"; then + format_center_literals "[ ~ ${CRed}Failed To Create Destination Directory$CClr ~ ]" + echo -e "$FormatCenterLiterals" + echo + sleep 3 + return 5 + fi + fi + + format_center_literals "[ ~ Moving Files ~ ]" + echo -e "$FormatCenterLiterals" + echo + + # Delete all contents of previous installation. + $(cd "$__installer_utils_run_update__output"; rm -rf *) + + mv "$InstallerUtilsWorkspacePath"/update_contents/*/* \ + "$__installer_utils_run_update__output" + + format_center_literals "[ ~ ${CSGrn}Update Completed$CClr ~ ]" + echo -e "$FormatCenterLiterals" + echo + sleep 5 +} + +# Parameters: $1 - CLI Tools required array $2 - CLI Tools missing array (will be populated) +installer_utils_check_dependencies() { + if [ ! "$1" ]; then return 1; fi + + local __installer_utils_check_dependencies__CLIToolsInfo=("${!1}") + InstallerUtilsCheckDependencies=() + + local __installer_utils_check_dependencies__CLIToolInfo + for __installer_utils_check_dependencies__CLIToolInfo in "${__installer_utils_check_dependencies__CLIToolsInfo[@]}"; do + local __installer_utils_check_dependencies__CLITool=${__installer_utils_check_dependencies__CLIToolInfo/:*/} + local __installer_utils_check_dependencies__identifier="$(printf "%-44s" "$__installer_utils_check_dependencies__CLITool")" + local __installer_utils_check_dependencies__state=".....$CGrn OK.$CClr" + + if ! hash "$__installer_utils_check_dependencies__CLITool" 2>/dev/null; then + __installer_utils_check_dependencies__state="$CRed Missing!$CClr" + InstallerUtilsCheckDependencies+=("$__installer_utils_check_dependencies__CLIToolInfo") + fi + + format_center_literals "$InstallerUtilsNoticeMark ${__installer_utils_check_dependencies__identifier// /.}$__installer_utils_check_dependencies__state" + echo -e "$FormatCenterLiterals" + done + + if [ ${#InstallerUtilsCheckDependencies[@]} -gt 0 ]; then return 2; fi +} + +# Parameters: $1 - CLI Tools missing array (will be installed) $2 - substitutes array +installer_utils_run_dependencies() { + if [ ! "$1" ]; then return 1; fi + if ! ping -q -w 1 -c 1 8.8.8.8 &> /dev/null; then + format_center_literals "[${CRed}!$CClr] ${CBYel}No internet connection found!$CClr" + echo -e "\n\n$FormatCenterLiterals" + + format_center_literals "[ ${CSRed}CANNOT CONTINUE${CClr} ]" + echo -e "$FormatCenterLiterals"; sleep 3 + + return 3 + fi + + # The array below holds all the packages that will be installed. + local __installer_utils_run_dependencies__dependenciesInfo=("${!1}") + + local __installer_utils_run_dependencies__managers=("$FLUXIONLibPath/installer/managers/"*) + + local __installer_utils_run_dependencies__manager + for __installer_utils_run_dependencies__manager in "${__installer_utils_run_dependencies__managers[@]}"; do + source "$__installer_utils_run_dependencies__manager" + if [ "$PackageManagerCLT" ]; then break; fi + done + + if [ ! "$PackageManagerCLT" ]; then + format_center_literals "${CRed}[ ~ No Suitable Package Manager Found ~ ]$CClr";echo + sleep 3 + return 2 + fi + + check_package_manager + prep_package_manager + + unset __installer_utils_run_dependencies__installerStatus + + for __installer_utils_run_dependencies__dependencyInfo in "${__installer_utils_run_dependencies__dependenciesInfo[@]}"; do + local __installer_utils_run_dependencies__target=${__installer_utils_run_dependencies__dependencyInfo/:*/} + local __installer_utils_run_dependencies__packages=${__installer_utils_run_dependencies__dependencyInfo/*:/} + unset __installer_utils_run_dependencies__packageStatus + + local __installer_utils_run_dependencies__package + for __installer_utils_run_dependencies__package in ${__installer_utils_run_dependencies__packages//|/ }; do + clear + if $PackageManagerCLT $PackageManagerCLTInstallOptions $__installer_utils_run_dependencies__package; then + local __installer_utils_run_dependencies__packageStatus="installed" + break + fi + done + + if [ -z ${__installer_utils_run_dependencies__packageStatus+x} ]; then + __installer_utils_run_dependencies__installerStatus="failed" + break + fi + done + + unprep_package_manager + + if [ "$__installer_utils_run_dependencies__installerStatus" = "failed" ]; then + return 3 + fi +} + +# FLUXSCRIPT END diff --git a/lib/installer/managers/apt.sh b/lib/installer/managers/apt.sh new file mode 100755 index 0000000..05cce57 --- /dev/null +++ b/lib/installer/managers/apt.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +if [ -f "/etc/debian_version" ]; then + PackageManagerCLT="apt" + PackageManagerCLTInstallOptions="install -y" + PackageManagerCLTRemoveOptions="remove -y" + + PackageManagerOutputDevice="/dev/stdout" + + unprep_package_manager() { + echo "$(cat /etc/apt/sources.list | grep -v 'deb http://http.kali.org/kali kali-rolling main non-free contrib # Installed By FLUXION')" >/etc/apt/sources.list + } + + check_package_manager() { + echo "Nothing to check." >$PackageManagerOutputDevice + } + + prep_package_manager() { + if [ ! "$(cat /etc/apt/sources.list | egrep 'deb http://http.kali.org/kali ((kali-rolling|main|contrib|non-free) )*')" ]; then + echo "Adding missing sources to package manager, please wait." + + echo "Adding keys.gnupg.net key, please wait." + if ! gpg --keyserver hkp://keys.gnupg.net --recv-key 7D8D0BF6 &>/dev/null; then + echo "ERROR: Failed to fetch or add the source key!" + return 1 + fi + + echo "Adding pgp.mit.edu key, please wait." + if ! apt-key adv --keyserver pgp.mit.edu --recv-keys ED444FF07D8D0BF60 &>/dev/null; then + echo "ERROR: Failed to fetch or add the source key!" + return 1 + fi + + echo "deb http://http.kali.org/kali kali-rolling main non-free contrib # Installed By FLUXION" >>/etc/apt/sources.list + fi + + # Cleanup package manager + apt-get install -f -y | tee -a $PackageManagerLog + apt-get autoremove -y | tee -a $PackageManagerLog + apt-get autoclean -y | tee -a $PackageManagerLog + apt-get clean -y | tee -a $PackageManagerLog + apt-get update | tee -a $PackageManagerLog + } +fi + +# FLUXSCRIPT END diff --git a/lib/installer/managers/emerge.sh b/lib/installer/managers/emerge.sh new file mode 100755 index 0000000..1266d08 --- /dev/null +++ b/lib/installer/managers/emerge.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [ -f "/etc/gentoo-release" ]; then + PackageManagerCLT="emerge" + PackageManagerCLTInstallOptions="-s" + PackageManagerCLTRemoveOptions="" + + PackageManagerOutputDevice="/dev/stdout" + + unprep_package_manager() { + echo "Nothing to unprepare." >$PackageManagerOutputDevice + } + + check_package_manager() { + echo "Nothing to check." >$PackageManagerOutputDevice + } + + prep_package_manager() { + echo "Nothing to prepare." >$PackageManagerOutputDevice + } +fi + +# FLUXSCRIPT END diff --git a/lib/installer/managers/pacman.sh b/lib/installer/managers/pacman.sh new file mode 100755 index 0000000..ffc6a3a --- /dev/null +++ b/lib/installer/managers/pacman.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +if [ -f "/etc/arch-release" ]; then + #Last entry is the default package manager to use (pacman) + AurHelpers="pacaur yaourt pacman" + for AurHelper in $AurHelpers; do + if [ "$(pacman -Qs $AurHelper)" ]; then + PackageManagerCLT=$AurHelper + break + fi + done + PackageManagerCLT='pacman' + PackageManagerCLTInstallOptions="-S --noconfirm" + PackageManagerCLTRemoveOptions="-Rs" + + PackageManagerOutputDevice="/dev/stdout" + + unprep_package_manager() { + echo "Nothing to unprepare." >$PackageManagerOutputDevice + } + + check_package_manager() { + if [ -f "/var/lib/pacman/db.lck" ];then echo -e "[\033[31m!\033[0m] Pacman is locked, can't install dependencies. Exit."; exit 4; fi + } + + prep_package_manager() { + echo "Nothing to prepare." >$PackageManagerOutputDevice + } +fi + +# FLUXSCRIPT END diff --git a/lib/installer/managers/yum.sh b/lib/installer/managers/yum.sh new file mode 100755 index 0000000..f9d53d3 --- /dev/null +++ b/lib/installer/managers/yum.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [ -f "/etc/redhat-release" ]; then + PackageManagerCLT="yum" + PackageManagerCLTInstallOptions="-y install" + PackageManagerCLTRemoveOptions="remove" + + PackageManagerOutputDevice="/dev/stdout" + + unprep_package_manager() { + echo "Nothing to unprepare." >$PackageManagerOutputDevice + } + + check_package_manager () { + echo "Nothing to check." >$PackageManagerOutputDevice + } + + prep_package_manager() { + echo "Nothing to prepare." >$PackageManagerOutputDevice + } +fi + +# FLUXSCRIPT END diff --git a/lib/installer/managers/zypp.sh b/lib/installer/managers/zypp.sh new file mode 100755 index 0000000..81df10f --- /dev/null +++ b/lib/installer/managers/zypp.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [ -f "/etc/SuSE-release" ]; then + PackageManagerCLT="zypp" + PackageManagerCLTInstallOptions="install" + PackageManagerCLTRemoveOptions="remove" + + PackageManagerOutputDevice="/dev/stdout" + + unprep_package_manager() { + echo "Nothing to unprepare." >$PackageManagerOutputDevice + } + + check_package_manager() { + echo "Nothing to check." >$PackageManagerOutputDevice + } + + prep_package_manager() { + echo "Nothing to prepare." >$PackageManagerOutputDevice + } +fi + +# FLUXSCRIPT END