-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathhashcat_mask_attack.sh
More file actions
executable file
·87 lines (76 loc) · 1.99 KB
/
hashcat_mask_attack.sh
File metadata and controls
executable file
·87 lines (76 loc) · 1.99 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
#!/bin/bash
set -o errexit -o nounset -o pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
DEFAULT_MASKS=("$DIR/masks/increment6chars.hcmask")
#HASHCAT="$DIR/hashcat-5.1.0/hashcat"
HASHCAT="hashcat"
usage() {
echo "================================================================================"
echo "usage: $(basename "$0") <hash_file> <hash_type> [mask1 [mask2]]"
echo
echo "Perform a mask 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 "mask - use a supplied dictionary (or multiple), otherwise defaults to"
echo
printf ' %s\n' "${DEFAULT_MASKS[@]}"
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
MASKS=("$@")
if [[ ${#MASKS[@]} -eq 0 ]]; then
MASKS=("${DEFAULT_MASKS[@]}")
fi
for MASK in "${MASKS[@]}"; do
if [[ ! -f "$MASK" ]]; then
echo "$MASK not found!"
exit 1
fi
done
if [ -z ${HASHCAT_DEVICE_ID+x} ]; then
HASHCAT_DEVICE_ID=3
fi
}
# main
args "$@"
for MASK in "${MASKS[@]}"; do
echo "$ hashcat -d $HASHCAT_DEVICE_ID -O -a 3 -m $HASH_TYPE --outfile $CRED_FILE $HASH_FILE $MASK"
set +e
$HASHCAT -d "$HASHCAT_DEVICE_ID" -O -a 3 -m "$HASH_TYPE" --outfile "$CRED_FILE" "$HASH_FILE" "$MASK"
set -e
echo
if [[ $? -lt 0 ]] || [[ $? -gt 1 ]]; then
exit $?
fi
done