#!/bin/sh
# 
# Shell Script for joining JOHN THE RIPPER and WEPDECRYPT
# by Dominik Blunk and Alain Girardet and Fernando Tarin
# 15-10-2002
#
# Wordlist mode with rules
#
# usage: ./wepdecrypt_word DUMPFILE
#

# edit /etc/wepdecrypt.conf for configuration
. /etc/wepdecrypt.conf

#
# command to join JOHN THE RIPPER and WEPDECRYPT
#

if which john &> /dev/null; then
        JOHNDIR=`which john | awk -F / '{for (i=1; i<=NF-1; i++){ printf "%s/", $i };}'`
fi

if [ $# -lt 1 -o $# -gt 3 ]; then
        echo "Usage: $0 Dumpfile [mac_address] [number_networks]";
        exit 1;
fi

if ! [ -f $1 ]; then
        echo "Error: Dumpfile '$1' does not exist.";
        exit 1;
fi

if [ $# -eq 1 ]; then
	if test -f $JOHNDIR/john; then
		$JOHNDIR/john -wordfile:$WORDLIST -rules -stdout:13\
	 	| wepdecrypt -f $1
		exit 0;
	else
		echo "John the ripper not found! Edit '/etc/wepdecrypt.conf' ";
		echo "to set correct path.."
		exit 1;
	fi
fi

if [ $# -eq 2 ]; then
        if test -f $JOHNDIR/john; then
                $JOHNDIR/john -wordfile:$WORDLIST -rules -stdout:13\
                | wepdecrypt -f $1 -b $2
                exit 0;
        else
                echo "John the ripper not found! Edit '/etc/wepdecrypt.conf' ";
                echo "to set correct path.."
                exit 1;
        fi
fi

if [ $# -eq 3 ]; then
        if test -f $JOHNDIR/john; then
                $JOHNDIR/john -wordfile:$WORDLIST -rules -stdout:13\
                | wepdecrypt -f $1 -b $2 -n $3
                exit 0;
        else
                echo "John the ripper not found! Edit '/etc/wepdecrypt.conf' ";
                echo "to set correct path.."
                exit 1;
        fi
fi
