diff options
author | makefu <github@syntax-fehler.de> | 2014-12-20 21:57:08 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2014-12-20 21:57:08 +0100 |
commit | 6a9beb12dad44b5e1efa984b112c7a6b8c13a118 (patch) | |
tree | 13384e4195cfcb4be3beebde33d402f1bbd4d1e4 | |
parent | 0077e1839cda806e2285bea1ca223dbaf670e4ef (diff) |
inspector_wifi: initial vomit
-rwxr-xr-x | usr/bin/autowifi_dryrun | 105 | ||||
-rwxr-xr-x | usr/bin/inspector_wifi | 75 |
2 files changed, 75 insertions, 105 deletions
diff --git a/usr/bin/autowifi_dryrun b/usr/bin/autowifi_dryrun deleted file mode 100755 index ee22473e..00000000 --- a/usr/bin/autowifi_dryrun +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/sh -cd $(dirname $(readlink -f $0)) - - -interface=${interface:-wlan0} -root=${root:-../../} -crackdir=$root/usr/lib/autowifi/plugins -wifi_keys=$root/etc/autowifi/wifi_keys -wifi_log=$root/var/log/autowifi.log -painmode=${painmode:-} - -# exists() run_hooks() -. $root/usr/lib/autowifi/lib/core - - -. $root/usr/lib/autowifi/lib/network - -# start_wpa_supplicant() -. $root/usr/lib/autowifi/lib/wpa_supplicant - - -find_count_of_ssid(){ - c=0 - for i in `seq 1 $WIFI_COUNT`; do - eval SSID=\${ESSID_${i}} - if [ "$SSID" = "$1" ]; then - c+=1 - echo "$i" - fi - done - if [ $c -eq 0 ];then - exit 1 - fi - exit 0 -} - - -connect_to_network_by_ssid(){ - find_count_of_ssid "$1" | (while read i - do - loop_over_cracks "$i" && exit 0 - done;exit 1) - if [ $? -eq 0 ]; then - exit 0 - fi - echo "no network found :(" - exit 1 -} - -connect_with_pw(){ - find_count_of_ssid "$1" | (while read i - do - KEY="$2" - eval connect \"\${MAC_${i}}\" \"\${ESSID_${i}}\" \${ENCRYPTION_${i}} \"\${KEY}\" - if [ $? -eq 0 ]; then - exit 0 - fi - done;exit 1) -} -wifi_init(){ - exists fortune && fortune -a - wpa_supplicant_is_usable || start_wpa_supplicant /tmp/autowifi.wpa_supplicant - wifi_scan > /tmp/${interface}.scan - . /tmp/${interface}.scan -} -loop_over_networks(){ - - for i in `seq 1 $WIFI_COUNT`; do - loop_over_cracks "$i" - if [ $? -eq 0 ]; then - return 0 - fi - done -} - -loop_over_cracks(){ - i=$1 - KEY='' - for crack in $(find $crackdir -type f | sort -u); do - KEY="$(eval root=$root painmode=$painmode \$crack \"\${ESSID_${i}}\" \"\${MAC_${i}}\" \${FREQ_${i}} \${ENCRYPTION_${i}})" - if [ $? -eq 0 ]; then - eval echo \"\${MAC_${i}}\" \"\${ESSID_${i}}\" \${ENCRYPTION_${i}} \"\${KEY}\" - fi - done - return 1 -} -loop_cracks_over_networks(){ - for crack in $(find $crackdir -type f | sort -u); do - for i in `seq 1 $WIFI_COUNT`; do - KEY="$(eval root=$root \$crack \"\${ESSID_${i}}\" \"\${MAC_${i}}\" \${FREQ_${i}} \${ENCRYPTION_${i}})" - if [ $? -eq 0 ]; then - eval echo \"\${MAC_${i}}\" \"\${ESSID_${i}}\" \${ENCRYPTION_${i}} \"\${KEY}\" - fi - done - done - -} - -wifi_init -if [ -n "$1" ]; then - echo cracking $1 - connect_to_network_by_ssid "$1" -else - loop_cracks_over_networks -fi diff --git a/usr/bin/inspector_wifi b/usr/bin/inspector_wifi new file mode 100755 index 00000000..17818b44 --- /dev/null +++ b/usr/bin/inspector_wifi @@ -0,0 +1,75 @@ +#!/bin/sh +# Usage; sudo iwlist wlan0 scan | ./inspector_wifi +# +# +set -eu + +cd "$(dirname "$(readlink -f "$0")")" +echo "waiting for iwlist scan data..." >&2 + +crack_wifi(){ + for i in ../lib/autowifi/plugins/*;do + if RET=$(./$i "$@" 2>/dev/null);then + echo "$@ - with crack $i succeeded - Key is $RET" + fi + done +} + +shell_escape(){ + sed 's/./\\&/g' +} +remove_quotes(){ + sed 's/^"\|"$//g' +} + + +iwlist_scan_parser(){ + count=0 + while read line; + do + case "$line" in + + *"Cell "*) + if [ $count -ne 0 ];then + crack_wifi "$ESSID" $MAC $CHANNEL any_encryption + fi + 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=$(echo "${line#*ESSID:}" | remove_quotes) + ;; + *"IE: IEEE 802.11i/WPA2"*) + WPA2=1 + ;; + *"IE: WPA Version 1"*) + WPA=1 + ;; + *);; #important, do not delete! + esac + done; + crack_wifi "$ESSID" $MAC $CHANNEL any_encryption + echo WIFI_COUNT=$count +} + +wifi_init(){ + iwlist_scan_parser +} + +loop_networks(){ + for i in `seq 1 $WIFI_COUNT`; do + loop_over_cracks "$i" + done +} +wifi_init |