-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawsl.sh
executable file
·163 lines (137 loc) · 4.47 KB
/
awsl.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
## Global variables
RED='\e[41m'
GREEN='\e[32m'
YELLOW='\e[33m'
BOLD='\e[1m'
NC='\e[0m' # No Color
PublicDnsName=""
PathOnAWS="/home/ec2-user/awsl"
## SET INSTACE OPTIONS HERE
INSTACE_ID=""
REGION=""
USERNAME="ec2-user"
function logo (){
local version="0.1.2"
echo -e "\e[21m \e[0m
db \`7MMF' A \`7MF' .M\"\"\"bgd \`7MMF'
;MM: \`MA ,MA ,V ,MI \"Y MM
,V^MM. VM: ,VVM: ,V \`MMb. MM
,M \`MM MM. M' MM. M' \`YMMNq. MM
AbmmmqMA \`MM A' \`MM A' . \`MM MM ,
A' VML :MM; :MM; Mb dM MM ,M
.AMA. .AMMA. VF VF P\"Ybmmd\" .JMMmmmmMMM ${BOLD}v$version\e[21m
\e[0m"
}
function help(){
echo "AWSL can be used to automate the following steps:"
echo " - starting the AWS EC2 instance"
echo " - copying sync_me folder (hashcat commands, custom masks/rules/wordlists, hashes)"
echo " - starting the cracking process on the AWS EC2 instance"
echo " - transfering the results to your shared OwnCloud folder"
echo " - stopping the AWS EC2 instance"
echo -e "\n\n${BOLD}Usage: awsl.sh [<PATH_ON_AWS>]\n${NC}"
echo -e "Optional parameters:"
echo -e "\t<PATH_ON_AWS>:\tThis is the path where the files will be stored."
echo -e "\t\t\tdefault: /home/ec2-user/awsl"
echo ""
exit 1
}
function installer() {
echo -e "${GREEN}Installing missing dependencies${NC}"
apt-get update
apt-get -y install jq python3-pip rsync
bash -c "python3 -m pip install awscli"
echo -e -n "\n${GREEN}Configuring AWS:${NC}\n"
bash -c "aws configure"
exit 1
}
function checks(){
## checking dependecies
if [[ $(aws --version 2>&1) == *"aws: command not found"* || $(jq -V 2>&1) == *"command not found"* ]]; then
installer
fi
## check if SSH key is there
if [ ! -f ./ssh_key.pem ]; then
echo -e "${RED}Error: ssh_key.pem not found!${NC}"
return 1
else
chmod 400 ./ssh_key.pem
fi
## check if istance options are set
if [[ $INSTACE_ID = "" || $REGION = "" ]]; then
echo -e "${RED}Error: You must set the INSTACE_ID and REGION parameters in this file${NC}"
return 1
fi
## set correct path if set
if [[ ! -z $@ ]]; then
PathOnAWS=$1
fi
}
# check if instance has started
function check_running() {
while true; do
local state=$(aws ec2 describe-instances --instance-id $INSTACE_ID --region $REGION | jq -r '.Reservations[] | {"name": .Instances[].PublicDnsName, "State": .Instances[].State.Name,}' | jq -r .[])
if [[ $state == *"running"* ]]; then
PublicDnsName=$(echo $state | cut -d ' ' -f 1)
echo -e "[+] Initializing ${GREEN}$PublicDnsName${NC}"
break
elif [[ $state = *"pending"* ]]; then
sleep 10
else
echo -e "${RED}Error: Instance has unknown state \"$(echo $state | cut -d ' ' -f 2)\"!${NC}"
exit -1
fi
done
}
# check instance status
function check_state() {
while true; do
local state=$(aws ec2 describe-instance-status --instance-id $INSTACE_ID --region $REGION | jq -r '.[] | {"State":.[].InstanceStatus.Status} .State')
if [[ $state = "ok" ]]; then
echo -e "${GREEN} | Done!${NC}"
break
elif [[ $state = "initializing" ]]; then
echo -e "${YELLOW} | still $state...${NC}"
sleep 25
else
echo -e "${RED}Error: Instance has unknown state \"$state\"!${NC}"
exit -1
fi
done
}
# start ec2 instance
function start_instance() {
echo "Waiting for instance to start (may need some minutes)"
# Exit if awscli is not configured, otherwise start instance
set -e
bash -c "aws ec2 start-instances --instance-id $INSTACE_ID --region $REGION > /dev/null"
sleep 15
# check if instance is up an running
check_running
sleep 25
check_state
}
# sending files to AWS instance
function send_files(){
echo -e "\n[+] Sending files to instance."
rsync -e 'ssh -i ./ssh_key.pem -oStrictHostKeyChecking=no' -a ./sync_me/ $USERNAME@$PublicDnsName:$PathOnAWS
}
# open ssh connection to instance
function hashcat(){
echo -e "\n${GREEN}[+] \e[5mRunning hashcat commands.\e[25m${NC}"
echo -e "\nResults will be uploaded to your OwnCloud share."
ssh -oStrictHostKeyChecking=no -i ./ssh_key.pem $USERNAME@$PublicDnsName 'cd $PathOnAWS && screen -L -d -m ./commands.sh'
}
# Main
#--------------------
logo
## show help
if [[ "$1" = "-h" || "$1" = "--help" ]]; then
help
fi
if checks; then
start_instance
send_files
hashcat
fi