-
Notifications
You must be signed in to change notification settings - Fork 15
/
run.sh
63 lines (43 loc) · 2.24 KB
/
run.sh
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
#!/bin/bash
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
REGION=$(echo $AZ | sed -e 's:\([0-9][0-9]*\)[a-z]*:\1:')
echo "Instance: $INSTANCE_ID - AZ: $AZ - REGION: $REGION"
S3BUCKET=cudahashcat
S3FOLDER=incoming
S3OBJECT=output.$( date +"%Y%m%d-%H%M" ).$INSTANCE_ID.txt
OUTFILE=output.txt
tmpdir=$(mktemp -d)
cd $tmpdir
cudahome=/root/cudaHashcat-1.33
chmod a+x $cudahome/*.bin
# Install awscli
( apt-get update -qq; apt-get install -qq -y awscli )
# This retrieves the rockyou password file, you might not want this if you're bruteforcing
aws s3 cp --region $REGION s3://$S3BUCKET/assets/rockyou.txt rockyou.txt
# Figured out a way to get the HASH and HASHTYPE parameters from Tags,
# but it takes a little more effort because we get it form the spot instance request
# The upside is if/when we get to parallelizing, all instances will get the same hash
SIRID=$(aws ec2 describe-instances --region $REGION --instance-id $INSTANCE_ID | grep SpotInstanceRequestId | tr -d '", ' | cut -f2 -d:)
HASHTYPE=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$SIRID" "Name=key,Values=HashType" --region $REGION --output=text | cut -f5)
HASH=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$SIRID" "Name=key,Values=Hash" --region $REGION --output=text | cut -f5)
HASHCAT_ARGS=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$SIRID" "Name=key,Values=HashcatArgs" --region $REGION --output=text | cut -f5)
if [ "$HASHCAT_ARGS" == "" ]; then
HASHCAT_ARGS="-a0"
fi
HASHCAT_ARGS="$HASHCAT_ARGS -m $HASHTYPE --status --status-timer=60 --outfile=$tmpdir/$OUTFILE --outfile-format=7"
HASHCAT_DICT=$(aws ec2 describe-tags --filters "Name=resource-id,Values=$SIRID" "Name=key,Values=HashcatDict" --region $REGION --output=text | cut -f5)
if [ "$HASHCAT_DICT" == "" ]; then
HASHCAT_DICT="rockyou.txt"
fi
echo $HASH > $tmpdir/passwd.txt
cat <<EOH > $tmpdir/screenrc
sessionname hashcat
screen -t shutdown 2
stuff "shutdown -h +55"
screen -t crack 0
stuff "$cudahome/cudaHashcat64.bin $HASHCAT_ARGS $tmpdir/passwd.txt $HASHCAT_DICT ; aws s3 cp --region $REGION $OUTFILE s3://$S3BUCKET/$S3FOLDER/$S3OBJECT "
EOH
screen -d -m -c $tmpdir/screenrc