-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathhashcat_dictionary_attack.sh
More file actions
executable file
·88 lines (77 loc) · 2.2 KB
/
hashcat_dictionary_attack.sh
File metadata and controls
executable file
·88 lines (77 loc) · 2.2 KB
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
#!/bin/bash
set -o errexit -o nounset -o pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
DEFAULT_WORDLISTS=("$DIR/wordlists/passwords/rockyou.txt.gz")
#HASHCAT="$DIR/hashcat-5.1.0/hashcat"
HASHCAT="hashcat"
usage() {
echo "================================================================================"
echo "usage: $(basename "$0") <hash_file> <hash_type> [dictionary1 [dictionary2]]"
echo
echo "Perform a dictionary attack against a list of hashes using the hashcat tool."
echo
echo "Required arguments:"
echo "hash_file - a file containing a list of hashes"
echo "hash_type - the hash type, see 'hashcat -h' for a list of possible values"
echo
echo "Optional arguments:"
echo "dictionary - use a supplied dictionary (or multiple), otherwise defaults to"
echo
printf ' %s\n' "${DEFAULT_WORDLISTS[@]}"
echo
echo "================================================================================"
}
args() {
if [ $# -lt 1 ]; then
usage
exit 1
fi
case $1 in
"" | "-h" | "--help")
usage
exit 0
esac
HASH_FILE=${1}
CRED_FILE="$HASH_FILE.cracked"
if [[ ! -f "$HASH_FILE" ]]; then
echo "$HASH_FILE not found!"
exit 1
fi
HASH_TYPE=${2:-}
if [[ ! -n $HASH_TYPE ]]; then
usage
exit 1
else
if ! [[ "$HASH_TYPE" =~ ^[0-9]+$ ]]; then
echo "The hash type needs to be an integer value!"
exit 1
fi
fi
shift 2
WORDLISTS=("$@")
if [[ ${#WORDLISTS[@]} -eq 0 ]]; then
WORDLISTS=("${DEFAULT_WORDLISTS[@]}")
fi
for WORDLIST in "${WORDLISTS[@]}"; do
if [[ ! -f "$WORDLIST" ]]; then
echo "$WORDLIST not found!"
exit 1
fi
done
if [ -z ${HASHCAT_DEVICE_ID+x} ]; then
HASHCAT_DEVICE_ID=3
fi
}
# main
args "$@"
for WORDLIST in "${WORDLISTS[@]}"; do
echo "$ hashcat -d $HASHCAT_DEVICE_ID -O -a 0 -m $HASH_TYPE --outfile $CRED_FILE $HASH_FILE $WORDLIST"
set +e
#$HASHCAT --potfile-disable -d "$HASHCAT_DEVICE_ID" -O -a 0 -m "$HASH_TYPE" --outfile "$CRED_FILE" "$HASH_FILE" "$WORDLIST"
$HASHCAT -d "$HASHCAT_DEVICE_ID" -O -a 0 -m "$HASH_TYPE" --outfile "$CRED_FILE" "$HASH_FILE" "$WORDLIST"
set -e
echo
if [[ $? -lt 0 ]] || [[ $? -gt 1 ]]; then
exit $?
fi
done