From 7ab63da7379af3d6d6487410cbcf29e99daaff93 Mon Sep 17 00:00:00 2001 From: Matias Barcenas Date: Tue, 5 Dec 2017 16:44:54 -0600 Subject: [PATCH] Fixed (bug) and improved AP services. Fixed a bug where once an AP was selected, it could not be changed. The AP service will now explicitly wait for xterm's child (AP service PID). Removed killing every process using the same service in the system. --- lib/ap/airbase-ng.sh | 31 ++++++++++++++++----------- lib/ap/hostapd.sh | 51 ++++++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/lib/ap/airbase-ng.sh b/lib/ap/airbase-ng.sh index bdcc193..6da4094 100755 --- a/lib/ap/airbase-ng.sh +++ b/lib/ap/airbase-ng.sh @@ -1,27 +1,29 @@ #!/bin/bash -if [ "$APServiceVersion" ]; then return 0; fi -readonly APServiceVersion="1.0" - +# ================================================================ +# Configuration Section +# ================================================================ VIGW="at0" VIAP=$WIAccessPoint -#APServiceAuthenticationMethods=("hash" "wpa_supplicant") -#APServiceAuthenticationMethodsInfo=("(handshake, recommended)" "(connection, slow)") - # airbase-ng uses a monitor-mode virtual interface # and creates a separate interface, atX, for dhcpd. VIAPAddress="$VIGWNetwork.2" # APServiceConfigDirectory=$FLUXIONWorkspacePath +# ================================================================ + + +#if [ "$APServiceVersion" ]; then return 0; fi +#readonly APServiceVersion="1.0" + function ap_stop() { - killall airbase-ng &> $FLUXIONOutputDevice - - local FLUXIONAPService=$(ps a | grep -e "FLUXION AP Service" | awk '{print $1'}) - if [ "$FLUXIONAPService" ]; then - kill $FLUXIONAPService &> $FLUXIONOutputDevice + if [ "$APServicePID" ] + then kill $APServicePID &> $FLUXIONOutputDevice fi + + APServicePID="" } function ap_reset() { @@ -41,11 +43,14 @@ function ap_prep() { } function ap_start() { + ap_stop + xterm $BOTTOMRIGHT -bg "#000000" -fg "#FFFFFF" -title "FLUXION AP Service [airbase-ng]" -e airbase-ng -P -e $APTargetSSID -c $APTargetChannel -a $APRogueMAC $VIAP & + local parentPID=$! # Wait till airebase-ng has started and created the extra virtual interface. - while [ ! $(ps a | awk '$5~/^airbase-ng/ && $0~/'"$APRogueMAC"'/{print $1}') ] - do sleep 1 + while [ ! "$APServicePID" ] + do sleep 1; APServicePID=$(pgrep -P $parentPID) done ap_route diff --git a/lib/ap/hostapd.sh b/lib/ap/hostapd.sh index 96c30bc..615f1e7 100755 --- a/lib/ap/hostapd.sh +++ b/lib/ap/hostapd.sh @@ -1,27 +1,29 @@ #!/bin/bash -if [ "$APServiceVersion" ]; then return 0; fi -readonly APServiceVersion="1.0" - +# ================================================================ +# Configuration Section +# ================================================================ VIGW=$WIAccessPoint VIAP=$WIAccessPoint -#APServiceAuthenticationMethods=("hash") -#APServiceAuthenticationMethodsInfo=("(handshake, recommended)") - # HostAPD sets the virtual interface mode # to master, which is supported by dhcpd. VIAPAddress=$VIGWAddress APServiceConfigDirectory=$FLUXIONWorkspacePath +# ================================================================ + + +#if [ "$APServiceVersion" ]; then return 0; fi +#readonly APServiceVersion="1.0" + function ap_stop() { - killall hostapd &> $FLUXIONOutputDevice - - local FLUXIONAPService=$(ps a | grep -e "FLUXION AP Service" | awk '{print $1'}) - if [ "$FLUXIONAPService" ]; then - kill $FLUXIONAPService &> $FLUXIONOutputDevice + if [ "$APServicePID" ] + then kill $APServicePID &> $FLUXIONOutputDevice fi + + APServicePID="" } function ap_reset() { @@ -29,17 +31,17 @@ function ap_reset() { # Reset MAC address to original. ifconfig $VIAP down - sleep 0.4 - + sleep 0.5 + macchanger -p $VIAP &> $FLUXIONOutputDevice - sleep 0.4 + sleep 0.5 ifconfig $VIAP up - sleep 0.4 + sleep 0.5 } function ap_route() { - echo "No custom routes for hostapd" > $FLUXIONOutputDevice + echo "APService: No custom routes for hostapd" > $FLUXIONOutputDevice } function ap_prep() { @@ -55,21 +57,24 @@ channel=$APTargetChannel\ # Spoof virtual interface MAC address. ifconfig $VIAP down - sleep 0.4 - + sleep 0.5 + macchanger --mac=$APRogueMAC $VIAP &> $FLUXIONOutputDevice - sleep 0.4 + sleep 0.5 ifconfig $VIAP up - sleep 0.4 + sleep 0.5 } function ap_start() { - xterm $HOLD $BOTTOMRIGHT -bg "#000000" -fg "#FFFFFF" -title "FLUXION AP Service [hostapd]" -e hostapd "$APServiceConfigDirectory/$APRogueMAC-hostapd.conf" & + ap_stop + + xterm $FLUXIONHoldXterm $BOTTOMRIGHT -bg "#000000" -fg "#FFFFFF" -title "FLUXION AP Service [hostapd]" -e hostapd "$APServiceConfigDirectory/$APRogueMAC-hostapd.conf" & + local parentPID=$! # Wait till hostapd has started and its virtual interface is ready. - while [ ! $(ps a | awk '$5~/^hostapd/ && $0~/'"$APRogueMAC-hostapd.conf"'/{print $1}') ] - do sleep 1 + while [ ! "$APServicePID" ] + do sleep 1; APServicePID=$(pgrep -P $parentPID) done ap_route