summaryrefslogtreecommitdiffstats
path: root/recon/inspector_wifi/inspector_wifi
blob: a13ecd3dce96fedadc762bd6484e7c3925c8d8f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
# Usage; sudo iwlist wlan0 scan | ./inspector_wifi
#
#
# set -eu

cd "$(dirname "$(readlink -f "$0")")"

usage(){
  echo '-h show this help'
  echo '-w output in wpa_supplicant.conf format'
  echo '-n normal output message'
  echo ''
  echo 'Example: iwlist wlan0 scan | ./inspector_wifi -w'

  exit 0
}

crack_wifi(){
  for i in plugins/*;do
    if RET=$(./$i "$@" 2>/dev/null);then
      if [ ! -z wpa_sup ]; then
        make_config $@ $RET
      else
        echo "$@ - with crack $i succeeded - Key is $RET"
      fi
    fi
  done
}

make_config(){
  cat<<EOF
network={
  ssid="$1"
  psk="$5"
}
EOF

}

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
}


loop_networks(){
    for i in `seq 1 $WIFI_COUNT`; do
        loop_over_cracks "$i"
    done
}

wifi_init(){
  iwlist_scan_parser
}

print_wpa_supplicant(){
  echo "args $@"
}


if [ $# -eq 0 ]; then
  usage
fi

while getopts wn OPT; do
  case "$OPT" in
    w)
      wpa_sup=1
      ;;
    n)
      ;;
    \?)
      usage
      ;;
  esac
done

iwlist_scan_parser