-
Notifications
You must be signed in to change notification settings - Fork 2
/
aws-accesskey-privesc.sh
75 lines (62 loc) · 2.29 KB
/
aws-accesskey-privesc.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
#!/bin/bash
# ANSI color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
RESET='\033[0m'
use_aws_credentials() {
aws configure
echo -e "\n${GREEN}AWS credentials have been set.${RESET}\n"
}
list_roles_for_ec2() {
roles_output=$(aws iam list-roles 2>&1)
if [[ $roles_output == *"An error occurred"* ]]; then
echo -e "\n${RED}Not authorized or an error occurred${RESET}\n"
elif [ -z "$roles_output" ]; then
echo -e "\n${YELLOW}No roles found${RESET}\n"
else
roles_ec2=$(echo "$roles_output" | jq -r '.Roles[] | select(.AssumeRolePolicyDocument.Statement[].Principal.Service == "ec2.amazonaws.com") | .RoleName')
if [ -z "$roles_ec2" ]; then
echo -e "\n${YELLOW}No roles found for EC2 instances${RESET}\n"
else
echo -e "\n${BLUE}Roles associated with EC2 instances:${RESET}\n$roles_ec2"
fi
fi
}
list_attached_policies() {
read -p "Insert role name: " selected_role
attached_policies=$(aws iam list-attached-role-policies --role-name "$selected_role")
if [[ -n "$attached_policies" ]]; then
echo -e "\n${BLUE}Attached policies for role '$selected_role':${RESET}\n$attached_policies\n"
else
echo -e "\n${YELLOW}No attached policies found for role '$selected_role'${RESET}\n"
fi
}
check_ec2_permission() {
ec2yes=$(aws ec2 describe-instances 2>/dev/null)
if [[ $ec2yes == *"Reservations"* ]]; then
echo -e "\n${GREEN}Access to create Instances available${RESET}\n"
else
echo -e "\n${RED}Access to create Instances not available${RESET}\n"
fi
}
main_menu() {
echo -e "\n=== ${YELLOW}AWS CREDENTIALS - Privilege Escalation Checker${RESET} ==="
echo -e "1. ${GREEN}Set AWS Credentials${RESET}"
echo -e "2. ${GREEN}Check EC2 Permission${RESET}"
echo -e "3. ${GREEN}Check List Roles for EC2 Instances${RESET}"
echo -e "4. ${GREEN}Check List Attached Policies in Roles${RESET}"
echo -e "5. ${RED}Exit${RESET}"
read -rp "Enter your choice: " choice
case $choice in
1) use_aws_credentials ;;
2) check_ec2_permission ;;
3) list_roles_for_ec2 ;;
4) list_attached_policies ;;
5) exit ;;
*) echo -e "${RED}Invalid choice${RESET}";;
esac
main_menu
}
main_menu