Minor bash improvements

- use pure bash
- fix escaping seq.
- fix global word spliting
- increase readability
This commit is contained in:
deltaxflux 2018-07-10 22:50:19 +02:00
parent 2f18a30a98
commit 3353955e1f
3 changed files with 74 additions and 49 deletions

View File

@ -6,7 +6,6 @@
HandshakeSnooperState="Not Ready" HandshakeSnooperState="Not Ready"
# ============================================================ # # ============================================================ #
# ========= < Handshake Snooper Helper Subroutines > ========= # # ========= < Handshake Snooper Helper Subroutines > ========= #
# ============================================================ # # ============================================================ #
@ -14,7 +13,6 @@ handshake_snooper_header() {
fluxion_header; fluxion_target_show; echo fluxion_header; fluxion_target_show; echo
} }
# ============================================================ # # ============================================================ #
# ============= < Handshake Snooper Subroutines > ============ # # ============= < Handshake Snooper Subroutines > ============ #
# ============================================================ # # ============================================================ #
@ -372,7 +370,7 @@ if [ ! "$HandshakeSnooperCLIArguments" ]; then
getopt --options="v:i:j:a" \ getopt --options="v:i:j:a" \
--longoptions="verifier:,interval:,jammer:,asynchronous" \ --longoptions="verifier:,interval:,jammer:,asynchronous" \
--name="Handshake Snooper V$FLUXIONVersion.$FLUXIONRevision" -- "$@" --name="Handshake Snooper V$FLUXIONVersion.$FLUXIONRevision" -- "$@"
); then );n then
echo -e "${CRed}Aborted$CClr, parameter error detected..." echo -e "${CRed}Aborted$CClr, parameter error detected..."
sleep 5 sleep 5
fluxion_handle_exit fluxion_handle_exit

View File

@ -4,7 +4,7 @@
# ================== < FLUXION Parameters > ================== # # ================== < FLUXION Parameters > ================== #
# ============================================================ # # ============================================================ #
# Path to directory containing the FLUXION executable script. # Path to directory containing the FLUXION executable script.
readonly FLUXIONPath=$(dirname $(readlink -f "$0")) readonly FLUXIONPath=$(dirname "$(readlink -f "$0")")
# Path to directory containing the FLUXION library (scripts). # Path to directory containing the FLUXION library (scripts).
readonly FLUXIONLibPath="$FLUXIONPath/lib" readonly FLUXIONLibPath="$FLUXIONPath/lib"
@ -22,7 +22,7 @@ readonly FLUXIONNoiseFloor=-90
readonly FLUXIONNoiseCeiling=-60 readonly FLUXIONNoiseCeiling=-60
readonly FLUXIONVersion=4 readonly FLUXIONVersion=4
readonly FLUXIONRevision=12 readonly FLUXIONRevision=13
# Declare window ration bigger = smaller windows # Declare window ration bigger = smaller windows
FLUXIONWindowRatio=4 FLUXIONWindowRatio=4
@ -34,32 +34,32 @@ FLUXIONSkipDependencies=0
# ================= < Script Sanity Checks > ================= # # ================= < Script Sanity Checks > ================= #
# ============================================================ # # ============================================================ #
if [ $EUID -ne 0 ]; then # Super User Check if [ $EUID -ne 0 ]; then # Super User Check
echo -e "\033[31mAborted, please execute the script as root.\033[0m"; exit 1 echo -e "\\033[31mAborted, please execute the script as root.\\033[0m"; exit 1
fi fi
# ===================== < XTerm Checks > ===================== # # ===================== < XTerm Checks > ===================== #
# TODO: Run the checks below only if we're not using tmux. # TODO: Run the checks below only if we're not using tmux.
if [ ! "${DISPLAY:-}" ]; then # Assure display is available. if [ ! "${DISPLAY:-}" ]; then # Assure display is available.
echo -e "\033[31mAborted, X (graphical) session unavailable.\033[0m"; exit 2 echo -e "\\033[31mAborted, X (graphical) session unavailable.\\033[0m"; exit 2
fi fi
if ! hash xdpyinfo 2>/dev/null; then # Assure display probe. if ! hash xdpyinfo 2>/dev/null; then # Assure display probe.
echo -e "\033[31mAborted, xdpyinfo is unavailable.\033[0m"; exit 3 echo -e "\\033[31mAborted, xdpyinfo is unavailable.\\033[0m"; exit 3
fi fi
if ! xdpyinfo &>/dev/null; then # Assure display info available. if ! xdpyinfo &>/dev/null; then # Assure display info available.
echo -e "\033[31mAborted, xterm test session failed.\033[0m"; exit 3 echo -e "\\033[31mAborted, xterm test session failed.\\033[0m"; exit 3
fi fi
# ================ < Parameter Parser Check > ================ # # ================ < Parameter Parser Check > ================ #
getopt --test > /dev/null # Assure enhanced getopt (returns 4). getopt --test > /dev/null # Assure enhanced getopt (returns 4).
if [ $? -ne 4 ]; then if [ $? -ne 4 ]; then
echo "\033[31mAborted, enhanced getopt isn't available.\033[0m"; exit 4 echo "\\033[31mAborted, enhanced getopt isn't available.\\033[0m"; exit 4
fi fi
# =============== < Working Directory Check > ================ # # =============== < Working Directory Check > ================ #
if ! mkdir -p "$FLUXIONWorkspacePath" &> /dev/null; then if ! mkdir -p "$FLUXIONWorkspacePath" &> /dev/null; then
echo "\033[31mAborted, can't generate a workspace directory.\033[0m"; exit 5 echo "\\033[31mAborted, can't generate a workspace directory.\\033[0m"; exit 5
fi fi
# Once sanity check is passed, we can start to load everything. # Once sanity check is passed, we can start to load everything.
@ -104,7 +104,7 @@ fi
eval set -- "$FLUXIONCLIArguments" # Set environment parameters. eval set -- "$FLUXIONCLIArguments" # Set environment parameters.
#[ "$1" != "--" ] && readonly FLUXIONAuto=1 # Auto-mode if using CLI. #[ "$1" != "--" ] && readonly FLUXIONAuto=1 # Auto-mode if using CLI.
while [ "$1" != "" -a "$1" != "--" ]; do while [ "$1" != "" ] && [ "$1" != "--" ]; do
case "$1" in case "$1" in
-v|--version) echo "FLUXION V$FLUXIONVersion.$FLUXIONRevision"; exit;; -v|--version) echo "FLUXION V$FLUXIONVersion.$FLUXIONRevision"; exit;;
-h|--help) fluxion_help; exit;; -h|--help) fluxion_help; exit;;
@ -165,7 +165,7 @@ fi
# FLUXIONDebug [Normal Mode "" / Developer Mode 1] # FLUXIONDebug [Normal Mode "" / Developer Mode 1]
if [ $FLUXIONDebug ]; then if [ $FLUXIONDebug ]; then
touch /tmp/fluxion_debug_log :> /tmp/fluxion_debug_log
readonly FLUXIONOutputDevice="/tmp/fluxion_debug_log" readonly FLUXIONOutputDevice="/tmp/fluxion_debug_log"
readonly FLUXIONHoldXterm="-hold" readonly FLUXIONHoldXterm="-hold"
else else
@ -233,7 +233,7 @@ fluxion_startup() {
"¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯ ¯¯¯ ¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯" "¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯ ¯¯¯ ¯¯¯¯ ¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯"
banner+=("$FormatCenterLiterals") banner+=("$FormatCenterLiterals")
clear printf "\\e[2J";
if [ "$FLUXIONAuto" ]; then echo -e "$CBlu"; else echo -e "$CRed"; fi if [ "$FLUXIONAuto" ]; then echo -e "$CBlu"; else echo -e "$CRed"; fi
@ -284,12 +284,12 @@ fluxion_startup() {
echo echo
echo -e "${CRed}Dependency installation failed!$CClr" echo -e "${CRed}Dependency installation failed!$CClr"
echo "Press enter to retry, ctrl+c to exit..." echo "Press enter to retry, ctrl+c to exit..."
read bullshit read -r bullshit
fi fi
done done
fi fi
echo -e "\n\n" # This echo is for spacing echo -e "\\n\\n" # This echo is for spacing
} }
fluxion_shutdown() { fluxion_shutdown() {
@ -315,7 +315,8 @@ fluxion_shutdown() {
local targetID # Program identifier/title local targetID # Program identifier/title
for targetID in "${targets[@]}"; do for targetID in "${targets[@]}"; do
# Get PIDs of all programs matching targetPID # Get PIDs of all programs matching targetPID
local targetPID=$( local targetPID
targetPID=$(
echo "${processes[@]}" | awk '$4~/'"$targetID"'/{print $1}' echo "${processes[@]}" | awk '$4~/'"$targetID"'/{print $1}'
) )
if [ ! "$targetPID" ]; then continue; fi if [ ! "$targetPID" ]; then continue; fi
@ -366,8 +367,8 @@ fluxion_shutdown() {
echo -e "$CWht[$CRed-$CWht] $FLUXIONRestartingNetworkManagerNotice$CClr" echo -e "$CWht[$CRed-$CWht] $FLUXIONRestartingNetworkManagerNotice$CClr"
# TODO: Add support for other network managers (wpa_supplicant?). # TODO: Add support for other network managers (wpa_supplicant?).
if [ $(which systemctl) ]; then if [ ! -x "$(command -v systemctl)" ]; then
if [ $(which service) ];then if [ -x "$(command -v service)" ];then
service network-manager restart &> $FLUXIONOutputDevice & service network-manager restart &> $FLUXIONOutputDevice &
service networkmanager restart &> $FLUXIONOutputDevice & service networkmanager restart &> $FLUXIONOutputDevice &
service networking restart &> $FLUXIONOutputDevice & service networking restart &> $FLUXIONOutputDevice &
@ -382,7 +383,7 @@ fluxion_shutdown() {
sleep 3 sleep 3
clear printf "\\e[2J";
exit 0 exit 0
} }
@ -394,7 +395,7 @@ fluxion_shutdown() {
# Delete log only in Normal Mode ! # Delete log only in Normal Mode !
fluxion_conditional_clear() { fluxion_conditional_clear() {
# Clear iff we're not in debug mode # Clear iff we're not in debug mode
if [ ! $FLUXIONDebug ]; then clear; fi if [ ! $FLUXIONDebug ]; then printf "\\e[2J"; fi
} }
fluxion_conditional_bail() { fluxion_conditional_bail() {
@ -405,7 +406,7 @@ fluxion_conditional_bail() {
return 1 return 1
fi fi
echo "Press any key to continue execution..." echo "Press any key to continue execution..."
read bullshit read -r bullshit
} }
# ERROR Report only in Developer Mode # ERROR Report only in Developer Mode
@ -484,9 +485,9 @@ trap fluxion_handle_target_change SIGALRM
fluxion_set_resolution() { # Windows + Resolution fluxion_set_resolution() { # Windows + Resolution
# Get dimensions # Get dimensions
SCREEN_SIZE=$(xdpyinfo | grep dimension | awk '{print $4}' | tr -d "(") shopt -s checkwinsize; (:;:)
SCREEN_SIZE_X=$(printf '%.*f\n' 0 $(echo $SCREEN_SIZE | sed -e s'/x/ /'g | awk '{print $1}')) SCREEN_SIZE_X="$LINES"
SCREEN_SIZE_Y=$(printf '%.*f\n' 0 $(echo $SCREEN_SIZE | sed -e s'/x/ /'g | awk '{print $2}')) SCREEN_SIZE_Y="$COLUMNS"
# Calculate proportional windows # Calculate proportional windows
if hash bc ;then if hash bc ;then
@ -540,7 +541,7 @@ declare -rA FLUXIONUndoable=( \
# Yes, I know, the identifiers are fucking ugly. If only we had # Yes, I know, the identifiers are fucking ugly. If only we had
# some type of mangling with bash identifiers, that'd be great. # some type of mangling with bash identifiers, that'd be great.
fluxion_do() { fluxion_do() {
if [ ${#@} -lt 2 ]; then return -1; fi if [ ${#@} -lt 2 ]; then return 1; fi
local -r __fluxion_do__namespace=$1 local -r __fluxion_do__namespace=$1
local -r __fluxion_do__identifier=$2 local -r __fluxion_do__identifier=$2
@ -553,7 +554,7 @@ fluxion_do() {
} }
fluxion_undo() { fluxion_undo() {
if [ ${#@} -ne 1 ]; then return -1; fi if [ ${#@} -ne 1 ]; then return 1; fi
local -r __fluxion_undo__namespace=$1 local -r __fluxion_undo__namespace=$1
@ -567,7 +568,7 @@ fluxion_undo() {
local __fluxion_undo__i local __fluxion_undo__i
for (( __fluxion_undo__i=${#__fluxion_undo__history[@]}; \ for (( __fluxion_undo__i=${#__fluxion_undo__history[@]}; \
__fluxion_undo__i > 0; __fluxion_undo__i-- )); do __fluxion_undo__i > 0; __fluxion_undo__i-- )); do
local __fluxion_undo__instruction=${__fluxion_undo__history[__fluxion_undo__i-1]} local __fluxion_undo__instruction=${__fluxion_undo__history[__fluxion_undo__i1]}
local __fluxion_undo__command=${__fluxion_undo__instruction%%_*} local __fluxion_undo__command=${__fluxion_undo__instruction%%_*}
local __fluxion_undo__identifier=${__fluxion_undo__instruction#*_} local __fluxion_undo__identifier=${__fluxion_undo__instruction#*_}
@ -582,21 +583,21 @@ fluxion_undo() {
fi fi
done done
return -2 # The undo-chain failed. return 2 # The undo-chain failed.
} }
fluxion_done() { fluxion_done() {
if [ ${#@} -ne 1 ]; then return -1; fi if [ ${#@} -ne 1 ]; then return 1; fi
local -r __fluxion_done__namespace=$1 local -r __fluxion_done__namespace=$1
eval "FluxionDone=\${FXDLog_$__fluxion_done__namespace[-1]}" eval "FluxionDone=\${FXDLog_${__fluxion_done__namespace[1]}}"
if [ ! "$FluxionDone" ]; then return 1; fi if [ ! "$FluxionDone" ]; then return 1; fi
} }
fluxion_done_reset() { fluxion_done_reset() {
if [ ${#@} -ne 1 ]; then return -1; fi if [ ${#@} -ne 1 ]; then return 1; fi
local -r __fluxion_done_reset__namespace=$1 local -r __fluxion_done_reset__namespace=$1
@ -604,7 +605,7 @@ fluxion_done_reset() {
} }
fluxion_do_sequence() { fluxion_do_sequence() {
if [ ${#@} -ne 2 ]; then return -1; fi if [ ${#@} -ne 2 ]; then return 1; fi
# TODO: Implement an alternative, better method of doing # TODO: Implement an alternative, better method of doing
# what this subroutine does, maybe using for-loop iteFLUXIONWindowRation. # what this subroutine does, maybe using for-loop iteFLUXIONWindowRation.
@ -692,7 +693,7 @@ fluxion_set_language() {
if [ ! "$FluxionLanguage" ]; then if [ ! "$FluxionLanguage" ]; then
# Get all languages available. # Get all languages available.
local languageCodes local languageCodes
readarray -t languageCodes < <(ls -1 language | sed -E 's/\.sh//') readarray -t languageCodes < <(ls 1 language | sed -E 's/\.sh//')
local languages local languages
readarray -t languages < <( readarray -t languages < <(
@ -767,7 +768,7 @@ fluxion_deallocate_interface() { # Release interfaces
fi fi
# Attempt to restore the original interface identifier. # Attempt to restore the original interface identifier.
if ! interface_reidentify $oldIdentifier $newIdentifier; then if ! interface_reidentify "$oldIdentifier" "$newIdentifier"; then
return 5 return 5
fi fi
fi fi
@ -952,7 +953,7 @@ fluxion_next_assignable_interface() {
# Parameters: <interfaces:lambda> [<query>] # Parameters: <interfaces:lambda> [<query>]
# Note: The interfaces lambda must print an interface per line. # Note: The interfaces lambda must print an interface per line.
# ------------------------------------------------------------ # # ------------------------------------------------------------ #
# Return -1: Go back # Return 1: Go back
# Return 1: Missing interfaces lambda identifier (not passed). # Return 1: Missing interfaces lambda identifier (not passed).
fluxion_get_interface() { fluxion_get_interface() {
if ! type -t "$1" &> /dev/null; then return 1; fi if ! type -t "$1" &> /dev/null; then return 1; fi
@ -1045,7 +1046,7 @@ fluxion_get_interface() {
FluxionInterfaceSelectedInfo="" FluxionInterfaceSelectedInfo=""
return 0;; return 0;;
"$FLUXIONGeneralRepeatOption") continue;; "$FLUXIONGeneralRepeatOption") continue;;
"$FLUXIONGeneralBackOption") return -1;; "$FLUXIONGeneralBackOption") return 1;;
*) *)
FluxionInterfaceSelected="${IOQueryFormatFields[1]}" FluxionInterfaceSelected="${IOQueryFormatFields[1]}"
FluxionInterfaceSelectedState="${IOQueryFormatFields[2]}" FluxionInterfaceSelectedState="${IOQueryFormatFields[2]}"
@ -1174,7 +1175,7 @@ fluxion_get_target() {
fluxion_target_get_candidates $interface $channels;; fluxion_target_get_candidates $interface $channels;;
"$FLUXIONGeneralBackOption") "$FLUXIONGeneralBackOption")
return -1;; return 1;;
esac esac
# Abort if errors occured while searching for candidates. # Abort if errors occured while searching for candidates.
@ -1191,7 +1192,7 @@ fluxion_get_target() {
# Gather information from all the candidates detected. # Gather information from all the candidates detected.
# TODO: Clean up this for loop using a cleaner algorithm. # TODO: Clean up this for loop using a cleaner algorithm.
# Maybe try using array appending & [-1] for last elements. # Maybe try using array appending & [1] for last elements.
for candidateAPInfo in "${FluxionTargetCandidates[@]}"; do for candidateAPInfo in "${FluxionTargetCandidates[@]}"; do
# Strip candidate info from any extraneous spaces after commas. # Strip candidate info from any extraneous spaces after commas.
candidateAPInfo=$(echo "$candidateAPInfo" | sed -r "s/,\s*/,/g") candidateAPInfo=$(echo "$candidateAPInfo" | sed -r "s/,\s*/,/g")
@ -1218,8 +1219,8 @@ fluxion_get_target() {
candidatesESSID[i]=$(eval "echo \$'$sanitizedESSID'") candidatesESSID[i]=$(eval "echo \$'$sanitizedESSID'")
local power=${candidatesPower[i]} local power=${candidatesPower[i]}
if [ $power -eq -1 ]; then if [ $power -eq 1 ]; then
# airodump-ng's man page says -1 means unsupported value. # airodump-ng's man page says 1 means unsupported value.
candidatesQuality[i]="??" candidatesQuality[i]="??"
elif [ $power -le $FLUXIONNoiseFloor ]; then elif [ $power -le $FLUXIONNoiseFloor ]; then
candidatesQuality[i]=0 candidatesQuality[i]=0
@ -1550,7 +1551,7 @@ fluxion_hash_verify() {
local -r verifier="cowpatty" ;; local -r verifier="cowpatty" ;;
"$FLUXIONGeneralBackOption") "$FLUXIONGeneralBackOption")
return -1 ;; return 1 ;;
esac esac
fi fi
@ -1624,7 +1625,7 @@ fluxion_hash_set_path() {
return $? ;; return $? ;;
"$FLUXIONGeneralBackOption") "$FLUXIONGeneralBackOption")
return -1 ;; return 1 ;;
esac esac
fi fi
fi fi
@ -1641,7 +1642,7 @@ fluxion_hash_set_path() {
# Back-track when the user leaves the hash path blank. # Back-track when the user leaves the hash path blank.
# Notice: Path is cleared if we return, no need to unset. # Notice: Path is cleared if we return, no need to unset.
if [ ! "$FluxionHashPath" ]; then return -1; fi if [ ! "$FluxionHashPath" ]; then return 1; fi
# Make sure the path points to a valid generic file. # Make sure the path points to a valid generic file.
if [ ! -f "$FluxionHashPath" -o ! -s "$FluxionHashPath" ]; then if [ ! -f "$FluxionHashPath" -o ! -s "$FluxionHashPath" ]; then
@ -1660,7 +1661,7 @@ fluxion_hash_get_path() {
while true; do while true; do
fluxion_hash_unset_path fluxion_hash_unset_path
if ! fluxion_hash_set_path "$@"; then if ! fluxion_hash_set_path "$@"; then
return -1 # WARNING: The recent error code is NOT contained in $? here! return 1 # WARNING: The recent error code is NOT contained in $? here!
fi fi
if fluxion_hash_verify "$FluxionHashPath" "$2" "$3"; then if fluxion_hash_verify "$FluxionHashPath" "$2" "$3"; then
@ -1692,7 +1693,7 @@ fluxion_set_attack() {
fluxion_target_show fluxion_target_show
local attacks local attacks
readarray -t attacks < <(ls -1 "$FLUXIONPath/attacks") readarray -t attacks < <(ls 1 "$FLUXIONPath/attacks")
local descriptions local descriptions
readarray -t descriptions < <( readarray -t descriptions < <(
@ -1726,7 +1727,7 @@ fluxion_set_attack() {
echo echo
if [ "${IOQueryFormatFields[1]}" = "$FLUXIONGeneralBackOption" ]; then if [ "${IOQueryFormatFields[1]}" = "$FLUXIONGeneralBackOption" ]; then
return -1 return 1
fi fi
if [ "${IOQueryFormatFields[1]}" = "$FLUXIONAttackRestartOption" ]; then if [ "${IOQueryFormatFields[1]}" = "$FLUXIONAttackRestartOption" ]; then
@ -1843,7 +1844,6 @@ fluxion_run_attack() {
fluxion_unset_attack fluxion_unset_attack
} }
# ============================================================ # # ============================================================ #
# ================= < Argument Executables > ================= # # ================= < Argument Executables > ================= #
# ============================================================ # # ============================================================ #
@ -1855,7 +1855,6 @@ while [ "$1" != "" -a "$1" != "--" ]; do
shift # Shift new parameters shift # Shift new parameters
done done
# ============================================================ # # ============================================================ #
# ===================== < FLUXION Loop > ===================== # # ===================== < FLUXION Loop > ===================== #
# ============================================================ # # ============================================================ #

28
misc/check_device.sh Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
fluxion_check_ap() {
readonly SUPPORT_AP=$(sed -n -e "$(echo $(($1+4)))p" devices.xml | cut -d ">" -f2 | cut -d "<" -f1)
if [ "$SUPPORT_AP" == "n" ];then
echo "false"
fi
}
fluxion_check_mo() {
readonly SUPPORT_MO=$(sed -n -e "$(echo $(($1+6)))p" devices.xml | cut -d ">" -f2 | cut -d "<" -f1)
if [ "$SUPPORT_MO" == "n" ];then
echo "false"
fi
}
# first identifier
fluxion_check_chipset() {
declare -r LINE=$(grep "$1" devices.xml -n | head -n 1 | cut -d ":" -f1)
if [ "$(fluxion_check_ap "$LINE")" == "false" ] || [ "$(fluxion_check_mo "$LINE")" == "false" ];then
echo "false"
else
echo "true"
fi
}
fluxion_check_chipset "$1"